Libraries


In [1]:
import pyfits as pf
import numpy  as np
import pandas as pd
import os
import matplotlib.pyplot as plt

In [2]:
spec_path = './../../GAMAII_SPEC/WHAN_NA_UVUP/'
spec_list = './../../GAMAII_SPEC/filelist_whan.csv'
csv_path  = './../../GAMAII_SPEC/WHAN_NA_UVUP/csv_files/'

In [3]:
specs = np.loadtxt(spec_list, delimiter=',', dtype=str)

In [4]:
header = ['wavelength', 'flux']
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,:]
    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
    data_temp = np.column_stack((wl_temp, flux_temp))
    data      = pd.DataFrame(data_temp).dropna()
    data.columns = header
    basename  = str(cataid)+'.csv'
    data.to_csv(os.path.join(csv_path, basename), index=False)

In [5]:
check_header  = pf.open(os.path.join(spec_path, specs[0]))

In [6]:
check_header[0].header


Out[6]:
SIMPLE  =                    T / file does conform to FITS standard             
BITPIX  =                  -32 / number of bits per data pixel                  
NAXIS   =                    2 / number of data axes                            
NAXIS1  =                 4952 / length of data axis 1                          
NAXIS2  =                    5 / length of data axis 2                          
EXTEND  =                    T / FITS dataset may contain extensions            
COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H 
BSCALE  =                   1. / True_value = BSCALE * FITS_value + BZERO       
BZERO   =                   0. / True_value = BSCALE * FITS_value + BZERO       
DATE    = '2015-03-24T14:04:33' / file creation date (YYYY-MM-DDThh:mm:ss UT)   
ORIGIN  = 'GAMA    '           / Source of the data                             
OBSERVAT= 'SSO     '           / Name of observatory                            
LATITUDE=            -31.27704 / Telescope latitude in deg                      
LONGITUD=             149.0661 / Telescope longitude in deg                     
ALTITUDE=                1164. / Telescope height above sea level in m          
TELESCOP= 'AAT     '           / 3.9m Anglo-Australian Telescope                
INSTRUME= 'AAOMEGA-2dF'        / AAOmega/2dF multi-fibre spectrograph           
SPECTID = 'RD      '           / Spectrograph ID                                
GRATID  = '385R 580V'          / Disperser ID                                   
DICHROIC= 'X5700   '           / Dichroic name                                  
PLATE   =                    0 / 2dF plate number                               
RDNOISE =                 3.49 / Readout noise in e-                            
GAIN    =                1.799 / Readout gain in e-/ADU                         
FIBRE   =                  220 / Fibre number                                   
PIVOT   =                  220 / Pivot number                                   
X       =                23817 / Fibre button x position on plate               
Y       =               -78974 / Fibre button y position on plate               
THETA   =               197.76 / Fibre angle in deg                             
N_EXP   =                    3 / Number of exposures                            
T_EXP   =                3600. / Total exposure time in s                       
N_NIGHTS=                    1 / Number of nights over which exposures were spre
DATE-OBS= '2008-03-01'         / UT date of observation                         
UTMJD   =     54526.5244930182 / Mean MJD of start of exposures                 
UTSTART = '12:12:57'           / UT of start of first exposure                  
UTEND   = '13:19:33'           / UT of end of last exposure                     
ZDSTART =                 32.5 / Zenith distance at start of first exposure in d
ZDEND   =                40.06 / Zenith distance at end of last exposure in deg 
HASTART =                 0.83 / Hour angle at start of first exposure in deg   
HAEND   =               -26.14 / Hour angle at end of last exposure in deg      
HEL_VC  =                -13.2 / Heliocentric velocity correction in km/s       
CTYPE1  = 'Wavelength'         / Type of coordinate on axis 1                   
CUNIT1  = 'Angstrom'           / Units for axis 1                               
CRPIX1  =                2476. / WCS reference point                            
CRVAL1  =       6291.743164062 / WCS reference value                            
CD1_1   =          1.035940794 / WCS transformation matrix element              
CD1_2   =                   0. / WCS transformation matrix element              
CD2_1   =                   0. / WCS transformation matrix element              
CD2_2   =                   1. / WCS transformation matrix element              
ROW1    = 'Spectrum'           / Flux-calibrated spectrum in 10^-17 erg/s/cm^2/A
ROW2    = 'Error   '           / 1 sigma error spectrum                         
ROW3    = 'Spectrum_nocalib'   / Spectrum without flux calibration              
ROW4    = 'Error_nocalib'      / 1 sigma error spectrum (no flux calibration)   
ROW5    = 'Sky     '           / Sky spectrum (no flux calibration)             
FIELDID = 'G09_Y1_BN1'         / ID of GAMA AAT field                           
SPECID  = 'G09_Y1_BN1_220'     / ID of GAMA AAT spectrum                        
RA      =            130.69321 / RA of spectrum in deg (J2000)                  
DEC     =              1.35583 / DEC of spectrum in deg (J2000)                 
WMIN    =              3727.79 / Minimum wavelength in A                        
WMAX    =              8856.73 / Maximum wavelength in A                        
Z       =              0.07871 / Heliocentric redshift                          
NQ      =                    4 / Normalised redshift quality (use nQ>2 for scien
PROB    =                   1. / Probability that redshift is correct           
SN      =                 7.01 / S/N as measured by runz                        
SN_ALT  =                 6.73 / Median S/N per pixel in 4500-6500 A band       
RFLUXFAC=          9.05726E-19 / Ratio of r-band petrosian to fibre flux        
CATAID  =               375789 / ID of matched GAMA object                      
OBJECT  =               375789 / ID of matched GAMA object                      
GAMANAME= 'GAMAJ084246.37+012120.9' / Name of matched GAMA object               
IC_FLAG =                 4104 / Catalogue source(s) of matched GAMA object     
DIST    =                 0.07 / Distance between spec and object in arcsec     
IS_SBEST=                    T / GAMA AAT spectrum with best redshift for this o

In [ ]: