Skip to content

Instantly share code, notes, and snippets.

@JohannesBuchner
Created April 29, 2024 11:26
Show Gist options
  • Save JohannesBuchner/93f6fa0f1df9f3257ea13c193bdebde2 to your computer and use it in GitHub Desktop.
Save JohannesBuchner/93f6fa0f1df9f3257ea13c193bdebde2 to your computer and use it in GitHub Desktop.
Health check for a FITS catalog: should have column descriptions, units and should not fail to load with astropy.
import warnings
import sys
import astropy.io.fits as pyfits
from astropy.table import Table
print("opening FITS file ...")
f = pyfits.open(sys.argv[1])
print("extensions: ", [e.name for e in f])
for i, col in enumerate(f[1].columns, start=1):
colname = col.name
fmt = col.format
unit = f[1].header.get('TUNIT%d' % i)
desc = f[1].header.get('TCOMM%d' % i)
#if fmt in ('E', 'D', 'J') and not fmt.endswith('A'):
# if unit is None:
# warnings.warn('no unit for column "%s", check if that is okay' % colname)
if desc is None:
warnings.warn('no description for column "%s"' % colname)
print('%3d: %s [comment=%s] %s unit=%s' % (i, colname, desc, fmt, unit))
print("opening as a Table ...")
t = Table.read(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment