Commit ba2e05fe authored by Simon Conseil's avatar Simon Conseil
Browse files

Allow to use functions for maskobj_name/masksky_name

parent b5c2c636
Loading
Loading
Loading
Loading
Loading
+7 −5
Original line number Original line Diff line number Diff line
@@ -235,9 +235,9 @@ def create_masks_from_segmap(
        Number of parallel processes (for joblib).
        Number of parallel processes (for joblib).
    skip_existing: bool
    skip_existing: bool
        If True, skip sources for which the mask file exists.
        If True, skip sources for which the mask file exists.
    masksky_name: str
    masksky_name: str or callable
        The filename for the sky mask.
        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
        The filename for the source masks, with a format string that will be
        substituted with the ID, e.g. ``%05d``.
        substituted with the ID, e.g. ``%05d``.
    idname, raname, decname: str
    idname, raname, decname: str
@@ -272,12 +272,13 @@ def create_masks_from_segmap(
                                                   psf_threshold)
                                                   psf_threshold)


    # create sky mask
    # 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('sky mask exists, skipping')
    else:
    else:
        logger.debug('creating sky mask')
        logger.debug('creating sky mask')
        segm.get_mask(0, inverse=True, dilate=dilateit, struct=struct,
        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
    # extract source masks
    minsize = 0.
    minsize = 0.
@@ -286,7 +287,8 @@ def create_masks_from_segmap(


    for row in catalog:
    for row in catalog:
        id_ = int(row[idname])  # need int, not np.int64
        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):
        if skip_existing and exists(source_path):
            stats['skipped'].append(id_)
            stats['skipped'].append(id_)
        else:
        else:
+4 −3
Original line number Original line Diff line number Diff line
@@ -76,11 +76,12 @@ def test_create_masks(tmpdir):
        idname='id', raname='ra', decname='dec', margin=5, mask_size=(10, 10),
        idname='id', raname='ra', decname='dec', margin=5, mask_size=(10, 10),
        convolve_fwhm=0)
        convolve_fwhm=0)


    # 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))
    create_masks_from_segmap(
    create_masks_from_segmap(
        segfile, catalog, reffile, n_jobs=1, skip_existing=True,
        segfile, catalog, reffile, n_jobs=1, skip_existing=True,
        masksky_name=str(tmpdir.join('mask2-sky.fits')),
        masksky_name=masksky_func, maskobj_name=maskobj_func,
        maskobj_name=str(tmpdir.join('mask2-source-%05d.fits')),
        idname='id', raname='ra', decname='dec', margin=5, mask_size=(10, 10),
        idname='id', raname='ra', decname='dec', margin=5, mask_size=(10, 10),
        convolve_fwhm=1, psf_threshold=0.5)
        convolve_fwhm=1, psf_threshold=0.5)