Skip to content

Commit

Permalink
Force all user-facing dates to be TAI.
Browse files Browse the repository at this point in the history
  • Loading branch information
czwa committed Jul 31, 2024
1 parent c0e3234 commit d195487
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 34 deletions.
42 changes: 17 additions & 25 deletions python/lsst/cp/pipe/utilsEfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ def selectTimeSeries(self, topicName, fields=[], startDate=None, endDate=None):
List of fields to return. If empty, all fields are
returned.
startDate : `astropy.time.Time`, optional
Start date (in UTC) to limit the results returned.
Start date (in TAI) to limit the results returned.
endDate : `astropy.time.Time`, optional
End date (in UTC) to limit the results returned.
End date (in TAI) to limit the results returned.
Returns
-------
Expand Down Expand Up @@ -207,15 +207,15 @@ def selectTimeSeries(self, topicName, fields=[], startDate=None, endDate=None):
# monotonic (and is in UTC). "private_sndStamp" comes from
# the device itself, and is therefore preferred.
table = Table(rows=series["values"], names=series["columns"], dtype=tableDtype)
table["time"] = Time(table["time"], scale="utc")
table["time"] = Time(table["time"], scale="utc").tai
table.sort("time")
if "private_sndStamp" in table.columns:
table["private_sndStamp"] = Time(table["private_sndStamp"], format="unix_tai")
table.sort("private_sndStamp")

return table

def searchResults(self, data, dateStr, scale="tai"):
def searchResults(self, data, dateStr):
"""Find the row entry in ``data`` immediately preceding the specified
date.
Expand All @@ -224,17 +224,15 @@ def searchResults(self, data, dateStr, scale="tai"):
data : `astropy.table.Table`
The table of results from the EFD.
dateStr : `str`
The date to look up in the status for.
scale : `str`, optional
Time scale to use. Default is "tai".
The date (in TAI) to look up in the status for.
Returns
-------
result = `astropy.table.Row`
The row of the data table corresponding to ``dateStr``.
"""
dateValue = Time(dateStr, format="isot", scale=scale)
# Table is now sorted on "time", which is in UTC.
dateValue = Time(dateStr, scale='tai', format="isot")
# Table is now sorted on "time", which is in TAI.

# Check that the date we want to consider is contained in the
# EFD data.
Expand Down Expand Up @@ -277,9 +275,9 @@ def getEfdMonochromatorData(self, dataSeries=None, dateMin=None, dateMax=None):
dataSeries : `str`, optional
Data series to request from the EFD.
dateMin : `str`, optional
Minimum date to retrieve from EFD.
Minimum date (in TAI) to retrieve from EFD.
dateMax : `str`, optional
Maximum date to retrieve from EFD.
Maximum date (in TAI) to retrieve from EFD.
Returns
-------
Expand Down Expand Up @@ -310,12 +308,12 @@ def parseMonochromatorStatus(self, data, dateStr):
data : `astropy.table.Table`
The dataframe of monochromator results from the EFD.
dateStr : `str`
The date to look up in the status for.
The date (in TAI) to look up in the status for.
Returns
-------
indexDate : `str`
Date string indicating the monochromator state change.
Date string (in TAI) indicating the monochromator state change.
wavelength : `float`
Monochromator commanded peak.
"""
Expand All @@ -331,9 +329,9 @@ def getEfdElectrometerData(self, dataSeries=None, dateMin=None, dateMax=None):
dataSeries : `str`, optional
Data series to request from the EFD.
dateMin : `str`, optional
Minimum date to retrieve from EFD.
Minimum date (in TAI) to retrieve from EFD.
dateMax : `str`, optional
Maximum date to retrieve from EFD.
Maximum date (in TAI) to retrieve from EFD.
Returns
-------
Expand Down Expand Up @@ -434,7 +432,7 @@ def parseElectrometerStatus(self, data, dateStr, dateEnd=None,
Parameters
----------
data : `astropy.table.Table`
The dataframe of monochromator results from the EFD.
The dataframe of electrometer results from the EFD.
dateStr : `str`
The date to look up in the status for.
dateEnd : `str`
Expand All @@ -449,23 +447,17 @@ def parseElectrometerStatus(self, data, dateStr, dateEnd=None,
Returns
-------
indexDate : `str`
Date string indicating the monochromator state change.
Date string (in TAI) indicating the electrometer state
change.
intensity: `float`
Average electrometer intensity.
"""
if index is not None:
mask = (data["salIndex"] == index)
data = data[mask]

if "intensityStd" in data.columns:
# The alternate access method appears to be in UTC, not TAI.
scale = "utc"
else:
scale = "tai"

# searchResults returns the first entry prior to this date
result, idx = self.searchResults(data, dateStr, scale=scale)
result, idx = self.searchResults(data, dateStr)

myTime = result["private_sndStamp"]
myIntensity = result["intensity"]
Expand Down
20 changes: 11 additions & 9 deletions tests/test_utilsEfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@ def test_monochromator(self):
self.assertEqual(indexDate, "2023-12-19T14:37:17.799")

def test_electrometer(self):
data = self.client.getEfdElectrometerData()
data = self.client.getEfdElectrometerData(
dateMin="2024-05-30T00:00:00",
dateMax="2024-05-30T05:00:00",
)

# Test single lookups:
for (iDate, rDate), (iVal, rVal) in zip([("2024-05-30T04:21:48", "2024-05-30T04:22:08"),
for (iDate, rDate), (iVal, rVal) in zip([("2024-05-30T04:21:48.6", "2024-05-30T04:22:08"),
("2024-05-30T04:21:50", "2024-05-30T04:22:10"),
("2024-05-30T04:21:53", "2024-05-30T04:22:13"),
("2024-05-30T04:21:58", "2024-05-30T04:22:18"),
("2024-05-30T04:22:17", "2024-05-30T04:22:37")],
[(-1.8932e-7, -1.5244e-07),
[(-1.5269e-07, -1.5244e-07),
(-1.5168e-07, -1.5137e-07),
(-1.5165e-07, -1.5205e-07),
(-1.5223e-07, -1.5147e-07),
Expand All @@ -77,7 +80,7 @@ def test_electrometer(self):
self.assertFloatsAlmostEqual(intensityReference, rVal, atol=1e-10)

# Test integrated lookups:
iDate = "2024-05-30T04:21:48"
iDate = "2024-05-30T04:21:48.6"
iDateEnd = "2024-05-30T04:22:18"
rDate = "2024-05-30T04:22:08"
rDateEnd = "2024-05-30T04:22:38"
Expand Down Expand Up @@ -110,15 +113,14 @@ def test_electrometer_alternate(self):
dateMax='2024-07-26T20:00:00')

# Test single lookups. These should not be integrated.
for iDate, iVal in zip(["2024-07-26T16:37:55.228",
"2024-07-26T16:38:17.581",
"2024-07-26T16:40:19.579",
"2024-07-26T16:42:21.553"],
for iDate, iVal in zip(["2024-07-26T16:38:32.228",
"2024-07-26T16:38:54.581",
"2024-07-26T16:40:56.579",
"2024-07-26T16:42:58.553"],
[-2.24234e-07,
-2.24388e-07,
-2.24105e-07,
-2.23784e-07]):
# import pdb; pdb.set_trace()
indexDate, intensity, _ = self.client.parseElectrometerStatus(
data,
iDate
Expand Down

0 comments on commit d195487

Please sign in to comment.