Skip to content

Commit

Permalink
Merge pull request #63 from lsst-sitcom/tickets/DM-40948
Browse files Browse the repository at this point in the history
DM-40948: Add TMA eventMaker function for getting a specific event
  • Loading branch information
mfisherlevine authored Sep 29, 2023
2 parents eb29332 + 87cecdf commit 273ad40
Show file tree
Hide file tree
Showing 11 changed files with 156,952 additions and 1 deletion.
35 changes: 35 additions & 0 deletions python/lsst/summit/utils/tmaUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,41 @@ def _mergeData(self, data):

return merged

def getEvent(self, dayObs, seqNum):
"""Get a specific event for a given dayObs and seqNum.
Repeated calls for the same ``dayObs`` will use the cached data if the
day is in the past, and so will be much quicker. If the ``dayObs`` is
the current day then the EFD will be queried for new data for each
call, so a call which returns ``None`` on the first try might return an
event on the next, if the TMA is still moving and thus generating
events.
Parameters
----------
dayObs : `int`
The dayObs to get the event for.
seqNum : `int`
The sequence number of the event to get.
Returns
-------
event : `lsst.summit.utils.tmaUtils.TMAEvent`
The event for the specified dayObs and seqNum, or `None` if the
event was not found.
"""
events = self.getEvents(dayObs)
if seqNum <= len(events):
event = events[seqNum]
if event.seqNum != seqNum:
# it's zero-indexed and contiguous so this must be true but
# a sanity check doesn't hurt.
raise AssertionError(f"Event sequence number mismatch: {event.seqNum} != {seqNum}")
return event
else:
self.log.warning(f"Event {seqNum} not found for {dayObs}")
return None

def getEvents(self, dayObs):
"""Get the TMA events for the specified dayObs.
Expand Down
23,826 changes: 23,826 additions & 0 deletions tests/data/cassettes/setUpClass.yaml

Large diffs are not rendered by default.

4,818 changes: 4,818 additions & 0 deletions tests/data/cassettes/test_endToEnd.yaml

Large diffs are not rendered by default.

38,544 changes: 38,544 additions & 0 deletions tests/data/cassettes/test_findEvent.yaml

Large diffs are not rendered by default.

15,246 changes: 15,246 additions & 0 deletions tests/data/cassettes/test_getAxisData.yaml

Large diffs are not rendered by default.

19,054 changes: 19,054 additions & 0 deletions tests/data/cassettes/test_getEvent.yaml

Large diffs are not rendered by default.

4,818 changes: 4,818 additions & 0 deletions tests/data/cassettes/test_helperFunctions.yaml

Large diffs are not rendered by default.

13,746 changes: 13,746 additions & 0 deletions tests/data/cassettes/test_noDataBehaviour.yaml

Large diffs are not rendered by default.

28,080 changes: 28,080 additions & 0 deletions tests/data/cassettes/test_plottingAndCommands.yaml

Large diffs are not rendered by default.

8,760 changes: 8,760 additions & 0 deletions tests/data/cassettes/test_printing.yaml

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion tests/test_tmaUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,13 @@ def test_endToEnd(self):
def test_noDataBehaviour(self):
eventMaker = self.tmaEventMaker
noDataDayObs = 19500101 # do not use 19700101 - there is data for that day!
with self.assertWarns(Warning, msg=f"No EFD data found for dayObs={noDataDayObs}"):
with self.assertLogs(level='WARNING') as cm:
correctMsg = f"No EFD data found for dayObs={noDataDayObs}"
events = eventMaker.getEvents(noDataDayObs)
self.assertIsInstance(events, list)
self.assertEqual(len(events), 0)
msg = cm.output[0]
self.assertIn(correctMsg, msg)

@vcr.use_cassette()
def test_helperFunctions(self):
Expand All @@ -338,6 +341,27 @@ def test_helperFunctions(self):
self.assertEqual(slews, foundSlews)
self.assertEqual(tracks, foundTracks)

@vcr.use_cassette()
def test_getEvent(self):
# test the singular event getter, and what happens if the event doesn't
# exist for the day
eventMaker = self.tmaEventMaker
events = eventMaker.getEvents(self.dayObs)
nEvents = len(events)

event = eventMaker.getEvent(self.dayObs, 0)
self.assertIsInstance(event, TMAEvent)
self.assertEqual(event, events[0])
event = eventMaker.getEvent(self.dayObs, 100)
self.assertIsInstance(event, TMAEvent)
self.assertEqual(event, events[100])

with self.assertLogs(level='WARNING') as cm:
correctMsg = f"Event {nEvents+1} not found for {self.dayObs}"
event = eventMaker.getEvent(self.dayObs, nEvents+1)
msg = cm.output[0]
self.assertIn(correctMsg, msg)

@vcr.use_cassette()
def test_printing(self):
eventMaker = self.tmaEventMaker
Expand Down

0 comments on commit 273ad40

Please sign in to comment.