def _fits_generate_header(tab):
""" Generate the corresponding fits Header that contains all necessary info
Parameters
----------
tab: SimpleTable instance
table
Returns
-------
hdr: pyfits.Header
header instance
"""
# get column cards
cards = []
# names units and comments
for e, k in enumerate(tab.keys()):
cards.append(('TTYPE{0:d}'.format(e + 1), k, tab._desc.get(k, '')))
u = tab._units.get(k, '')
if u not in ['', 'None', None]:
cards.append(('TUNIT{0:d}'.format(e + 1), tab._units.get(k, ''),
'unit of {0:s}'.format(k)))
# add aliases
for e, v in enumerate(tab._aliases.items()):
cards.append( ('ALIAS{0:d}'.format(e + 1), '='.join(v), '') )
if tab.header['NAME'] not in ['', 'None', None, 'No Name']:
cards.append(('EXTNAME', tab.header['NAME'], ''))
hdr = pyfits.Header(cards)
for k, v in tab.header.items():
if (v not in ['', 'None', None]) & (k != 'NAME'):
if (k != 'COMMENT') & (k != 'HISTORY'):
hdr.update(k, v)
else:
txt = v.split('\n')
for j in txt:
if k == 'COMMENT':
hdr.add_comment(j)
elif k == 'HISTORY':
hdr.add_history(j)
return hdr
评论列表
文章目录