Coverage for python/lsst/ap/association/diaForcedSource.py : 35%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# This file is part of ap_association. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (https://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>.
locations. """
ForcedMeasurementTask, ForcedTransformedCentroidConfig, ForcedTransformedCentroidPlugin)
"""Configuration for the forced transformed coord algorithm. """
"""Record the transformation of the reference catalog coord. The coord recorded in the reference catalog is tranformed to the measurement coordinate system and stored.
Parameters ---------- config : `ForcedTransformedCentroidFromCoordConfig` Plugin configuration name : `str` Plugin name schemaMapper : `lsst.afw.table.SchemaMapper` A mapping from reference catalog fields to output catalog fields. Output fields are added to the output schema. metadata : `lsst.daf.base.PropertySet` Plugin metadata that will be attached to the output catalog.
Notes ----- This can be used as the slot centroid in forced measurement when only a reference coord exits, allowing subsequent measurements to simply refer to the slot value just as they would in single-frame measurement. """
targetWcs = exposure.getWcs()
targetPos = targetWcs.skyToPixel(refRecord.getCoord()) measRecord.set(self.centroidKey, targetPos)
if self.flagKey is not None: measRecord.set(self.flagKey, refRecord.getCentroidFlag())
"""Configuration for the generic DiaForcedSourcedTask class. """ target=ForcedMeasurementTask, doc="Subtask to force photometer DiaObjects in the direct and " "difference images.", ) dtype=str, doc="Columns produced in forced measurement that can be dropped upon " "creation and storage of the final pandas data.", )
self.forcedMeasurement.plugins = ["ap_assoc_TransformedCentroid", "base_PsfFlux"] self.forcedMeasurement.doReplaceWithNoise = False self.forcedMeasurement.copyColumns = { "id": "diaObjectId", "coord_ra": "coord_ra", "coord_dec": "coord_dec"} self.forcedMeasurement.slots.centroid = "ap_assoc_TransformedCentroid" self.forcedMeasurement.slots.psfFlux = "base_PsfFlux" self.forcedMeasurement.slots.shape = None self.dropColumns = ['coord_ra', 'coord_dec', 'parent', 'ap_assoc_TransformedCentroid_x', 'ap_assoc_TransformedCentroid_y', 'base_PsfFlux_instFlux', 'base_PsfFlux_instFluxErr', 'base_PsfFlux_area', 'slot_PsfFlux_area', 'base_PsfFlux_flag', 'slot_PsfFlux_flag', 'base_PsfFlux_flag_noGoodPixels', 'slot_PsfFlux_flag_noGoodPixels', 'base_PsfFlux_flag_edge', 'slot_PsfFlux_flag_edge']
"""Task for measuring and storing forced sources at DiaObject locations in both difference and direct images. """
pipeBase.Task.__init__(self, **kwargs) self.makeSubtask("forcedMeasurement", refSchema=afwTable.SourceTable.makeMinimalSchema())
"""Measure forced sources on the direct and different images, calibrate, and store them in the Apdb.
Parameters ---------- dia_objects : `pandas.DataFrame` Catalog of previously observed and newly created DiaObjects contained within the difference and direct images. expIdBits : `int` Bit length of the exposure id. exposure : `lsst.afw.image.Exposure` Direct image exposure. diffim : `lsst.afw.image.Exposure` Difference image. apdb : `lsst.dax.apdb.Apdb` Connection to the association database.
Returns ------- output_forced_sources : `pandas.DataFrame` Catalog of calibrated forced photometered fluxes on both the difference and direct images at DiaObject locations. """
afw_dia_objects = self._convert_from_pandas(dia_objects)
idFactoryDiff = afwTable.IdFactory.makeSource( diffim.getInfo().getVisitInfo().getExposureId(), afwTable.IdFactory.computeReservedFromMaxBits(int(expIdBits)))
diffForcedSources = self.forcedMeasurement.generateMeasCat( diffim, afw_dia_objects, diffim.getWcs(), idFactory=idFactoryDiff) self.forcedMeasurement.run( diffForcedSources, diffim, afw_dia_objects, diffim.getWcs())
directForcedSources = self.forcedMeasurement.generateMeasCat( exposure, afw_dia_objects, exposure.getWcs()) self.forcedMeasurement.run( directForcedSources, exposure, afw_dia_objects, exposure.getWcs())
output_forced_sources = self._calibrate_and_merge(diffForcedSources, directForcedSources, diffim, exposure) apdb.storeDiaForcedSources(output_forced_sources)
return output_forced_sources
"""Create minimal schema SourceCatalog from a pandas DataFrame.
We need a catalog of this type to run within the forced measurement subtask.
Parameters ---------- input_objects : `pandas.DataFrame` DiaObjects with locations and ids. ``
Returns ------- outputCatalog : `lsst.afw.table.SourceTable` Output catalog with minimal schema. """ schema = afwTable.SourceTable.makeMinimalSchema()
outputCatalog = afwTable.SourceCatalog(schema) outputCatalog.reserve(len(input_objects))
for obj_id, df_row in input_objects.iterrows(): outputRecord = outputCatalog.addNew() outputRecord.setId(obj_id) outputRecord.setCoord( geom.SpherePoint(df_row["ra"], df_row["decl"], geom.degrees)) return outputCatalog
diff_sources, direct_sources, diff_exp, direct_exp): """Take the two output catalogs from the ForcedMeasurementTasks and calibrate, combine, and convert them to Pandas.
Parameters ---------- diff_sources : `lsst.afw.table.SourceTable` Catalog with PsFluxes measured on the difference image. direct_sources : `lsst.afw.table.SourceTable` Catalog with PsfFluxes measured on the direct (calexp) image. diff_exp : `lsst.afw.image.Exposure` Difference exposure ``diff_sources`` were measured on. direct_exp : `lsst.afw.image.Exposure` Direct (calexp) exposure ``direct_sources`` were measured on.
Returns ------- output_catalog : `pandas.DataFrame` Catalog calibrated diaForcedSources. """ diff_calib = diff_exp.getPhotoCalib() direct_calib = direct_exp.getPhotoCalib()
diff_fluxes = diff_calib.instFluxToNanojansky(diff_sources, "slot_PsfFlux") direct_fluxes = direct_calib.instFluxToNanojansky(direct_sources, "slot_PsfFlux")
output_catalog = diff_sources.asAstropy().to_pandas() output_catalog.rename(columns={"id": "diaForcedSourceId", "slot_PsfFlux_instFlux": "psFlux", "slot_PsfFlux_instFluxErr": "psFluxErr", "slot_Centroid_x": "x", "slot_Centroid_y": "y"}, inplace=True) output_catalog.loc[:, "psFlux"] = diff_fluxes[:, 0] output_catalog.loc[:, "psFluxErr"] = diff_fluxes[:, 1]
output_catalog["totFlux"] = direct_fluxes[:, 0] output_catalog["totFluxErr"] = direct_fluxes[:, 1]
visit_info = direct_exp.getInfo().getVisitInfo() ccdVisitId = visit_info.getExposureId() midPointTaiMJD = visit_info.getDate().get(system=DateTime.MJD) output_catalog["ccdVisitId"] = ccdVisitId output_catalog["midPointTai"] = midPointTaiMJD
# Drop superfluous columns from output DataFrame. output_catalog.drop(columns=self.config.dropColumns, inplace=True)
return output_catalog |