lsst.afw  15.0-33-g5c41f601f+4
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 lsst.afw.geom import Box2D
23 from .cameraGeomLib import FOCAL_PLANE
24 
25 
27  """!An immutable collection of Detectors that can be accessed by name or ID
28  """
29 
30  def __init__(self, detectorList):
31  """!Construct a DetectorCollection
32 
33  @param[in] detectorList a sequence of detectors in index order
34  """
35  self._idDetectorDict = dict((d.getId(), d) for d in detectorList)
36  self._nameDetectorDict = dict((d.getName(), d) for d in detectorList)
37  self._fpBBox = Box2D()
38  for detector in detectorList:
39  for corner in detector.getCorners(FOCAL_PLANE):
40  self._fpBBox.include(corner)
41  if len(self._idDetectorDict) < len(detectorList):
42  raise RuntimeError("Detector IDs are not unique")
43  if len(self._nameDetectorDict) < len(detectorList):
44  raise RuntimeError("Detector names are not unique")
45 
46  def __iter__(self):
47  """!Support the iter function: return an iterator over all detectors in this collection
48  """
49  return iter(self._idDetectorDict.values())
50 
51  def __len__(self):
52  """!Support the len function: return the number of detectors
53  """
54  return len(self._idDetectorDict)
55 
56  def __getitem__(self, key):
57  """!Support the [key] operator: return the specified detector
58 
59  @param[in] key detector name or ID
60  """
61  if isinstance(key, str):
62  return self._nameDetectorDict[key]
63  else:
64  return self._idDetectorDict[key]
65 
66  def __contains__(self, key):
67  """!Implement the "in" operator: return true if the specified detector is in the collection
68 
69  @param[in] key detector name or ID
70  """
71  if isinstance(key, str):
72  return key in self._nameDetectorDict
73  else:
74  return key in self._idDetectorDict
75 
76  def getNameIter(self):
77  """!Get an iterator over detector names
78  """
79  return iter(self._nameDetectorDict.keys())
80 
81  def getIdIter(self):
82  """!Get an iterator over detector IDs
83  """
84  return iter(self._idDetectorDict.keys())
85 
86  def getFpBBox(self):
87  """!Return a focal plane bounding box that encompasses all detectors
88  """
89  return self._fpBBox
def __len__(self)
Support the len function: return the number of detectors.
def __contains__(self, key)
Implement the "in" operator: return true if the specified detector is in the collection.
def getFpBBox(self)
Return a focal plane bounding box that encompasses all detectors.
def __getitem__(self, key)
Support the [key] operator: return the specified detector.
def __init__(self, detectorList)
Construct a DetectorCollection.
def getNameIter(self)
Get an iterator over detector names.
def __iter__(self)
Support the iter function: return an iterator over all detectors in this collection.
def getIdIter(self)
Get an iterator over detector IDs.
An immutable collection of Detectors that can be accessed by name or ID.