def open_lc(fichier, fichier_results_salt):
    lc = NTuple.fromfile(fichier)
    tableau = NTuple.fromfile(fichier_results_salt)
    bands = np.unique(lc['Filter'])
    if lc.keys['SURVEY'] == 'SDSS':
        sn_name = lc.keys['SURVEY'] + str(int(lc.keys['SN']))
    else:
        sn_name = lc.keys['SN']
    idx_name = None
    for i, t_name in enumerate(tableau['name']):
        if sn_name not in t_name:
            continue
        else:
            idx_name = i
    if idx_name is None:
        raise ValueError('No entry in %s found for the SN in %s' %
                         (fichier_results_salt, fichier))
    snr = np.zeros(len(bands))  #, dtype=np.dtype([(a, float) for a in bands]))
    for i, band in enumerate(bands):
        idx = lc['Filter'] == band
        wi = 1. / self.lc[idx]['Fluxerr']**2
        fi2 = self.lc[idx]['Flux']**2
        snr[i] = np.sqrt(np.sum(wi * fi2))
    return bands, snr, tableau
Exemplo n.º 2
0
def get_sne_measurments(fichier, lcs=None, bands='grizy', taille_max=100000):
    dt = [('z', float), ('c', float), ('X0', float), 
          ('X1', float), ('dL', float),
          ('band', 'S1'), ('#SN', int),
          ('A', float), 
          ('l_eff', float),
          ('zp', float), 
          ('snr', float)]
    if os.path.exists(fichier):
        print 'Already have a data file --- '+time.ctime()
        data_ok = NTuple.fromfile(fichier).view(np.ndarray)
    elif lcs is not None:
        if len(lcs) > taille_max:
            lcs = np.random.choice(lcs, taille_max)
        data = np.zeros(6*len(lcs), dtype=dt)

        lambda_effs = np.zeros(1, dtype=[(band, object) for band in 'grizy'])
        zps = np.zeros(1, dtype=[(band, object) for band in 'grizy'])
        for band in 'grizy':
            lambda_effs[band] = get_lambda_f(band)
            zps[band] = get_zp(band)

        k = 0
        print 'Creating data ntuple (needs SALT2 redo) --- '+time.ctime()
        for i, lc in enumerate(lcs):
            bands = np.unique(lc.lc['band'])
            for j, band1 in enumerate(bands):
                band = band1[-1]
                data[k+j] = (lc.sn['z'], lc.sn['Color'], lc.lcmodel.X0(lc.sn), lc.sn['X1'], lc.sn['dL'], band, i,
                             find_amplitude(lc, band), lambda_effs[band][0], zps[band][0], find_snr(lc, band))
            k += len(bands)
            if (i+1)%100 == 0:
                print 'Data computed for %d supernovae' % (i+1)

        data['l_eff'] = 1./(1.+data['z'])*data['l_eff']
        data = data[data['band'] != '']

        data_ok = data[data['snr'] != 0]
        data_ok.view(NTuple).tofile(fichier)
    else:
        raise ValueError('Could not produce a data NTuple without an existing datafile or a list of light curves')
    return np.sort(data_ok, order='z')
Exemplo n.º 3
0
        snr[i] = np.sqrt(np.sum(wi * fi2))
        mags[i] = _mags[bands == band]
        zps[i] = np.mean(lc[idx]['ZP'])
    return bands, mags, snr, zps, tableau[idx_name]


entree = NTuple.fromtxt('selected_sn_complete.list')
# fichier = 'data_jla.nxt' ### Ne prend pas de courbes de lumière
fichier = 'data_test_lc.nxt'  ### Prend des courbes de lumière et sommes les SNR

# lcs_files = glob('/home/betoule/cosmo_jla1/data/lowz-2013-06-20_schlafly/*.list') + glob('/home/betoule/cosmo_jla1/data/sdss_2013-06-20_schlafly/SDSS*.DAT') + glob('/home/betoule/cosmo_jla1/data/snls3_recalibrated_lc_v2_5/lc*.list')

lcs_files = glob('/data/betoule/jla1/preproc_GMG5BWI/data/lc*.list')
if os.path.exists(fichier):
    print 'Already have a data file --- ' + time.ctime()
    data_ok = NTuple.fromfile(fichier).view(np.ndarray)
else:
    data = np.zeros(720 * 10, dtype=dt)
    k = 0
    ii = 0
    print 'Creating data ntuple (needs SALT2 redo) --- ' + time.ctime()
    for i, lc_file in enumerate(lcs_files):
        try:
            bands, mags, snr, zps, lc = open_lc(lc_file, entree)
        except NotKeptError:
            print "No line found for %s in %s" % (lc_file,
                                                  'selected_sn_complete.list')
            continue
        for j in range(len(bands)):
            instru = InstrumentModel(bands[j].split('_')[0])
            # data[k+j] = (lc['z'], lc['c'], lc['x0'], lc['x1'], np.nan, bands[j], i,
        return self.C

    def reset(self):
        if self.impacted:
            self.lines, self.cols, self.J_dat = self.J_reco
            self.Clines, self.Ccols, self.C_dat = self.C_reco
            self.W = self.W_reco
        else:
            return 0


###############
#### FIT ######
###############

data_ok = NTuple.fromfile('data_ntuples/jla_mags.nxt')

data_ok['l_eff'] = data_ok['l_eff'] / (1 + data_ok['z'])

# data_ok = data_ok[~np.isnan(data_ok['dAdX0'])]

data_ok['dAdX0'] = data_ok['dAdX0'] / data_ok['dL']

# model_type = "wwa"
model_type = "lambdaCDM"

if model_type == "wwa":
    mod = cosmo.Cosmow0wa()
else:
    mod = cosmo.CosmoLambda()
Exemplo n.º 5
0
    den = (l * filtre_trans).integrate(x_min, x_max)
    return num / den


### Pas un vrai Zp, : -2.5 log(\int T(\lambda) \lambda d\lambda))
def get_zp(band):
    it = 0.1
    lambdas = np.arange(2000, 12000 + it, it)
    filtre = m.EffectiveFilterByBand(band)
    return -2.5 * np.log10((lambdas * filtre(lambdas)).sum() * it)


##### Calcul du NTuple des flux interpolés à DayMax

if os.path.exists('data.nxt'):
    data_ok = NTuple.fromfile('data.nxt').view(np.ndarray)
else:
    #lcs, log, model = example.main()
    lcs_deep, log_deep, model = example.create_survey('deep')
    lcs_wide, log_wide, model_wide = example.create_survey('wide')
    lcs = lcs_wide + lcs_deep

    if len(lcs) > 10000:
        lcs1 = np.random.choice(lcs, 10000)
    else:
        lcs1 = lcs

    data = np.zeros(4 * len(lcs1), dtype=dt)

    lambda_effs = np.zeros(1, dtype=[(band, object) for band in 'grizy'])
    zps = np.zeros(1, dtype=[(band, object) for band in 'grizy'])