Skip to content

Commit

Permalink
Add more consistent log reporting of filename+obsid
Browse files Browse the repository at this point in the history
Now use a single method to calculate the prefix to use
for log messages.
  • Loading branch information
timj committed Nov 4, 2020
1 parent d58c221 commit cee7db0
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions python/lsst/obs/lsst/translators/comCam.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def fix_header(cls, header, instrument, obsid, filename=None):
"""
modified = False

# Prefer filename to obsid for log messages
log_label = filename or obsid
# Calculate the standard label to use for log messages
log_label = cls._construct_log_prefix(obsid, filename)

if "LSST_NUM" not in header:
slot = header.get("CCDSLOT", None)
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/obs/lsst/translators/imsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def to_physical_filter(self):
break
if throughputs_version is None:
log.warning("%s: throughputs version not found. Using FILTER keyword value '%s'.",
self.to_observation_id(), self._header["FILTER"])
self._log_prefix, self._header["FILTER"])
return self._header["FILTER"]
return "_".join((self._header["FILTER"], "sim", throughputs_version))

Expand Down
19 changes: 11 additions & 8 deletions python/lsst/obs/lsst/translators/latiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def is_non_science_or_lab(self):

# This is a science observation on the mountain so we should not
# use defaults
raise KeyError("Required key is missing and this is a mountain science observation")
raise KeyError(f"{self._log_prefix}: Required key is missing and this is a mountain science observation")


class LatissTranslator(LsstBaseTranslator):
Expand Down Expand Up @@ -210,14 +210,17 @@ def fix_header(cls, header, instrument, obsid, filename=None):
"""
modified = False

# Prefer filename to obsid for log messages
log_label = filename or obsid
# Calculate the standard label to use for log messages
log_label = cls._construct_log_prefix(obsid, filename)

if "OBSID" not in header:
# Very old data used IMGNAME
header["OBSID"] = obsid
modified = True
log.debug("Assigning OBSID to a value of '%s'", header["OBSID"])
# We are reporting the OBSID so no need to repeat it at start
# of log message. Use filename if we have it.
log_prefix = f"{filename}: " if filename else ""
log.debug("%sAssigning OBSID to a value of '%s'", log_prefix, header["OBSID"])

if "DAYOBS" not in header:
# OBS-NITE could have the value for DAYOBS but it is safer
Expand Down Expand Up @@ -406,7 +409,7 @@ def to_dark_time(self):
reason = "Dark time not defined."

log.warning("%s: %s Setting dark time to the exposure time.",
self.to_observation_id(), reason)
self._log_prefix, reason)
return exptime

@cache_translation
Expand All @@ -421,7 +424,7 @@ def to_exposure_time(self):
# A missing or undefined EXPTIME is problematic. Set to -1
# to indicate that none was found.
log.warning("%s: Insufficient information to derive exposure time. Setting to -1.0s",
self.to_observation_id())
self._log_prefix)
return -1.0 * u.s

@cache_translation
Expand Down Expand Up @@ -469,7 +472,7 @@ def to_observation_type(self):
else:
obstype = "unknown"
log.warning("%s: Unable to determine observation type. Guessing '%s'",
self.to_observation_id(), obstype)
self._log_prefix, obstype)
return obstype

@cache_translation
Expand Down Expand Up @@ -545,5 +548,5 @@ def to_boresight_airmass(self):
return altaz.secz.to_value()

log.warning("%s: Unable to determine airmass of a science observation, returning 1.",
self.to_observation_id())
self._log_prefix)
return 1.0
6 changes: 3 additions & 3 deletions python/lsst/obs/lsst/translators/lsst.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def to_dark_time(self):
self._used_these_cards("DARKTIME")
else:
log.warning("%s: Unable to determine dark time. Setting from exposure time.",
self.to_observation_id())
self._log_prefix)
darktime = self.to_exposure_time()
return darktime

Expand Down Expand Up @@ -711,7 +711,7 @@ def _determine_primary_filter(self):
obstype = self.to_observation_type()
if obstype not in ("bias", "dark"):
log.warning("%s: Unable to determine the filter",
self.to_observation_id())
self._log_prefix)

return physical_filter

Expand Down Expand Up @@ -753,5 +753,5 @@ def to_observation_counter(self):

# 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())
self._log_prefix)
return 0
6 changes: 3 additions & 3 deletions python/lsst/obs/lsst/translators/lsstCam.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def is_non_science_or_lab(self):
return
if not self._is_on_mountain():
return
raise KeyError("Required key is missing and this is a mountain science observation")
raise KeyError(f"{self._log_prefix}: Required key is missing and this is a mountain science observation")


class LsstCamTranslator(LsstBaseTranslator):
Expand Down Expand Up @@ -91,8 +91,8 @@ def fix_header(cls, header, instrument, obsid, filename=None):

modified = False

# Prefer filename to obsid for log messages
log_label = filename or obsid
# Calculate the standard label to use for log messages
log_label = cls._construct_log_prefix(obsid, filename)

if "FILTER" not in header and header.get("FILTER2") is not None:
ccdslot = header.get("CCDSLOT", "unknown")
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/obs/lsst/translators/lsst_ucdcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def to_physical_filter(self):
return self._header["FILTER"].lower()
else:
log.warning("%s: FILTER key not found in header (assuming NONE)",
self.to_observation_id())
self._log_prefix)
return "NONE"

def to_exposure_id(self):
Expand Down
6 changes: 3 additions & 3 deletions python/lsst/obs/lsst/translators/ts8.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def to_detector_group(self):
match = re.search(r"(RTM-\d\d\d)", raft_name)
if match:
return match.group(0)
raise ValueError(f"RAFTNAME has unexpected form of '{raft_name}'")
raise ValueError(f"{self._log_prefix}: RAFTNAME has unexpected form of '{raft_name}'")

@cache_translation
def to_detector_serial(self):
Expand Down Expand Up @@ -206,7 +206,7 @@ def to_physical_filter(self):
self._used_these_cards("FILTPOS")
except KeyError:
log.warning("%s: FILTPOS key not found in header (assuming NONE)",
self.to_observation_id())
self._log_prefix)
return "NONE"

try:
Expand All @@ -219,7 +219,7 @@ def to_physical_filter(self):
}[filter_pos]
except KeyError:
log.warning("%s: Unknown filter position (assuming NONE): %d",
self.to_observation_id(), filter_pos)
self._log_prefix, filter_pos)
return "NONE"

def to_exposure_id(self):
Expand Down

0 comments on commit cee7db0

Please sign in to comment.