LSSTApplications  11.0-22-g33de520,12.1+25,13.0+25,13.0+30,13.0-1-g174df6e+3,13.0-1-g41367f3+3,13.0-1-g47a359c+3,13.0-1-g52a7baa+3,13.0-1-g976b40b+3,13.0-10-gcc6134a+6,13.0-10-gf7c21d5+2,13.0-13-gdd29b46+5,13.0-14-gc9904b0,13.0-2-g15de9a1+3,13.0-2-ga4f5e85+6,13.0-2-gf5c5ced+6,13.0-2-gf9e84ea+5,13.0-22-g8f1d162,13.0-3-g7fa07e0+4,13.0-34-ga37f01a,13.0-4-g0bde1de,13.0-5-g0db1a30+1,13.0-5-g6708b9e+9,13.0-6-g7b63e3f+6,13.0-8-gba0f85f,13.0-9-gc47bba1,master-gb637561bb9
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 166 of file multiindex.py.

Constructor & Destructor Documentation

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

Constructor.

Parameters
andConfigConfiguration (an AstrometryNetDataConfig)

Definition at line 177 of file multiindex.py.

178  def __init__(self, andConfig):
179  """!Constructor
180 
181  @param andConfig Configuration (an AstrometryNetDataConfig)
182  """
183  self.config = andConfig
184  cacheName = getIndexPath(self._cacheFilename)
185  if self.config.allowCache and os.path.exists(cacheName):
186  self._initFromCache(cacheName)
187  else:
188  self._initFromIndexFiles(self.config)
def getIndexPath
Get the path to the specified astrometry.net index file.
Definition: multiindex.py:17

Member Function Documentation

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

Definition at line 253 of file multiindex.py.

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

Definition at line 256 of file multiindex.py.

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

Definition at line 259 of file multiindex.py.

260  def __len__(self):
261  return len(self._multiInds)
262 
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 231 of file multiindex.py.

232  def _initFromCache(self, filename):
233  """Initialise from a cache file
234 
235  Ingest the cache file written by the 'writeCache' method and
236  use that to quickly instantiate the AstrometryNetCatalog.
237  """
238  with pyfits.open(filename) as hduList:
239  first = hduList[1].data
240  second = hduList[2].data
241 
242  # first JOIN second USING(id)
243  filenames = {i: [] for i in first.field("id")}
244  for id2, fn in zip(second.field("id"), second.field("filename")):
245  filenames[id2].append(fn)
246  self._multiInds = [MultiIndexCache(filenames[i], hp, nside) for i, hp, nside in
247  zip(first.field("id"), first.field("healpix"), first.field("nside"))]
248 
249  # Check for consistency
250  cacheFiles = set(second.field("filename"))
251  configFiles = set(sum(self.config.multiIndexFiles, []) + self.config.indexFiles)
252  assert(cacheFiles == configFiles)
def lsst.meas.astrom.multiindex.AstrometryNetCatalog._initFromIndexFiles (   self,
  andConfig 
)
private
Initialise from the index files in an AstrometryNetDataConfig

Definition at line 189 of file multiindex.py.

190  def _initFromIndexFiles(self, andConfig):
191  """Initialise from the index files in an AstrometryNetDataConfig"""
192  indexFiles = list(zip(andConfig.indexFiles, andConfig.indexFiles)) + andConfig.multiIndexFiles
193  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 194 of file multiindex.py.

195  def writeCache(self):
196  """Write a cache file
197 
198  The cache file is a FITS file with all the required information to build the
199  AstrometryNetCatalog quickly. The first table extension contains a row for each multiindex,
200  storing the healpix and nside values. The second table extension contains a row
201  for each filename in all the multiindexes. The two may be JOINed through the
202  'id' column.
203  """
204  outName = getIndexPath(self._cacheFilename)
205  numFilenames = sum(len(ind._filenameList) for ind in self._multiInds)
206  maxLength = max(len(fn) for ind in self._multiInds for fn in ind._filenameList) + 1
207 
208  # First table
209  first = pyfits.new_table([pyfits.Column(name="id", format="K"),
210  pyfits.Column(name="healpix", format="K"),
211  pyfits.Column(name="nside", format="K"),
212  ], nrows=len(self._multiInds))
213  first.data.field("id")[:] = numpy.arange(len(self._multiInds), dtype=int)
214  first.data.field("healpix")[:] = numpy.array([ind._healpix for ind in self._multiInds])
215  first.data.field("nside")[:] = numpy.array([ind._nside for ind in self._multiInds])
216 
217  # Second table
218  second = pyfits.new_table([pyfits.Column(name="id", format="K"),
219  pyfits.Column(name="filename", format="%dA" % (maxLength)),
220  ], nrows=numFilenames)
221  ident = second.data.field("id")
222  filenames = second.data.field("filename")
223  i = 0
224  for j, ind in enumerate(self._multiInds):
225  for fn in ind._filenameList:
226  ident[i] = j
227  filenames[i] = fn
228  i += 1
229 
230  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:17

Member Data Documentation

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

Definition at line 175 of file multiindex.py.

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

Definition at line 192 of file multiindex.py.

lsst.meas.astrom.multiindex.AstrometryNetCatalog.config

Definition at line 182 of file multiindex.py.


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