Skip to content

Commit

Permalink
Merge pull request #263 from lsst/tickets/DM-27298
Browse files Browse the repository at this point in the history
DM-27298: Calculate observation_counter and observing_day
  • Loading branch information
timj committed Oct 28, 2020
2 parents a257d2e + 20cf50b commit dfd489e
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 23 deletions.
17 changes: 2 additions & 15 deletions python/lsst/obs/lsst/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from lsst.pipe.tasks.ingestCalibs import CalibsParseTask
from astro_metadata_translator import ObservationInfo
import lsst.log as lsstLog
from .translators.lsst import ROLLOVERTIME
from .translators import LsstCamTranslator
from .lsstCamMapper import LsstCamMapper
from ._fitsHeader import readRawFitsHeader
Expand Down Expand Up @@ -195,20 +194,8 @@ def translate_dayObs(self, md):
dayObs : `str`
The day that the data was taken, e.g. ``1958-02-05``.
"""
# Trust DAYOBS if it is there
if "DAYOBS" in md:
dayObs = str(md.getScalar("DAYOBS"))

if re.match(r"^\d{8}$", dayObs):
dateObs = f"{dayObs[:4]}-{dayObs[4:6]}-{dayObs[6:8]}"
return dateObs

# Try to work it out from date of observation
dateObs = self.observationInfo.datetime_begin
dateObs -= ROLLOVERTIME
dateObs.format = "iso"
dateObs.out_subfmt = "date" # YYYY-MM-DD format
return str(dateObs)
dayObs = str(self.observationInfo.observing_day)
return "-".join([dayObs[:4], dayObs[4:6], dayObs[6:]])

def translate_snap(self, md):
"""Extract snap number from metadata.
Expand Down
50 changes: 47 additions & 3 deletions python/lsst/obs/lsst/translators/lsst.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

"""Metadata translation support code for LSST headers"""

__all__ = ("ROLLOVERTIME", "TZERO", "SIMONYI_LOCATION", "read_detector_ids",
__all__ = ("TZERO", "SIMONYI_LOCATION", "read_detector_ids",
"compute_detector_exposure_id_generic", "LsstBaseTranslator",
"SIMONYI_TELESCOPE")

Expand All @@ -32,8 +32,7 @@
from astro_metadata_translator.translators.helpers import tracking_from_degree_headers, \
altaz_from_degree_headers

# LSST day clock starts at UTC+8
ROLLOVERTIME = TimeDelta(8*60*60, scale="tai", format="sec")

TZERO = Time("2015-01-01T00:00", format="isot", scale="utc")
TZERO_DATETIME = TZERO.to_datetime()

Expand Down Expand Up @@ -162,6 +161,10 @@ class LsstBaseTranslator(FitsTranslator):
_DEFAULT_LOCATION = SIMONYI_LOCATION
"""Default telescope location in absence of relevant FITS headers."""

_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."""

@classmethod
def __init_subclass__(cls, **kwargs):
"""Ensure that subclasses clear their own detector mapping entries
Expand Down Expand Up @@ -711,3 +714,44 @@ def _determine_primary_filter(self):
self.to_observation_id())

return physical_filter

@cache_translation
def to_observing_day(self):
"""Return the day of observation as YYYYMMDD integer.
For LSSTCam and other compliant instruments this is the value
of the DAYOBS header.
Returns
-------
obs_day : `int`
The day of observation.
"""
if self.is_key_ok("DAYOBS"):
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"))

@cache_translation
def to_observation_counter(self):
"""Return the sequence number within the observing day.
Returns
-------
counter : `int`
The sequence number for this day.
"""
if self.is_key_ok("SEQNUM"):
# Some older LATISS data may not have the header
# but this is corrected in fix_header for LATISS.
self._used_these_cards("SEQNUM")
return int(self._header["SEQNUM"])

# This indicates a problem so we warn and return a 0
log.warning("%s: Unable to determine the observation counter so returning 0",
self.to_observation_id())
return 0
5 changes: 4 additions & 1 deletion python/lsst/obs/lsst/translators/lsst_ucdcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import os.path

import astropy.units as u
from astropy.time import Time
from astropy.time import Time, TimeDelta

from astro_metadata_translator import cache_translation

Expand Down Expand Up @@ -79,6 +79,9 @@ class LsstUCDCamTranslator(LsstBaseTranslator):
"""Maximum number of detectors to use when calculating the
detector_exposure_id."""

_ROLLOVER_TIME = TimeDelta(8*60*60, scale="tai", format="sec")
"""Time delta for the definition of a Rubin Test Stand start of day."""

@classmethod
def can_translate(cls, header, filename=None):
"""Indicate whether this translation class can translate the
Expand Down
7 changes: 5 additions & 2 deletions python/lsst/obs/lsst/translators/lsstsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ class LsstSimTranslator(LsstBaseTranslator):
"""Shared routines for LSST Simulated Data.
"""

# No constant or trivial mappings defined
_const_map = {}
# Reset mappings
_const_map = {
# neither phosim nor imsim report a counter
"observation_counter": 0,
}
_trivial_map = {}

@classmethod
Expand Down
5 changes: 4 additions & 1 deletion python/lsst/obs/lsst/translators/ts3.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import os.path

import astropy.units as u
from astropy.time import Time
from astropy.time import Time, TimeDelta

from astro_metadata_translator import cache_translation

Expand Down Expand Up @@ -69,6 +69,9 @@ class LsstTS3Translator(LsstBaseTranslator):

cameraPolicyFile = "policy/ts3.yaml"

_ROLLOVER_TIME = TimeDelta(8*60*60, scale="tai", format="sec")
"""Time delta for the definition of a Rubin Test Stand start of day."""

@classmethod
def can_translate(cls, header, filename=None):
"""Indicate whether this translation class can translate the
Expand Down
5 changes: 4 additions & 1 deletion python/lsst/obs/lsst/translators/ts8.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import re

import astropy.units as u
from astropy.time import Time
from astropy.time import Time, TimeDelta

from astro_metadata_translator import cache_translation

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

cameraPolicyFile = "policy/ts8.yaml"

_ROLLOVER_TIME = TimeDelta(8*60*60, scale="tai", format="sec")
"""Time delta for the definition of a Rubin Test Stand start of day."""

@classmethod
def can_translate(cls, header, filename=None):
"""Indicate whether this translation class can translate the
Expand Down

0 comments on commit dfd489e

Please sign in to comment.