Skip to content

Commit

Permalink
Use mask when making segmentation image.
Browse files Browse the repository at this point in the history
  • Loading branch information
schlafly committed Jan 8, 2025
1 parent f538ba0 commit d4f710d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion romancal/lib/psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def fit_psf_to_image_model(
"or arrays for the data and error."
)

ignore_flags = pixel.NO_LIN_CORR
ignore_flags = pixel.NO_LIN_CORR | pixel.DEAD
# presently the linearity correction is somewhat problematic in
# CRDS reference files; we should replace this with ignore_flags = 0
# at some point in the future.
Expand Down
10 changes: 8 additions & 2 deletions romancal/source_catalog/source_catalog_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
from roman_datamodels import datamodels, maker_utils
from roman_datamodels.datamodels import ImageModel, MosaicModel
from roman_datamodels.maker_utils import mk_datamodel
from roman_datamodels.dqflags import pixel

from romancal.source_catalog.background import RomanBackground
from romancal.source_catalog.detection import convolve_data, make_segmentation_image
from romancal.source_catalog.reference_data import ReferenceData
from romancal.source_catalog.source_catalog import RomanSourceCatalog
from romancal.stpipe import RomanStep
from romancal.lib import psf

if TYPE_CHECKING:
from typing import ClassVar
Expand Down Expand Up @@ -76,6 +78,10 @@ def process(self, step_input):
err=input_model.err.copy(),
dq=input_model.dq,
)
mask = (model.err <= 0) | np.isnan(model.data) | np.isnan(model.err)
ignore_flags = pixel.NO_LIN_CORR | pixel.DEAD
mask |= psf.dq_to_boolean_mask(model.dq, ignore_flags=ignore_flags)
coverage_mask = mask.copy()
elif isinstance(input_model, MosaicModel):
model = mk_datamodel(
MosaicModel,
Expand All @@ -85,6 +91,8 @@ def process(self, step_input):
err=input_model.err.copy(),
weight=input_model.weight,
)
mask = np.isnan(model.data) | np.isnan(model.err)
coverage_mask = mask.copy()

if isinstance(model, ImageModel):
cat_model = datamodels.ImageSourceCatalogModel
Expand All @@ -103,8 +111,6 @@ def process(self, step_input):
refdata = ReferenceData(model, aperture_ee)
aperture_params = refdata.aperture_params

mask = np.isnan(model.data)
coverage_mask = np.isnan(model.err)
bkg = RomanBackground(
model.data,
box_size=self.bkg_boxsize,
Expand Down

0 comments on commit d4f710d

Please sign in to comment.