diff --git a/CHANGES.rst b/CHANGES.rst index 166b2a524..fbfe17173 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,16 @@ mosaic_pipeline - Only load patch table when needed. [#1367] +source_catalog +-------------- + +- Populate segmentation image metadata. [#1391] + +resample +-------- + +- Use association product name for output meta.filename by default [#1391] + 0.16.2 (2024-08-23) =================== diff --git a/romancal/outlier_detection/outlier_detection_step.py b/romancal/outlier_detection/outlier_detection_step.py index 1441bc903..332791e4b 100644 --- a/romancal/outlier_detection/outlier_detection_step.py +++ b/romancal/outlier_detection/outlier_detection_step.py @@ -152,7 +152,7 @@ def process(self, input_models): intermediate_files_suffixes = ( "*blot.asdf", "*median.asdf", - f'*{pars.get("resample_suffix")}*.asdf', + f'*outlier_{pars.get("resample_suffix")}.asdf', ) for current_path in intermediate_files_paths: for suffix in intermediate_files_suffixes: diff --git a/romancal/pipeline/mosaic_pipeline.py b/romancal/pipeline/mosaic_pipeline.py index 6ea40e26f..36effdcbd 100644 --- a/romancal/pipeline/mosaic_pipeline.py +++ b/romancal/pipeline/mosaic_pipeline.py @@ -131,10 +131,9 @@ def process(self, input): ) wcs_file = asdf.open(self.resample.output_wcs) self.suffix = "i2d" - result = self.resample(result) self.output_file = input.asn["products"][0]["name"] - # force the SourceCatalogStep to save the results - self.sourcecatalog.save_results = True + result = self.resample(result) + self.sourcecatalog.output_file = self.output_file result_catalog = self.sourcecatalog(result) else: log.info("resampling a mosaic file is not yet supported") @@ -144,7 +143,7 @@ def process(self, input): self.resample.suffix = "i2d" self.output_file = input.asn["products"][0]["name"] result = self.resample(result) - self.sourcecatalog.save_results = True + self.sourcecatalog.output_file = self.output_file result_catalog = self.sourcecatalog(result) # noqa: F841 self.suffix = "i2d" if input_filename: diff --git a/romancal/resample/resample_step.py b/romancal/resample/resample_step.py index 79b9587f4..5315f150d 100644 --- a/romancal/resample/resample_step.py +++ b/romancal/resample/resample_step.py @@ -83,11 +83,14 @@ def process(self, input): output = input_models.asn["products"][0]["name"] elif isinstance(input, ModelLibrary): input_models = input - # set output filename using the common prefix of all datamodels - output = f"{os.path.commonprefix([x['expname'] for x in input_models.asn['products'][0]['members']])}.asdf" - if len(output) == 0: - # set default filename if no common prefix can be determined - output = "resample_output.asdf" + if "name" in input_models.asn["products"][0]: + output = input_models.asn["products"][0]["name"] + else: + # set output filename using the common prefix of all datamodels + output = f"{os.path.commonprefix([x['expname'] for x in input_models.asn['products'][0]['members']])}.asdf" + if len(output) == 0: + # set default filename if no common prefix can be determined + output = "resample_output.asdf" else: raise TypeError( "Input must be an ASN filename, a ModelLibrary, " diff --git a/romancal/source_catalog/source_catalog_step.py b/romancal/source_catalog/source_catalog_step.py index e1d0f32f6..9946d037b 100644 --- a/romancal/source_catalog/source_catalog_step.py +++ b/romancal/source_catalog/source_catalog_step.py @@ -145,10 +145,21 @@ def process(self, input_model): def save_base_results(self, segment_img, source_catalog_model): # save the segmentation map and - output_filename = source_catalog_model.meta.filename - segmentation_model = maker_utils.mk_datamodel( - datamodels.MosaicSegmentationMapModel + output_filename = ( + self.output_file + if self.output_file is not None + else source_catalog_model.meta.filename ) + + if isinstance(source_catalog_model, datamodels.SourceCatalogModel): + seg_model = datamodels.SegmentationMapModel + else: + seg_model = datamodels.MosaicSegmentationMapModel + + segmentation_model = maker_utils.mk_datamodel(seg_model) + for key in segmentation_model.meta.keys(): + segmentation_model.meta[key] = source_catalog_model.meta[key] + if segment_img is not None: segmentation_model.data = segment_img.data.astype(np.uint32) self.save_model( diff --git a/romancal/source_catalog/tests/test_source_catalog.py b/romancal/source_catalog/tests/test_source_catalog.py index f9e0b62d0..f1dfd15bf 100644 --- a/romancal/source_catalog/tests/test_source_catalog.py +++ b/romancal/source_catalog/tests/test_source_catalog.py @@ -14,6 +14,7 @@ MosaicModel, MosaicSegmentationMapModel, MosaicSourceCatalogModel, + SegmentationMapModel, SourceCatalogModel, ) from roman_datamodels.maker_utils import mk_level2_image, mk_level3_mosaic @@ -461,7 +462,7 @@ def test_do_psf_photometry_column_names(tmp_path, image_model, fit_psf): ImageModel, { "cat": SourceCatalogModel, - "segm": MosaicSegmentationMapModel, + "segm": SegmentationMapModel, "sourcecatalog": ImageModel, }, ), @@ -474,7 +475,7 @@ def test_do_psf_photometry_column_names(tmp_path, image_model, fit_psf): SourceCatalogModel, { "cat": SourceCatalogModel, - "segm": MosaicSegmentationMapModel, + "segm": SegmentationMapModel, }, ), ( @@ -486,7 +487,7 @@ def test_do_psf_photometry_column_names(tmp_path, image_model, fit_psf): ImageModel, { "cat": SourceCatalogModel, - "segm": MosaicSegmentationMapModel, + "segm": SegmentationMapModel, }, ), ( @@ -498,7 +499,7 @@ def test_do_psf_photometry_column_names(tmp_path, image_model, fit_psf): SourceCatalogModel, { "cat": SourceCatalogModel, - "segm": MosaicSegmentationMapModel, + "segm": SegmentationMapModel, }, ), ),