Skip to content

Commit

Permalink
Add method to translator for calculating observing day offset
Browse files Browse the repository at this point in the history
This allows the base translator to calculate the observing day.
Need to change some of the dates in tests now that the offset
is being included properly.
  • Loading branch information
timj committed Feb 26, 2024
1 parent eb9e6dd commit 8c7ce12
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
24 changes: 20 additions & 4 deletions python/lsst/obs/lsst/translators/lsst.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,25 @@ def search_paths(self):
"""
return [os.path.join(obs_lsst_packageDir, "corrections")]

@classmethod
def observing_date_to_offset(cls, observing_date: astropy.time.Time) -> astropy.time.TimeDelta | None:
"""Return the offset to use when calculating the observing day.
Parameters
----------
observing_date : `astropy.time.Time`
The date of the observation. Unused.
Returns
-------
offset : `astropy.time.TimeDelta`
The offset to apply. The default implementation returns a fixed
number but subclasses can return a different value depending
on whether the instrument is in the instrument lab or on the
mountain.
"""
return cls._ROLLOVER_TIME

@classmethod
def compute_detector_exposure_id(cls, exposure_id, detector_num):
"""Compute the detector exposure ID from detector number and
Expand Down Expand Up @@ -807,10 +826,7 @@ def to_observing_day(self):
self._used_these_cards("DAYOBS")
return int(self._header["DAYOBS"])

# Calculate it ourselves correcting for the Rubin offset
date = self.to_datetime_begin().tai
date -= self._ROLLOVER_TIME
return int(date.strftime("%Y%m%d"))
return super().to_observing_day()

@cache_translation
def to_observation_counter(self):
Expand Down
34 changes: 34 additions & 0 deletions python/lsst/obs/lsst/translators/lsstCam.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
__all__ = ("LsstCamTranslator", )

import logging

import pytz
import astropy.time
import astropy.units as u

from astro_metadata_translator import cache_translation
Expand All @@ -25,6 +28,8 @@
# Normalized name of the LSST Camera
LSST_CAM = "LSSTCam"

_LSST_CAM_SHIP_DATE = 202406


def is_non_science_or_lab(self):
"""Pseudo method to determine whether this is a lab or non-science
Expand Down Expand Up @@ -157,3 +162,32 @@ def to_physical_filter(self):
joined = joined.removesuffix("~empty")

return joined

@classmethod
def observing_date_to_offset(cls, observing_date: astropy.time.Time) -> astropy.time.TimeDelta | None:
"""Return the offset to use when calculating the observing day.
Parameters
----------
observing_date : `astropy.time.Time`
The date of the observation. Unused.
Returns
-------
offset : `astropy.time.TimeDelta`
The offset to apply. During lab testing the offset is Pacific
Time which can mean UTC-7 or UTC-8 depending on daylight savings.
In Chile the offset is always UTC-12.
"""
# Timezone calculations are slow. Only do this if the instrument
# is in the lab.
if int(observing_date.strftime("%Y%m")) > _LSST_CAM_SHIP_DATE:
return cls._ROLLOVER_TIME # 12 hours in base class

# Convert the date to a datetime UTC.
pacific_tz = pytz.timezone("US/Pacific")
pacific_time = observing_date.utc.to_datetime(timezone=pacific_tz)

# We need the offset to go the other way.
offset = pacific_time.utcoffset() * -1
return astropy.time.TimeDelta(offset)
12 changes: 6 additions & 6 deletions tests/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def test_phosim_translator(self):
observation_id="204595",
observation_type="science",
observation_reason="phosim",
observing_day=20221004,
observing_day=20221005,
physical_filter="i",
pressure=520.0*cds.mmHg,
relative_humidity=40.0,
Expand Down Expand Up @@ -932,7 +932,7 @@ def test_imsim_translator(self):
observation_id="3010002",
observation_type="science", # The header is wrong
observation_reason="imsim",
observing_day=20211231,
observing_day=20220101,
physical_filter="i",
pressure=None,
relative_humidity=40.0,
Expand Down Expand Up @@ -963,7 +963,7 @@ def test_imsim_translator(self):
observation_id="204595",
observation_type="science", # The header is wrong
observation_reason="imsim",
observing_day=20221004,
observing_day=20221005,
physical_filter="i_sim_1.4",
pressure=None,
relative_humidity=40.0,
Expand Down Expand Up @@ -994,7 +994,7 @@ def test_imsim_translator(self):
observation_id="5000007",
observation_type="flat",
observation_reason="imsim",
observing_day=20220805,
observing_day=20220806,
physical_filter="i",
pressure=None,
relative_humidity=40.0,
Expand Down Expand Up @@ -1025,7 +1025,7 @@ def test_imsim_translator(self):
observation_id="4010003",
observation_type="science", # The header is wrong
observation_reason="imsim",
observing_day=20211231,
observing_day=20220101,
physical_filter="i",
pressure=None,
relative_humidity=40.0,
Expand Down Expand Up @@ -1084,7 +1084,7 @@ def test_ts3_translator(self):
observation_id="ITL-3800C-098_lambda_flat_1000_067_20160722020740",
observation_type="flat",
observation_reason="lambda",
observing_day=20160721,
observing_day=20160722,
physical_filter="550CutOn",
science_program="2016-07-22",
visit_id=201607220607067)),
Expand Down

0 comments on commit 8c7ce12

Please sign in to comment.