Skip to content

Commit

Permalink
Propagate coordinate covariance in catalogs
Browse files Browse the repository at this point in the history
  • Loading branch information
cmsaunders committed Sep 14, 2023
1 parent 80d919d commit 59eea10
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 10 deletions.
1 change: 1 addition & 0 deletions python/lsst/pipe/tasks/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ def __init__(self, astromRefObjLoader=None,
else:
self.schemaMapper = None
self.schema = afwTable.SourceTable.makeMinimalSchema()
afwTable.CoordKey.addErrorFields(self.schema)
self.makeSubtask('detection', schema=self.schema)

self.algMetadata = dafBase.PropertyList()
Expand Down
1 change: 1 addition & 0 deletions python/lsst/pipe/tasks/calibrateImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def __init__(self, initial_stars_schema=None, **kwargs):
# star measurement subtasks
if initial_stars_schema is None:
initial_stars_schema = afwTable.SourceTable.makeMinimalSchema()
afwTable.CoordKey.addErrorFields(initial_stars_schema)
self.makeSubtask("star_detection", schema=initial_stars_schema)
self.makeSubtask("star_deblend", schema=initial_stars_schema)
self.makeSubtask("star_measurement", schema=initial_stars_schema)
Expand Down
34 changes: 34 additions & 0 deletions python/lsst/pipe/tasks/functors.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,40 @@ def __call__(self, catalog, **kwargs):
return super().__call__(catalog, **kwargs)


class RAErrColumn(CoordColumn):
"""Uncertainty in Right Ascension, in degrees."""
name = 'RAErr'
_defaultNoDup = True

def __init__(self, **kwargs):
super().__init__('coord_raErr', **kwargs)


class DecErrColumn(CoordColumn):
"""Uncertainty in declination, in degrees."""
name = 'DecErr'
_defaultNoDup = True

def __init__(self, **kwargs):
super().__init__('coord_decErr', **kwargs)


class RADecCovColumn(Column):
"""Coordinate covariance column, in degrees."""
_radians = True
name = 'RADecCov'
_defaultNoDup = True

def __init__(self, **kwargs):
super().__init__('coord_ra_dec_Cov', **kwargs)

def _func(self, df):
# Must not modify original column in case that column is used by
# another functor.
output = df[self.col]*(180/np.pi)**2 if self._radians else df[self.col]
return output


class HtmIndex20(Functor):
"""Compute the level 20 HtmIndex for the catalog.
Expand Down
1 change: 1 addition & 0 deletions python/lsst/pipe/tasks/multiBand.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ def __init__(self, schema=None, peakSchema=None, refObjLoader=None, initInputs=N
self.schemaMapper = afwTable.SchemaMapper(schema)
self.schemaMapper.addMinimalSchema(schema)
self.schema = self.schemaMapper.getOutputSchema()
afwTable.CoordKey.addErrorFields(self.schema)
self.algMetadata = PropertyList()
self.makeSubtask("measurement", schema=self.schema, algMetadata=self.algMetadata)
self.makeSubtask("setPrimaryFlags", schema=self.schema)
Expand Down
26 changes: 24 additions & 2 deletions schemas/Object.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ funcs:
# coord_dec because "dec" is reserved in most SQL DBs
functor: DecColumn
dataset: ref
coord_raErr:
# error in reference position for merged "ref" cat.
functor: RAErrColumn
dataset: ref
coord_decErr:
# error in reference position for merged "ref" cat.
functor: DecErrColumn
dataset: ref
coord_ra_dec_Cov:
# covariance in reference position for merged "ref" cat.
functor: RADecCovColumn
dataset: ref
ra:
functor: CoordColumn
args: coord_ra
Expand All @@ -34,8 +46,18 @@ funcs:
args: coord_dec
dataset: meas

# raErr: not available yet DM-15180
# decErr: not available yet DM-15180
raErr:
functor: RAErrColumn
dataset: meas
noDup: False
decErr:
functor: DecErrColumn
dataset: meas
noDup: False
ra_dec_Cov:
functor: RADecCovColumn
dataset: meas
noDup: False
# Reference band is same for all measurements
refBand:
functor: ReferenceBand
Expand Down
11 changes: 7 additions & 4 deletions schemas/Source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,20 @@ funcs:
# x_y_Cov: not available
ra:
functor: RAColumn
# raErr: not available yet DM-15180
dec:
functor: DecColumn

# RFC-924: Temporarily keep a duplicate "decl" entry for backwards
# compatibility. To be removed after September 2023.
decl:
functor: DecColumn

# decErr: not available yet DM-15180
# ra_dec_Cov: not available yet

raErr:
functor: RAErrColumn
decErr:
functor: DecErrColumn
ra_dec_Cov:
functor: RADecCovColumn
# One calibrated Calib flux is important:
calibFlux:
functor: LocalNanojansky
Expand Down
6 changes: 2 additions & 4 deletions tests/test_calibrateImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ def setUp(self):
dataset.addSource(instFlux=500*noise*psf_scale, centroid=center, shape=shape)

schema = dataset.makeMinimalSchema()
schema.addField("truth_flux", type=np.float64, doc="true flux", units="nJy")
schema.addField("truth_fluxErr", type=np.float64, doc="true fluxErr", units="nJy")

self.truth_exposure, self.truth_cat = dataset.realize(noise=noise, schema=dataset.makeMinimalSchema())
afwTable.CoordKey.addErrorFields(schema)
self.truth_exposure, self.truth_cat = dataset.realize(noise=noise, schema=schema)
lsst.afw.table.updateSourceCoords(self.truth_exposure.wcs, self.truth_cat)
# To make it look like a version=1 (nJy fluxes) refcat
self.truth_cat = self.truth_exposure.photoCalib.calibrateCatalog(self.truth_cat)
Expand Down

0 comments on commit 59eea10

Please sign in to comment.