Skip to content

Commit

Permalink
Add a test reading a version 0 export YAML file
Browse files Browse the repository at this point in the history
This required that code is added to derive day_obs from the
datetime_begin field (something which should have been added
long ago when universe version 1 came out).
  • Loading branch information
timj committed Feb 15, 2024
1 parent 7009767 commit 3458a15
Show file tree
Hide file tree
Showing 3 changed files with 8,257 additions and 0 deletions.
22 changes: 22 additions & 0 deletions python/lsst/daf/butler/transfers/_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,19 @@ def __init__(self, stream: IO, registry: SqlRegistry):
if "visit" in self.registry.dimensions and "day_obs" in self.registry.dimensions["visit"].implied:
migrate_visit_day_obs = True

# If this is pre-v1 universe we may need to fill in a missing
# visit.day_obs field.
migrate_add_visit_day_obs = False
if (
universe_version < 1
and universe_namespace == "daf_butler"
and (
"day_obs" in self.registry.dimensions["visit"].implied
or "day_obs" in self.registry.dimensions["visit"].metadata
)
):
migrate_add_visit_day_obs = True

# Some conversions may need the day_obs offset from the instrument
# records later on. Not all imports will be populating from scratch so
# read them from the registry if they already exist.
Expand Down Expand Up @@ -415,6 +428,15 @@ def __init__(self, stream: IO, registry: SqlRegistry):
if migrate_visit_seeing:
for record in data["records"]:
record.pop("seeing", None)
if migrate_add_visit_day_obs:
# The day_obs field is missing. It can be derived from
# the datetime_begin field.
for record in data["records"]:
offset = astropy.time.TimeDelta(
instrument_offsets[record["instrument"]], scale="tai", format="sec"
)
date = record["datetime_begin"].tai - offset
record["day_obs"] = int(date.strftime("%Y%m%d"))
if migrate_visit_day_obs:
# Poke the entry for this dimension to make sure it
# appears in the right order, even though we'll
Expand Down

0 comments on commit 3458a15

Please sign in to comment.