Skip to content

Commit

Permalink
Add DQ flags
Browse files Browse the repository at this point in the history
  • Loading branch information
larrybradley committed Apr 30, 2024
1 parent c0b8064 commit 32e49e5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
13 changes: 10 additions & 3 deletions romancal/regtest/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions romancal/source_catalog/source_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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):
"""
Expand Down

0 comments on commit 32e49e5

Please sign in to comment.