Skip to content

Commit

Permalink
lightcones run now
Browse files Browse the repository at this point in the history
  • Loading branch information
daviesje committed Oct 22, 2024
1 parent c6d3dc8 commit 7ee286e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/py21cmfast/drivers/coeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ def _write(self, direc=None, fname=None, clobber=False):
for k, val in self.photon_nonconservation_data.items():
photon_data[k] = val

f.attrs["redshift"] = self.redshift
f.attrs["random_seed"] = self.random_seed
f.attrs["version"] = __version__

Expand Down
10 changes: 6 additions & 4 deletions src/py21cmfast/drivers/lightcone.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ def _run_lightcone_from_perturbed_fields(
(initial_conditions, *perturbed_fields),
astro_params=astro_params,
flag_options=flag_options,
redshift=None,
)

lightconer.validate_options(inputs.user_params, inputs.flag_options)
Expand Down Expand Up @@ -647,7 +648,7 @@ def _run_lightcone_from_perturbed_fields(
if flag_options.USE_TS_FLUCT:
z_halos.append(z)
hboxes.append(hbox2)
xray_source_box = sf.xray_source(
xray_source_box = sf.compute_xray_source_field(
redshift=z,
z_halos=z_halos,
hboxes=hboxes,
Expand All @@ -666,9 +667,9 @@ def _run_lightcone_from_perturbed_fields(
**kw,
)

ib2 = sf.ionize_box(
ib2 = sf.compute_ionization_field(
redshift=z,
previous_ionize_box=ib,
previous_ionized_box=ib,
perturbed_field=pf2,
previous_perturbed_field=prev_perturb,
spin_temp=st2,
Expand Down Expand Up @@ -921,6 +922,7 @@ def run_lightcone(
user_params=user_params,
astro_params=astro_params,
flag_options=flag_options,
redshift=None,
)

if pf_given:
Expand All @@ -929,7 +931,7 @@ def run_lightcone(
node_redshifts = get_logspaced_redshifts(
lightconer.lc_redshifts.min(),
global_params.ZPRIME_STEP_FACTOR,
lightconer.lc_redshifts.max(),
max(lightconer.lc_redshifts.max(), global_params.Z_HEAT_MAX),
)

lcz = lightconer.lc_redshifts
Expand Down
15 changes: 8 additions & 7 deletions src/py21cmfast/drivers/single_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ def perturb_field(
redshift=redshift,
)

logger.info(inputs)

# Initialize perturbed boxes.
fields = PerturbedField(inputs=inputs)

Expand Down Expand Up @@ -263,7 +261,6 @@ def determine_halo_list(
astro_params=astro_params,
flag_options=flag_options,
)
logger.info(inputs)

if inputs.user_params.HMF != "ST":
warnings.warn(
Expand Down Expand Up @@ -345,7 +342,7 @@ def perturb_halo_list(
Returns
-------
:class:`~XraySourceBox`
:class:`~PerturbHaloField`
Other Parameters
----------------
Expand Down Expand Up @@ -655,7 +652,7 @@ def compute_xray_source_field(
direc, regenerate, hooks = _get_config_options(direc, regenerate, write, hooks)

inputs = InputParameters.from_output_structs(
hboxes + [initial_conditions], redshift=hboxes[-1:].redshift
hboxes + [initial_conditions], redshift=hboxes[-1].redshift
)

# Initialize halo list boxes.
Expand Down Expand Up @@ -952,7 +949,11 @@ def compute_ionization_field(
inputs=inputs.evolve(redshift=0.0), initial=True
)

if previous_perturbed_field is None:
if not inputs.flag_options.USE_MINI_HALOS:
previous_perturbed_field = PerturbedField(
inputs=inputs.evolve(redshift=0.0), dummy=True
)
elif previous_perturbed_field is None:
# If we are beyond Z_HEAT_MAX, just make an empty box
if prev_z == 0:
previous_perturbed_field = PerturbedField(
Expand Down Expand Up @@ -1126,7 +1127,7 @@ def spin_temperature(
)
else:
# Set prev_z to anything, since we don't need it.
prev_z = np.inf
prev_z = 300 # needs to be castable to float type

# Ensure the previous spin temperature has a higher redshift than this one.
if prev_z <= inputs.redshift:
Expand Down
2 changes: 1 addition & 1 deletion src/py21cmfast/src/Stochasticity.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void print_hs_consts(struct HaloSamplingConstants * c){
}

//This function, designed to be used in the wrapper to estimate Halo catalogue size, takes the parameters and returns average number of halos within the entire box
double expected_nhalo(double redshift, struct UserParams *user_params, struct CosmoParams *cosmo_params){
double expected_nhalo(double redshift, UserParams *user_params, CosmoParams *cosmo_params){
//minimum sampled mass
Broadcast_struct_global_noastro(user_params,cosmo_params);
double M_min = user_params->SAMPLER_MIN_MASS;
Expand Down
8 changes: 2 additions & 6 deletions src/py21cmfast/wrapper/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,7 @@ class TsBox(_AllParamsBox):

_c_compute_function = lib.ComputeTsBox
_meta = False
_inputs = _AllParamsBox._inputs + (
"prev_spin_redshift",
"perturbed_field_redshift",
)
_inputs = _AllParamsBox._inputs + ("prev_spin_redshift",)

def __init__(
self,
Expand All @@ -594,7 +591,6 @@ def __init__(
**kwargs,
):
self.prev_spin_redshift = prev_spin_redshift
self.perturbed_field_redshift = perturbed_field_redshift
super().__init__(**kwargs)

def _get_box_structures(self) -> dict[str, dict | tuple[int]]:
Expand Down Expand Up @@ -683,7 +679,7 @@ def compute(
self.cosmo_params,
self.astro_params,
self.flag_options,
self.perturbed_field_redshift,
perturbed_field.redshift,
cleanup,
perturbed_field,
xray_source_box,
Expand Down
7 changes: 5 additions & 2 deletions src/py21cmfast/wrapper/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,11 @@ def write(
f"key {kk} with value {v} is not able to be written to HDF5 attrs!"
) from e
else:
fl.attrs[kfile] = q
try:
fl.attrs[kfile] = q
except TypeError as e:
logger.info(f"name {k} val {q}, type {type(q)}")
raise e

# Write 21cmFAST version to the file
fl.attrs["version"] = __version__
Expand Down Expand Up @@ -1124,7 +1128,6 @@ def _compute(
f"You are trying to compute {self.__class__.__name__}, but it has already been computed."
)

logger.info(f"Arguments to {self._c_compute_function.__name__}: " f"{inputs}")
# Perform the C computation
try:
exitcode = self._c_compute_function(*inputs, self())
Expand Down

0 comments on commit 7ee286e

Please sign in to comment.