LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
cameraFactory.py
Go to the documentation of this file.
1 import os.path
2 import lsst.afw.geom as afwGeom
3 from lsst.afw.table import AmpInfoCatalog
4 from .cameraGeomLib import FOCAL_PLANE, PUPIL, PIXELS, TAN_PIXELS, ACTUAL_PIXELS, CameraSys, \
5  Detector, Orientation, CameraTransformMap
6 from .camera import Camera
7 from .makePixelToTanPixel import makePixelToTanPixel
8 
9 __all__ = ["makeCameraFromPath", "makeCameraFromCatalogs", "makeDetector"]
10 
11 cameraSysList = [PUPIL, FOCAL_PLANE, PIXELS, TAN_PIXELS, ACTUAL_PIXELS]
12 cameraSysMap = dict((sys.getSysName(), sys) for sys in cameraSysList)
13 
14 def makeDetector(detectorConfig, ampInfoCatalog, focalPlaneToPupil):
15  """!Make a Detector instance from a detector config and amp info catalog
16 
17  @param detectorConfig config for this detector (an lsst.pex.config.Config)
18  @param ampInfoCatalog amplifier information for this detector (an lsst.afw.table.AmpInfoCatalog)
19  @param focalPlaneToPupil FOCAL_PLANE to PUPIL XYTransform
20  @return detector (an lsst.afw.cameraGeom.Detector)
21  """
22  orientation = makeOrientation(detectorConfig)
23  pixelSizeMm = afwGeom.Extent2D(detectorConfig.pixelSize_x, detectorConfig.pixelSize_y)
24  transforms = makeTransformDict(detectorConfig.transformDict.transforms)
25  transforms[FOCAL_PLANE] = orientation.makePixelFpTransform(pixelSizeMm)
26 
27  llPoint = afwGeom.Point2I(detectorConfig.bbox_x0, detectorConfig.bbox_y0)
28  urPoint = afwGeom.Point2I(detectorConfig.bbox_x1, detectorConfig.bbox_y1)
29  bbox = afwGeom.Box2I(llPoint, urPoint)
30 
31  tanPixSys = CameraSys(TAN_PIXELS, detectorConfig.name)
32  transforms[tanPixSys] = makePixelToTanPixel(
33  bbox = bbox,
34  orientation = orientation,
35  focalPlaneToPupil = focalPlaneToPupil,
36  pixelSizeMm = pixelSizeMm,
37  )
38 
39  return Detector(
40  detectorConfig.name,
41  detectorConfig.id,
42  detectorConfig.detectorType,
43  detectorConfig.serial,
44  bbox,
45  ampInfoCatalog,
46  orientation,
47  pixelSizeMm,
48  transforms,
49  )
50 
51 def makeOrientation(detectorConfig):
52  """!Make an Orientation instance from a detector config
53 
54  @param detectorConfig config for this detector (an lsst.pex.config.Config)
55  @return orientation (an lsst.afw.cameraGeom.Orientation)
56  """
57  offset = afwGeom.Point2D(detectorConfig.offset_x, detectorConfig.offset_y)
58  refPos = afwGeom.Point2D(detectorConfig.refpos_x, detectorConfig.refpos_y)
59  yaw = afwGeom.Angle(detectorConfig.yawDeg, afwGeom.degrees)
60  pitch = afwGeom.Angle(detectorConfig.pitchDeg, afwGeom.degrees)
61  roll = afwGeom.Angle(detectorConfig.rollDeg, afwGeom.degrees)
62  return Orientation(offset, refPos, yaw, pitch, roll)
63 
64 def makeTransformDict(transformConfigDict):
65  """!Make a dictionary of CameraSys: lsst.afw.geom.XYTransform from a config dict.
66 
67  @param transformConfigDict an lsst.pex.config.ConfigDictField from an lsst.afw.geom.XYTransform
68  registry; keys are camera system names.
69  @return a dict of CameraSys or CameraSysPrefix: lsst.afw.geom.XYTransform
70  """
71  resMap = dict()
72  if transformConfigDict is not None:
73  for key in transformConfigDict:
74  transform = transformConfigDict[key].transform.apply()
75  resMap[CameraSys(key)] = transform
76  return resMap
77 
78 def makeCameraFromPath(cameraConfig, ampInfoPath, shortNameFunc):
79  """!Make a Camera instance from a directory of ampInfo files
80 
81  The directory must contain one ampInfo fits file for each detector in cameraConfig.detectorList.
82  The name of each ampInfo file must be shortNameFunc(fullDetectorName) + ".fits".
83 
84  @param[in] cameraConfig an instance of CameraConfig
85  @param[in] ampInfoPath path to ampInfo data files
86  @param[in] shortNameFunc a function that converts a long detector name to a short one
87  @return camera (an lsst.afw.cameraGeom.Camera)
88  """
89  ampInfoCatDict = dict()
90  for detectorConfig in cameraConfig.detectorList.values():
91  shortName = shortNameFunc(detectorConfig.name)
92  ampCatPath = os.path.join(ampInfoPath, shortName + ".fits")
93  ampInfoCatalog = AmpInfoCatalog.readFits(ampCatPath)
94  ampInfoCatDict[detectorConfig.name] = ampInfoCatalog
95 
96  return makeCameraFromCatalogs(cameraConfig, ampInfoCatDict)
97 
98 def makeCameraFromCatalogs(cameraConfig, ampInfoCatDict):
99  """!Construct a Camera instance from a dictionary of detector name: AmpInfoCatalog
100 
101  @param[in] cameraConfig an instance of CameraConfig
102  @param[in] ampInfoCatDict a dictionary of detector name: AmpInfoCatalog
103  @return camera (an lsst.afw.cameraGeom.Camera)
104  """
105  nativeSys = cameraSysMap[cameraConfig.transformDict.nativeSys]
106  transformDict = makeTransformDict(cameraConfig.transformDict.transforms)
107  focalPlaneToPupil = transformDict[PUPIL]
108  transformMap = CameraTransformMap(nativeSys, transformDict)
109 
110  detectorList = []
111  for detectorConfig in cameraConfig.detectorList.values():
112  ampInfoCatalog = ampInfoCatDict[detectorConfig.name]
113 
114  detectorList.append(makeDetector(
115  detectorConfig = detectorConfig,
116  ampInfoCatalog = ampInfoCatalog,
117  focalPlaneToPupil = focalPlaneToPupil,
118  ))
119 
120  return Camera(cameraConfig.name, detectorList, transformMap)
Camera coordinate system; used as a key in in TransformMap.
Definition: CameraSys.h:77
def makeTransformDict
Make a dictionary of CameraSys: lsst.afw.geom.XYTransform from a config dict.
An integer coordinate rectangle.
Definition: Box.h:53
Describe a detector's orientation in the focal plane.
Definition: Orientation.h:53
A class representing an Angle.
Definition: Angle.h:103
def makeOrientation
Make an Orientation instance from a detector config.
def makeCameraFromPath
Make a Camera instance from a directory of ampInfo files.
def makePixelToTanPixel
Make an XYTransform whose forward direction converts PIXEL to TAN_PIXEL for one detector.
def makeDetector
Make a Detector instance from a detector config and amp info catalog.
Information about a CCD or other imaging detector.
Definition: Detector.h:65
def makeCameraFromCatalogs
Construct a Camera instance from a dictionary of detector name: AmpInfoCatalog.