LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
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 import lsst.geom as geom
27 from ._cameraGeom import Orientation
28 from ._transformConfig import TransformMapConfig
29 
30 
31 class DetectorConfig(pexConfig.Config):
32  """A configuration that represents (and can be used to construct) a
33  Detector.
34  """
35  transformDict = pexConfig.ConfigField(
36  "Dictionary of camera transforms keyed on the transform type.", TransformMapConfig)
37  name = pexConfig.Field("Name of detector slot", str)
38  id = pexConfig.Field("ID of detector slot", int)
39  bbox_x0 = pexConfig.Field("x0 of pixel bounding box", int)
40  bbox_y0 = pexConfig.Field("y0 of pixel bounding box", int)
41  bbox_x1 = pexConfig.Field("x1 of pixel bounding box", int)
42  bbox_y1 = pexConfig.Field("y1 of pixel bounding box", int)
43  detectorType = pexConfig.Field(
44  "Detector type: SCIENCE=0, FOCUS=1, GUIDER=2, WAVEFRONT=3", int)
45  physicalType = pexConfig.Field(
46  "How this specific detector is constructed; e.g. CCD, E2V, HgCdTe ", str, default="CCD")
47  serial = pexConfig.Field(
48  "Serial string associated with this specific detector", str)
49  offset_x = pexConfig.Field(
50  "x offset from the origin of the camera in mm in the transposed system.", float)
51  offset_y = pexConfig.Field(
52  "y offset from the origin of the camera in mm in the transposed system.", float)
53  refpos_x = pexConfig.Field("x position of the reference point in the detector in pixels "
54  "in transposed coordinates.", float)
55  refpos_y = pexConfig.Field("y position of the reference point in the detector in pixels "
56  "in transposed coordinates.", float)
57  yawDeg = pexConfig.Field("yaw (rotation about z) of the detector in degrees. "
58  "This includes any necessary rotation to go from "
59  "detector coordinates to camera coordinates "
60  "after optional transposition.", float)
61  pitchDeg = pexConfig.Field(
62  "pitch (rotation about y) of the detector in degrees", float)
63  rollDeg = pexConfig.Field(
64  "roll (rotation about x) of the detector in degrees", float)
65  pixelSize_x = pexConfig.Field("Pixel size in the x dimension in mm", float)
66  pixelSize_y = pexConfig.Field("Pixel size in the y dimension in mm", float)
67 
68  # Depending on the choice of detector coordinates, the pixel grid may need
69  # to be transposed before rotation to put it in camera coordinates.
70  transposeDetector = pexConfig.Field(
71  "Transpose the pixel grid before orienting in focal plane?", bool)
72 
73  crosstalk = pexConfig.ListField(
74  dtype=float,
75  doc=("Flattened crosstalk coefficient matrix; should have nAmps x nAmps entries. "
76  "Once 'reshape'-ed, ``coeffs[i][j]`` is the fraction of the j-th amp present on the i-th amp."),
77  optional=True
78  )
79 
80  # Accessors to get "compiled" versions of parameters.
81  def getCrosstalk(self, numAmps):
82  """Return a 2-D numpy array of crosstalk coefficients of the proper shape"""
83  if not self.crosstalkcrosstalk:
84  return None
85 
86  if numAmps != int(np.sqrt(len(self.crosstalkcrosstalk))):
87  numAmps = int(np.sqrt(len(self.crosstalkcrosstalk)))
88  try:
89  return np.array(self.crosstalkcrosstalk, dtype=np.float32).reshape((numAmps, numAmps))
90  except Exception as e:
91  raise RuntimeError(f"Cannot reshape 'crosstalk' coefficients to square matrix: {e}")
92 
93  @property
94  def bbox(self):
95  """Return the detector bounding box from the separate box endpoint
96  values.
97  """
98  return geom.BoxI(geom.PointI(self.bbox_x0bbox_x0, self.bbox_y0bbox_y0),
99  geom.PointI(self.bbox_x1bbox_x1, self.bbox_y1bbox_y1))
100 
101  @property
102  def offset(self):
103  """Return the detector offset as a Point2D from the separate config
104  values.
105  """
106  return geom.Point2D(self.offset_xoffset_x, self.offset_yoffset_y)
107 
108  @property
109  def refPos(self):
110  """Return the detector reference position as a Point2D from the
111  separate config values.
112  """
113  return geom.Point2D(self.refpos_xrefpos_x, self.refpos_yrefpos_y)
114 
115  @property
116  def orientation(self):
117  """Return the cameraGeom.Orientation() object defined by the
118  configuration values.
119  """
120  return Orientation(self.offsetoffset, self.refPosrefPos,
121  geom.Angle(self.yawDegyawDeg, geom.degrees),
122  geom.Angle(self.pitchDegpitchDeg, geom.degrees),
123  geom.Angle(self.rollDegrollDeg, geom.degrees))
124 
125  @property
126  def pixelSize(self):
127  """Return the pixel size as an Extent2D from the separate values.
128  """
129  return geom.Extent2D(self.pixelSize_xpixelSize_x, self.pixelSize_ypixelSize_y)
130 
131 
132 class CameraConfig(pexConfig.Config):
133  """A configuration that represents (and can be used to construct) a Camera.
134  """
135  detectorList = pexConfig.ConfigDictField(
136  "List of detector configs", keytype=int, itemtype=DetectorConfig)
137  transformDict = pexConfig.ConfigField(
138  "Dictionary of camera transforms keyed on the transform type.", TransformMapConfig)
139  name = pexConfig.Field("Name of this camera", str)
140 
141  plateScale = pexConfig.Field(
142  "Plate scale of the camera in arcsec/mm", float)
143  # Note that the radial transform will also apply a scaling, so all coefficients should be
144  # scaled by the plate scale in appropriate units
145  radialCoeffs = pexConfig.ListField(
146  "Coefficients for radial distortion", float)
A class representing an angle.
Definition: Angle.h:127
An integer coordinate rectangle.
Definition: Box.h:55