In [1]:
import pyfits as pf
import numpy as np
import pandas as pd
import os
import matplotlib.pyplot as plt
In [2]:
%matplotlib notebook
In [3]:
spec_path = './../../GAMAII_SPEC/WHAN_NA_UVUP/'
spec_list = './../../GAMAII_SPEC/filelist_whan.csv'
cxt_path = './../../STARLIGHT/OUTPUTS/'
In [4]:
specs = np.loadtxt(spec_list, delimiter=',', dtype=str)
In [19]:
example = pf.getdata(os.path.join(spec_path, specs[3]))
stuff = pf.open(os.path.join(spec_path, specs[3]))
stuff[0].header
flux = example[0,:]
flux_e = example[1,:]
flux_nc = example[2,:]
fnc_e = example[3,:]
wl_i = stuff[0].header['WMIN']
wl_step = stuff[0].header['CD1_1']
wl_temp = np.arange(flux.size)*wl_step+wl_i # wavelength
data = np.column_stack([flux, flux_e, wl_temp])
datadf = pd.DataFrame(data).dropna()
dataf = datadf.values
In [25]:
plt.subplots(figsize=(10,3))
# plt.plot(wl_temp, flux, '-', label='spectrum')
plt.errorbar(wl_temp, flux, yerr=flux_e, ecolor='pink', alpha=0.5)
plt.xlim([wl_temp.min()-100, wl_temp.max()-100])
plt.show()
In [26]:
header = ['wavelength', 'flux', 'flux_err']
for spec in specs:
fit_file = pf.open(os.path.join(spec_path, spec))
flux_temp = pf.getdata(os.path.join(spec_path, spec))[0,:]
flux_err_temp = pf.getdata(os.path.join(spec_path, spec))[1,:]
cataid = fit_file[0].header['CATAID']
wl_i = fit_file[0].header['WMIN']
wl_step = fit_file[0].header['CD1_1']
wl_temp = np.arange(flux_temp.size)*wl_step+wl_i # wavelength
flag_temp = np.zeros((flux_temp).shape)
data_temp = np.column_stack([wl_temp, flux_temp, flux_err_temp, flag_temp])
data_df = pd.DataFrame(data_temp).dropna()
data = data_df.values
basename = str(cataid)+'.cxt'
np.savetxt(os.path.join(cxt_path, basename), data, fmt=('%6.f', '%11.7f', '%11.8f', '%1d'))
In [ ]: