From ebc8d34c39bd5ff5fd3e9ed0ceca46c5e44a5989 Mon Sep 17 00:00:00 2001 From: Pierre-Francois Leget Date: Tue, 10 Jun 2025 10:10:48 -0700 Subject: [PATCH] Add max pixel value to table. --- python/lsst/pipe/tasks/calibrateImage.py | 12 +++++++++++- python/lsst/pipe/tasks/characterizeImage.py | 7 ++++++- python/lsst/pipe/tasks/finalizeCharacterization.py | 13 +++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/python/lsst/pipe/tasks/calibrateImage.py b/python/lsst/pipe/tasks/calibrateImage.py index c9064837b..01df39498 100644 --- a/python/lsst/pipe/tasks/calibrateImage.py +++ b/python/lsst/pipe/tasks/calibrateImage.py @@ -588,6 +588,11 @@ def __init__(self, initial_stars_schema=None, **kwargs): self.makeSubtask("psf_repair") self.makeSubtask("psf_subtract_background") self.psf_schema = afwTable.SourceTable.makeMinimalSchema() + self.psf_schema.addField( + 'psf_max_value', + type=np.float32, + doc="PSF max value.", + ) afwTable.CoordKey.addErrorFields(self.psf_schema) self.makeSubtask("psf_detection", schema=self.psf_schema) self.makeSubtask("psf_source_measurement", schema=self.psf_schema) @@ -607,14 +612,18 @@ def __init__(self, initial_stars_schema=None, **kwargs): "calib_astrometry_used", # TODO DM-39203: these can be removed once apcorr is gone. "apcorr_slot_CalibFlux_used", "apcorr_base_GaussianFlux_used", - "apcorr_base_PsfFlux_used") + "apcorr_base_PsfFlux_used",) for field in self.psf_fields: item = self.psf_schema.find(field) initial_stars_schema.addField(item.getField()) id_type = self.psf_schema["id"].asField().getTypeString() + psfmaxvaluetype = self.psf_schema['psf_max_value'].asField().getTypeString() initial_stars_schema.addField("psf_id", type=id_type, doc="id of this source in psf_stars; 0 if there is no match.") + initial_stars_schema.addField("psf_max_value", + type=psfmaxvaluetype, + doc="PSF max value.") afwTable.CoordKey.addErrorFields(initial_stars_schema) self.makeSubtask("star_detection", schema=initial_stars_schema) @@ -1242,6 +1251,7 @@ def _match_psf_stars(self, psf_stars, stars): result[idx_stars] = psf_stars[field][idx_psf_stars] stars[field] = result stars['psf_id'][idx_stars] = psf_stars['id'][idx_psf_stars] + stars['psf_max_value'][idx_stars] = psf_stars['psf_max_value'][idx_psf_stars] def _fit_astrometry(self, exposure, stars): """Fit an astrometric model to the data and return the reference diff --git a/python/lsst/pipe/tasks/characterizeImage.py b/python/lsst/pipe/tasks/characterizeImage.py index 6dbc428e6..a32164359 100644 --- a/python/lsst/pipe/tasks/characterizeImage.py +++ b/python/lsst/pipe/tasks/characterizeImage.py @@ -559,7 +559,12 @@ def detectMeasureAndEstimatePsf(self, exposure, idGenerator, background): if background is None: background = BackgroundList() - + self.schema.addField( + 'psf_max_value', + type=np.float32, + doc="PSF max value.", + doReplace=True, + ) sourceIdFactory = idGenerator.make_table_id_factory() table = SourceTable.make(self.schema, sourceIdFactory) table.setMetadata(self.algMetadata) diff --git a/python/lsst/pipe/tasks/finalizeCharacterization.py b/python/lsst/pipe/tasks/finalizeCharacterization.py index 6b9ef0819..5d5672d12 100644 --- a/python/lsst/pipe/tasks/finalizeCharacterization.py +++ b/python/lsst/pipe/tasks/finalizeCharacterization.py @@ -433,6 +433,12 @@ def _make_output_schema_mapper(self, input_schema): size=10, doc="Color used in PSF fit." ) + output_schema.addField( + 'psf_max_value', + type=np.float32, + doc="PSF max value.", + doReplace=True, + ) alias_map = input_schema.getAliasMap() alias_map_output = afwTable.AliasMap() @@ -477,6 +483,12 @@ def _make_selection_schema_mapper(self, input_schema): size=10, doc="Color used in PSF fit." ) + selection_schema.addField( + 'psf_max_value', + type=np.float32, + doc="PSF max value.", + doReplace=True, + ) return mapper, selection_schema @@ -700,6 +712,7 @@ def compute_psf_and_ap_corr_map(self, visit, detector, exposure, src, # Select the psf candidates from the selection catalog try: psf_selection_result = self.make_psf_candidates.run(selected_src, exposure=exposure) + _ = self.make_psf_candidates.run(measured_src, exposure=exposure) except Exception as e: self.log.exception('Failed to make PSF candidates for visit %d, detector %d: %s', visit, detector, e)