Package gavo :: Package grammars :: Module fitstablegrammar
[frames] | no frames]

Source Code for Module gavo.grammars.fitstablegrammar

 1  """ 
 2  A grammar taking rows from a FITS table. 
 3  """ 
 4   
 5  #c Copyright 2008-2019, the GAVO project 
 6  #c 
 7  #c This program is free software, covered by the GNU GPL.  See the 
 8  #c COPYING file in the source distribution. 
 9   
10   
11  from gavo import base 
12  from gavo.grammars import common 
13   
14  from gavo.utils import pyfits 
15   
16 -class FITSTableIterator(common.RowIterator):
17 """The row iterator for FITSTableGrammars. 18 """
19 - def _iterRows(self):
20 hdus = pyfits.open(self.sourceToken) 21 fitsTable = hdus[self.grammar.hdu].data 22 names = [n for n in fitsTable.dtype.names] 23 for row in fitsTable: 24 res = dict(zip(names, row)) 25 yield res
26 27
28 -class FITSTableGrammar(common.Grammar):
29 """A grammar parsing from FITS tables. 30 31 fitsTableGrammar result in typed records, i.e., values normally come 32 in the types they are supposed to have. Of course, that won't work 33 for datetimes, STC-S regions, and the like. 34 35 The keys of the result dictionaries are simpily the names given in 36 the FITS. 37 """ 38 name_ = "fitsTableGrammar" 39 40 _hduIndex = base.IntAttribute("hdu", default=1, 41 description="Take the data from this extension (primary=0)." 42 " Tabular data typically resides in the first extension.") 43 44 rowIterator = FITSTableIterator
45