Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-37196: Update fields to reflect new APDB schema #785

Merged
merged 5 commits into from
Jun 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions python/lsst/pipe/tasks/computeExposureSummaryStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ComputeExposureSummaryStatsTask(pipeBase.Task):
- psfIyy
- psfIxy
- ra
- decl
- dec
- zenithDistance
- zeroPoint
- skyBg
Expand Down Expand Up @@ -318,7 +318,7 @@ def update_wcs_stats(self, summary, wcs, bbox, visitInfo):
summary.raCorners = [nan]*4
summary.decCorners = [nan]*4
summary.ra = nan
summary.decl = nan
summary.dec = nan
summary.zenithDistance = nan

if wcs is None:
Expand All @@ -330,7 +330,7 @@ def update_wcs_stats(self, summary, wcs, bbox, visitInfo):

sph_pt = wcs.pixelToSky(bbox.getCenter())
summary.ra = sph_pt.getRa().asDegrees()
summary.decl = sph_pt.getDec().asDegrees()
summary.dec = sph_pt.getDec().asDegrees()

date = visitInfo.getDate()

Expand All @@ -347,7 +347,7 @@ def update_wcs_stats(self, summary, wcs, bbox, visitInfo):
location=loc, format='mjd')
coord = SkyCoord(
summary.ra*units.degree,
summary.decl*units.degree,
summary.dec*units.degree,
obstime=obstime,
location=loc,
)
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/pipe/tasks/drpAssociationPipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def run(self,
assocDiaSourceTable=assocResult.assocDiaSources)

def _addDiaObjectCoords(self, objects, sources):
obj = objects[['ra', 'decl']].rename(columns={"ra": "coord_ra", "decl": "coord_dec"})
obj = objects[['ra', 'dec']].rename(columns={"ra": "coord_ra", "dec": "coord_dec"})
df = pd.merge(sources.reset_index(), obj, left_on='diaObjectId', right_index=True,
how='inner').set_index('diaSourceId')
return df
Expand All @@ -252,6 +252,6 @@ def _trimToPatch(self, cat, innerPatchBox, wcs):
isInPatch = np.array([
innerPatchBox.contains(
wcs.skyToPixel(
geom.SpherePoint(row["ra"], row["decl"], geom.degrees)))
geom.SpherePoint(row["ra"], row["dec"], geom.degrees)))
for idx, row in cat.iterrows()])
return isInPatch
10 changes: 5 additions & 5 deletions python/lsst/pipe/tasks/functors.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,23 +710,23 @@ class in case it may be useful for something else.
htmLevel = 20
_radians = True

def __init__(self, ra, decl, **kwargs):
def __init__(self, ra, dec, **kwargs):
self.pixelator = sphgeom.HtmPixelization(self.htmLevel)
self.ra = ra
self.decl = decl
self._columns = [self.ra, self.decl]
self.dec = dec
self._columns = [self.ra, self.dec]
super().__init__(**kwargs)

def _func(self, df):

def computePixel(row):
if self._radians:
sphPoint = geom.SpherePoint(row[self.ra],
row[self.decl],
row[self.dec],
geom.radians)
else:
sphPoint = geom.SpherePoint(row[self.ra],
row[self.decl],
row[self.dec],
geom.degrees)
return self.pixelator.index(sphPoint.getVector())

Expand Down
2 changes: 1 addition & 1 deletion python/lsst/pipe/tasks/isolatedStarAssociation.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class IsolatedStarAssociationConfig(pipeBase.PipelineTaskConfig,
dec_column = pexConfig.Field(
doc='Name of column with declination.',
dtype=str,
default='decl',
default='dec',
)
physical_filter_column = pexConfig.Field(
doc='Name of column with physical filter name',
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/pipe/tasks/matchFakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _processFakes(self, fakeCat, diffIm, associatedDiaSources):
trimmedFakes[self.config.dec_col])
diaSrcVects = self._getVectors(
np.radians(associatedDiaSources.loc[:, "ra"]),
np.radians(associatedDiaSources.loc[:, "decl"]))
np.radians(associatedDiaSources.loc[:, "dec"]))

diaSrcTree = cKDTree(diaSrcVects)
dist, idxs = diaSrcTree.query(
Expand Down
15 changes: 13 additions & 2 deletions python/lsst/pipe/tasks/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def run(self, catalog, ccdVisitId=None, **kwargs):
self.log.info("Generating DataFrame from src catalog ccdVisitId=%s", ccdVisitId)
df = catalog.asAstropy().to_pandas().set_index('id', drop=True)
df['ccdVisitId'] = ccdVisitId

return pipeBase.Struct(table=df)


Expand Down Expand Up @@ -1448,7 +1449,7 @@ def run(self, visitSummaryRefs):

ccdEntry = {}
summaryTable = visitSummary.asAstropy()
selectColumns = ['id', 'visit', 'physical_filter', 'band', 'ra', 'decl', 'zenithDistance',
selectColumns = ['id', 'visit', 'physical_filter', 'band', 'ra', 'dec', 'zenithDistance',
'zeroPoint', 'psfSigma', 'skyBg', 'skyNoise',
'astromOffsetMean', 'astromOffsetStd', 'nPsfStar',
'psfStarDeltaE1Median', 'psfStarDeltaE2Median',
Expand All @@ -1462,6 +1463,11 @@ def run(self, visitSummaryRefs):
# Technically you should join to get the visit from the visit
# table.
ccdEntry = ccdEntry.rename(columns={"visit": "visitId"})

# RFC-924: Temporarily keep a duplicate "decl" entry for backwards
# compatibility. To be removed after September 2023.
ccdEntry["decl"] = ccdEntry.loc[:, "dec"]

ccdEntry['ccdVisitId'] = [
self.config.idGenerator.apply(
visitSummaryRef.dataId,
Expand Down Expand Up @@ -1566,7 +1572,12 @@ def run(self, visitSummaries):
visitEntry["band"] = visitRow['band']
raDec = visitInfo.getBoresightRaDec()
visitEntry["ra"] = raDec.getRa().asDegrees()
visitEntry["decl"] = raDec.getDec().asDegrees()
visitEntry["dec"] = raDec.getDec().asDegrees()

# RFC-924: Temporarily keep a duplicate "decl" entry for backwards
# compatibility. To be removed after September 2023.
visitEntry["decl"] = visitEntry["dec"]

visitEntry["skyRotation"] = visitInfo.getBoresightRotAngle().asDegrees()
azAlt = visitInfo.getBoresightAzAlt()
visitEntry["azimuth"] = azAlt.getLongitude().asDegrees()
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/pipe/tasks/selectImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,8 @@ def doesIntersectPolygon(self, visitSummary, polygon):
for detectorSummary in visitSummary:
if (np.all(np.isfinite(detectorSummary['raCorners']))
and np.all(np.isfinite(detectorSummary['decCorners']))):
corners = [lsst.geom.SpherePoint(ra, decl, units=lsst.geom.degrees).getVector()
for (ra, decl) in
corners = [lsst.geom.SpherePoint(ra, dec, units=lsst.geom.degrees).getVector()
for (ra, dec) in
zip(detectorSummary['raCorners'], detectorSummary['decCorners'])]
detectorPolygon = lsst.sphgeom.ConvexPolygon.convexHull(corners)
if detectorPolygon.intersects(polygon):
Expand Down
24 changes: 12 additions & 12 deletions python/lsst/pipe/tasks/simpleAssociation.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def run(self, diaSources, tractPatchId=None, skymapBits=None, idGenerator=None):
for diaSourceId, diaSrc in ccdVisitSources.iterrows():
# Find matches.
matchResult = self.findMatches(diaSrc["ra"],
diaSrc["decl"],
diaSrc["dec"],
2*self.config.tolerance,
healPixIndices,
diaObjectCat)
Expand Down Expand Up @@ -204,7 +204,7 @@ def run(self, diaSources, tractPatchId=None, skymapBits=None, idGenerator=None):

objs = diaObjectCat if diaObjectCat else np.array([], dtype=[('diaObjectId', 'int64'),
('ra', 'float64'),
('decl', 'float64'),
('dec', 'float64'),
('nDiaSources', 'int64')])
diaObjects = pd.DataFrame(data=objs)

Expand Down Expand Up @@ -251,18 +251,18 @@ def addNewDiaObject(self,
"""
hpIndex = toIndex(self.config.nside,
diaSrc["ra"],
diaSrc["decl"])
diaSrc["dec"])
healPixIndices.append(hpIndex)

sphPoint = geom.SpherePoint(diaSrc["ra"],
diaSrc["decl"],
diaSrc["dec"],
geom.degrees)
diaObjCoords.append([sphPoint])

diaObjId = idCat.addNew().get("id")
diaObjCat.append(self.createDiaObject(diaObjId,
diaSrc["ra"],
diaSrc["decl"]))
diaSrc["dec"]))
diaSources.loc[(ccdVisit, diaSourceId), "diaObjectId"] = diaObjId

def updateCatalogs(self,
Expand Down Expand Up @@ -301,17 +301,17 @@ def updateCatalogs(self,
"""
# Update location and healPix index.
sphPoint = geom.SpherePoint(diaSrc["ra"],
diaSrc["decl"],
diaSrc["dec"],
geom.degrees)
diaObjCoords[matchIndex].append(sphPoint)
aveCoord = geom.averageSpherePoint(diaObjCoords[matchIndex])
diaObjCat[matchIndex]["ra"] = aveCoord.getRa().asDegrees()
diaObjCat[matchIndex]["decl"] = aveCoord.getDec().asDegrees()
diaObjCat[matchIndex]["dec"] = aveCoord.getDec().asDegrees()
nSources = diaObjCat[matchIndex]["nDiaSources"]
diaObjCat[matchIndex]["nDiaSources"] = nSources + 1
healPixIndices[matchIndex] = toIndex(self.config.nside,
diaObjCat[matchIndex]["ra"],
diaObjCat[matchIndex]["decl"])
diaObjCat[matchIndex]["dec"])
# Update DiaObject Id that this source is now associated to.
diaSources.loc[(ccdVisit, diaSourceId), "diaObjectId"] = \
diaObjCat[matchIndex]["diaObjectId"]
Expand Down Expand Up @@ -358,13 +358,13 @@ def findMatches(self, src_ra, src_dec, tol, hpIndices, diaObjs):
dists = np.array(
[np.sqrt(np.sum((eq2xyz(src_ra, src_dec)
- eq2xyz(diaObjs[match]["ra"],
diaObjs[match]["decl"]))**2))
diaObjs[match]["dec"]))**2))
for match in matchIndices])
return pipeBase.Struct(
dists=dists,
matches=matchIndices)

def createDiaObject(self, objId, ra, decl):
def createDiaObject(self, objId, ra, dec):
"""Create a simple empty DiaObject with location and id information.

Parameters
Expand All @@ -373,7 +373,7 @@ def createDiaObject(self, objId, ra, decl):
Unique ID for this new DiaObject.
ra : `float`
RA location of this DiaObject.
decl : `float`
dec : `float`
Dec location of this DiaObject

Returns
Expand All @@ -383,6 +383,6 @@ def createDiaObject(self, objId, ra, decl):
"""
new_dia_object = {"diaObjectId": objId,
"ra": ra,
"decl": decl,
"dec": dec,
"nDiaSources": 1}
return new_dia_object
8 changes: 8 additions & 0 deletions schemas/Object.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ funcs:
functor: CoordColumn
args: coord_ra
dataset: meas
dec:
functor: CoordColumn
args: coord_dec
dataset: meas

# RFC-924: Temporarily keep a duplicate "decl" entry for backwards
# compatibility. To be removed after September 2023.
decl:
functor: CoordColumn
args: coord_dec
dataset: meas

# raErr: not available yet DM-15180
# decErr: not available yet DM-15180
# Reference band is same for all measurements
Expand Down
10 changes: 8 additions & 2 deletions schemas/Source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ funcs:
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
# declErr: not available yet DM-15180
# ra_decl_Cov: not available yet

# decErr: not available yet DM-15180
# ra_dec_Cov: not available yet
# One calibrated Calib flux is important:
calibFlux:
functor: LocalNanojansky
Expand Down
2 changes: 1 addition & 1 deletion tests/surveyPropertyMapsTestUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def makeMockVisitSummary(visit,
row['decCorners'] = np.array([float(sph.getDec().asDegrees()) for sph in sph_pts])
sph_pt = wcs.pixelToSky(bbox.getCenter())
row['ra'] = sph_pt.getRa().asDegrees()
row['decl'] = sph_pt.getDec().asDegrees()
row['dec'] = sph_pt.getDec().asDegrees()

# Generate a visitInfo.
# This does not need to be consistent with the zenith angle in the table,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_computeExposureSummaryStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def testComputeExposureSummary(self):
self.assertFloatsAlmostEqual(a, b, atol=1e-10)

self.assertFloatsAlmostEqual(summary.ra, raCenter.asDegrees(), atol=1e-10)
self.assertFloatsAlmostEqual(summary.decl, decCenter.asDegrees(), atol=1e-10)
self.assertFloatsAlmostEqual(summary.dec, decCenter.asDegrees(), atol=1e-10)

self.assertFloatsAlmostEqual(summary.zeroPoint, zp)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_drpAssociationPipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def setUp(self):
x + 10 * self.innerPatchBox.getWidth(),
y + 10 * self.innerPatchBox.getHeight())
dataIn.append({"ra": coordIn.getRa().asDegrees(),
"decl": coordIn.getDec().asDegrees()})
"dec": coordIn.getDec().asDegrees()})
dataOut.append({"ra": coordOut.getRa().asDegrees(),
"decl": coordOut.getDec().asDegrees()})
"dec": coordOut.getDec().asDegrees()})

self.diaSrcCatIn = pd.DataFrame(data=dataIn)
self.diaSrcCatOut = pd.DataFrame(data=dataOut)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_finalizeCharacterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _make_isocats(self):
"""
dtype_cat = [('isolated_star_id', 'i8'),
('ra', 'f8'),
('decl', 'f8'),
('dec', 'f8'),
('primary_band', 'U2'),
('source_cat_index', 'i4'),
('nsource', 'i4'),
Expand Down Expand Up @@ -105,7 +105,7 @@ def _make_isocats(self):
cat = np.zeros(nstar, dtype=dtype_cat)
cat['isolated_star_id'] = tract*nstar + np.arange(nstar)
cat['ra'] = ra
cat['decl'] = dec
cat['dec'] = dec
if tract < 2:
cat['primary_band'][0: 100] = 'i'
cat['primary_band'][100:] = 'r'
Expand Down