Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-41267: Enable calculation of weather data in translator #474

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions python/lsst/obs/lsst/translators/latiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ class LatissTranslator(LsstBaseTranslator):
"detector_group": _DETECTOR_GROUP_NAME,
"detector_num": 0,
"detector_name": _DETECTOR_NAME, # Single sensor
"relative_humidity": None,
"pressure": None,
"temperature": None,
}

_trivial_map = {
Expand Down Expand Up @@ -380,6 +377,15 @@ def fix_header(cls, header, instrument, obsid, filename=None):
header['ROTPA'] = header['ROTPA'] - 180
modified = True

if obsgeo := header.get("OBSGEO-Z"):
try:
if obsgeo > 0.0:
obsgeo *= -1.0
header["OBSGEO-Z"] = obsgeo
modified = True
except TypeError:
pass

return modified

def _is_on_mountain(self):
Expand Down
31 changes: 31 additions & 0 deletions python/lsst/obs/lsst/translators/lsst.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,3 +934,34 @@ def to_has_simulated_content(self):

# No simulation flags set.
return False

@cache_translation
def to_relative_humidity(self) -> float | None:
key = "HUMIDITY"
if self.is_key_ok(key):
self._used_these_cards(key)
return self._header[key]

return None

@cache_translation
def to_pressure(self):
key = "PRESSURE"
if self.is_key_ok(key):
value = self._header[key]
# There has been an inconsistency in units for the pressure reading
# so we need to adjust for this.
if value > 10_000:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we think this was a one-off blip then it might be more efficient to do this in header fixup. Doing it here makes it fixes it for LSSTCam/ComCam and LATISS but if it's a thing that is in the past and won't change in the future doing the fix just for LATISS and for a restricted date range makes more sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have strong feelings either way. I guess maybe it depends what you mean by "more efficient" though. If it's just this if statement, then I don't think it even helps, because you still have to check the date anyway, plus it's negligible either way. But therefore perhaps you meant something else.

I personally like this approach, because it should fix it everywhere forever, and feels safe and non-costly, and we never thought this would happen, so it's hard to say it won't happen again, I think. But like I said, I don't feel strongly if you want to make it time-based and remove this general check, but I think it's fine to leave as is, myself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that putting it here means we check it for the rest of the survey in both LSSTCam and LATISS data. Putting it in the LATISS fix_header limits the check to LATISS data and if we are clever with the date checking we might be able to limit it to commissioning data without needing an extra check.

If the CSCs can randomly change units on us and we expect the units to switch multiple times over the survey we have much bigger problems. cc/ @tribeiro

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly, the CSCs will not change units randomly. However, we can't rule out that sensor changes and software bugs may cause data to be published with wrong units. We'll do our best to minimize those, of course.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood those considerations, I just wasn't sure what you meant by "more efficient", but I'm fine with however you choose to deal with this.

unit = u.Pa
else:
unit = u.hPa
return value * unit

return None

@cache_translation
def to_temperature(self):
key = "AIRTEMP"
if self.is_key_ok(key):
return self._header[key] * u.deg_C
return None
3 changes: 0 additions & 3 deletions python/lsst/obs/lsst/translators/lsstCam.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ class LsstCamTranslator(LsstBaseTranslator):
# includes them
"altaz_begin": None,
"object": "UNKNOWN",
"relative_humidity": None,
"temperature": None,
"pressure": None,
}

_trivial_map = {
Expand Down
137 changes: 137 additions & 0 deletions tests/headers/latiss-AT_O_20230705_000379_R00_S00.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{
"__CONTENT__" : "metadata",
"SIMPLE" : true,
"BITPIX" : 8,
"NAXIS" : 0,
"EXTEND" : true,
"CCD_MANU" : "ITL",
"CCD_TYPE" : "3800C",
"DETSIZE" : "[1:4072,1:4000]",
"BINX" : 1,
"BINY" : 1,
"CCDGAIN" : 1.0,
"CCDNOISE" : 10.0,
"CCDSLOT" : "S00",
"RAFTBAY" : "R00",
"FIRMWARE" : "11384004",
"PLATFORM" : "auxtel",
"CONTNUM" : "189216ee",
"DAQVERS" : "R5-V6.1 2023-04-19T04:26:24Z (1fa91971)",
"DAQPART" : "lat",
"DAQFOLD" : "raw",
"SEQFILE" : "FP_ITL_2s_ir2_v26_no_RG.seq",
"SEQNAME" : "FP_ITL_2s_ir2_v26_no_RG.seq",
"SEQCKSUM" : "1477162166",
"LSST_NUM" : "ITL-3800C-068",
"CCD_SERN" : "20862",
"REBNAME" : "Unknown",
"RAFTNAME" : "AuxTel-Raft",
"FPVERS" : "1.1.8",
"IHVERS" : "1.0.38",
"HIERARCH.STUTTER.ROWS" : 0,
"HIERARCH.STUTTER.DELAY" : 0.0,
"HIERARCH.STUTTER.NSHIFTS" : 0,
"FILTPOS" : null,
"CCDTEMP" : -90.4308,
"DATE" : "2023-07-06T04:56:32.155",
"MJD" : 60131.20592771983,
"IMGTYPE" : "OBJECT",
"DATE-OBS" : "2023-07-06T04:56:01.913",
"MJD-OBS" : 60131.20557769667,
"DATE-TRG" : "2023-07-06T04:56:32.150",
"MJD-TRG" : 60131.205927662086,
"OBSID" : "AT_O_20230705_000379",
"DATE-BEG" : "2023-07-06T04:56:01.913",
"MJD-BEG" : 60131.20557769667,
"DATE-END" : "2023-07-06T04:56:32.155",
"MJD-END" : 60131.20592771983,
"GROUPID" : "2023-07-06T04:53:15.609",
"BUNIT" : "adu",
"TIMESYS" : "TAI",
"INSTRUME" : "LATISS",
"TELESCOP" : "LSST AuxTelescope",
"OBS-LONG" : -70.7476862,
"OBS-LAT" : -30.2447889,
"OBS-ELEV" : 2663.0,
"OBSGEO-X" : 1819093.52,
"OBSGEO-Y" : -5208408.1,
"OBSGEO-Z" : 3195186.45,
"FACILITY" : "Vera C. Rubin Observatory",
"RA" : 272.1186216000001,
"DEC" : -21.25310639,
"RASTART" : 272.08100988065354,
"DECSTART" : -21.29189769138964,
"RAEND" : 272.08106447161356,
"DECEND" : -21.29192959685414,
"ROTPA" : 218.0120692722092,
"ROTCOORD" : "sky",
"HASTART" : 0.972610195793257,
"ELSTART" : 74.13288637448854,
"AZSTART" : -59.070243942086414,
"AMSTART" : 1.0391822914647533,
"AHAEND" : null,
"AELEND" : null,
"AAZEND" : null,
"AAMEND" : null,
"TRACKSYS" : null,
"RADESYS" : "ICRS",
"FOCUSZ" : -0.008921561762690544,
"OBJECT" : "HD165763",
"INSTPORT" : 2,
"ATM3PORT" : null,
"DOMEAZ" : 305.73,
"SHUTLOWR" : 0.0,
"SHUTUPPR" : 100.0,
"WCSAXES" : null,
"CTYPE1" : null,
"CTYPE2" : null,
"CUNIT1" : null,
"CUNIT2" : null,
"CRVAL1" : null,
"CRVAL2" : null,
"CRPIX1" : null,
"CRPIX2" : null,
"CD1_1" : null,
"CD1_2" : null,
"CD2_1" : null,
"CD2_2" : null,
"EQUINOX" : null,
"TESTTYPE" : "OBJECT",
"CAMCODE" : "AT",
"CONTRLLR" : "O",
"DAYOBS" : "20230705",
"SEQNUM" : 379,
"PROGRAM" : "BLOCK-59",
"REASON" : "SITCOM-857",
"CURINDEX" : 1,
"MAXINDEX" : 1,
"TSTAND" : null,
"IMAGETAG" : "c2cb16b93091b0ec",
"OBSANNOT" : "",
"TEMP_SET" : -94.15,
"GRATING" : "holo4_003",
"GRATBAND" : "H4-003",
"GRATSLOT" : 3,
"LINSPOS" : -324.40301513671875,
"FILTBAND" : "EMPTY",
"FILTER" : "empty_1",
"FILTSLOT" : 0,
"EXPTIME" : 30.0,
"DARKTIME" : 30.2418,
"SHUTTIME" : 30.0,
"AIRTEMP" : 5.775000095367432,
"PRESSURE" : 77780.0,
"HUMIDITY" : 15.149999618530273,
"WINDSPD" : 10.008000373840332,
"WINDDIR" : 37.21355438232422,
"SEEING" : 2.2614493370056152,
"FILENAME" : "AT_O_20230705_000379_R00_S00.fits",
"HEADVER" : 2,
"HIERARCH.SIMULATE.ATMCS" : null,
"HIERARCH.SIMULATE.ATHEXAPOD" : 0,
"HIERARCH.SIMULATE.ATPNEUMATICS" : null,
"HIERARCH.SIMULATE.ATDOME" : 0,
"HIERARCH.SIMULATE.ATSPECTROGRAPH" : 0,
"CHECKSUM" : "ALi2BIg2AIg2AIg2",
"DATASUM" : "0"
}
45 changes: 38 additions & 7 deletions tests/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,10 @@ def test_latiss_translator(self):
observation_reason="object",
observing_day=20220405,
physical_filter="SDSSr~empty",
pressure=None,
relative_humidity=None,
pressure=744.3*u.hPa,
relative_humidity=19.0,
science_program="LATISS_E6A",
temperature=None,
temperature=12.3*u.deg_C,
visit_id=2291434871810000,
# We have some timing discrepancies in the headers
# that make it hard to match the demand RA/DEC to
Expand Down Expand Up @@ -760,10 +760,10 @@ def test_latiss_translator(self):
observation_reason="object",
observing_day=20220405,
physical_filter="SDSSr~empty",
pressure=None,
relative_humidity=None,
pressure=744.3*u.hPa,
relative_humidity=19.0,
science_program="LATISS_E6A",
temperature=None,
temperature=12.3*u.deg_C,
visit_id=2291434871810000,
# We have some timing discrepancies in the headers
# that make it hard to match the demand RA/DEC to
Expand Down Expand Up @@ -800,7 +800,38 @@ def test_latiss_translator(self):
temperature=None,
visit_id=2593446676330000,
check_altaz=True,
))
)),
("latiss-AT_O_20230705_000379_R00_S00.json",
dict(telescope="Rubin Auxiliary Telescope",
instrument="LATISS",
boresight_rotation_coord="sky",
dark_time=30.2418*u.s,
detector_exposure_id=0x9a2817b00,
detector_group="RXX",
detector_name="S00",
detector_num=0,
detector_serial="ITL-3800C-068",
exposure_id=2023070500379,
exposure_group="2023-07-06T04:53:15.609",
exposure_time=30.0*u.s,
focus_z=-0.008921561762690544*u.mm,
group_counter_end=379,
group_counter_start=379,
has_simulated_content=False,
object="HD165763",
observation_counter=379,
observation_id="AT_O_20230705_000379",
observation_type="science",
observation_reason="sitcom-857",
observing_day=20230705,
physical_filter="empty~holo4_003",
pressure=777.80*u.hPa,
relative_humidity=15.149999618530273,
science_program="BLOCK-59",
temperature=5.775000095367432*u.deg_C,
visit_id=2685487956090000,
check_altaz=True,
)),
)
with warnings.catch_warnings():
# Avoid warnings from too-long FITS header keys.
Expand Down