Commit ba2e05fe authored by Simon Conseil's avatar Simon Conseil

Allow to use functions for maskobj_name/masksky_name

parent b5c2c636
Pipeline #3181 passed with stage
in 15 minutes and 27 seconds
......@@ -235,9 +235,9 @@ def create_masks_from_segmap(
Number of parallel processes (for joblib).
skip_existing: bool
If True, skip sources for which the mask file exists.
masksky_name: str
masksky_name: str or callable
The filename for the sky mask.
maskobj_name: str
maskobj_name: str or callable
The filename for the source masks, with a format string that will be
substituted with the ID, e.g. ``%05d``.
idname, raname, decname: str
......@@ -272,12 +272,13 @@ def create_masks_from_segmap(
# create sky mask
if exists(masksky_name) and skip_existing:
masksky = masksky_name() if callable(masksky_name) else masksky_name
if exists(masksky) and skip_existing:
logger.debug('sky mask exists, skipping')
logger.debug('creating sky mask')
segm.get_mask(0, inverse=True, dilate=dilateit, struct=struct,
regrid_to=ref_image, outname=masksky_name)
regrid_to=ref_image, outname=masksky)
# extract source masks
minsize = 0.
......@@ -286,7 +287,8 @@ def create_masks_from_segmap(
for row in catalog:
id_ = int(row[idname]) # need int, not np.int64
source_path = maskobj_name % id_
source_path = (maskobj_name(id_) if callable(maskobj_name)
else maskobj_name % id_)
if skip_existing and exists(source_path):
......@@ -76,11 +76,12 @@ def test_create_masks(tmpdir):
idname='id', raname='ra', decname='dec', margin=5, mask_size=(10, 10),
# test convolve_fwhm
# test convolve_fwhm and callables for mask filenames
masksky_func = lambda: str(tmpdir.join('mask2-sky.fits'))
maskobj_func = lambda x: str(tmpdir.join('mask2-source-%05d.fits' % x))
segfile, catalog, reffile, n_jobs=1, skip_existing=True,
masksky_name=masksky_func, maskobj_name=maskobj_func,
idname='id', raname='ra', decname='dec', margin=5, mask_size=(10, 10),
convolve_fwhm=1, psf_threshold=0.5)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment