Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 13 additions & 44 deletions python/lsst/ip/diffim/detectAndMeasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,28 +420,6 @@ def __init__(self, **kwargs):
self.schema.addField(
"ip_diffim_forced_PsfFlux_flag_edge", "Flag",
"Forced PSF flux object was too close to the edge of the image to use the full PSF model.")
self.schema.addField(
"ip_diffim_forced_template_PsfFlux_instFlux", "D",
"Forced PSF flux measured on the template image.",
units="count")
self.schema.addField(
"ip_diffim_forced_template_PsfFlux_instFluxErr", "D",
"Forced PSF flux error measured on the template image.",
units="count")
self.schema.addField(
"ip_diffim_forced_template_PsfFlux_area", "F",
"Forced template PSF flux effective area of PSF.",
units="pixel")
self.schema.addField(
"ip_diffim_forced_template_PsfFlux_flag", "Flag",
"Forced template PSF flux general failure flag.")
self.schema.addField(
"ip_diffim_forced_template_PsfFlux_flag_noGoodPixels", "Flag",
"Forced template PSF flux not enough non-rejected pixels in data to attempt the fit.")
self.schema.addField(
"ip_diffim_forced_template_PsfFlux_flag_edge", "Flag",
"""Forced template PSF flux object was too close to the edge of the image """
"""to use the full PSF model.""")
self.makeSubtask("forcedMeasurement", refSchema=self.schema)

self.schema.addField("refMatchId", "L", "unique id of reference catalog match")
Expand Down Expand Up @@ -716,8 +694,6 @@ def processResults(self, science, matchedTemplate, difference, sources, idFactor

if self.config.doForcedMeasurement:
self.measureForcedSources(diaSources, science, difference.getWcs())
self.measureForcedSources(diaSources, matchedTemplate, difference.getWcs(),
template=True)

measurementResults.subtractedMeasuredExposure = difference

Expand Down Expand Up @@ -881,42 +857,35 @@ def measureDiaSources(self, diaSources, science, difference, matchedTemplate):
apCorrMap=apCorrMap,
)

def measureForcedSources(self, diaSources, image, wcs, template=False):
"""Perform forced measurement of the diaSources on a direct image.
def measureForcedSources(self, diaSources, science, wcs):
"""Perform forced measurement of the diaSources on the science image.

Parameters
----------
diaSources : `lsst.afw.table.SourceCatalog`
The catalog of detected sources.
image: `lsst.afw.image.ExposureF`
Exposure that the forced measurement is being performed on
science : `lsst.afw.image.ExposureF`
Science exposure that the template was subtracted from.
wcs : `lsst.afw.geom.SkyWcs`
Coordinate system definition (wcs) for the exposure.
template : `bool`
Is the forced measurement being performed on the template?
"""
# Run forced psf photometry on the image at the diaSource locations.
# Run forced psf photometry on the PVI at the diaSource locations.
# Copy the measured flux and error into the diaSource.
forcedSources = self.forcedMeasurement.generateMeasCat(image, diaSources, wcs)
self.forcedMeasurement.run(forcedSources, image, diaSources, wcs)

if template:
base_key = 'ip_diffim_forced_template_PsfFlux'
else:
base_key = 'ip_diffim_forced_PsfFlux'
forcedSources = self.forcedMeasurement.generateMeasCat(science, diaSources, wcs)
self.forcedMeasurement.run(forcedSources, science, diaSources, wcs)
mapper = afwTable.SchemaMapper(forcedSources.schema, diaSources.schema)
mapper.addMapping(forcedSources.schema.find("base_PsfFlux_instFlux")[0],
f"{base_key}_instFlux", True)
"ip_diffim_forced_PsfFlux_instFlux", True)
mapper.addMapping(forcedSources.schema.find("base_PsfFlux_instFluxErr")[0],
f"{base_key}_instFluxErr", True)
"ip_diffim_forced_PsfFlux_instFluxErr", True)
mapper.addMapping(forcedSources.schema.find("base_PsfFlux_area")[0],
f"{base_key}_area", True)
"ip_diffim_forced_PsfFlux_area", True)
mapper.addMapping(forcedSources.schema.find("base_PsfFlux_flag")[0],
f"{base_key}_flag", True)
"ip_diffim_forced_PsfFlux_flag", True)
mapper.addMapping(forcedSources.schema.find("base_PsfFlux_flag_noGoodPixels")[0],
f"{base_key}_flag_noGoodPixels", True)
"ip_diffim_forced_PsfFlux_flag_noGoodPixels", True)
mapper.addMapping(forcedSources.schema.find("base_PsfFlux_flag_edge")[0],
f"{base_key}_flag_edge", True)
"ip_diffim_forced_PsfFlux_flag_edge", True)
for diaSource, forcedSource in zip(diaSources, forcedSources):
diaSource.assign(forcedSource, mapper)

Expand Down
6 changes: 2 additions & 4 deletions tests/test_detectAndMeasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ def test_raise_bad_psf(self):
def test_measurements_finite(self):
"""Measured fluxes and centroids should always be finite.
"""
columnNames = ["coord_ra", "coord_dec", "ip_diffim_forced_PsfFlux_instFlux",
"ip_diffim_forced_template_PsfFlux_instFlux"]
columnNames = ["coord_ra", "coord_dec", "ip_diffim_forced_PsfFlux_instFlux"]

# Set up the simulated images
noiseLevel = 1.
Expand Down Expand Up @@ -756,8 +755,7 @@ def test_detection_xy0(self):
def test_measurements_finite(self):
"""Measured fluxes and centroids should always be finite.
"""
columnNames = ["coord_ra", "coord_dec", "ip_diffim_forced_PsfFlux_instFlux",
"ip_diffim_forced_template_PsfFlux_instFlux"]
columnNames = ["coord_ra", "coord_dec", "ip_diffim_forced_PsfFlux_instFlux"]

# Set up the simulated images
noiseLevel = 1.
Expand Down