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