LSSTApplications  18.1.0
LSSTDataManagementBasePackage
cameraConfig.py
Go to the documentation of this file.
1 # This file is part of afw.
2 #
3 # Developed for the LSST Data Management System.
4 # This product includes software developed by the LSST Project
5 # (https://www.lsst.org).
6 # See the COPYRIGHT file at the top-level directory of this distribution
7 # for details of code ownership.
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <https://www.gnu.org/licenses/>.
21 
22 __all__ = ["CameraConfig", "DetectorConfig"]
23 
24 import numpy as np
25 import lsst.pex.config as pexConfig
26 from .transformConfig import TransformMapConfig
27 
28 
29 class DetectorConfig(pexConfig.Config):
30  """A configuration that represents (and can be used to construct) a
31  Detector.
32  """
33  transformDict = pexConfig.ConfigField(
34  "Dictionary of camera transforms keyed on the transform type.", TransformMapConfig)
35  name = pexConfig.Field("Name of detector slot", str)
36  id = pexConfig.Field("ID of detector slot", int)
37  bbox_x0 = pexConfig.Field("x0 of pixel bounding box", int)
38  bbox_y0 = pexConfig.Field("y0 of pixel bounding box", int)
39  bbox_x1 = pexConfig.Field("x1 of pixel bounding box", int)
40  bbox_y1 = pexConfig.Field("y1 of pixel bounding box", int)
41  detectorType = pexConfig.Field(
42  "Detector type: SCIENCE=0, FOCUS=1, GUIDER=2, WAVEFRONT=3", int)
43  physicalType = pexConfig.Field(
44  "How this specific detector is constructed; e.g. CCD, E2V, HgCdTe ", str, default="CCD")
45  serial = pexConfig.Field(
46  "Serial string associated with this specific detector", str)
47  offset_x = pexConfig.Field(
48  "x offset from the origin of the camera in mm in the transposed system.", float)
49  offset_y = pexConfig.Field(
50  "y offset from the origin of the camera in mm in the transposed system.", float)
51  refpos_x = pexConfig.Field("x position of the reference point in the detector in pixels "
52  "in transposed coordinates.", float)
53  refpos_y = pexConfig.Field("y position of the reference point in the detector in pixels "
54  "in transposed coordinates.", float)
55  yawDeg = pexConfig.Field("yaw (rotation about z) of the detector in degrees. "
56  "This includes any necessary rotation to go from "
57  "detector coordinates to camera coordinates "
58  "after optional transposition.", float)
59  pitchDeg = pexConfig.Field(
60  "pitch (rotation about y) of the detector in degrees", float)
61  rollDeg = pexConfig.Field(
62  "roll (rotation about x) of the detector in degrees", float)
63  pixelSize_x = pexConfig.Field("Pixel size in the x dimension in mm", float)
64  pixelSize_y = pexConfig.Field("Pixel size in the y dimension in mm", float)
65 
66  # Depending on the choice of detector coordinates, the pixel grid may need
67  # to be transposed before rotation to put it in camera coordinates.
68  transposeDetector = pexConfig.Field(
69  "Transpose the pixel grid before orienting in focal plane?", bool)
70 
71  crosstalk = pexConfig.ListField(
72  dtype=float,
73  doc=("Flattened crosstalk coefficient matrix; should have nAmps x nAmps entries. "
74  "Once 'reshape'-ed, ``coeffs[i][j]`` is the fraction of the j-th amp present on the i-th amp."),
75  optional=True
76  )
77 
78  def getCrosstalk(self, numAmps):
79  """Return a 2-D numpy array of crosstalk coefficients of the proper shape"""
80  if not self.crosstalk:
81  return None
82  try:
83  return np.array(self.crosstalk, dtype=np.float32).reshape((numAmps, numAmps))
84  except Exception as e:
85  raise RuntimeError("Cannot reshape 'crosstalk' coefficients to square matrix: %s" % (e,))
86 
87 
88 class CameraConfig(pexConfig.Config):
89  """A configuration that represents (and can be used to construct) a Camera.
90  """
91  detectorList = pexConfig.ConfigDictField(
92  "List of detector configs", keytype=int, itemtype=DetectorConfig)
93  transformDict = pexConfig.ConfigField(
94  "Dictionary of camera transforms keyed on the transform type.", TransformMapConfig)
95  name = pexConfig.Field("Name of this camera", str)
96 
97  plateScale = pexConfig.Field(
98  "Plate scale of the camera in arcsec/mm", float)
99  # Note that the radial transform will also apply a scaling, so all coefficients should be
100  # scaled by the plate scale in appropriate units
101  radialCoeffs = pexConfig.ListField(
102  "Coefficients for radial distortion", float)