1 """
2 A grammar taking rows from a FITS table.
3 """
4
5
6
7
8
9
10
11 from gavo import base
12 from gavo.grammars import common
13
14 from gavo.utils import pyfits
15
17 """The row iterator for FITSTableGrammars.
18 """
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
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