示例#1
0
def get_CfA_templates():
    [snparam, NA, tmaxparam] = readcol("cfaspec_snIa/cfasnIa_param.dat", 'aff')
    [snclass, NA, NA, NA, NA, NA, classclass] = readcol("cfaspec_snIa/branchwangclass.dat", 'affffaa')
    [specname, specdate] = readcol("cfaspec_snIa/cfasnIa_mjdspec.dat", 'af')

    spectra2 = []
    sntypes2 = []
    
    print specname[:10]
    print snparam[:10]
    print snclass[:10]
    
    for i in range(len(snparam)):
        found = 0
        for j in range(len(specname)):
            if specname[j].count(snparam[i] + "-"):
                print snparam[i], specname[j]
                found = 1

                if snclass.count(snparam[i]):
                    ind = snclass.index(snparam[i])
                    phase = specdate[j] - tmaxparam[i]
                    
                    if phase > -10 and phase < 5:
                        spectra2.append(glob.glob("cfaspec_snIa/*/" + specname[j])[0])
                        sntypes2.append("Ia-" + classclass[ind])
    return spectra2, sntypes2
示例#2
0
def Kim13_PCs():
    [bands, pcs, phases, mags] = readcol("input/LC_PCs.txt", 'aiff')
    bands = array(bands)

    interpfns = {}
    for i, band in enumerate('griz'):
        plt.subplot(2,2,i+1)
        plt.title(band)
        for pc in range(4):
            inds = where((bands == band)*(pcs == pc))
            phase = phases[inds]
            mag = mags[inds]
            
            phase = concatenate(([-100.], phase, [100.]))
            mag = concatenate(([mag[0]], mag, [mag[-1]]))
            
            interpfns[(band, pc)] = interp1d(phase, mag, kind = 'linear')
            plt.plot(arange(-10., 36.), interpfns[(band, pc)](arange(-10., 36.)), label = str(pc))
        plt.legend(loc = 'best')
    plt.savefig("pc_interps.pdf")
    plt.close()

    redshift = 1.2

    sncosmo_model = realize_SN_model(redshift = redshift, x1 = 0.0, c = 0.0, MV = -19.08 + 2.1*0.0)
    if redshift == 1.2:
        colors = {"Z087": 'm', "Y106": 'b', "J129": 'g', "H158": 'orange'} # "F184": 'red'
        obs_to_pc_filt = {"Z087": 'g', "Y106": 'r', "J129": 'i', "H158": 'z'}
    else:
        colors = {"Y106": 'b', "J129": 'g', "H158": 'orange', "F184": 'red'}
        obs_to_pc_filt = {"Y106": 'g', "J129": 'r', "H158": 'i', "F184": 'z'}

    dates = arange(-10*(1. + redshift), 35*(1 + redshift), 5)
    phases = dates/(1. + redshift)
    jacobian = zeros([len(phases)*4, 6], dtype=float64) # parameters are daymax, mag, pc0123
    jacobian[:,1] = 1.

    weight_matrix = zeros([len(phases)*4]*2, dtype=float64)
    total_SNR_all = 0.

    for i, date in enumerate(dates):
        phase = date/(1. + redshift)
        for j, filt in enumerate(colors):

            total_SN = 0
            f_lamb_SN = sncosmo_model.flux(date, obs_waves)
            args["mdl"] = f_lamb_SN


            for dither in range(1):
                ETC_result = get_imaging_SN(redshift = redshift, exp_time = 100.*(1. + (filt == "F184")), effective_meters2_fl = filt + ".txt", phase = phase,
                                            offset_i = random.random()*22, offset_j = random.random()*22, **args)
                
                total_SN += ETC_result["PSF_phot_S/N"]**2.
            total_SNR_all += total_SN
            total_SN = sqrt(total_SN)

            dmag = (2.5/log(10.))/total_SN
            weight_matrix[i + j*len(dates), i + j*len(dates)] = 1./(dmag**2.)

            f_lamb_SN = sncosmo_model.flux(date + 0.2*(1. + redshift), obs_waves)
            args["mdl"] = f_lamb_SN
            ETC_result_dphase = get_imaging_SN(redshift = redshift, exp_time = 100., effective_meters2_fl = filt + ".txt", phase = phase + 0.2,
                                               offset_i = random.random()*22, offset_j = random.random()*22, **args)

            jacobian[i + j*len(dates), 0] = (ETC_result_dphase["AB_mag"] - ETC_result["AB_mag"])/0.2


            for k in range(4):
                jacobian[i + j*len(dates), k+2] = interpfns[(obs_to_pc_filt[filt], k)](phase)

    total_SNR_all = sqrt(total_SNR_all)
    print weight_matrix
    save_img(jacobian, "jacobian.fits")
    save_img(weight_matrix, "weight_matrix.fits")
    param_wmat = dot(transpose(jacobian), dot(weight_matrix, jacobian))
    param_cmat = linalg.inv(param_wmat)
    print param_cmat
    print total_SNR_all, sqrt(diag(param_cmat))
示例#3
0
#[spectra, types] = readcol("selected_spectra.txt", 'aa')
PSFs = initialize_PSFs(pixel_scales = [15, 30], slice_scales = [30, 30], PSF_source = "WebbPSF", path = wfirst_data_path + "/pixel-level/")

args = {"pixel_scale": 0.075, "slice_scale": 0.15, "source_dir": wfirst_data_path + "/pixel-level/input/", "IFURfl": "IFU_R_160720.txt", "min_wave": 4200.,
        "max_wave": 20000., "PSFs": PSFs, "phase": 0, "redshift": 1.0}


first_ETC_run = get_spec_with_err(exp_time = 100., **args)
args["waves"] = first_ETC_run["obs_waves"]

rest_waves = args["waves"]/(1 + args["redshift"])

for spectrum, sntype in zip(spectra, sntypes):
    print spectrum

    [orig_waves, orig_fluxes] = readcol(spectrum, 'ff')
    orig_fluxes /= max(orig_fluxes)

    # First, we just get the correct normalization

    spec = interp1d(orig_waves, orig_fluxes, kind = 'linear', fill_value = 0, bounds_error = False)(rest_waves)

    inds = where((rest_waves > 5000.)*(rest_waves < 6000.))
    orig_fluxes *= dot(first_ETC_run["f_lamb_SN"][inds], first_ETC_run["f_lamb_SN"][inds])/dot(spec[inds], first_ETC_run["f_lamb_SN"][inds])
    
    matched_resolution = spectrum_to_matched_resolution(orig_waves*(1 + args["redshift"]), orig_fluxes, min_wave = args["min_wave"], max_wave = args["max_wave"],
                                                        IFUR = interpfile(wfirst_data_path + "/pixel-level/input/IFU_R_160720.txt"), pixel_scale = 0.075)


    args["mdl"] = matched_resolution
    exp_time = solve_for_exptime(S_to_N = 23.2, key1= "rest_frame_band_S/N", key2= (5000, 6000), **args)
示例#4
0
from numpy import *
from FileRead import readcol
import glob

for fl in glob.glob("*dat"):
    [phase, wave, flux] = readcol(fl, 'fff')
    if len(phase) > 0:
        
        assert median(wave) > 5000 and median(wave) < 15000, fl
        dwave = wave[1:] - wave[:-1]
        print fl, sum(dwave != median(dwave))/float(len(dwave))
        inds = where(dwave < 0)[0]
        
        for ind in inds:
            assert wave[ind - 1] < 18000.
            
        for i in range(len(wave))[::-1]:
            if wave[i] >= 18000.:
                dwave = wave[i] - wave[i - 1]
                print dwave
                new_waves = arange(wave[i] + dwave, 21999.9 + dwave, dwave)
                new_phases = ones(len(new_waves), dtype=float64)*phase[i]
                new_fluxes = ones(len(new_waves), dtype=float64)*flux[i]
                
                wave = concatenate((wave[:i+1], new_waves, wave[i+1:]))
                phase = concatenate((phase[:i+1], new_phases, phase[i+1:]))
                flux = concatenate((flux[:i+1], new_fluxes, flux[i+1:]))


        f = open(fl, 'w')
        for i in range(len(wave)):