Commit cb150c5a authored by Simon Conseil's avatar Simon Conseil

Add code to create masks from a segmap (from musex)

parent adcb9dcd
This diff is collapsed.
......@@ -36,3 +36,4 @@ from .source import *
from .linelist import *
from .muselet import muselet
from .sea import *
from .segmap import *
This diff is collapsed.
import numpy as np
from astropy.io import fits
from glob import glob
from mpdaf.obj import Image
from mpdaf.sdetect import Segmap, create_masks_from_segmap
from mpdaf.tests.utils import get_data_file
from numpy.testing import assert_array_equal
def test_segmap():
segfile = get_data_file('segmap', 'segmap.fits')
img = Image(segfile)
refdata = np.arange(14)
for arg in (segfile, img, img.data):
segmap = Segmap(arg)
assert segmap.img.shape == (90, 90)
assert str(segmap.img.data.dtype) == '>i8'
assert np.max(segmap.img._data) == 13
assert_array_equal(np.unique(segmap.img._data), refdata)
assert_array_equal(segmap.copy().img.data, segmap.img.data)
def test_align_segmap():
segmap = Segmap(get_data_file('segmap', 'segmap.fits'))
ref = Image(get_data_file('segmap', 'image.fits'))
aligned = segmap.align_with_image(ref, truncate=True)
assert aligned.img.shape == ref.shape
assert (aligned.img.wcs.get_rot() - ref.wcs.get_rot()) < 1e-3
def test_create_masks(tmpdir):
segfile = get_data_file('segmap', 'segmap.fits')
reffile = get_data_file('segmap', 'image.fits')
catalog = get_data_file('segmap', 'catalog.fits')
create_masks_from_segmap(
segfile, catalog, reffile, n_jobs=1, skip_existing=True,
masksky_name=str(tmpdir.join('mask-sky.fits')),
maskobj_name=str(tmpdir.join('mask-source-%05d.fits')),
idname='id', raname='ra', decname='dec', margin=5, mask_size=(10, 10),
convolve_fwhm=0)
assert len(glob(str(tmpdir.join('mask-source*')))) == 13
assert len(glob(str(tmpdir.join('mask-sky*')))) == 1
mask = fits.getdata(str(tmpdir.join('mask-source-00001.fits')))
assert mask.shape == (50, 50)
assert mask.sum() == 56
create_masks_from_segmap(
segfile, catalog, reffile, n_jobs=1, skip_existing=True,
masksky_name=str(tmpdir.join('mask2-sky.fits')),
maskobj_name=str(tmpdir.join('mask2-source-%05d.fits')),
idname='id', raname='ra', decname='dec', margin=5, mask_size=(10, 10),
convolve_fwhm=1, psf_threshold=0.5)
mask = fits.getdata(str(tmpdir.join('mask2-source-00001.fits')))
assert mask.shape == (50, 50)
assert mask.sum() == 106
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment