diff --git a/romancal/regtest/test_catalog.py b/romancal/regtest/test_catalog.py index 2055646ec..8322b6dd0 100644 --- a/romancal/regtest/test_catalog.py +++ b/romancal/regtest/test_catalog.py @@ -39,26 +39,33 @@ def test_catalog_l3(rtdata, ignore_asdf_paths): catalogfp = asdf.open(outputfn) catalog = catalogfp["roman"]["source_catalog"] step = SourceCatalogStep() - fields = catalog.dtype.names + has_pos = ("ra_centroid" in fields) and ("dec_centroid" in fields) step.log.info( "DMS374 MSG: L3 Catalog contains sky coordinates of sources? :" + passfail(has_pos) ) assert has_pos + has_flux = "aper_total_flux" in fields - has_flux_err = "aper_total_flux_err" in fields - has_type = "is_extended" in fields step.log.info("DMS375 MSG: L3 Catalog contains fluxes? :" + passfail(has_flux)) assert has_flux + + has_type = "is_extended" in fields step.log.info( "DMS376 MSG: L3 Catalog contains source classification? :" + passfail(has_type) ) assert has_type + + has_flux_err = "aper_total_flux_err" in fields step.log.info( "DMS386 MSG: L3 Catalog contains flux uncertainties? :" + passfail(has_flux_err) ) assert has_flux_err + has_flags = "flags" in fields + step.log.info("DMS387 MSG: L3 Catalog contains DQ flags? :" + passfail(has_flags)) + assert has_flags + # no compare_asdf on the catalogs diff --git a/romancal/source_catalog/source_catalog.py b/romancal/source_catalog/source_catalog.py index 8cb93d603..4437d360a 100644 --- a/romancal/source_catalog/source_catalog.py +++ b/romancal/source_catalog/source_catalog.py @@ -17,6 +17,7 @@ from photutils.aperture import CircularAnnulus, CircularAperture, aperture_photometry from photutils.segmentation import SourceCatalog from roman_datamodels.datamodels import ImageModel, MosaicModel +from roman_datamodels.dqflags import pixel from scipy import ndimage from scipy.spatial import KDTree @@ -621,6 +622,7 @@ def extras_colnames(self): for idx, colname in enumerate(self.ci_colnames): desc[colname] = self.ci_colname_descriptions[idx] + desc["flags"] = "Data quality flags" desc["is_extended"] = "Flag indicating whether the source is extended" desc["sharpness"] = "The DAOFind source sharpness statistic" desc["roundness"] = "The DAOFind source roundness statistic" @@ -630,6 +632,27 @@ def extras_colnames(self): return list(desc.keys()) + @lazyproperty + def flags(self): + """ + Data quality flags. + """ + xyidx = np.round(self._xypos).astype(int) + + try: + # L2 images have a dq array + dqflags = self.model.dq[xyidx[:, 1], xyidx[:, 0]] + # if dqflags contains the DO_NOT_USE flag, set to DO_NOT_USE + # (dq=1), otherwise 0 + flags = dqflags & pixel.DO_NOT_USE + + except AttributeError: + # L3 images + mask = self.model.weight == 0 + flags = mask[xyidx[:, 1], xyidx[:, 0]].astype(int) + + return flags + @lazyproperty def _ci_ee_indices(self): """