Пример #1
0
def params_to_chi2(params_modelo,Mabs):
    '''Dados los parámetros del modelo devuelve un chi2'''

    [b,c,d,r_0,n] = params_modelo

    def dX_dz(z, variables):
        x = variables[0]
        y = variables[1]
        v = variables[2]
        w = variables[3]
        r = variables[4]

        G = gamma(r,b,c,d,n)

        s0 = (-w + x**2 + (1+v)*x - 2*v + 4*y) / (z+1)
        s1 = - (v*x*G - x*y + 4*y - 2*y*v) / (z+1)
        s2 = -v * (x*G + 4 - 2*v) / (z+1)
        s3 = w * (-1 + x+ 2*v) / (z+1)
        s4 = -x*r*G/(1+z)
        return [s0,s1,s2,s3,s4]

    z,E = integrador(dX_dz,ci, params_modelo)
    os.chdir(path_git+'/Software/Estadística/')
    zcmb,zhel, Cinv, mb = leer_data_pantheon('lcparam_full_long_zhel.txt')
    muth = magn_aparente_teorica(z,E,zhel,zcmb)

    if isinstance(Mabs,list):
        chis_M = np.zeros(len(Mabs))
        for i,M_0 in enumerate(Mabs):
            chis_M[i] = chi_2(muth,mb,M_0,Cinv)
        return chis_M
    else:
        chi2 = chi_2(muth,mb,Mabs,Cinv)
        return chi2
omega_m = 0.1
H0 = 73.48
eps = 10**(-41)
mstep = 8*10**(-8)
params_fisicos = [omega_m,b,H0]

#Integramos con RK45
#zs_ode, H_HS = integrador(params_fisicos, verbose=True, model='HS')
#_, H_ST = integrador(params_fisicos, verbose=True, model='ST')
#_, H_EXP = integrador(params_fisicos, epsilon=eps, verbose=True, model='EXP',max_step=10**(-6))

#Integramos con LSODA
#zs_ode, H_HS_1 = integrador(params_fisicos, verbose=True, model='HS',method='LSODA')
#_, H_ST_1 = integrador(params_fisicos, verbose=True, model='ST',method='LSODA')
zs_ode, H_EXP_1 = integrador(params_fisicos, epsilon=eps,
                verbose=True, model='EXP',method='LSODA'
                ,max_step=mstep)
plt.plot(zs_ode,H_EXP_1)
#%%
def porcentual_error(vec_ref,vec_compare):
    error = 100 * (1 - (vec_compare/vec_ref))
    return error

#error_HS = porcentual_error(H_HS,H_HS_1)
#error_ST = porcentual_error(H_ST,H_ST_1)
error_EXP = porcentual_error(H_EXP,H_EXP_1)

%matplotlib qt5
plt.figure()
plt.title('Error en integracion comparando distintos métodos')
plt.xlabel('z (redshift)')
Пример #3
0
    return H

#%%
omega_m = 0.24
H0 = 73.48

#bs = np.linspace(0.1, 5, 3)
bs = [3, 6]
cantidad_zs = int(10**3)
max_steps = 10**(-4)

Hs = np.zeros((len(bs),cantidad_zs))

for i, b in enumerate(bs):
    params_fisicos = [omega_m,b,H0]
    zs, H_ode = integrador(params_fisicos, n=2, cantidad_zs=cantidad_zs,
                max_step=max_steps)
    Hs[i,:] = H_ode

#%%
H_lcdm = H_LCDM(zs, omega_m, H0)
Da_lcdm = (c_luz_km/(1 +zs)) * cumtrapz(H_lcdm**(-1), zs, initial=0)
Dl_lcdm = (c_luz_km*(1 +zs)) * cumtrapz(H_lcdm**(-1), zs, initial=0)

#%%
%matplotlib qt5
plt.close()
plt.figure()
plt.grid(True)

#plt.title('Modelo de Hu-Sawicki con $n=1$', fontsize=15)
plt.title('Modelo de Starobinsky con $n=1$', fontsize=15)
import sys
import os
from os.path import join as osjoin
from pc_path import definir_path
path_git, path_datos_global = definir_path()
os.chdir(path_git)
sys.path.append('./Software/Funcionales/')
from funciones_int import integrador
from funciones_taylor import Taylor_HS

b = 0.15
omega_m = 0.3
H0 = 73.48
params_fisicos=[omega_m,b,H0]
zs, H_RK45 = integrador(params_fisicos, cantidad_zs=int(10**5),
                        max_step=10**(-5), model='HS',method='RK45')
_, H_LSODA = integrador(params_fisicos, cantidad_zs=int(10**5),
                        max_step=10**(-5), model='HS',method='LSODA')
error = 100*np.abs(1-(H_LSODA/H_RK45))

#%%
%matplotlib qt5
plt.close()
plt.figure()
plt.grid(True)
plt.title('Error Porcentual para Hu-Sawicki',fontsize=15)

plt.xlabel('z',fontsize=13)
plt.ylabel('Error Porcentual',fontsize=13)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
from scipy.interpolate import interp1d
from scipy.constants import c as c_luz #metros/segundos
c_luz_km = c_luz/1000 #km/seg
#ORDEN DE PRESENTACION DE LOS PARAMETROS: Mabs,omega_m,b,H_0,n

z_final = 30
cantidad_zs = int(10**5)
max_step = 10**(-5)

b = 0.5
omega_m = 0.24
H0 = 73.48
params_fisicos = [omega_m,b,H0]

zs_ref, H_ref = integrador(params_fisicos, n=2, cantidad_zs=cantidad_zs,
            max_step=max_step, z_inicial=z_final, z_final=0,
            model='HS')

f = interp1d(zs_ref,H_ref)


z_inicial = np.linspace(3,z_final,5)
error_porcentual = np.zeros(len(z_inicial))
for i,z0 in enumerate(z_inicial):

    zs, H_ode = integrador(params_fisicos, n=2, cantidad_zs=cantidad_zs,
                max_step=max_step, z_inicial=z0, z_final=0,
                model='HS')
    H_ref = f(zs)

    error_porcentual[i] = 100*np.abs(np.mean(1-(H_ode/H_ref)))
os.chdir(path_git)
sys.path.append('./Software/Funcionales/')
from funciones_int import integrador

#%%
b = 0.1
omega_m = 0.24
H0 = 73.48
params_fisicos=[omega_m,b,H0]

#%%
archivo_math = '/Software/Sandbox/Integracion numérica/chequeos_ODE/chequeo_otros_lenguajes/Mathematica'
os.chdir(path_git+archivo_math)
z_math,E_math=np.loadtxt('mfile_ODE_{}.csv'.format(b),unpack=True,delimiter = ',')

zs, H_ode=integrador(params_fisicos,max_step=0.003,cantidad_zs=int(10**5))
f = interp1d(zs,H_ode)
H_int = f(z_math)
E_int = H_int/H0

#%%
%matplotlib qt5
plt.figure()
plt.grid(True)
plt.xlabel('z(redshift)')
plt.ylabel('Error porcentual')
plt.plot(z_math,100*(1-E_int/E_math),label='Error porcentual')
plt.legend(loc='best')
np.mean(100*(1-(E_int/E_math)))

#%%
bs=np.linspace(0.01,0.5,500)
#bs=np.array([0.01, 0.02, 0.05, 0.1, 0.12, 0.15, 0.2, 0.3, 0.4, 0.5, 1, 2]) #HS

error_b = np.zeros(len(bs))
omega_m = 0.3
H0 = 73.48


#%% Hu-Sawicki n=2
for i, b in enumerate(bs):
    print(i)
    params_fisicos = [omega_m,b,H0]

    zs, H_ode = integrador(params_fisicos, cantidad_zs=int(10**5), max_step=10**(-5), model='HS')
    H_taylor = Taylor_HS(zs,omega_m,b,H0)

    error_b[i] = 100*np.abs(np.mean(1-(H_taylor/H_ode)))

#%%
%matplotlib qt5
plt.close()
plt.figure()
plt.grid(True)
plt.title('Error Porcentual para Hu-Sawicki n=1',fontsize=15)

plt.xlabel('b',fontsize=13)
plt.ylabel('Error Porcentual',fontsize=13)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
params_fisicos = [omega_m,b,H0]

z_inicial = 30
z_final = 0
cantidad_zs = int(10**6)

zs_patron  = np.linspace(z_inicial,z_final,10000)
cantidad_zs = np.linspace(10,10000,10)

cant_zs = np.array([int(i) for i in cantidad_zs])
print(cant_zs)
Hs = []

for i,cant in enumerate(cant_zs):

    zs, H_ode = integrador(params_fisicos, n=1, cantidad_zs=cant,
    max_step=0.003)

    f = interp1d(zs,H_ode)
    Hs.append(f(zs_patron))

final = []
for j in range(1,len(Hs)):
    aux = np.mean((Hs[j]-Hs[j-1])/Hs[j]);
    final.append(aux);
#%%
%matplotlib qt5
plt.close()
plt.figure()
plt.grid(True)
plt.xlabel('cantidad_zs')
plt.ylabel('%Hs')
Пример #9
0
if __name__ == '__main__':
    from matplotlib import pyplot as plt

    b = 0.6
    omega_m = 0.24
    H0 = 73.48
    params_fisicos = [omega_m,b,H0]

    z_inicial = 10
    z_final = 0

    cantidad_zs = int(10**5)
    max_step = 10**(-4)

    zs, H_ode = integrador(params_fisicos, n=1, cantidad_zs=cantidad_zs,
                max_step=max_step, z_inicial=z_inicial, z_final=z_final,
                verbose=True,
                model='EXP')
    plt.plot(zs,H_ode)

    #%%
    zs_LCDM = np.linspace(z_final,z_inicial,cantidad_zs)
    Hs_LCDM = H0 * np.sqrt(omega_m * (1+zs_LCDM)**3 + (1-omega_m))

    from matplotlib import pyplot as plt
    %matplotlib qt5
    plt.plot(zs_ode,H_ode)
    plt.plot(zs_LCDM,Hs_LCDM)
    #%%
    #out= np.zeros((len(zs),2))
    #out[:,0] = zs
    #out[:,1] = H_ode/H0
Пример #10
0
from pc_path import definir_path
path_git, path_datos_global = definir_path()
os.chdir(path_git)
sys.path.append('./Software/Funcionales/')
from funciones_condiciones_iniciales import condiciones_iniciales
from funciones_cambio_parametros import params_fisicos_to_modelo
from funciones_int import integrador
from funciones_taylor import Taylor_HS
#%%

b = 0.01
omega_m = 0.24
H0 = 73.48
params_fisicos = [omega_m, b, H0]

zs, H_ode = integrador(params_fisicos)
H_taylor = Taylor_HS(zs, omega_m, b, H0)

#%%
#%matplotlib qt5
plt.close()
plt.figure()
plt.grid(True)
plt.xlabel('z(redshift)')
plt.ylabel('E(z)')
plt.plot(zs, H_taylor / H0, label='Taylor')
plt.plot(zs, H_ode / H0, label='ODE')
plt.legend(loc='best')

#%% Calculo el error porcentual entre la ODE y el taylor a b fijo.
plt.figure()