Skip to content

Commit

Permalink
functions provided to interface with py21cmfast,
Browse files Browse the repository at this point in the history
which fixes #52
When py21cmfast will updagrade to v4, reliable dark matter haloes can also be retrieved.
  • Loading branch information
sambit-giri committed Sep 4, 2024
1 parent d351e15 commit c4aaa80
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

setup(
name='tools21cm',
version='2.2.0',
version='2.2.1',
author='Sambit Giri',
author_email='sambit.giri@gmail.com',
packages=find_packages(where="src"),
Expand Down
3 changes: 3 additions & 0 deletions src/tools21cm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
from .position_dependent_power_spectrum import *
from .test_case import *

# Interface to simulation codes
from .model_21cmfast import *

#Suppress warnings from zero-divisions and nans
import numpy
numpy.seterr(all='ignore')
91 changes: 91 additions & 0 deletions src/tools21cm/model_21cmfast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import numpy as np
try:
import py21cmfast as p21c
except:
print('Install py21cmfast (https://21cmfast.readthedocs.io/) to model reionization with 21cmFAST.')


def run_21cmfast_init(
user_params={"HII_DIM":32, "DIM":32*3, "BOX_LEN":128, "USE_INTERPOLATION_TABLES": True},
cosmo_params={"OMb":0.049, "OMm":0.31, "POWER_INDEX":0.96, "SIGMA_8":0.83, "hlittle":0.67},
write=True,
direc=None,
random_seed=42,
regenerate=False,
verbose=True,
**global_kwargs):
if verbose: print('Creating initial conditions...')
ic = p21c.initial_conditions(
user_params=user_params,
cosmo_params=cosmo_params,
write=write,
direc=direc,
random_seed=random_seed,
regenerate=regenerate,
**global_kwargs)
if verbose: print('...done')
return ic

def run_21cmfast_matter(redshift,
init_boxes=None,
user_params={"HII_DIM":32, "DIM":32*3, "BOX_LEN":128, "USE_INTERPOLATION_TABLES": True},
cosmo_params={"OMb":0.049, "OMm":0.31, "POWER_INDEX":0.96, "SIGMA_8":0.83, "hlittle":0.67},
random_seed=42,
regenerate=False,
write=True,
direc=None,
verbose=True,
**global_kwargs):
if init_boxes is None:
if verbose: print('Creating initial conditions...')
init_boxes = p21c.initial_conditions(
user_params=user_params,
cosmo_params=cosmo_params,
write=write,
direc=direc,
random_seed=random_seed,
regenerate=regenerate,
**global_kwargs)
if verbose: print('...done')
if verbose: print('Creating matter distribution...')
fields = p21c.perturb_field(redshift=redshift,
init_boxes=init_boxes,
**global_kwargs)
if verbose: print('...done')
out = {zi: fields[ii] for ii,zi in enumerate(redshift)}
return out

def run_21cmfast_coeval(redshift,
user_params={"HII_DIM":32, "DIM":32*3, "BOX_LEN":128, "USE_INTERPOLATION_TABLES": True},
cosmo_params={"OMb":0.049, "OMm":0.31, "POWER_INDEX":0.96, "SIGMA_8":0.83, "hlittle":0.67},
astro_params={"F_STAR10":np.log10(0.05), "ALPHA_STAR":0.5, "F_ESC10":np.log10(0.1), "ALPHA_ESC":-0.5, "t_STAR":0.5, "M_TURN":8.7, "R_BUBBLE_MAX":15, "L_X":40},
flag_options={"USE_HALO_FIELD":False, "USE_MASS_DEPENDENT_ZETA":True, "INHOMO_RECO":False, "PHOTON_CONS":False},
regenerate=False,
write=False,
direc=None,
init_box=None,
perturb=None,
use_interp_perturb_field=False,
pt_halos=False,
random_seed=42,
verbose=True,
**global_kwargs):
if isinstance(redshift,(int,float)): redshift = [float(redshift)]
if verbose: print('Modelling reionization...')
coeval = p21c.run_coeval(redshift=redshift,
user_params=user_params,
cosmo_params=cosmo_params,
astro_params=astro_params,
flag_options=flag_options,
regenerate=regenerate,
write=write,
direc=direc,
init_box=init_box,
perturb=perturb,
use_interp_perturb_field=use_interp_perturb_field,
pt_halos=pt_halos,
random_seed=random_seed,
**global_kwargs)
if verbose: print('...done')
return coeval[0]

File renamed without changes.

0 comments on commit c4aaa80

Please sign in to comment.