@@ -310,6 +310,28 @@ def __init__(self, **kwargs):
310310 self .schema .addField (
311311 "ip_diffim_forced_PsfFlux_flag_edge" , "Flag" ,
312312 "Forced PSF flux object was too close to the edge of the image to use the full PSF model." )
313+ self .schema .addField (
314+ "ip_diffim_forced_template_PsfFlux_instFlux" , "D" ,
315+ "Forced PSF flux measured on the template image." ,
316+ units = "count" )
317+ self .schema .addField (
318+ "ip_diffim_forced_template_PsfFlux_instFluxErr" , "D" ,
319+ "Forced PSF flux error measured on the template image." ,
320+ units = "count" )
321+ self .schema .addField (
322+ "ip_diffim_forced_template_PsfFlux_area" , "F" ,
323+ "Forced template PSF flux effective area of PSF." ,
324+ units = "pixel" )
325+ self .schema .addField (
326+ "ip_diffim_forced_template_PsfFlux_flag" , "Flag" ,
327+ "Forced template PSF flux general failure flag." )
328+ self .schema .addField (
329+ "ip_diffim_forced_template_PsfFlux_flag_noGoodPixels" , "Flag" ,
330+ "Forced template PSF flux not enough non-rejected pixels in data to attempt the fit." )
331+ self .schema .addField (
332+ "ip_diffim_forced_template_PsfFlux_flag_edge" , "Flag" ,
333+ """Forced template PSF flux object was too close to the edge of the image """
334+ """to use the full PSF model.""" )
313335 self .makeSubtask ("forcedMeasurement" , refSchema = self .schema )
314336
315337 self .schema .addField ("refMatchId" , "L" , "unique id of reference catalog match" )
@@ -489,6 +511,8 @@ def processResults(self, science, matchedTemplate, difference, sources, idFactor
489511
490512 if self .config .doForcedMeasurement :
491513 self .measureForcedSources (diaSources , science , difference .getWcs ())
514+ self .measureForcedSources (diaSources , matchedTemplate , difference .getWcs (),
515+ template = True )
492516
493517 self .calculateMetrics (difference )
494518
@@ -647,35 +671,42 @@ def measureDiaSources(self, diaSources, science, difference, matchedTemplate):
647671 apCorrMap = apCorrMap ,
648672 )
649673
650- def measureForcedSources (self , diaSources , science , wcs ):
651- """Perform forced measurement of the diaSources on the science image.
674+ def measureForcedSources (self , diaSources , image , wcs , template = False ):
675+ """Perform forced measurement of the diaSources on a direct image.
652676
653677 Parameters
654678 ----------
655679 diaSources : `lsst.afw.table.SourceCatalog`
656680 The catalog of detected sources.
657- science : `lsst.afw.image.ExposureF`
658- Science exposure that the template was subtracted from.
681+ image : `lsst.afw.image.ExposureF`
682+ Exposure that the forced measurement is being performed on
659683 wcs : `lsst.afw.geom.SkyWcs`
660684 Coordinate system definition (wcs) for the exposure.
685+ template : `bool`
686+ Is the forced measurement being performed on the template?
661687 """
662- # Run forced psf photometry on the PVI at the diaSource locations.
688+ # Run forced psf photometry on the image at the diaSource locations.
663689 # Copy the measured flux and error into the diaSource.
664- forcedSources = self .forcedMeasurement .generateMeasCat (science , diaSources , wcs )
665- self .forcedMeasurement .run (forcedSources , science , diaSources , wcs )
690+ forcedSources = self .forcedMeasurement .generateMeasCat (image , diaSources , wcs )
691+ self .forcedMeasurement .run (forcedSources , image , diaSources , wcs )
692+
693+ if template :
694+ base_key = 'ip_diffim_forced_template_PsfFlux'
695+ else :
696+ base_key = 'ip_diffim_forced_PsfFlux'
666697 mapper = afwTable .SchemaMapper (forcedSources .schema , diaSources .schema )
667698 mapper .addMapping (forcedSources .schema .find ("base_PsfFlux_instFlux" )[0 ],
668- "ip_diffim_forced_PsfFlux_instFlux " , True )
699+ f" { base_key } _instFlux " , True )
669700 mapper .addMapping (forcedSources .schema .find ("base_PsfFlux_instFluxErr" )[0 ],
670- "ip_diffim_forced_PsfFlux_instFluxErr " , True )
701+ f" { base_key } _instFluxErr " , True )
671702 mapper .addMapping (forcedSources .schema .find ("base_PsfFlux_area" )[0 ],
672- "ip_diffim_forced_PsfFlux_area " , True )
703+ f" { base_key } _area " , True )
673704 mapper .addMapping (forcedSources .schema .find ("base_PsfFlux_flag" )[0 ],
674- "ip_diffim_forced_PsfFlux_flag " , True )
705+ f" { base_key } _flag " , True )
675706 mapper .addMapping (forcedSources .schema .find ("base_PsfFlux_flag_noGoodPixels" )[0 ],
676- "ip_diffim_forced_PsfFlux_flag_noGoodPixels " , True )
707+ f" { base_key } _flag_noGoodPixels " , True )
677708 mapper .addMapping (forcedSources .schema .find ("base_PsfFlux_flag_edge" )[0 ],
678- "ip_diffim_forced_PsfFlux_flag_edge " , True )
709+ f" { base_key } _flag_edge " , True )
679710 for diaSource , forcedSource in zip (diaSources , forcedSources ):
680711 diaSource .assign (forcedSource , mapper )
681712
0 commit comments