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-40948: Add TMA eventMaker function for getting a specific event #63

Merged
merged 4 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
call, so a call which returns ```None` on the first try might return an
call, so a call which returns ``None`` on the first try might return an

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And actually, might even just be None I'm fuzzy on the different use cases for single vs double `.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that was supposed to be a single-backquoted None. Not sure how to invoke that with github markdown...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am equally fuzzy 😬 We can certainly both agree that three/one isn't the right format though 😛

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.

24 changes: 23 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,25 @@ 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the API supports it, but could you add self.assertEqual(event, events[0]) ?
And similar for events[100]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it looks like past-Merlin actually did implement __eq__ for these objects, so yes, I'll do that - nice!

event = eventMaker.getEvent(self.dayObs, 100)
self.assertIsInstance(event, TMAEvent)

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