Skip to content

Add working bubble model for reionization#27

Open
yonboyage wants to merge 37 commits intomainfrom
BMF_and_ionized_maps
Open

Add working bubble model for reionization#27
yonboyage wants to merge 37 commits intomainfrom
BMF_and_ionized_maps

Conversation

@yonboyage
Copy link
Copy Markdown
Collaborator

Bubble mass function, barriers, iterations, and ionized maps.

@yonboyage yonboyage requested a review from JulianBMunoz March 7, 2025 18:02
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Oct 24, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 78.35420% with 121 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.27%. Comparing base (9ea7c39) to head (f6b6c1e).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
zeus21/maps.py 62.44% 92 Missing ⚠️
zeus21/cosmology.py 42.85% 8 Missing ⚠️
zeus21/reionization.py 96.29% 8 Missing ⚠️
zeus21/sfrd.py 86.36% 6 Missing ⚠️
zeus21/z21_utilities.py 82.35% 6 Missing ⚠️
zeus21/UVLFs.py 50.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #27      +/-   ##
==========================================
+ Coverage   73.11%   74.27%   +1.16%     
==========================================
  Files           9       11       +2     
  Lines        1700     2220     +520     
==========================================
+ Hits         1243     1649     +406     
- Misses        457      571     +114     
Flag Coverage Δ
unittests 74.27% <78.35%> (+1.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
zeus21/__init__.py 100.00% <100.00%> (ø)
zeus21/correlations.py 50.18% <100.00%> (ø)
zeus21/inputs.py 92.55% <ø> (ø)
zeus21/xrays.py 87.50% <100.00%> (ø)
zeus21/UVLFs.py 84.50% <50.00%> (ø)
zeus21/sfrd.py 78.30% <86.36%> (+1.21%) ⬆️
zeus21/z21_utilities.py 82.35% <82.35%> (ø)
zeus21/cosmology.py 77.10% <42.85%> (-2.80%) ⬇️
zeus21/reionization.py 96.29% <96.29%> (ø)
zeus21/maps.py 67.25% <62.44%> (-30.86%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ea7c39...f6b6c1e. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Owner

@JulianBMunoz JulianBMunoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job Yonny and Emilie! This looks like pro coding. There are some physics questions in the comments (plus the slack). There are also some suggestions for docs, and also for optimization. Let's discuss it, but you can start working on it in the meantime

numexpr
astropy No newline at end of file
astropy
tqdm
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@@ -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)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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

from scipy.interpolate import interp1d
from scipy.interpolate import InterpolatedUnivariateSpline as spline
from pyfftw import empty_aligned as empty
from tqdm import trange
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

from scipy.interpolate import InterpolatedUnivariateSpline as spline
from pyfftw import empty_aligned as empty
from tqdm import trange
import time
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

zeus21/maps.py Outdated
"""

#Measure time elapsed from start
start_time = time.time()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

idx.append((np.abs(array - values[i])).argmin())
return np.unique(idx)

def print_timer(start_time, text_before="", text_after=""):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and same

SFRD_II_dR = np.trapz(integrand_II, HMF_interpolator.logtabMh, axis = 2)
# Compute SFRD and niondot quantities
SFRD_II_dR = np.trapezoid(integrand_II, HMF_interpolator.logtabMh, axis = 2)
niondot_II_dR = np.trapezoid(integrand_II*fesctab_II[None, None, :, None], HMF_interpolator.logtabMh, axis = 2)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnt there an ionizing efficiency here? generically it could depend on Mh so let's bring it here if it was elsewhere

self.gamma_II_index2D = np.log(SFRD_II_dR[:,:,-1]/SFRD_II_dR[:,:,0]) / (deltaArray[:,:,0,-1] - deltaArray[:,:,0,0])
midpoint = deltaArray.shape[-1]//2 #midpoint of deltaArray at delta = 0

self.gamma_II_index2D = np.log(SFRD_II_dR[:,:,midpoint+1]/SFRD_II_dR[:,:,midpoint-1]) / (deltaArray[:,:,0,midpoint+1] - deltaArray[:,:,0,midpoint-1])
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we repeat this (and the 2nd derivative) a lot, is it worth functionalizing? take array, deltarray, midpoint, and return everything


self.niondot_avg_II = Astro_Parameters.N_ion_perbaryon_II/cosmology.rho_baryon(Cosmo_Parameters,0.) * np.trapz(integrand_II_table * fesctab_II, HMF_interpolator.logtabMh, axis = 1)
self.niondot_avg_III = Astro_Parameters.N_ion_perbaryon_II/cosmology.rho_baryon(Cosmo_Parameters,0.) * np.trapz(integrand_III_table * fesctab_III, HMF_interpolator.logtabMh, axis = 1)
self.niondot_avg_II = Astro_Parameters.N_ion_perbaryon_II/cosmology.rho_baryon(Cosmo_Parameters,0.) * np.trapezoid(integrand_II_table * fesctab_II, HMF_interpolator.logtabMh, axis = 1)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's discuss this, I'd prefer to parametrize this through xiion directly in nion. That said, I'm confused why this is repeated w.r.t. above

Fixed single-z map computation by precomputing partial ionizations as a function of density in reionization.py

Allowed extrapolation of small R values in partial ionizations. This lets the user make more highly resolved maps than before.
yonboyage and others added 10 commits November 18, 2025 15:44
maps.py: density array used for partial ionizations and massweighting now the density field smoothed by the pixel scale.

reionization.py: minor tweaks for self-consistency
Maps:
- Added mass variance correction to account for lack of ergodicity in smaller simulations
- Fixed partial ionization computation accounting for this sigma correction.

Bubbles:
- Changed all interpolators to allow for linear extrapolation
- Added new moving pivot for linear barrier to account for the typical bubble size changing at different redshifts. Now the typical bubbles are the ones best approximated in the linear barrier.
- Now computing the ionized fraction from the analytic solution to the integral of the BMF. This accounts for contribution from bubbles outside the set radius range rather than integrating numerically.
- Increased tolerance for wiggle between iterations of the BMF.
Forgot to add input to function
densities in reionization_maps, and
delete_class_attributes to z21_utilities.
Removed density_allz from partials in
reionization_maps.
Created astro_variations class in
reionization_maps.
Changed CosmoParams.Rsmmin to 0.05.
+ increase kmax in test_correlations
+ remove classy.class from cosmo_wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants