Skip to content

Commit

Permalink
Set day_obs_offset in Instrument to be consistent with translator
Browse files Browse the repository at this point in the history
The translator already had a ROLLOVER TIME used to calculate
observing_day if it was not found in the header.
  • Loading branch information
timj committed Feb 16, 2024
1 parent 2856c2d commit f002937
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
20 changes: 20 additions & 0 deletions python/lsst/obs/lsst/_instrument.py
Expand Up @@ -46,6 +46,17 @@
PACKAGE_DIR = getPackageDir("obs_lsst")


class classproperty: # noqa: N801
"""Simple decorator that can emulate a class property.
"""

def __init__(self, func):
self.fget = func

def __get__(self, instance, owner):
return self.fget(owner)


class LsstCam(Instrument):
"""Gen3 Butler specialization for the LSST Main Camera.
Expand Down Expand Up @@ -89,6 +100,15 @@ class LsstCam(Instrument):
obsDataPackage = "obs_lsst_data"
visitSystem = VisitSystem.BY_SEQ_START_END

@classproperty
def day_obs_offset(cls) -> int: # noqa: N805
"""Offset to use when calculating day_obs.
Do not cache for now. Need to ensure that subclass values do not
get overridden by the value from this class.
"""
return round(cls.translatorClass._ROLLOVER_TIME.to_value("s"))

@property
def configPaths(self):
return [os.path.join(PACKAGE_DIR, "config"),
Expand Down
4 changes: 4 additions & 0 deletions python/lsst/obs/lsst/translators/imsim.py
Expand Up @@ -15,6 +15,7 @@
import logging
import astropy.units as u
from astropy.coordinates import Angle, AltAz
from astropy.time import TimeDelta

try:
import erfa
Expand Down Expand Up @@ -58,6 +59,9 @@ class LsstCamImSimTranslator(LsstSimTranslator):

cameraPolicyFile = "policy/imsim.yaml"

_ROLLOVER_TIME = TimeDelta(0, scale="tai", format="sec")
"""This instrument did not offset the observing day."""

@classmethod
def can_translate(cls, header, filename=None):
"""Indicate whether this translation class can translate the
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/obs/lsst/translators/lsst.py
Expand Up @@ -178,7 +178,8 @@ class LsstBaseTranslator(FitsTranslator):

_ROLLOVER_TIME = TimeDelta(12*60*60, scale="tai", format="sec")
"""Time delta for the definition of a Rubin Observatory start of day.
Used when the header is missing. See LSE-400 for details."""
Used when the header is missing. See LSE-400 or SITCOMTN-032 for details.
"""

@classmethod
def __init_subclass__(cls, **kwargs):
Expand Down
4 changes: 4 additions & 0 deletions python/lsst/obs/lsst/translators/lsst_ucdcam.py
Expand Up @@ -14,6 +14,7 @@

import logging
import astropy.units as u
from astropy.time import TimeDelta

from .lsst import LsstBaseTranslator

Expand Down Expand Up @@ -58,6 +59,9 @@ class LsstUCDCamTranslator(LsstBaseTranslator):

cameraPolicyFile = "policy/ucd.yaml"

_ROLLOVER_TIME = TimeDelta(0, scale="tai", format="sec")
"""This instrument did not offset the observing day."""

@classmethod
def can_translate(cls, header, filename=None):
"""Indicate whether this translation class can translate the
Expand Down
4 changes: 4 additions & 0 deletions python/lsst/obs/lsst/translators/phosim.py
Expand Up @@ -18,6 +18,7 @@
import astropy.units as u
import astropy.units.cds as cds
from astropy.coordinates import Angle
from astropy.time import TimeDelta

from astro_metadata_translator import cache_translation, merge_headers
from astro_metadata_translator.translators.helpers import (
Expand Down Expand Up @@ -62,6 +63,9 @@ class LsstCamPhoSimTranslator(LsstSimTranslator):

cameraPolicyFile = "policy/phosim.yaml"

_ROLLOVER_TIME = TimeDelta(0, scale="tai", format="sec")
"""This instrument did not offset the observing day."""

@classmethod
def can_translate(cls, header, filename=None):
"""Indicate whether this translation class can translate the
Expand Down
6 changes: 6 additions & 0 deletions tests/test_gen3.py
Expand Up @@ -28,6 +28,7 @@

import numpy as np

from astropy.time import TimeDelta
from astro_metadata_translator import ObservationInfo
from lsst.obs.lsst import (LsstCam, LsstComCam, LsstCamImSim, LsstCamPhoSim,
LsstTS8, LsstTS3, LsstUCDCam, Latiss, LsstComCamSim,
Expand Down Expand Up @@ -134,6 +135,11 @@ def checkInstrumentWithRegistry(self, cls, testRaw):
self.assertEqual(cameraGeomDetector.getName(), cameraGeomDetector2.getName())
self.assertEqual(cameraGeomDetector.getSerial(), cameraGeomDetector2.getSerial())

# Check that the day_obs offset in the Instrument is consistent with
# the translator rollover time.
self.assertEqual(TimeDelta(instrument.day_obs_offset, format="sec", scale="tai"),
cls.translatorClass._ROLLOVER_TIME)

def testLsstCam(self):
testFpath = "lsstCam/raw/2019-03-22/3019032200002/3019032200002-R10-S22-det035.fits"
self.checkInstrumentWithRegistry(LsstCam, testFpath)
Expand Down

0 comments on commit f002937

Please sign in to comment.