Skip to content

Commit

Permalink
fix xray_source turnover bug, improve box summary printing
Browse files Browse the repository at this point in the history
  • Loading branch information
daviesje committed Nov 13, 2024
1 parent 862cf3f commit 246d89c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/py21cmfast/drivers/single_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,11 @@ def compute_xray_source_field(
R_outer = R_range[i].to("Mpc").value

if zpp_avg[i] >= z_max:
box.filtered_sfr[i] = 0
box.filtered_sfr_mini[i] = 0
box.filtered_xray[i] = 0
box.mean_log10_Mcrit_LW[i] = inputs.astro_params.M_TURN # minimum
logger.debug(f"ignoring Radius {i} which is above Z_HEAT_MAX")
box.filtered_sfr[i, ...] = 0
continue

hbox_interp = interp_halo_boxes(
Expand All @@ -730,6 +733,7 @@ def compute_xray_source_field(
box.filtered_sfr[i] = 0
box.filtered_sfr_mini[i] = 0
box.filtered_xray[i] = 0
box.mean_log10_Mcrit_LW[i] = hbox_interp.log10_Mcrit_MCG_ave

Check warning on line 736 in src/py21cmfast/drivers/single_field.py

View check run for this annotation

Codecov / codecov/patch

src/py21cmfast/drivers/single_field.py#L736

Added line #L736 was not covered by tests
logger.debug(f"ignoring Radius {i} due to no stars")
continue

Expand Down
25 changes: 16 additions & 9 deletions src/py21cmfast/wrapper/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,26 +1082,33 @@ def ensure_input_computed(self, input_box, load=False) -> bool:
def summarize(self, indent=0) -> str:
"""Generate a string summary of the struct."""
indent = indent * " "
out = f"\n{indent}{self.__class__.__name__}\n"

out += "".join(
f"{indent} {fieldname:>15}: {getattr(self, fieldname, 'non-existent')}\n"
for fieldname in self.struct.primitive_fields
# print array type and column headings
out = (

Check warning on line 1087 in src/py21cmfast/wrapper/structs.py

View check run for this annotation

Codecov / codecov/patch

src/py21cmfast/wrapper/structs.py#L1087

Added line #L1087 was not covered by tests
f"\n{indent}{self.__class__.__name__:>25} "
+ " 1st: End: Min: Max: Mean: \n"
)

# print array extrema and means
for fieldname, state in self._array_state.items():
if not state.initialized:
out += f"{indent} {fieldname:>15}: uninitialized\n"
out += f"{indent} {fieldname:>25}: uninitialized\n"

Check warning on line 1095 in src/py21cmfast/wrapper/structs.py

View check run for this annotation

Codecov / codecov/patch

src/py21cmfast/wrapper/structs.py#L1095

Added line #L1095 was not covered by tests
elif not state.computed:
out += f"{indent} {fieldname:>15}: initialized\n"
out += f"{indent} {fieldname:>25}: initialized\n"

Check warning on line 1097 in src/py21cmfast/wrapper/structs.py

View check run for this annotation

Codecov / codecov/patch

src/py21cmfast/wrapper/structs.py#L1097

Added line #L1097 was not covered by tests
elif not state.computed_in_mem:
out += f"{indent} {fieldname:>15}: computed on disk\n"
out += f"{indent} {fieldname:>25}: computed on disk\n"

Check warning on line 1099 in src/py21cmfast/wrapper/structs.py

View check run for this annotation

Codecov / codecov/patch

src/py21cmfast/wrapper/structs.py#L1099

Added line #L1099 was not covered by tests
else:
x = getattr(self, fieldname).flatten()
if len(x) > 0:
out += f"{indent} {fieldname:>15}: {x[0]:1.4e}, {x[-1]:1.4e}, {x.min():1.4e}, {x.max():1.4e}, {np.mean(x):1.4e}\n"
out += f"{indent} {fieldname:>25}: {x[0]:11.4e}, {x[-1]:11.4e}, {x.min():11.4e}, {x.max():11.4e}, {np.mean(x):11.4e}\n"

Check warning on line 1103 in src/py21cmfast/wrapper/structs.py

View check run for this annotation

Codecov / codecov/patch

src/py21cmfast/wrapper/structs.py#L1103

Added line #L1103 was not covered by tests
else:
out += f"{indent} {fieldname:>15}: size zero\n"
out += f"{indent} {fieldname:>25}: size zero\n"

Check warning on line 1105 in src/py21cmfast/wrapper/structs.py

View check run for this annotation

Codecov / codecov/patch

src/py21cmfast/wrapper/structs.py#L1105

Added line #L1105 was not covered by tests

# print primitive fields
out += "".join(

Check warning on line 1108 in src/py21cmfast/wrapper/structs.py

View check run for this annotation

Codecov / codecov/patch

src/py21cmfast/wrapper/structs.py#L1108

Added line #L1108 was not covered by tests
f"{indent} {fieldname:>25}: {getattr(self, fieldname, 'non-existent')}\n"
for fieldname in self.struct.primitive_fields
)

return out

Expand Down
9 changes: 7 additions & 2 deletions tests/test_segfaults.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
"""
This file contains tests which run a lightcone under various flag options to test the C backend for segfaults.
These will not test the outputs of the run, just that the run completes without error
This file contains tests which run a lightcone under various flag options
to test the C backend for segfaults.
These will not test the outputs of the run past the fact that they are finite,
just that the run completes without error
"""

import pytest

import numpy as np

import py21cmfast as p21c

from . import produce_integration_test_data as prd
Expand Down Expand Up @@ -131,3 +135,4 @@ def test_lc_runs(name, max_redshift):
)

assert isinstance(lightcone, p21c.LightCone)
assert np.all(np.isfinite(lightcone.brightness_temp))

0 comments on commit 246d89c

Please sign in to comment.