Hi all,
I’ve been trying to run the LSST forced photometry pipelines on specific ra/dec in images from DP0.2 on the RSP, but no luck so far. It would be great if anyone can point me towards any existing code and/or tutorials on how to do this. I went through the tutorials on the RSP but they do not cover doing forced photometry yourself.
This is what I have so far:
I’ve come to the conclusion that I likely need to use ForcedMeasurementTask
(ForcedMeasurementTask — LSST Science Pipelines). The run
method needs:
exposure
: the DP0.2 image
refWcs
: Coordinate system, I can get that from the simulated DP0.2 image
measCat
: a SourceCatalog that will collect the measurement results
refCat
: a SourceCatalog that contains the information of where I want to do forced photometry.
I’m having trouble with generating measCat
and refCat
correctly.
For the measCat
variable, I currently do:
schema = afwTable.SourceTable.makeMinimalSchema()
measurement_config = measBase.ForcedMeasurementConfig()
measurement = measBase.ForcedMeasurementTask(schema, config=measurement_config)
measCat = measurement.generateMeasCat(exposure, sourceCat, exposure.getWcs())
which results in this error:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[40], line 6
4 schema = afwTable.SourceTable.makeMinimalSchema()
5 measurement_config = measBase.ForcedMeasurementConfig()
----> 6 measurement = measBase.ForcedMeasurementTask(schema, config=measurement_config)
7 measCat = measurement.generateMeasCat(exposure, sourceCat, exposure.getWcs())
File [/opt/lsst/software/stack/stack/miniconda3-py38_4.9.2-8.0.0/Linux64/meas_base/g212a7c68fe](https://data.lsst.cloud/opt/lsst/software/stack/stack/miniconda3-py38_4.9.2-8.0.0/Linux64/meas_base/g212a7c68fe)+a4f2ea4efa[/python/lsst/meas/base/forcedMeasurement.py:254](https://data.lsst.cloud/python/lsst/meas/base/forcedMeasurement.py#line=253), in ForcedMeasurementTask.__init__(self, refSchema, algMetadata, **kwds)
252 self.config.slots.setupSchema(self.mapper.editOutputSchema())
253 for refName, targetName in self.config.copyColumns.items():
--> 254 refItem = refSchema.find(refName)
255 self.mapper.addMapping(refItem.key, targetName)
256 self.config.slots.setupSchema(self.mapper.editOutputSchema())
KeyError: "Field with name 'deblend_nChild' not found"
And I’m not sure how to proceed from this.
For the refCat
variable, I currently create a SourceCatalog and add my ra/dec:
source = pd.Series({'ra': 56.5498060077, 'dec':-36.4269781414}) #my ra/dec where I want to do forced photometry
schema = afwTable.SourceTable.makeMinimalSchema()
sourceCat = afwTable.SourceCatalog(schema)
coord = geom.SpherePoint(source['ra']*geom.degrees, source['dec']*geom.degrees)
sourceRec.setCoord(coord)
The next step seems to be that I need to add a Footprint to this, but I can’t seem to get that to work (the documentation on this is not super clear). I currently do:
coord = geom.SpherePoint(source['ra']*geom.degrees,
source['dec']*geom.degrees)
point = exposure.getWcs().skyToPixel(coord)
fpCenter = geom.Point2I(point)
radius = 6
footprint = afwDetection.Footprint(fpCenter, radius)
which results in the error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[17], line 6
4 fpCenter = geom.Point2I(point)
5 radius = 6
----> 6 footprint = afwDetection.Footprint(fpCenter, radius)
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
1. lsst.afw.detection.Footprint(inputSpans: lsst.afw.geom.SpanSet, region: lsst.geom.Box2I = Box2I(corner=Point2I(0, 0), dimensions=Extent2I(0, 0)))
2. lsst.afw.detection.Footprint(inputSpans: lsst.afw.geom.SpanSet, peakSchema: lsst.afw.table.Schema, region: lsst.geom.Box2I = Box2I(corner=Point2I(0, 0), dimensions=Extent2I(0, 0)))
3. lsst.afw.detection.Footprint(arg0: lsst.afw.detection.Footprint)
4. lsst.afw.detection.Footprint()
Invoked with: Point2I(2039, 2028), 6
I can get it to run with a Box2I instead, but then I’m confused on how to define the aperture (radius), and I’m not sure if this is the recommended way to do it.
Any advice on how to correctly set up the refCat
and measCat
variables is greatly appreciated. Also please let me know if I’m heading towards the wrong solution entirely.
FYI I have found this thread (How do I do forced-photometry on a set of RA, Dec - #13 by mwv), which covers the same question, but the last answer is from 7 years ago and the code shown there doesn’t work anymore (presumably since LSST pipelines seems to have changed since then).
Thanks!
Cheers,
Tobias