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