Skip to content

Instantly share code, notes, and snippets.

@boada
Created July 14, 2015 18:29
Show Gist options
  • Save boada/e3a4ca3de3d0db280b2b to your computer and use it in GitHub Desktop.
Save boada/e3a4ca3de3d0db280b2b to your computer and use it in GitHub Desktop.
from glob import glob
from astropy import table
from astropy.io import fits
from os.path import exists
files = glob('*.fit')
for f in files:
print f, '.....',
if not exists(f.replace('fit', 'hdf5')):
try:
t = table.Table.read(f, 'r')
t.write(f.replace('.fit', '.hdf5'),
path=f.split('_')[1]+'_'+f.split('.')[1])
print 'Done'
except IOError:
data = fits.getdata(f, ignore_missing_end=True)
t = table.Table(data)
t.write(f.replace('.fit', '.hdf5'),
path=f.split('_')[1]+'_'+f.split('.')[1])
print 'Done'
else:
print 'Already Done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment