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
Public Member Functions | Public Attributes | Private Attributes | List of all members
lsst.meas.astrom.multiindex.MultiIndexCache Class Reference
Inheritance diagram for lsst.meas.astrom.multiindex.MultiIndexCache:

Public Member Functions

def __init__
 Constructor. More...
 
def fromFilenameList
 
def read
 
def reload
 
def unload
 
def isWithinRange
 Is the index within range of the provided coordinates? More...
 
def __getitem__
 
def __len__
 
def __iter__
 

Public Attributes

 log
 

Private Attributes

 _filenameList
 
 _healpix
 
 _nside
 
 _mi
 
 _loaded
 

Detailed Description

A wrapper for the multiindex_t, which only reads the data when it needs to

The MultiIndexCache may be instantiated directly, or via the 'fromFilenameList'
class method, which loads it from a list of filenames.

Definition at line 53 of file multiindex.py.

Constructor & Destructor Documentation

def lsst.meas.astrom.multiindex.MultiIndexCache.__init__ (   self,
  filenameList,
  healpix,
  nside 
)

Constructor.

Parameters
filenameListList of filenames; first is the multiindex, then follows the individual index files
healpixHealpix number
nsideHealpix nside

Definition at line 59 of file multiindex.py.

59 
60  def __init__(self, filenameList, healpix, nside):
61  """!Constructor
62 
63  @param filenameList List of filenames; first is the multiindex, then
64  follows the individual index files
65  @param healpix Healpix number
66  @param nside Healpix nside
67  """
68  if len(filenameList) < 2:
69  raise RuntimeError("Insufficient filenames provided for multiindex (%s): expected >= 2" %
70  (filenameList,))
71  self._filenameList = filenameList
72  self._healpix = int(healpix)
73  self._nside = int(nside)
74  self._mi = None
75  self._loaded = False
76  self.log = getDefaultLog()

Member Function Documentation

def lsst.meas.astrom.multiindex.MultiIndexCache.__getitem__ (   self,
  i 
)

Definition at line 146 of file multiindex.py.

147  def __getitem__(self, i):
148  self.reload()
149  return self._mi[i]
def lsst.meas.astrom.multiindex.MultiIndexCache.__iter__ (   self)

Definition at line 153 of file multiindex.py.

154  def __iter__(self):
155  self.reload()
156  return iter(self._mi)
157 
int iter
def lsst.meas.astrom.multiindex.MultiIndexCache.__len__ (   self)

Definition at line 150 of file multiindex.py.

151  def __len__(self):
152  return len(self._filenameList) - 1 # The first is the multiindex; the rest are the indices
def lsst.meas.astrom.multiindex.MultiIndexCache.fromFilenameList (   cls,
  filenameList 
)
Construct from a list of filenames

The list of filenames should contain the multiindex filename first,
then the individual index filenames.  The healpix and nside are
determined by reading the indices, so this is not very efficient.

Definition at line 78 of file multiindex.py.

78 
79  def fromFilenameList(cls, filenameList):
80  """Construct from a list of filenames
81 
82  The list of filenames should contain the multiindex filename first,
83  then the individual index filenames. The healpix and nside are
84  determined by reading the indices, so this is not very efficient.
85  """
86  self = cls(filenameList, 0, 0)
87  self.reload()
88  healpixes = set(self[i].healpix for i in range(len(self)))
89  nsides = set(self[i].hpnside for i in range(len(self)))
90  assert len(healpixes) == 1
91  assert len(nsides) == 1
92  self._healpix = healpixes.pop()
93  self._nside = nsides.pop()
94  return self
def lsst.meas.astrom.multiindex.MultiIndexCache.isWithinRange (   self,
  coord,
  distance 
)

Is the index within range of the provided coordinates?

Parameters
coordCoordinate to check (lsst.afw.coord.Coord)
distanceAngular distance (lsst.afw.geom.Angle)

Definition at line 138 of file multiindex.py.

139  def isWithinRange(self, coord, distance):
140  """!Is the index within range of the provided coordinates?
141 
142  @param coord Coordinate to check (lsst.afw.coord.Coord)
143  @param distance Angular distance (lsst.afw.geom.Angle)
144  """
145  return (self._nside == 0 or healpixDistance(self._healpix, self._nside, coord) <= distance)
def isWithinRange
Is the index within range of the provided coordinates?
Definition: multiindex.py:138
def lsst.meas.astrom.multiindex.MultiIndexCache.read (   self)
Read the indices

Definition at line 95 of file multiindex.py.

95 
96  def read(self):
97  """Read the indices"""
98  if self._mi is not None:
99  return
100  fn = getIndexPath(self._filenameList[0])
101  if not os.path.exists(fn):
102  raise RuntimeError("Unable to get filename for astrometry star file %s" % (self._filenameList[0],))
103  self._mi = multiindex_new(fn)
104  if self._mi is None:
105  # Can't proceed at all without stars
106  raise RuntimeError('Failed to read stars from astrometry multiindex filename "%s"' % fn)
107  for i, fn in enumerate(self._filenameList[1:]):
108  if fn is None:
109  self.log.logdebug('Unable to find index part of multiindex %s' % fn)
110  continue
111  fn = getIndexPath(fn)
112  if not os.path.exists(fn):
113  self.log.warn("Unable to get filename for astrometry index %s" % (fn,))
114  continue
115  self.log.logdebug('Reading index from multiindex file "%s"' % fn)
116  if multiindex_add_index(self._mi, fn, INDEX_ONLY_LOAD_METADATA):
117  raise RuntimeError('Failed to read index from multiindex filename "%s"' % fn)
118  ind = self._mi[i]
119  self.log.logdebug(' index %i, hp %i (nside %i), nstars %i, nquads %i' %
120  (ind.indexid, ind.healpix, ind.hpnside, ind.nstars, ind.nquads))
def getIndexPath
Get the path to the specified astrometry.net index file.
Definition: multiindex.py:11
def lsst.meas.astrom.multiindex.MultiIndexCache.reload (   self)
Reload the indices.

Definition at line 121 of file multiindex.py.

122  def reload(self):
123  """Reload the indices."""
124  if self._loaded:
125  return
126  if self._mi is None:
127  self.read()
128  else:
129  self._mi.reload()
130  self._loaded = True
def lsst.meas.astrom.multiindex.MultiIndexCache.unload (   self)
Unload the indices

Definition at line 131 of file multiindex.py.

132  def unload(self):
133  """Unload the indices"""
134  if not self._loaded:
135  return
136  self._mi.unload()
137  self._loaded = False

Member Data Documentation

lsst.meas.astrom.multiindex.MultiIndexCache._filenameList
private

Definition at line 70 of file multiindex.py.

lsst.meas.astrom.multiindex.MultiIndexCache._healpix
private

Definition at line 71 of file multiindex.py.

lsst.meas.astrom.multiindex.MultiIndexCache._loaded
private

Definition at line 74 of file multiindex.py.

lsst.meas.astrom.multiindex.MultiIndexCache._mi
private

Definition at line 73 of file multiindex.py.

lsst.meas.astrom.multiindex.MultiIndexCache._nside
private

Definition at line 72 of file multiindex.py.

lsst.meas.astrom.multiindex.MultiIndexCache.log

Definition at line 75 of file multiindex.py.


The documentation for this class was generated from the following file: