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

Public Member Functions

def __init__
 Constructor. More...
 
def writeCache
 
def __getitem__
 
def __iter__
 
def __len__
 

Public Attributes

 config
 

Private Member Functions

def _initFromIndexFiles
 
def _initFromCache
 

Private Attributes

 _multiInds
 

Static Private Attributes

string _cacheFilename = "andCache.fits"
 

Detailed Description

An interface to an astrometry.net catalog

Behaves like a list of MultiIndexCache (or multiindex_t).

These should usually be constructed using the 'fromEnvironment'
class method, which wraps the 'fromIndexFiles' and 'fromCache'
alternative class methods.

Definition at line 158 of file multiindex.py.

Constructor & Destructor Documentation

def lsst.meas.astrom.multiindex.AstrometryNetCatalog.__init__ (   self,
  andConfig 
)

Constructor.

Parameters
andConfigConfiguration (an AstrometryNetDataConfig)

Definition at line 169 of file multiindex.py.

170  def __init__(self, andConfig):
171  """!Constructor
172 
173  @param andConfig Configuration (an AstrometryNetDataConfig)
174  """
175  self.config = andConfig
176  cacheName = getIndexPath(self._cacheFilename)
177  if self.config.allowCache and os.path.exists(cacheName):
178  self._initFromCache(cacheName)
179  else:
180  self._initFromIndexFiles(self.config)
def getIndexPath
Get the path to the specified astrometry.net index file.
Definition: multiindex.py:11

Member Function Documentation

def lsst.meas.astrom.multiindex.AstrometryNetCatalog.__getitem__ (   self,
  ii 
)

Definition at line 245 of file multiindex.py.

246  def __getitem__(self, ii):
247  return self._multiInds[ii]
def lsst.meas.astrom.multiindex.AstrometryNetCatalog.__iter__ (   self)

Definition at line 248 of file multiindex.py.

249  def __iter__(self):
250  return iter(self._multiInds)
int iter
def lsst.meas.astrom.multiindex.AstrometryNetCatalog.__len__ (   self)

Definition at line 251 of file multiindex.py.

252  def __len__(self):
253  return len(self._multiInds)
254 
def lsst.meas.astrom.multiindex.AstrometryNetCatalog._initFromCache (   self,
  filename 
)
private
Initialise from a cache file

Ingest the cache file written by the 'writeCache' method and
use that to quickly instantiate the AstrometryNetCatalog.

Definition at line 223 of file multiindex.py.

224  def _initFromCache(self, filename):
225  """Initialise from a cache file
226 
227  Ingest the cache file written by the 'writeCache' method and
228  use that to quickly instantiate the AstrometryNetCatalog.
229  """
230  with pyfits.open(filename) as hduList:
231  first = hduList[1].data
232  second = hduList[2].data
233 
234  # first JOIN second USING(id)
235  filenames = {i: [] for i in first.field("id")}
236  for id2, fn in zip(second.field("id"), second.field("filename")):
237  filenames[id2].append(fn)
238  self._multiInds = [MultiIndexCache(filenames[i], hp, nside) for i, hp, nside in
239  zip(first.field("id"), first.field("healpix"), first.field("nside"))]
240 
241  # Check for consistency
242  cacheFiles = set(second.field("filename"))
243  configFiles = set(sum(self.config.multiIndexFiles, []) + self.config.indexFiles)
244  assert(cacheFiles == configFiles)
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
Definition: operators.h:1250
def lsst.meas.astrom.multiindex.AstrometryNetCatalog._initFromIndexFiles (   self,
  andConfig 
)
private
Initialise from the index files in an AstrometryNetDataConfig

Definition at line 181 of file multiindex.py.

182  def _initFromIndexFiles(self, andConfig):
183  """Initialise from the index files in an AstrometryNetDataConfig"""
184  indexFiles = zip(andConfig.indexFiles, andConfig.indexFiles) + andConfig.multiIndexFiles
185  self._multiInds = [MultiIndexCache.fromFilenameList(fnList) for fnList in indexFiles]
def lsst.meas.astrom.multiindex.AstrometryNetCatalog.writeCache (   self)
Write a cache file

The cache file is a FITS file with all the required information to build the
AstrometryNetCatalog quickly.  The first table extension contains a row for each multiindex,
storing the healpix and nside values.  The second table extension contains a row
for each filename in all the multiindexes.  The two may be JOINed through the
'id' column.

Definition at line 186 of file multiindex.py.

187  def writeCache(self):
188  """Write a cache file
189 
190  The cache file is a FITS file with all the required information to build the
191  AstrometryNetCatalog quickly. The first table extension contains a row for each multiindex,
192  storing the healpix and nside values. The second table extension contains a row
193  for each filename in all the multiindexes. The two may be JOINed through the
194  'id' column.
195  """
196  outName = getIndexPath(self._cacheFilename)
197  numFilenames = sum(len(ind._filenameList) for ind in self._multiInds)
198  maxLength = max(len(fn) for ind in self._multiInds for fn in ind._filenameList) + 1
199 
200  # First table
201  first = pyfits.new_table([pyfits.Column(name="id", format="K"),
202  pyfits.Column(name="healpix", format="K"),
203  pyfits.Column(name="nside", format="K"),
204  ], nrows=len(self._multiInds))
205  first.data.field("id")[:] = numpy.arange(len(self._multiInds), dtype=int)
206  first.data.field("healpix")[:] = numpy.array([ind._healpix for ind in self._multiInds])
207  first.data.field("nside")[:] = numpy.array([ind._nside for ind in self._multiInds])
208 
209  # Second table
210  second = pyfits.new_table([pyfits.Column(name="id", format="K"),
211  pyfits.Column(name="filename", format="%dA" % (maxLength)),
212  ], nrows=numFilenames)
213  ident = second.data.field("id")
214  filenames = second.data.field("filename")
215  i = 0
216  for j, ind in enumerate(self._multiInds):
217  for fn in ind._filenameList:
218  ident[i] = j
219  filenames[i] = fn
220  i += 1
221 
222  pyfits.HDUList([pyfits.PrimaryHDU(), first, second]).writeto(outName, clobber=True)
def getIndexPath
Get the path to the specified astrometry.net index file.
Definition: multiindex.py:11
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
Definition: operators.h:1250

Member Data Documentation

string lsst.meas.astrom.multiindex.AstrometryNetCatalog._cacheFilename = "andCache.fits"
staticprivate

Definition at line 167 of file multiindex.py.

lsst.meas.astrom.multiindex.AstrometryNetCatalog._multiInds
private

Definition at line 184 of file multiindex.py.

lsst.meas.astrom.multiindex.AstrometryNetCatalog.config

Definition at line 174 of file multiindex.py.


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