-
Notifications
You must be signed in to change notification settings - Fork 16
Add working bubble model for reionization #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bb3348e
723066a
db1c397
c8b3b2b
7b498f4
cb721ca
7068282
39fe965
a6ea097
94bbe4f
622055a
347ea86
323f38d
2acf595
4285137
6daacaa
bf41563
1efe55c
b84b0c4
ff54cc3
100a0b0
c4798f7
85a0634
c4c06ff
3a4e2fe
7858c48
2f32de5
547115d
f5f1b78
7788c87
8a5d1f6
f6b6c1e
24aa05b
6b87804
b2f1c0a
a9564e4
20c4e13
d6976a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,9 @@ scipy | |
| mcfit | ||
| numexpr | ||
| astropy | ||
| powerbox | ||
| tqdm | ||
| matplotlib | ||
| pyfftw | ||
| powerbox | ||
| sphinx | ||
| myst_parser | ||
| myst_parser | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,5 +20,8 @@ | |
| "classy", | ||
| "numexpr", | ||
| "astropy", | ||
| "powerbox", | ||
| "pyfftw", | ||
| "tqdm" | ||
| ], | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
|
|
||
| from zeus21.sfrd import * | ||
| from zeus21.correlations import * | ||
| from zeus21.reionization import * | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should write more tests, basically for all functions/classes |
||
|
|
||
| UserParams = zeus21.User_Parameters() | ||
|
|
||
|
|
@@ -41,6 +42,9 @@ | |
| CosmoParams_21cmfast = zeus21.Cosmo_Parameters(UserParams, CosmoParams_input_21cmfast, ClassyCosmo_21cmfast) | ||
| AstroParams_21cmfast = zeus21.Astro_Parameters(UserParams,CosmoParams_21cmfast, astromodel = 1) | ||
|
|
||
| #and for bubbles: | ||
| BMF_class = zeus21.BMF(Coeffs, HMFintclass, CosmoParams, AstroParams, ClassyCosmo) | ||
|
|
||
|
|
||
| ztest = 20. | ||
| iztest = min(range(len(Coeffs.zintegral)), key=lambda i: np.abs(Coeffs.zintegral[i]-ztest)) | ||
|
|
@@ -128,6 +132,9 @@ def test_background(): | |
|
|
||
| assert( (Coeffs.gamma_index2D >= 0.0).all()) #effective biases have to be larger than 0 in reasonable models, since galaxies live in haloes that are more clustered than average matter (in other words, SFRD grows monotonically with density) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about an assert like this for the gamma_nion and gamma2 indices? Not sure if they have to always be positive, but at least that they're not nan |
||
|
|
||
| assert( ((BMF_class.ion_frac >= 0.0)*(BMF_class.ion_frac <= 1.0) ).all()) | ||
| assert( (BMF_class.BMF >= 0.0).all()) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,8 +27,8 @@ def cosmo_wrapper(User_Parameters, Cosmo_Parameters_Input): | |
| Cosmo_Parameters, Class_Cosmo, Correlations, HMF_interpolator | ||
| """ | ||
|
|
||
| ClassCosmo = Class() | ||
| ClassCosmo.compute() | ||
| #ClassCosmo = Class() | ||
| #ClassCosmo.compute() | ||
|
|
||
| ClassyCosmo = runclass(Cosmo_Parameters_Input) | ||
| CosmoParams = Cosmo_Parameters(User_Parameters, Cosmo_Parameters_Input, ClassyCosmo) | ||
|
|
@@ -75,13 +75,13 @@ def runclass(CosmologyIn): | |
| theta_b = velTransFunc['t_b'] | ||
| theta_c = velTransFunc['t_cdm'] | ||
|
|
||
| sigma_vcb = np.sqrt(np.trapz(CosmologyIn.As * (kVel/0.05)**(CosmologyIn.ns-1) /kVel * (theta_b - theta_c)**2/kVel**2, kVel)) * constants.c_kms | ||
| sigma_vcb = np.sqrt(np.trapezoid(CosmologyIn.As * (kVel/0.05)**(CosmologyIn.ns-1) /kVel * (theta_b - theta_c)**2/kVel**2, kVel)) * constants.c_kms | ||
| ClassCosmo.pars['sigma_vcb'] = sigma_vcb | ||
|
|
||
| ###HAC: now computing average velocity assuming a Maxwell-Boltzmann distribution of velocities | ||
| velArr = np.geomspace(0.01, constants.c_kms, 1000) #in km/s | ||
| vavgIntegrand = (3 / (2 * np.pi * sigma_vcb**2))**(3/2) * 4 * np.pi * velArr**2 * np.exp(-3 * velArr**2 / (2 * sigma_vcb**2)) | ||
| ClassCosmo.pars['v_avg'] = np.trapz(vavgIntegrand * velArr, velArr) | ||
| ClassCosmo.pars['v_avg'] = np.trapezoid(vavgIntegrand * velArr, velArr) | ||
|
|
||
| ###HAC: Computing Vcb Power Spectrum | ||
| ClassCosmo.pars['k_vcb'] = kVel | ||
|
|
@@ -99,8 +99,8 @@ def runclass(CosmologyIn): | |
| j0bessel = lambda x: np.sin(x)/x | ||
| j2bessel = lambda x: (3 / x**2 - 1) * np.sin(x)/x - 3*np.cos(x)/x**2 | ||
|
|
||
| psi0 = 1 / 3 / (sigma_vcb/constants.c_kms)**2 * np.trapz(kVelIntp**2 / 2 / np.pi**2 * p_vcb_intp(np.log(kVelIntp)) * j0bessel(kVelIntp * np.transpose([rVelIntp])), kVelIntp, axis = 1) | ||
| psi2 = -2 / 3 / (sigma_vcb/constants.c_kms)**2 * np.trapz(kVelIntp**2 / 2 / np.pi**2 * p_vcb_intp(np.log(kVelIntp)) * j2bessel(kVelIntp * np.transpose([rVelIntp])), kVelIntp, axis = 1) | ||
| psi0 = 1 / 3 / (sigma_vcb/constants.c_kms)**2 * np.trapezoid(kVelIntp**2 / 2 / np.pi**2 * p_vcb_intp(np.log(kVelIntp)) * j0bessel(kVelIntp * np.transpose([rVelIntp])), kVelIntp, axis = 1) | ||
| psi2 = -2 / 3 / (sigma_vcb/constants.c_kms)**2 * np.trapezoid(kVelIntp**2 / 2 / np.pi**2 * p_vcb_intp(np.log(kVelIntp)) * j2bessel(kVelIntp * np.transpose([rVelIntp])), kVelIntp, axis = 1) | ||
|
|
||
| k_eta, P_eta = mcfit.xi2P(rVelIntp, l=0, lowring = True)((6 * psi0**2 + 3 * psi2**2), extrap = False) | ||
|
|
||
|
|
@@ -115,6 +115,38 @@ def runclass(CosmologyIn): | |
|
|
||
| return ClassCosmo | ||
|
|
||
| def time_at_redshift(ClassyCosmo,z): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems pretty inefficient, it's reading the ts and zs every time it's called and then interpolating. Why not do the reading once in CosmoParams (since it does the same for chi comoving distance vs z) and then this function just evaluats the interpolator with CosmoParams.zlistage and CosmoParams.tlistages saved? |
||
| """ | ||
| Returns the age of the Universe (in Gyrs) corresponding to a given redshift. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| ClassyCosmo: zeus21.runclass class | ||
| Sets up Class cosmology. | ||
| z: float | ||
| Redshift. | ||
| """ | ||
| background = ClassyCosmo.get_background() | ||
| classy_t, classy_z = background['proper time [Gyr]'], background['z'] | ||
| classy_tinterp = interp1d(classy_z, classy_t) | ||
| return classy_tinterp(z) | ||
|
|
||
| def redshift_at_time(ClassyCosmo,t): | ||
| """ | ||
| Returns the redshift corresponding to a given age of the Universe (in Gyrs). | ||
|
|
||
| Parameters | ||
| ---------- | ||
| ClassyCosmo: zeus21.runclass class | ||
| Sets up Class cosmology. | ||
| t: float | ||
| Age in Gyrs. | ||
| """ | ||
| background = ClassyCosmo.get_background() | ||
| classy_t, classy_z = background['proper time [Gyr]'], background['z'] | ||
| classy_tinterp = interp1d(classy_t, classy_z) | ||
| return classy_tinterp(t) | ||
|
|
||
| def Hub(Cosmo_Parameters, z): | ||
| #Hubble(z) in km/s/Mpc | ||
| return Cosmo_Parameters.h_fid * 100 * np.sqrt(Cosmo_Parameters.OmegaM * pow(1+z,3.)+Cosmo_Parameters.OmegaR * pow(1+z,4.)+Cosmo_Parameters.OmegaL) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove