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
17 changes: 17 additions & 0 deletions python/lsst/ap/association/packageAlerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ def run(self,
self._patchDiaSources(diaSrcHistory)
detector = diffIm.detector.getId()
visit = diffIm.visitInfo.id
observation_reason = diffIm.visitInfo.getObservationReason()
target_name = diffIm.visitInfo.getObject()
midpoint_unix = diffIm.visitInfo.date.toAstropy().tai.unix
exposure_time = diffIm.visitInfo.exposureTime
diffImPhotoCalib = diffIm.getPhotoCalib()
Expand Down Expand Up @@ -347,6 +349,8 @@ def run(self,

alerts.append(
self.makeAlertDict(diaSource["diaSourceId"],
observation_reason,
target_name,
diaSource,
diaObject,
objSourceHistory,
Expand Down Expand Up @@ -584,6 +588,8 @@ def makeLocalTransformMatrix(self, wcs, center, skyCenter):

def makeAlertDict(self,
diaSourceId,
observationReason,
targetName,
diaSource,
diaObject,
objDiaSrcHistory,
Expand All @@ -600,6 +606,10 @@ def makeAlertDict(self,
Unique identifier of the triggering diaSource
diaSource : `pandas.DataFrame`
New single DiaSource to package.
observationReason : `str`
Scheduler reason for the image containing this diaSource.
targetName : `str`
Scheduler target for the image containing this diaSource.
diaObject : `pandas.DataFrame`
DiaObject that ``diaSource`` is matched to.
objDiaSrcHistory : `pandas.DataFrame`
Expand All @@ -618,6 +628,13 @@ def makeAlertDict(self,
"""
alert = dict()
alert['diaSourceId'] = diaSourceId
# alerts should have NULL if scheduler fields are not populated
if not len(observationReason):
observationReason = None
if not len(targetName):
targetName = None
alert['observation_reason'] = observationReason
alert['target_name'] = targetName
alert['diaSource'] = diaSource.to_dict()

if objDiaSrcHistory is None:
Expand Down
34 changes: 33 additions & 1 deletion tests/test_packageAlerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,17 +383,21 @@ def testMakeAlertDict(self):
objForcedSources = self.diaForcedSources.loc[srcIdx[0]]
alert = packageAlerts.makeAlertDict(
dia_source_id,
self.exposure.visitInfo.getObservationReason(),
self.exposure.visitInfo.getObject(),
diaSource,
self.diaObjects.loc[srcIdx[0]],
objSources,
objForcedSources,
ccdCutout,
ccdCutout,
ccdCutout)
self.assertEqual(len(alert), 11)
self.assertEqual(len(alert), 13)

self.assertEqual(alert["diaSourceId"], dia_source_id)
self.assertEqual(alert["diaSource"], diaSource.to_dict())
self.assertIsNone(alert["observation_reason"])
self.assertIsNone(alert["target_name"])
self.assertEqual(alert["cutoutDifference"],
cutoutBytes)
self.assertEqual(alert["cutoutScience"],
Expand All @@ -407,6 +411,34 @@ def testMakeAlertDict(self):
self.assertAlmostEqual(science_cutout.header["ROTPA"],
template_cutout.header["ROTPA"])

def testMakeAlertDictSchedulerFields(self):
"""Test non-null scheduler fields pass through as expected.

"""
packageAlerts = PackageAlertsTask()
dia_source_id = 1234

for srcIdx, diaSource in self.diaSources.iterrows():
objSources = self.diaSourceHistory.loc[srcIdx[0]]
objForcedSources = self.diaForcedSources.loc[srcIdx[0]]
obs_reason = f"obs_reason_{srcIdx}",
target = f"target_name_{srcIdx}",
alert = packageAlerts.makeAlertDict(
dia_source_id,
obs_reason,
target,
diaSource,
self.diaObjects.loc[srcIdx[0]],
objSources,
objForcedSources,
None,
None,
None)
self.assertEqual(len(alert), 13)

self.assertEqual(alert["observation_reason"], obs_reason)
self.assertEqual(alert["target_name"], target)

def testCutoutRotpa(self):
"""Test that the ROTPA header keyword matches the boresightRotAngle from visitInfo.
"""
Expand Down