138 def process(self, dataRef, inputExposure, enableWriteSources=True):
141 @param dataRef: data reference that corresponds to the input image
142 @param inputExposure: exposure to process
143 @param enableWriteSources: if True then writing sources is allowed.
144 Set False if you need to postprocess sources before writing them.
146 @return pipe_base Struct containing these fields:
147 - postIsrExposure: exposure after ISR performed if calib.doIsr or config.doCalibrate, else None
148 - exposure: calibrated exposure (calexp): as computed if config.doCalibrate,
149 else as upersisted and updated if config.doDetection, else None
150 - calib: object returned by calibration process if config.doCalibrate, else None
151 - sources: detected source if config.doPhotometry, else None
156 calExposure = inputExposure
159 backgrounds = afwMath.BackgroundList()
160 if self.config.doCalibrate:
161 calib = self.calibrate.run(inputExposure, idFactory=idFactory)
162 calExposure = calib.exposure
163 if self.config.doWriteCalibrate:
164 dataRef.put(calib.sources, self.
dataPrefix +
"icSrc")
165 if calib.matches
is not None and self.config.doWriteCalibrateMatches:
167 normalizedMatches.table.setMetadata(calib.matchMeta)
168 dataRef.put(normalizedMatches, self.
dataPrefix +
"icMatch")
170 for bg
in calib.backgrounds:
171 backgrounds.append(bg)
173 backgrounds.append(calib.backgrounds)
174 except AttributeError:
175 self.log.warn(
"The calibration task did not return any backgrounds. " +
176 "Any background subtracted in the calibration process cannot be persisted.")
180 if self.config.doDetection:
181 table = afwTable.SourceTable.make(self.
schema, idFactory)
183 detections = self.detection.run(table, calExposure)
184 sources = detections.sources
185 fpSets = detections.fpSets
186 if fpSets.background:
187 backgrounds.append(fpSets.background)
189 if self.config.doDeblend:
190 self.deblend.run(calExposure, sources, calExposure.getPsf())
192 if self.config.doMeasurement:
193 self.measurement.run(calExposure, sources, exposureId=self.
getExposureId(dataRef))
195 if self.config.doWriteCalibrate:
200 if calExposure
is None:
201 self.log.warn(
"calibrated exposure is None; cannot save it")
203 if self.config.persistBackgroundModel:
207 dataRef.put(calExposure, self.
dataPrefix +
"calexp")
209 if calib
is not None:
212 if sources
is not None and self.config.doWriteSources:
213 sourceWriteFlags = (0
if self.config.doWriteHeavyFootprintsInSources
214 else afwTable.SOURCE_IO_NO_HEAVY_FOOTPRINTS)
215 if enableWriteSources:
216 dataRef.put(sources, self.
dataPrefix +
'src', flags=sourceWriteFlags)
218 if self.config.doMeasurement
and self.config.doWriteSourceMatches:
219 self.log.info(
"Matching src to reference catalogue" % (dataRef.dataId))
220 srcMatches, srcMatchMeta = self.
matchSources(calExposure, sources)
223 normalizedSrcMatches.table.setMetadata(srcMatchMeta)
224 dataRef.put(normalizedSrcMatches, self.
dataPrefix +
"srcMatch")
226 srcMatches =
None; srcMatchMeta =
None
228 return pipeBase.Struct(
229 inputExposure = inputExposure,
230 exposure = calExposure,
233 matches = srcMatches,
234 matchMeta = srcMatchMeta,
235 backgrounds = backgrounds,