LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
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)
def makeTransformDict
Make a dictionary of CameraSys: lsst.afw.geom.XYTransform from a config dict.
An integer coordinate rectangle.
Definition: Box.h:53
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.
def makeCameraFromCatalogs
Construct a Camera instance from a dictionary of detector name: AmpInfoCatalog.