Commit 8293a308 authored by Monica Rainer's avatar Monica Rainer
Browse files

Add gofio2ascii.py

parent be3f1d35
from astropy.io import fits,ascii
import numpy as np
lista = raw_input('List of s1d/ms1d fits files to convert in ascii (default = fits.lis):\n')
if lista == '':
lista='fits.lis'
split = raw_input('Do you want to split the orders of the ms1d files (if any) ([y/n] default yes)? ')
if split == '':
split = 'y'
lis = open(lista,'r')
with open(lista) as framelist:
for frame in framelist:
frame = frame.strip()
calib_ascii = frame.replace('.fits','.txt')
spettro = fits.open(frame)
try:
sdata = spettro[1].data
wcalib = sdata.field(1)
spec = sdata.field(2)
snr = sdata.field(3)
for o in xrange(50):
wcalib[o] = wcalib[o][::-1]
spec[o] = spec[o][::-1]
snr[o] = snr[o][::-1]
if split == 'y':
txt = '_' + str(o+32) + '.txt'
order_ascii = frame.replace('.fits',txt)
order = np.vstack((wcalib[o],spec[o],snr[o]))
ascii.write(np.transpose(order),order_ascii, format='no_header')
print 'Saved %s' % (order_ascii)
if split == 'n':
optCal = np.vstack((np.concatenate(np.flipud(wcalib)),np.concatenate(np.flipud(spec)),np.concatenate(np.flipud(snr))))
ascii.write(np.transpose(optCal),calib_ascii, format='no_header')
print 'Saved %s' % (calib_ascii)
except:
hea = spettro[0].header
data = spettro[0].data
start = hea['CRVAL1']
step = hea['CDELT1']
new = open(calib_ascii,'w')
k = 0
while k < len(data):
wave = start + (k*step)
new.write(str(wave) + '\t' + str(data[k]) + '\n')
k = k+1
new.close()
print 'Saved %s' % (calib_ascii)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment