Skip to content

Commit e415d04

Browse files
committed
perform forced photometry on template
1 parent 68385bb commit e415d04

2 files changed

Lines changed: 48 additions & 15 deletions

File tree

python/lsst/ip/diffim/detectAndMeasure.py

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

tests/test_detectAndMeasure.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ def test_raise_bad_psf(self):
196196
def test_measurements_finite(self):
197197
"""Measured fluxes and centroids should always be finite.
198198
"""
199-
columnNames = ["coord_ra", "coord_dec", "ip_diffim_forced_PsfFlux_instFlux"]
199+
columnNames = ["coord_ra", "coord_dec", "ip_diffim_forced_PsfFlux_instFlux",
200+
"ip_diffim_forced_template_PsfFlux_instFlux"]
200201

201202
# Set up the simulated images
202203
noiseLevel = 1.
@@ -685,7 +686,8 @@ def test_detection_xy0(self):
685686
def test_measurements_finite(self):
686687
"""Measured fluxes and centroids should always be finite.
687688
"""
688-
columnNames = ["coord_ra", "coord_dec", "ip_diffim_forced_PsfFlux_instFlux"]
689+
columnNames = ["coord_ra", "coord_dec", "ip_diffim_forced_PsfFlux_instFlux",
690+
"ip_diffim_forced_template_PsfFlux_instFlux"]
689691

690692
# Set up the simulated images
691693
noiseLevel = 1.

0 commit comments

Comments
 (0)