Coverage for python/lsst/obs/lsst/translators/lsst.py : 32%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# This file is currently part of obs_lsst but is written to allow it # to be migrated to the astro_metadata_translator package at a later date. # # This product includes software developed by the LSST Project # (http://www.lsst.org). # See the LICENSE file in this directory for details of code ownership. # # Use of this source code is governed by a 3-clause BSD-style # license that can be found in the LICENSE file.
"compute_detector_exposure_id_generic")
# LSST day clock starts at UTC+8
# LSST Default location in the absence of headers
"""Read a camera policy file and retrieve the mapping from CCD name to ID.
Parameters ---------- policyFile : `str` Name of YAML policy file to read, relative to the obs_lsst package.
Returns ------- mapping : `dict` of `str` to `int` A `dict` with keys being the full names of the detectors, and the value is the integer detector number.
Notes ----- Reads the camera YAML definition file directly and extracts just the IDs. This routine does not use the standard `~lsst.obs.base.yamlCamera.YAMLCamera` infrastructure or `lsst.afw.cameraGeom`. This is because the translators are intended to have minimal dependencies on LSST infrastructure. """
file = os.path.join(obs_lsst_packageDir, policyFile) with open(file) as fh: # Use the fast parser since these files are large camera = yaml.load(fh, Loader=yaml.CLoader)
mapping = {} for ccd, value in camera["CCDs"].items(): mapping[ccd] = int(value["id"])
return mapping
"""Compute the detector_exposure_id from the exposure id and the detector number.
Parameters ---------- exposure_id : `int` The exposure ID. detector_num : `int` The detector number. max_num : `int`, optional Maximum number of detectors to make space for. Defaults to 1000. mode : `str`, optional Computation mode. Defaults to "concat". - concat : Concatenate the exposure ID and detector number, making sure that there is space for max_num and zero padding. - multiply : Multiply the exposure ID by the maximum detector number and add the detector number.
Returns ------- detector_exposure_id : `int` Computed ID.
Raises ------ ValueError The detector number is out of range. """
if detector_num is None: raise ValueError("Detector number must be defined.") if detector_num >= max_num or detector_num < 0: raise ValueError(f"Detector number out of range 0 <= {detector_num} <= {max_num}")
if mode == "concat": npad = len(str(max_num)) return int(f"{exposure_id}{detector_num:0{npad}d}") elif mode == "multiply": return max_num*exposure_id + detector_num else: raise ValueError(f"Computation mode of '{mode}' is not understood") |