예제 #1
0
def read_xmm(filepath):
    """
    collects data from CS's xmm outputs and for the apec models
    """
    hdul = fits.open(filepath)
    #spectrum
    data = hdul[1].data
    w, f, e = data['Wave'], data['CFlux'], data['CFLux_Err']
    w0, w1 = w - (data['bin_width']/2), w+(data['bin_width']/2)
    hdr = hdul[0].header
    exptime = np.full(len(w), hdr['HIERARCH pn_DURATION'])
    expstart = Time(hdr['HIERARCH pn_DATE-OBS']).mjd
    expend = Time(hdr['HIERARCH pn_DATE-END']).mjd
    instrument_list = ['xmm_epc_multi','xmm_epc_pn---']
    instrument_code = np.sum([inst.getinsti(i) for i in instrument_list])
    xmm_collection = dict_builder(w0, w1, w, f, e, np.zeros(len(w)),exptime, expstart, expend, instrument_code)
    #model
    data = hdul[2].data
    w, f = data['Wave'], data['Flux']
    w0, w1 = w - (data['bin_width']/2), w+(data['bin_width']/2)
   # hdr = hdul[0].header
    instrument_code = inst.getinsti('mod_apc_-----')
    apec_collection = dict_builder(w0, w1, w, f, np.zeros(len(w)), np.zeros(len(w)),np.zeros(len(w)), 0., 0., instrument_code)
    hdul.close()
    return xmm_collection, apec_collection
예제 #2
0
def read_phoenix(filepath, wavepath):
    """
    gather information from a phoenix model. Note that flux and wavelegth are in different files
    """
    w = fits.getdata(wavepath, 0)
    f = fits.getdata(filepath)
    w0, w1 = wavelength_edges(w)
    instrument_code = inst.getinsti('mod_phx_-----')
    phx_collection = dict_builder(w0,w1,w,f, np.zeros(len(w)), np.zeros(len(w)), np.zeros(len(w)), 0., 0., instrument_code)
    return phx_collection
예제 #3
0
def read_ecsv_phoenix(filepath):
    """
    gather information from a phoenix model saved as ecsv
    """
    data = Table.read(filepath)
    w, f = data['WAVELENGTH'], data['FLUX']
    w0, w1 = wavelength_edges(w)
    instrument_code = inst.getinsti('mod_phx_-----')
    phx_collection = dict_builder(w0,w1,w,f, np.zeros(len(w)), np.zeros(len(w)), np.zeros(len(w)), 0., 0., instrument_code)
    return phx_collection
예제 #4
0
def read_lyamod(filepath):
    """
    gather information from a lya model
    """
    lya = Table.read(filepath, format='ascii')
    w, f = lya['WAVELENGTH'], lya['FLUX']
    w0, w1 = wavelength_edges(w)
    instrument_code = inst.getinsti('mod_lya_young')
    lya_collection = dict_builder(w0,w1,w,f, np.zeros(len(w)), np.zeros(len(w)), np.zeros(len(w)), 0., 0., instrument_code)
    return lya_collection
예제 #5
0
def make_euv(lya, distance):
    """
    collects the bits for an euv estimation
    """
    w, f = euv_estimator(lya, distance)
    w0, w1 = wavelength_edges(w)
    e, dq, exptime = np.zeros(len(w)), np.zeros(len(w)), np.zeros(len(w))
    expstart, expend = 0., 0.
    instrument_code = inst.getinsti('mod_euv_young')
    euv_collection = dict_builder(w0, w1, w, f, e, dq, exptime, expstart, expend, instrument_code)
    return euv_collection
예제 #6
0
def read_ecsv(filepath, instrument):
    """
    reads an escv with a coadded spectrum. Not much in these yet, need to improve.
    """
    data = Table.read(filepath)#
    w, f, e, dq = data['WAVELENGTH'], data['FLUX'], data['ERROR'], data['DQ']
    w0, w1 = wavelength_edges(w)
    #needs everything else!
    instrument_code = inst.getinsti(instrument.lower())
    ecsv_collection =  dict_builder(w0, w1, w, f, e, dq, np.zeros(len(w)), 0.,0, instrument_code)
    return ecsv_collection
예제 #7
0
def hst_instrument_column(table):
    """
    Builds an instrument column and adds it to data. For HST data.
    """
    telescope, instrument, grating = table.meta['TELESCOP'], table.meta['INSTRUME'], table.meta['GRATING']
    if instrument == 'STIS':
        instrument = 'sts'
    inst_string = '%s_%s_%s' % (telescope.lower(), instrument.lower(), grating.lower())
    inst_code = instruments.getinsti(inst_string)
    inst_array = np.full(len(table['WAVELENGTH']), inst_code, dtype=int)
    table['INSTRUMENT'] = inst_array
    return inst_code, table
예제 #8
0
def read_stis_ccd(filepath):
    """
    collects data for a STIS ccd observation
    """
    data = fits.getdata(filepath)[0]
    hdr = fits.getheader(filepath,0)
    w, f, e, dq = data['WAVELENGTH'], data['FLUX'], data['ERROR'], data['DQ']
    w0, w1 = wavelength_edges(w)
    exptime = np.full(len(w), hdr['TEXPTIME'])
    expstart, expend = hdr['TEXPSTRT'], hdr['TEXPEND']
    instrument_name = hdr['TELESCOP']+'_sts_'+hdr['OPT_ELEM']  #nb STIS=sts in Pl code 
    instrument_code = inst.getinsti(instrument_name.lower())
    stis_ccd_collection = dict_builder(w0, w1, w, f, e, dq, exptime, expstart, expend, instrument_code)
    return stis_ccd_collection
예제 #9
0
def read_idl(filepath):
    """
    Extracts data from KF's IDL files
    """
    data = readsav(filepath)
    w, f, e, exptime = data['wave'], data['flux'], data['err'], data['exptime']
    dq = np.zeros(len(w)) #consult with kf on this
    w0, w1 = wavelength_edges(w)
    instrument_list = np.unique(data['grating'])
    instruments = np.array([('hst_cos_'+str(i)[2:-1].lower()) for i in instrument_list])
    instrument_code = np.sum([inst.getinsti(i) for i in instruments])
    expstart, expend = 0, 0 #not in idl, placeholder.
    idl_collection = dict_builder(w0, w1, w, f, e, dq, exptime, expstart, expend, instrument_code)
    return idl_collection
예제 #10
0
def read_dem(filepath):
    """
    adds a dem model to the EUV
    """
    data = fits.getdata(filepath,1)
    w, bin_f, bin_e = data['Wavelength'], data['Bin-Integrated Flux'], data['Error']
    w0, w1 = wavelength_edges(w)
    f = bin_f/(w1-w0) #convert from bin-intergrated flux to flux 
    w, f = dem_to_1A(w,f)
    w0, w1 = wavelength_edges(w) #remake bin edges
    e, dq, exptime = np.zeros(len(w)), np.zeros(len(w)), np.zeros(len(w))
    expstart, expend = 0., 0.
    instrument_code = inst.getinsti('oth_---_other')
    dem_collection = dict_builder(w0, w1, w, f, e, dq, exptime, expstart, expend, instrument_code)
    return dem_collection
예제 #11
0
def read_cos_nuv(filepath, fillgap=True):
    """
    collects data from a COS nuv observation. If fill gap =True, fits a polynomial to the gap and trims the zero-flux inner ends off the spectra
    """
    data = fits.getdata(filepath,1)[0:2] #not using reflected order
    hdr0 = fits.getheader(filepath,0)
    hdr1 = fits.getheader(filepath,1)
    w = np.array([], dtype=float)
    f = np.array([], dtype=float)
    e = np.array([], dtype=float)
    dq = np.array([], dtype=int)
    if fillgap == True:
        gap_w, gap_f = nuv_fill(data)
        for dt in data:
            mask = (dt['WAVELENGTH'] < gap_w[0]) | (dt['WAVELENGTH'] > gap_w[-1])
            w= np.concatenate((w, dt['WAVELENGTH'][mask]))
            f = np.concatenate((f, dt['FLUX'][mask]))
            e = np.concatenate((e, dt['ERROR'][mask]))
            dq = np.concatenate((dq, dt['DQ'][mask]))
        gap_w0, gap_w1 = wavelength_edges(gap_w)
        gap_code = inst.getinsti('oth_---_other')
        gap_collection = dict_builder(gap_w0, gap_w1, gap_w, gap_f, np.zeros(len(gap_w)), np.zeros(len(gap_w)),np.zeros(len(gap_w)), 0., 0., gap_code)        
    else:
        for dt in data:
            w= np.concatenate((w, dt['WAVELENGTH']))
            f = np.concatenate((f, dt['FLUX']))
            e = np.concatenate((e, dt['ERROR']))
            dq = np.concatenate((dq, dt['DQ']))
        gap_collection = {}
    w0, w1 = wavelength_edges(w)
    exptime = np.full(len(w), hdr1['EXPTIME'])
    expstart, expend = hdr1['EXPSTART'], hdr1['EXPEND']
    instrument_name = hdr0['TELESCOP']+'_cos_'+hdr0['OPT_ELEM']   
    instrument_code = inst.getinsti(instrument_name.lower())
    cos_nuv_collection = dict_builder(w0, w1, w, f, e, dq, exptime, expstart, expend, instrument_code)
    return cos_nuv_collection, gap_collection
예제 #12
0
def read_stis_x1d(filepath):
    """
    Extracts data from a hst x1d file
    """
    hdul = fits.open(filepath)
    data = hdul[1].data[0]
    w, f, e, dq = data['WAVELENGTH'], data['FLUX'], data['ERROR'], data['DQ']
    w0, w1 = wavelength_edges(w)
    hdr = hdul[0].header
    exptime = np.full(len(w), hdr['TEXPTIME'])
    expstart, expend = hdr['TEXPSTRT'], hdr['TEXPEND']
    instrument_name = hdr['TELESCOP']+'_sts_'+hdr['OPT_ELEM']  #nb STIS=sts in Pl code 
    instrument_code = inst.getinsti(instrument_name.lower())
    stis_x1d_collection = dict_builder(w0, w1, w, f, e, dq, exptime, expstart, expend, instrument_code)
    hdul.close()
    return stis_x1d_collection
예제 #13
0
def fill_model(table, model_name):
    """
    Fills out the missing columns from a model ecsv
    """
    table_length = len(table['WAVELENGTH'])
    fill_zeros = np.zeros(table_length)
    extra_names = ['ERROR', 'EXPTIME', 'DQ', 'EXPSTART', 'EXPEND']
    for i in range(len(extra_names)):
        table[extra_names[i]] = fill_zeros  #*units[i]
    inst_code = instruments.getinsti(model_name)
    inst_array = np.full(table_length, inst_code, dtype=int)
    table['INSTRUMENT'] = inst_array
    norm_array = np.full(len(table['WAVELENGTH']),
                         table.meta['NORMFAC'],
                         dtype=float)
    table['NORMFAC'] = norm_array
    return inst_code, table