Ejemplo n.º 1
0
 def init_params(self, fixed_pars, n_spline):
     data = self.data
     mod = self.model_cosmo
     n = n_spline
     leff = np.array(data['l_eff'])
     n_SN = self.n_sn
     par_list = [('color_law', len(color_law_params)), 'Omega_m', 'Omega_k', 'w', 'wa', 'H0', 'Omega_b_h2', 'beta', ('theta_salt', n+1),  ('mB', n_SN), ('c', n_SN)] + ['zp'+band for band in self.bands] + ['dl'+band for band in self.bands]
     lambda_grid = np.linspace(np.min(leff)-10, np.max(leff)+10, n)
     base = bspline.BSpline(lambda_grid, order=3)
     params = FitParameters(par_list)
     par_names = []
     for ppp in par_list:
         if type(ppp) == tuple:
             a = ppp[0]
         else:
             a = ppp
         if a in fixed_pars:
             continue
         else:
             par_names += [a]
     from saunerie.indextools import make_index
     snindex = make_index(data['#SN'])
     snindex = [sn[0] for sn in snindex]
     params['mB'] = -2.5*np.log10(X0)
     params['c'] = data[snindex]['c']
     params['color_law'] = color_law_params
     params['Omega_m'] = mod.Omega_m
     params['Omega_k'] = mod.Omega_k
     params['w'], params['wa'] = mod.w, mod.wa
     params['H0'], params['Omega_b_h2'] = mod.H0, mod.Omega_b_h2
     params['beta'] = beta
     zpb = np.zeros(len(data))
     for band in self.bands:
         zpb[data['band']==band] = params['zp'+band].free
     flx = -2.5*np.log10(data['A']) - (params['mB'].free[data['#SN']] + mod.mu(data['z']) + zpb + 20 + 2.5*np.log10(1+data['z']) + data['zp'] - 2.5*np.log10(A_hc) + params['c'].free[data['#SN']]*(np.polyval(params['color_law'].free, transfo(data['l_eff']))+params['beta'].free))
     spectrum_fit = base.linear_fit(np.array(data['l_eff']), np.array(flx))
     params['theta_salt'] = spectrum_fit
     for par in fixed_pars:
         params.fix(par)
     return params, base
Ejemplo n.º 2
0
###


class NotKeptError(Exception):
    pass


print 'Starting --- ' + time.ctime()
m = InstrumentModel("LSSTPG")
cfg = saltpath.read_card_file(saltpath.fitmodel_filename)
salt2_model_path = saltpath.SALTPATH + os.sep + cfg['SALT2']
M0_filename = salt2_model_path + os.sep + 'salt2_template_0.dat'
nt = NTuple.fromtxt(M0_filename)
idx = nt['f0'] == 0
gx = np.linspace(nt['f1'][idx].min() - 1e-10, nt['f1'][idx].max() + 1e-10, 100)
base = bspline.BSpline(gx, order=4)
p = base.linear_fit(nt['f1'][idx], nt['f2'][idx])

color_disp_fit = np.array([
    -1.33846154e-18, 3.98286713e-14, -4.66894522e-10, 2.69988432e-06,
    -7.71355752e-03, 8.74507867e+00
])

# def color_disp_func(l):
#     """ SALT2 colour dispersion as a function of wavelength (from Guy et al. 2010, Fig 8)
#     """
#     disps = np.zeros(len(l))
#     disps[l<3000] = 2e-1
#     disps[(3000 <= l) & (l < 4000)] = 2e-1 - (1.8e-1 / 1000. * (l[(3000 <= l) & (l < 4000)]-3000))
#     disps[(4000 <= l) & (l < 5500)] = 2e-2
#     disps[(5500 <= l) & (l < 6250)] = 2e-2 + (1.5e-2 / 750. * (l[(5500 <= l) & (l < 6250)]-5500))
Ejemplo n.º 3
0
der_dl = []
for band in 'grizy':
    filtre = m.EffectiveFilterByBand(band)
    der_dl += [-2.5*np.log10(spec_2.IntegFlux(filtre)/spec.IntegFlux(filtre))]
der_dl = np.array(der_dl)
#####################################################################


mod = cosmo.Cosmow0wa()
leff = np.array(data_ok['l_eff'])
n_SN = len(np.unique(data_ok['#SN']))
X0 = 76516964.662612781

nbase = 30
lambda_grid = np.linspace(np.min(leff)-10, np.max(leff)+10, nbase)
base = bspline.BSpline(lambda_grid, order=3)
# idxfit = nt['f0'] ==0
# idxfit &= nt['f1'] <= leff.max()+1
# idxfit &= nt['f1'] >= leff.min()-1
# wls = np.array(nt['f1'][idxfit])
# flx = np.array(nt['f2'][idxfit])

par_list = [('color_law', len(color_law_params)), 'Omega_m', 'Omega_k', 'w', 'wa', 'H0', 'Omega_b_h2', 'beta', 'zpg', 'zpr', 'zpi', 'zpz', 'zpy', ('theta_salt', nbase+1),  ('mB', n_SN), ('c', n_SN), 'dlg', 'dlr', 'dli', 'dlz', 'dly']
params = FitParameters(par_list)
#fixed_pars = ['dlg', 'dlr', 'dli', 'dlz', 'dly', "theta_salt", "color_law"]
#fixed_pars = []
fixed_pars = ['theta_salt', 'color_law']

par_names = []
for ppp in par_list:
    if type(ppp) == tuple: