LSSTApplications  20.0.0
LSSTDataManagementBasePackage
Functions
lsst.obs.base.yamlCamera Namespace Reference

Functions

def makeCamera (cameraFile)
 
def makeDetectorConfigList (ccdParams)
 
def makeAmplifierList (ccd)
 
def makeAmpInfoCatalog (ccd)
 
def makeBBoxFromList (ylist)
 
def makeTransformDict (nativeSys, transformDict, plateScale)
 
def makeCameraFromCatalogs (cameraName, detectorConfigList, nativeSys, transformDict, amplifierDict, pupilFactoryClass=cameraGeom.pupil.PupilFactory)
 

Function Documentation

◆ makeAmpInfoCatalog()

def lsst.obs.base.yamlCamera.makeAmpInfoCatalog (   ccd)
Backward compatible name.

Definition at line 186 of file yamlCamera.py.

186 def makeAmpInfoCatalog(ccd):
187  """Backward compatible name.
188  """
189  return makeAmplifierList(ccd)
190 
191 

◆ makeAmplifierList()

def lsst.obs.base.yamlCamera.makeAmplifierList (   ccd)
Construct a list of AmplifierBuilder objects

Definition at line 108 of file yamlCamera.py.

108 def makeAmplifierList(ccd):
109  """Construct a list of AmplifierBuilder objects
110  """
111  # Much of this will need to be filled in when we know it.
112  assert len(ccd) > 0
113  amp = list(ccd['amplifiers'].values())[0]
114 
115  rawBBox = makeBBoxFromList(amp['rawBBox']) # total in file
116  xRawExtent, yRawExtent = rawBBox.getDimensions()
117 
118  readCorners = {"LL": ReadoutCorner.LL,
119  "LR": ReadoutCorner.LR,
120  "UL": ReadoutCorner.UL,
121  "UR": ReadoutCorner.UR}
122 
123  amplifierList = []
124  for name, amp in sorted(ccd['amplifiers'].items(), key=lambda x: x[1]['hdu']):
125  amplifier = Amplifier.Builder()
126  amplifier.setName(name)
127 
128  ix, iy = amp['ixy']
129  perAmpData = amp['perAmpData']
130  if perAmpData:
131  x0, y0 = 0, 0 # origin of data within each amp image
132  else:
133  x0, y0 = ix*xRawExtent, iy*yRawExtent
134 
135  rawDataBBox = makeBBoxFromList(amp['rawDataBBox']) # Photosensitive area
136  xDataExtent, yDataExtent = rawDataBBox.getDimensions()
137  amplifier.setBBox(geom.BoxI(
138  geom.PointI(ix*xDataExtent, iy*yDataExtent), rawDataBBox.getDimensions()))
139 
140  rawBBox = makeBBoxFromList(amp['rawBBox'])
141  rawBBox.shift(geom.ExtentI(x0, y0))
142  amplifier.setRawBBox(rawBBox)
143 
144  rawDataBBox = makeBBoxFromList(amp['rawDataBBox'])
145  rawDataBBox.shift(geom.ExtentI(x0, y0))
146  amplifier.setRawDataBBox(rawDataBBox)
147 
148  rawSerialOverscanBBox = makeBBoxFromList(amp['rawSerialOverscanBBox'])
149  rawSerialOverscanBBox.shift(geom.ExtentI(x0, y0))
150  amplifier.setRawHorizontalOverscanBBox(rawSerialOverscanBBox)
151 
152  rawParallelOverscanBBox = makeBBoxFromList(amp['rawParallelOverscanBBox'])
153  rawParallelOverscanBBox.shift(geom.ExtentI(x0, y0))
154  amplifier.setRawVerticalOverscanBBox(rawParallelOverscanBBox)
155 
156  rawSerialPrescanBBox = makeBBoxFromList(amp['rawSerialPrescanBBox'])
157  rawSerialPrescanBBox.shift(geom.ExtentI(x0, y0))
158  amplifier.setRawPrescanBBox(rawSerialPrescanBBox)
159 
160  if perAmpData:
161  amplifier.setRawXYOffset(geom.Extent2I(ix*xRawExtent, iy*yRawExtent))
162  else:
163  amplifier.setRawXYOffset(geom.Extent2I(0, 0))
164 
165  amplifier.setReadoutCorner(readCorners[amp['readCorner']])
166  amplifier.setGain(amp['gain'])
167  amplifier.setReadNoise(amp['readNoise'])
168  amplifier.setSaturation(amp['saturation'])
169  amplifier.setSuspectLevel(amp.get('suspect', np.nan))
170 
171  # flip data when assembling if needs be (e.g. data from the serial at the top of a CCD)
172  flipX, flipY = amp.get("flipXY")
173 
174  amplifier.setRawFlipX(flipX)
175  amplifier.setRawFlipY(flipY)
176  # linearity placeholder stuff
177  amplifier.setLinearityCoeffs([float(val) for val in amp['linearityCoeffs']])
178  amplifier.setLinearityType(amp['linearityType'])
179  amplifier.setLinearityThreshold(float(amp['linearityThreshold']))
180  amplifier.setLinearityMaximum(float(amp['linearityMax']))
181  amplifier.setLinearityUnits("DN")
182  amplifierList.append(amplifier)
183  return amplifierList
184 
185 

◆ makeBBoxFromList()

def lsst.obs.base.yamlCamera.makeBBoxFromList (   ylist)
Given a list [(x0, y0), (xsize, ysize)], probably from a yaml file,
return a BoxI

Definition at line 192 of file yamlCamera.py.

192 def makeBBoxFromList(ylist):
193  """Given a list [(x0, y0), (xsize, ysize)], probably from a yaml file,
194  return a BoxI
195  """
196  (x0, y0), (xsize, ysize) = ylist
197  return geom.BoxI(geom.PointI(x0, y0), geom.ExtentI(xsize, ysize))
198 
199 

◆ makeCamera()

def lsst.obs.base.yamlCamera.makeCamera (   cameraFile)
An imaging camera (e.g. the LSST 3Gpix camera)

Parameters
----------
cameraFile : `str`
    Camera description YAML file.

Returns
-------
camera : `lsst.afw.cameraGeom.Camera`
    The desired Camera

Definition at line 34 of file yamlCamera.py.

34 def makeCamera(cameraFile):
35  """An imaging camera (e.g. the LSST 3Gpix camera)
36 
37  Parameters
38  ----------
39  cameraFile : `str`
40  Camera description YAML file.
41 
42  Returns
43  -------
44  camera : `lsst.afw.cameraGeom.Camera`
45  The desired Camera
46  """
47 
48  with open(cameraFile) as fd:
49  cameraParams = yaml.load(fd, Loader=yaml.CLoader)
50 
51  cameraName = cameraParams["name"]
52 
53  #
54  # Handle distortion models.
55  #
56  plateScale = geom.Angle(cameraParams["plateScale"], geom.arcseconds)
57  nativeSys = cameraGeom.CameraSys(cameraParams["transforms"].pop("nativeSys"))
58  transforms = makeTransformDict(nativeSys, cameraParams["transforms"], plateScale)
59 
60  ccdParams = cameraParams["CCDs"]
61  detectorConfigList = makeDetectorConfigList(ccdParams)
62 
63  amplifierDict = {}
64  for ccdName, ccdValues in ccdParams.items():
65  amplifierDict[ccdName] = makeAmplifierList(ccdValues)
66 
67  return makeCameraFromCatalogs(cameraName, detectorConfigList, nativeSys, transforms, amplifierDict)
68 
69 

◆ makeCameraFromCatalogs()

def lsst.obs.base.yamlCamera.makeCameraFromCatalogs (   cameraName,
  detectorConfigList,
  nativeSys,
  transformDict,
  amplifierDict,
  pupilFactoryClass = cameraGeom.pupil.PupilFactory 
)
Construct a Camera instance from a dictionary of
   detector name : `lsst.afw.cameraGeom.amplifier`

Parameters
----------
cameraName : `str`
    The name of the camera
detectorConfigList : `list`
    A list of `lsst.afw.cameraGeom.cameraConfig.DetectorConfig`
nativeSys : `lsst.afw.cameraGeom.CameraSys`
    The native transformation type; must be `lsst.afw.cameraGeom.FOCAL_PLANE`
transformDict : `dict`
    A dict of lsst.afw.cameraGeom.CameraSys : `lsst.afw.geom.TransformPoint2ToPoint2`
amplifierDict : `dict`
    A dictionary of detector name :
                       `lsst.afw.cameraGeom.Amplifier.Builder`
pupilFactoryClass : `type`, optional
    Class to attach to camera;
         `lsst.default afw.cameraGeom.PupilFactory`

Returns
-------
camera : `lsst.afw.cameraGeom.Camera`
    New Camera instance.

Notes
------
Copied from `lsst.afw.cameraGeom.cameraFactory` with permission and encouragement
from Jim Bosch

Definition at line 254 of file yamlCamera.py.

254 def makeCameraFromCatalogs(cameraName, detectorConfigList, nativeSys, transformDict, amplifierDict,
255  pupilFactoryClass=cameraGeom.pupil.PupilFactory):
256  """Construct a Camera instance from a dictionary of
257  detector name : `lsst.afw.cameraGeom.amplifier`
258 
259  Parameters
260  ----------
261  cameraName : `str`
262  The name of the camera
263  detectorConfigList : `list`
264  A list of `lsst.afw.cameraGeom.cameraConfig.DetectorConfig`
265  nativeSys : `lsst.afw.cameraGeom.CameraSys`
266  The native transformation type; must be `lsst.afw.cameraGeom.FOCAL_PLANE`
267  transformDict : `dict`
268  A dict of lsst.afw.cameraGeom.CameraSys : `lsst.afw.geom.TransformPoint2ToPoint2`
269  amplifierDict : `dict`
270  A dictionary of detector name :
271  `lsst.afw.cameraGeom.Amplifier.Builder`
272  pupilFactoryClass : `type`, optional
273  Class to attach to camera;
274  `lsst.default afw.cameraGeom.PupilFactory`
275 
276  Returns
277  -------
278  camera : `lsst.afw.cameraGeom.Camera`
279  New Camera instance.
280 
281  Notes
282  ------
283  Copied from `lsst.afw.cameraGeom.cameraFactory` with permission and encouragement
284  from Jim Bosch
285  """
286 
287  # nativeSys=FOCAL_PLANE seems to be assumed in various places in this file
288  # (e.g. the definition of TAN_PIXELS), despite CameraConfig providing the
289  # illusion that it's configurable.
290  # Note that we can't actually get rid of the nativeSys config option
291  # without breaking lots of on-disk camera configs.
292  assert nativeSys == cameraGeom.FOCAL_PLANE, "Cameras with nativeSys != FOCAL_PLANE are not supported."
293 
294  focalPlaneToField = transformDict[cameraGeom.FIELD_ANGLE]
295 
296  cameraBuilder = Camera.Builder(cameraName)
297  cameraBuilder.setPupilFactoryClass(pupilFactoryClass)
298 
299  # Ensure all transforms in the camera transform dict are included.
300  for toSys, transform in transformDict.items():
301  cameraBuilder.setTransformFromFocalPlaneTo(toSys, transform)
302 
303  for detectorConfig in detectorConfigList:
304  # This should build all detector pixel -> focalPlane transforms.
305  cameraGeom.addDetectorBuilderFromConfig(cameraBuilder, detectorConfig,
306  amplifierDict[detectorConfig.name],
307  focalPlaneToField)
308 
309  # For reasons I don't understand, some obs_ packages (e.g. HSC) set
310  # nativeSys to None for their detectors (which doesn't seem to be
311  # permitted by the config class!), but they really mean PIXELS. For
312  # backwards compatibility we use that as the default...
313  detectorNativeSys = detectorConfig.transformDict.nativeSys
314  detectorNativeSys = (cameraGeom.PIXELS if detectorNativeSys is None else
315  cameraGeom.CameraSysPrefix(detectorNativeSys))
316 
317  # ...well, actually, it seems that we've always assumed down in C++
318  # that the answer is always PIXELS without ever checking that it is.
319  # So let's assert that it is, since there are hints all over this file
320  # (e.g. the definition of TAN_PIXELS) that other parts of the codebase
321  # have regularly made that assumption as well. Note that we can't
322  # actually get rid of the nativeSys config option without breaking
323  # lots of on-disk camera configs.
324  assert detectorNativeSys == cameraGeom.PIXELS, \
325  "Detectors with nativeSys != PIXELS are not supported."
326  detectorNativeSys = cameraGeom.CameraSys(detectorNativeSys, detectorConfig.name)
327 
328  return cameraBuilder.finish()

◆ makeDetectorConfigList()

def lsst.obs.base.yamlCamera.makeDetectorConfigList (   ccdParams)
Make a list of detector configs

Returns
-------
detectorConfig : `list` of `lsst.afw.cameraGeom.DetectorConfig`
    A list of detector configs.

Definition at line 70 of file yamlCamera.py.

70 def makeDetectorConfigList(ccdParams):
71  """Make a list of detector configs
72 
73  Returns
74  -------
75  detectorConfig : `list` of `lsst.afw.cameraGeom.DetectorConfig`
76  A list of detector configs.
77  """
78  detectorConfigs = []
79  for name, ccd in ccdParams.items():
80  detectorConfig = cameraGeom.DetectorConfig()
81  detectorConfigs.append(detectorConfig)
82 
83  detectorConfig.name = name
84  detectorConfig.id = ccd['id']
85  detectorConfig.serial = ccd['serial']
86  detectorConfig.detectorType = ccd['detectorType']
87  if 'physicalType' in ccd:
88  detectorConfig.physicalType = ccd['physicalType']
89  # This is the orientation we need to put the serial direction along the x-axis
90  detectorConfig.bbox_x0, detectorConfig.bbox_y0 = ccd['bbox'][0]
91  detectorConfig.bbox_x1, detectorConfig.bbox_y1 = ccd['bbox'][1]
92  detectorConfig.pixelSize_x, detectorConfig.pixelSize_y = ccd['pixelSize']
93  detectorConfig.transformDict.nativeSys = ccd['transformDict']['nativeSys']
94  transforms = ccd['transformDict']['transforms']
95  detectorConfig.transformDict.transforms = None if transforms == 'None' else transforms
96  detectorConfig.refpos_x, detectorConfig.refpos_y = ccd['refpos']
97  detectorConfig.offset_x, detectorConfig.offset_y = ccd['offset']
98  detectorConfig.transposeDetector = ccd['transposeDetector']
99  detectorConfig.pitchDeg = ccd['pitch']
100  detectorConfig.yawDeg = ccd['yaw']
101  detectorConfig.rollDeg = ccd['roll']
102  if 'crosstalk' in ccd:
103  detectorConfig.crosstalk = ccd['crosstalk']
104 
105  return detectorConfigs
106 
107 

◆ makeTransformDict()

def lsst.obs.base.yamlCamera.makeTransformDict (   nativeSys,
  transformDict,
  plateScale 
)
Make a dictionary of TransformPoint2ToPoint2s from yaml, mapping from nativeSys

Parameters
----------
nativeSys : `lsst.afw.cameraGeom.CameraSys`
transformDict : `dict`
    A dict specifying parameters of transforms; keys are camera system names.
plateScale : `lsst.geom.Angle`
    The size of a pixel in angular units/mm (e.g. 20 arcsec/mm for LSST)

Returns
-------
transforms : `dict`
    A dict of `lsst.afw.cameraGeom.CameraSys` : `lsst.afw.geom.TransformPoint2ToPoint2`

The resulting dict's keys are `~lsst.afw.cameraGeom.CameraSys`,
and the values are Transforms *from* NativeSys *to* CameraSys

Definition at line 200 of file yamlCamera.py.

200 def makeTransformDict(nativeSys, transformDict, plateScale):
201  """Make a dictionary of TransformPoint2ToPoint2s from yaml, mapping from nativeSys
202 
203  Parameters
204  ----------
205  nativeSys : `lsst.afw.cameraGeom.CameraSys`
206  transformDict : `dict`
207  A dict specifying parameters of transforms; keys are camera system names.
208  plateScale : `lsst.geom.Angle`
209  The size of a pixel in angular units/mm (e.g. 20 arcsec/mm for LSST)
210 
211  Returns
212  -------
213  transforms : `dict`
214  A dict of `lsst.afw.cameraGeom.CameraSys` : `lsst.afw.geom.TransformPoint2ToPoint2`
215 
216  The resulting dict's keys are `~lsst.afw.cameraGeom.CameraSys`,
217  and the values are Transforms *from* NativeSys *to* CameraSys
218  """
219  # As other comments note this is required, and this is one function where it's assumed
220  assert nativeSys == cameraGeom.FOCAL_PLANE, "Cameras with nativeSys != FOCAL_PLANE are not supported."
221 
222  resMap = dict()
223 
224  for key, transform in transformDict.items():
225  transformType = transform["transformType"]
226  knownTransformTypes = ["affine", "radial"]
227  if transformType not in knownTransformTypes:
228  raise RuntimeError("Saw unknown transform type for %s: %s (known types are: [%s])" % (
229  key, transform["transformType"], ", ".join(knownTransformTypes)))
230 
231  if transformType == "affine":
232  affine = geom.AffineTransform(np.array(transform["linear"]),
233  np.array(transform["translation"]))
234 
235  transform = afwGeom.makeTransform(affine)
236  elif transformType == "radial":
237  # radial coefficients of the form [0, 1 (no units), C2 (rad), usually 0, C3 (rad^2), ...]
238  # Radial distortion is modeled as a radial polynomial that converts from focal plane radius
239  # (in mm) to field angle (in radians). The provided coefficients are divided by the plate
240  # scale (in radians/mm) meaning that C1 is always 1.
241  radialCoeffs = np.array(transform["coeffs"])
242 
243  radialCoeffs *= plateScale.asRadians()
244  transform = afwGeom.makeRadialTransform(radialCoeffs)
245  else:
246  raise RuntimeError("Impossible condition \"%s\" is not in: [%s])" % (
247  transform["transformType"], ", ".join(knownTransformTypes)))
248 
249  resMap[cameraGeom.CameraSys(key)] = transform
250 
251  return resMap
252 
253 
lsst.obs.base.yamlCamera.makeTransformDict
def makeTransformDict(nativeSys, transformDict, plateScale)
Definition: yamlCamera.py:200
lsst.obs.base.yamlCamera.makeBBoxFromList
def makeBBoxFromList(ylist)
Definition: yamlCamera.py:192
lsst::geom::AffineTransform
An affine coordinate transformation consisting of a linear transformation and an offset.
Definition: AffineTransform.h:75
lsst::afw::geom::makeRadialTransform
std::shared_ptr< TransformPoint2ToPoint2 > makeRadialTransform(std::vector< double > const &forwardCoeffs, std::vector< double > const &inverseCoeffs)
A purely radial polynomial distortion.
Definition: transformFactory.cc:183
lsst.obs.base.yamlCamera.makeAmpInfoCatalog
def makeAmpInfoCatalog(ccd)
Definition: yamlCamera.py:186
lsst.obs.base.yamlCamera.makeAmplifierList
def makeAmplifierList(ccd)
Definition: yamlCamera.py:108
items
std::vector< SchemaItem< Flag > > * items
Definition: BaseColumnView.cc:142
list
daf::base::PropertyList * list
Definition: fits.cc:913
lsst::geom::Point< int, 2 >
lsst::geom::Angle
A class representing an angle.
Definition: Angle.h:127
lsst::geom::Box2I
An integer coordinate rectangle.
Definition: Box.h:55
lsst.obs.base.yamlCamera.makeCameraFromCatalogs
def makeCameraFromCatalogs(cameraName, detectorConfigList, nativeSys, transformDict, amplifierDict, pupilFactoryClass=cameraGeom.pupil.PupilFactory)
Definition: yamlCamera.py:254
lsst.obs.base.yamlCamera.makeCamera
def makeCamera(cameraFile)
Definition: yamlCamera.py:34
lsst.obs.base.yamlCamera.makeDetectorConfigList
def makeDetectorConfigList(ccdParams)
Definition: yamlCamera.py:70
lsst::afw::geom::makeTransform
std::shared_ptr< TransformPoint2ToPoint2 > makeTransform(lsst::geom::AffineTransform const &affine)
Wrap an lsst::geom::AffineTransform as a Transform.
Definition: transformFactory.cc:154
lsst::geom::Extent< int, 2 >