LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
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.