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
detectorCollection.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2014 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 from __future__ import absolute_import, division
23 from past.builtins import basestring
24 from builtins import object
25 from lsst.afw.geom import Box2D
26 from .cameraGeomLib import FOCAL_PLANE
27 
28 class DetectorCollection(object):
29  """!An immutable collection of Detectors that can be accessed by name or ID
30  """
31  def __init__(self, detectorList):
32  """!Construct a DetectorCollection
33 
34  @param[in] detectorList a sequence of detectors in index order
35  """
36  self._idDetectorDict = dict((d.getId(), d) for d in detectorList)
37  self._nameDetectorDict = dict((d.getName(), d) for d in detectorList)
38  self._fpBBox = Box2D()
39  for detector in detectorList:
40  for corner in detector.getCorners(FOCAL_PLANE):
41  self._fpBBox.include(corner)
42  if len(self._idDetectorDict) < len(detectorList):
43  raise RuntimeError("Detector IDs are not unique")
44  if len(self._nameDetectorDict) < len(detectorList):
45  raise RuntimeError("Detector names are not unique")
46 
47  def __iter__(self):
48  """!Support the iter function: return an iterator over all detectors in this collection
49  """
50  return iter(self._idDetectorDict.values())
51 
52  def __len__(self):
53  """!Support the len function: return the number of detectors
54  """
55  return len(self._idDetectorDict)
56 
57  def __getitem__(self, key):
58  """!Support the [key] operator: return the specified detector
59 
60  @param[in] key detector name or ID
61  """
62  if isinstance(key, basestring):
63  return self._nameDetectorDict[key]
64  else:
65  return self._idDetectorDict[key]
66 
67  def __contains__(self, key):
68  """!Implement the "in" operator: return true if the specified detector is in the collection
69 
70  @param[in] key detector name or ID
71  """
72  if isinstance(key, basestring):
73  return key in self._nameDetectorDict
74  else:
75  return key in self._idDetectorDict
76 
77  def getNameIter(self):
78  """!Get an iterator over detector names
79  """
80  return iter(self._nameDetectorDict.keys())
81 
82  def getIdIter(self):
83  """!Get an iterator over detector IDs
84  """
85  return iter(self._idDetectorDict.keys())
86 
87  def getFpBBox(self):
88  """!Return a focal plane bounding box that encompasses all detectors
89  """
90  return self._fpBBox
int iter
def __contains__
Implement the &quot;in&quot; operator: return true if the specified detector is in the collection.
def __iter__
Support the iter function: return an iterator over all detectors in this collection.
def getFpBBox
Return a focal plane bounding box that encompasses all detectors.
def getNameIter
Get an iterator over detector names.
def __getitem__
Support the [key] operator: return the specified detector.
def __len__
Support the len function: return the number of detectors.
A floating-point coordinate rectangle geometry.
Definition: Box.h:271
An immutable collection of Detectors that can be accessed by name or ID.