Skip to content
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

Radio excess from ACG, MCG and PBH #297

Open
wants to merge 127 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
5dc0377
Added a new file
Junsong-Cang Sep 25, 2022
590bb03
Re-formatted SP.c
Junsong-Cang Sep 25, 2022
47179ed
Added SandBox
Junsong-Cang Sep 25, 2022
ff59e23
Replaced SP.c
Junsong-Cang Sep 25, 2022
36ad43e
Removed some test files
Junsong-Cang Sep 25, 2022
21195a7
Testing
Junsong-Cang Sep 25, 2022
f5d5b45
Added a camb style for 21cmFAST in SandBox, main.py is the main modul…
Junsong-Cang Sep 25, 2022
60b4bc4
Added Radio_Excess parameters in AstroParams, Trad_box and SFRD_box a…
Junsong-Cang Sep 25, 2022
7201c01
Added main modules for Radio Excess, main calculations are done in SP…
Junsong-Cang Sep 25, 2022
4598bdc
Added Hawking Radiation module (Hawking_Radiation.h, see 2108.13256) …
Junsong-Cang Sep 25, 2022
b1624c3
Added Hawking Radiation module (Hawking_Radiation.h, see 2108.13256) …
Junsong-Cang Sep 25, 2022
48f7395
Added caching interface for Trad_box
Junsong-Cang Sep 25, 2022
85bccf1
Merge branch 'Radio_Excess' of https://github.com/JSC42/21cmFAST into…
Junsong-Cang Sep 25, 2022
b80ad48
Added parameters interface for radio excess and Hawking Radiation
Junsong-Cang Sep 25, 2022
e03dd6f
inputs.py seems to have been updated in current version of 21cmFAST, …
Junsong-Cang Sep 25, 2022
4c64a79
Merge branch 'Radio_Excess' of https://github.com/JSC42/21cmFAST into…
Junsong-Cang Sep 25, 2022
e267ba1
Updating inputs.py again, this version of inputs.py is identical to t…
Junsong-Cang Sep 25, 2022
76297c6
Added new parameter interface, sorry about the confusion but please i…
Junsong-Cang Sep 25, 2022
9f6aa84
Please ignore all previous commits associated with outputs.py, the la…
Junsong-Cang Sep 25, 2022
1755427
Added T_Radio to T21 calculation
Junsong-Cang Sep 25, 2022
8f67b78
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 25, 2022
0d229bf
removed SandBox interface
Junsong-Cang Sep 25, 2022
0f90408
Removed signatures
Junsong-Cang Sep 30, 2022
6739b2a
Added the USE_Radio_ACG FlagOption to c
Junsong-Cang Oct 17, 2022
a6a677e
Added flag_options handlings for all the new features
Junsong-Cang Oct 17, 2022
cb25b35
Added FlagOptions for all the new features, sending to SNS server fro…
Junsong-Cang Oct 17, 2022
d5f3a4a
Added a test string
Oct 25, 2022
0bb6c64
Removed debug strings, moving all tests to Trantor now
Oct 25, 2022
31abb66
Added test string
Oct 25, 2022
4258715
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 25, 2022
dde5b8b
Added sth
Oct 25, 2022
bc35ff7
Merge branch 'Radio_Excess' of https://github.com/JSC42/21cmFAST into…
Oct 25, 2022
b6acb7b
Removed test string, sending to SNS Trantor
Junsong-Cang Oct 25, 2022
925cd86
Merge branch 'Radio_Excess' of https://github.com/JSC42/21cmFAST into…
Oct 25, 2022
18860a4
Fixed pre-commit error
Junsong-Cang Oct 26, 2022
0b9dfaa
Merge branch '21cmfast:master' into Radio_Excess
Junsong-Cang Oct 26, 2022
f287a95
Changed Use_Radio_ACG to Use_RADIO_ACG, other FlagOptions will be in …
Junsong-Cang Oct 27, 2022
f2a0e1b
Merge branch 'master' into Radio_Excess
Junsong-Cang Oct 27, 2022
8fa39ec
All went well with initial test, moving on to the other FlagOptions
Junsong-Cang Oct 27, 2022
cb94c30
Changed USE_Radio_PBH to USE_RADIO_PBH, preparing for remake tests
Junsong-Cang Oct 27, 2022
930327f
All new FlagOptions set to cap, preparing for tests
Junsong-Cang Oct 27, 2022
d756b52
Revereted BrightnessTemperatureBox.c to the original indentation style
Junsong-Cang Oct 28, 2022
be73362
Merge branch '21cmfast:master' into Radio_Excess
Junsong-Cang Nov 8, 2022
f5a6aef
Added excess radio background for SUBCELL_RSD
Junsong-Cang Nov 8, 2022
a159507
Added comments for new params
Junsong-Cang Nov 8, 2022
f63bc9e
Removed Use_Radio_ACG switch in SP.c, ACG radio bkg switches are now …
Junsong-Cang Nov 8, 2022
6296e5c
Fixed a bug
Junsong-Cang Nov 8, 2022
062ad26
Changed some doc strings
Junsong-Cang Nov 8, 2022
bce63ac
Removed Use_Radio_MCG Bool in SP.c
Junsong-Cang Nov 9, 2022
790ce61
Removed fbh>1 checks, I will leave it to the user to make sure this d…
Junsong-Cang Nov 9, 2022
29f58e1
Removed Use_Radio_PBH switch in PS.c
Junsong-Cang Nov 9, 2022
d72cda9
Previous commit might have failed, USE_HAWKING_RADIATION bool removed…
Junsong-Cang Nov 9, 2022
b753f38
Removed subcel_RSD warning in SP.c
Junsong-Cang Nov 9, 2022
9a46a7b
Fixed a small bug in Get_Radio_Temp_HMG_Astro
Junsong-Cang Nov 9, 2022
9969115
Moved all Radio_Temp_HMG calculations to RadioExcess.h
Junsong-Cang Nov 9, 2022
e029c3e
Added doc
Junsong-Cang Nov 9, 2022
bc87c1a
Fotgot what I changed
Junsong-Cang Nov 10, 2022
62b24ae
Moved overdensity boundary calculation outside of the parallel loop, …
Junsong-Cang Nov 10, 2022
9304216
Testing error module ( not sure why previous push didn't work)
Junsong-Cang Nov 10, 2022
7a61720
More tests in error modul
Junsong-Cang Nov 10, 2022
c980cf0
more tests
Junsong-Cang Nov 10, 2022
a1a4d0c
Sending to Trantor server for more tests
Junsong-Cang Nov 10, 2022
266d2c9
Removed test
Junsong-Cang Nov 10, 2022
03247fe
Moved Radio_MCG param check to python
Junsong-Cang Nov 11, 2022
4b6692e
Reformatted inputs.py
Junsong-Cang Nov 11, 2022
bed0853
Moved Radio_PBH and Hawking radiation param checks to inputs.py
Junsong-Cang Nov 11, 2022
8943520
Updating doc
Junsong-Cang Nov 11, 2022
4f86ea9
Updating docs v2
Junsong-Cang Nov 11, 2022
16a8ed3
Fixed a bug, USE_INTERPOLATION_TABLES is in user_params, not flag_opt…
Junsong-Cang Nov 11, 2022
5feeba0
Moved parameter check features in SP.c to inputs.py, allowed basicall…
Junsong-Cang Nov 11, 2022
db5996b
Changed fR to be entered in log
Junsong-Cang Dec 18, 2022
25005eb
fR_mini now entered in log10
Junsong-Cang Dec 18, 2022
e02e95b
fbh now entered in log10
Junsong-Cang Dec 18, 2022
beef88d
mbh now entered in log10
Junsong-Cang Dec 18, 2022
5b2d71c
Print mbh in input.py
Junsong-Cang Dec 18, 2022
363ba57
Changed debugging
Junsong-Cang Dec 18, 2022
a54b8d1
Removed debug feature in SP.c
Junsong-Cang Dec 18, 2022
6a538d8
Fixed the Radio_Zmin factor in Get_Radio_Temp_HMG_Astro
Junsong-Cang Feb 13, 2023
fa65e81
Added the Radio_Zmax factor in Get_Radio_Temp_HMG_PBH
Junsong-Cang Feb 13, 2023
804021c
Set Debug_Printer in RadioExcess.h to false
Junsong-Cang Feb 15, 2023
1cc504d
removed a backup file (bak.c) and unused OutputFile from Get_Radio_Te…
Junsong-Cang Mar 27, 2023
c34e94a
Fixed Phi_ave and Phi_ave_mini issues
Junsong-Cang Apr 18, 2023
7340184
removed bak.c
Junsong-Cang Apr 18, 2023
db643e6
added a doc
Junsong-Cang Oct 23, 2023
9f959da
added compilation flag for macos
Junsong-Cang Oct 23, 2023
0b1b414
moved pbh features to the DarkSide branch, added SFRD_box and SFRD_MI…
Junsong-Cang Oct 23, 2023
a74dcea
added debugging features for printing HMF and mturn, mc
Junsong-Cang Oct 23, 2023
ef2827f
commented for test
Junsong-Cang Oct 23, 2023
538eef8
test
Junsong-Cang Oct 23, 2023
20e40b6
using debug for io.c
Junsong-Cang Oct 24, 2023
7b093d2
moved debug features to the back
Junsong-Cang Oct 28, 2023
ffea85c
added some doc for History_box, considering replacing SFRD_box and SF…
Junsong-Cang Oct 28, 2023
55f479b
preparing to expand History_box to store m_turn_II and m_turn_III
Junsong-Cang Oct 28, 2023
86c03db
changed history_box length and passed mturns from io.c to sp.c, next:…
Junsong-Cang Oct 28, 2023
b98caa7
upgraded and tested Find_Index and Interp_1D, works well
Junsong-Cang Oct 29, 2023
5ec1584
removed redudent features, upgraded interpolation
Junsong-Cang Oct 29, 2023
66acc2a
compilation works ok
Junsong-Cang Oct 29, 2023
ee2d24c
added debug format
Junsong-Cang Oct 29, 2023
1513d55
Test 1: Test_History_box_Interp shows identical agreement with Histor…
Junsong-Cang Oct 29, 2023
77419bb
Test 2: mturns successfully passed from io.c to History_Box
Junsong-Cang Oct 29, 2023
699554e
tests show that mturns has been passed from io.c to history_box, so n…
Junsong-Cang Oct 29, 2023
282767e
fixed a minor bug detected in new Get_Radio_Temp_HMG function
Junsong-Cang Oct 29, 2023
fc4c88c
added a flag Calibrate_EoR_feedback to determine whether to use EoR f…
Junsong-Cang Oct 29, 2023
fc1f5bf
moved some variables to head
Junsong-Cang Oct 29, 2023
b25a3b2
added empty function for calibrating Phi_mini, maybe also need to do …
Junsong-Cang Oct 29, 2023
3ea5254
dded module for EoR-calibrated Phi_ave_mini
Junsong-Cang Oct 30, 2023
e28ae66
oops, missed a factor in Calibrate_Phi_mini
Junsong-Cang Oct 30, 2023
77c54ae
allow for multiple radio sources, still have to have same spectra ind…
Junsong-Cang Oct 30, 2023
c2766fc
nothing new, just testing github speed-up tool
Junsong-Cang Oct 31, 2023
51ceb2f
changed something
Junsong-Cang Oct 31, 2023
cba2fc0
changed things
Junsong-Cang Oct 31, 2023
bda9b34
kjkhug
Junsong-Cang Oct 31, 2023
4fed2d5
found the NaN thing
Junsong-Cang Oct 31, 2023
ae1ce46
all done, starting tests
Junsong-Cang Nov 1, 2023
fe2254d
add tests complete, ready for new run
Junsong-Cang Nov 1, 2023
ddc2579
silenced some warnings, debug feature
Junsong-Cang Nov 4, 2023
3702790
Tests complete, transfered all debug features to Radio_debug branch
Junsong-Cang Nov 4, 2023
78eb7f0
addec back SFRD_box, malloc error on cluster is caused by accessing u…
Junsong-Cang Nov 5, 2023
aebcec6
moved Calibrate_Phi_mini back to the old place
Junsong-Cang Nov 5, 2023
cd03b56
actually let's keep the debug features for now
Junsong-Cang Nov 5, 2023
4cc9e93
gfht
Junsong-Cang Nov 6, 2023
2ee4d17
removed SFRD boxes to save memory, turned off debug features
Junsong-Cang Nov 8, 2023
58636ed
sdfvfb
Junsong-Cang Nov 11, 2023
0f5ee9d
pass mturn info from IO.c to SP.c using mturns_EoR array in TsBox, po…
Junsong-Cang Nov 14, 2023
1e66a83
moved Radio_Temp_ave outside mpi loop, relavent only for EoR calibration
Junsong-Cang Nov 14, 2023
039b84b
removed initialisation for Trad_box and History_box, did this later
Junsong-Cang Nov 15, 2023
c2b72eb
added mpi clauses for radio module
Junsong-Cang Nov 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions build_cffi.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
"""Build the C code with CFFI."""
import os
import os, platform
from cffi import FFI

ffi = FFI()
LOCATION = os.path.dirname(os.path.abspath(__file__))
CLOC = os.path.join(LOCATION, "src", "py21cmfast", "src")
include_dirs = [CLOC]

# =================================================================
# Set compilation arguments dependent on environment... a bit buggy
# =================================================================
# ========================================================================
# Set compilation arguments dependent on environment and OS... a bit buggy
# ========================================================================
OS_Name = platform.system()

if "DEBUG" in os.environ:
extra_compile_args = ["-fopenmp", "-w", "-g", "-O0"]
if OS_Name == 'Darwin':
# fopenmp is known to fail on mac
extra_compile_args = ["-w", "-g", "-O0"]
else:
extra_compile_args = ["-fopenmp", "-w", "-g", "-O0"]
else:
extra_compile_args = ["-fopenmp", "-Ofast", "-w"]
if OS_Name == 'Darwin':
extra_compile_args = ["-Ofast", "-w"]
else:
extra_compile_args = ["-fopenmp", "-Ofast", "-w"]

# Set the C-code logging level.
# If DEBUG is set, we default to the highest level, but if not,
Expand Down
4 changes: 4 additions & 0 deletions src/py21cmfast/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,15 @@ def __init__(self, *args, **kwargs):
setattr(self, "_" + k, v)

if kwargs:
pass
'''
# JSC: cannot silence this using warnings module
logger.warning(
"The following parameters to {thisclass} are not supported: {lst}".format(
thisclass=self.__class__.__name__, lst=list(kwargs.keys())
)
)
'''

def convert(self, key, val):
"""Make any conversions of values before saving to the instance."""
Expand Down
41 changes: 41 additions & 0 deletions src/py21cmfast/inputs.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -484,13 +484,16 @@ class UserParams(StructWithDefaults):
def USE_INTERPOLATION_TABLES(self):
"""Whether to use interpolation tables for integrals, speeding things up."""
if self._USE_INTERPOLATION_TABLES is None:
'''
JSC: force-silence warnings
warnings.warn(
"The USE_INTERPOLATION_TABLES setting has changed in v3.1.2 to be "
"default True. You can likely ignore this warning, but if you relied on"
"having USE_INTERPOLATION_TABLES=False by *default*, please set it "
"explicitly. To silence this warning, set it explicitly to True. This"
"warning will be removed in v4."
)
'''
self._USE_INTERPOLATION_TABLES = True

return self._USE_INTERPOLATION_TABLES
Expand Down Expand Up @@ -518,6 +521,7 @@ def POWER_SPECTRUM(self):
See :func:`power_spectrum_model` for a string representation.
"""
if self.USE_RELATIVE_VELOCITIES:
''' jsc: this is too noisy
if self._POWER_SPECTRUM != 5 or (
isinstance(self._POWER_SPECTRUM, str)
and self._POWER_SPECTRUM.upper() != "CLASS"
Expand All @@ -526,6 +530,7 @@ def POWER_SPECTRUM(self):
"Automatically setting POWER_SPECTRUM to 5 (CLASS) as you are using "
"relative velocities"
)
'''
return 5
else:
if isinstance(self._POWER_SPECTRUM, str):
Expand Down Expand Up @@ -626,6 +631,12 @@ class FlagOptions(StructWithDefaults):
Determines whether to use a fixed vcb=VAVG (*regardless* of USE_RELATIVE_VELOCITIES). It includes the average effect of velocities but not its fluctuations. See Muñoz+21 (2110.13919).
USE_VELS_AUX: bool, optional
Auxiliary variable (not input) to check if minihaloes are being used without relative velocities and complain
USE_RADIO_ACG: bool, optional
Determines whether to use radio excess background from ACG, if True then AstroParams.fR is used
USE_RADIO_MCG: bool, optional
Determines whether to use radio excess background from MCG, if True then AstroParams.fR_mini is used
Calibrate_EoR_feedback: bool
Whether to calibrate EoR/photo-heating feedback for Pop II/III radio excess, used only when MINIHALO is activated
"""

_ffi = ffi
Expand All @@ -640,6 +651,9 @@ class FlagOptions(StructWithDefaults):
"M_MIN_in_Mass": False,
"PHOTON_CONS": False,
"FIX_VCB_AVG": False,
"USE_RADIO_ACG": False,
"USE_RADIO_MCG": False,
"Calibrate_EoR_feedback": False,
}

@property
Expand Down Expand Up @@ -796,6 +810,17 @@ class AstroParams(StructWithDefaults):
Impact of the LW feedback on Mturn for minihaloes. Default is 22.8685 and 0.47 following Machacek+01, respectively. Latest simulations suggest 2.0 and 0.6. See Sec 2 of Muñoz+21 (2110.13919).
A_VCB, BETA_VCB: float, optional
Impact of the DM-baryon relative velocities on Mturn for minihaloes. Default is 1.0 and 1.8, and agrees between different sims. See Sec 2 of Muñoz+21 (2110.13919).
fR: float, optional
Radio efficiency for galaxies, normalised to 1 for modern day galaxies. Given in log10 units.
aR: float, optional
Power-law energy spectra index
fR_mini: float, optional
Radio efficiency for molecularly cooling galaxies (MCG) in mini-halos, normalised to 1 for modern day galaxies. Given in log10 units.
aR_mini: float, optional
Power-law energy spectra index for mini-halos
PBH X-ray emission efficiency
Radio_Zmin: float, optional
Turn off radio emmisivity below this redshift, a phenomenological param motivated by ARCADE2 upper limit
"""

_ffi = ffi
Expand Down Expand Up @@ -824,6 +849,12 @@ class AstroParams(StructWithDefaults):
"BETA_LW": 0.6,
"A_VCB": 1.0,
"BETA_VCB": 1.8,
# Radio excess and PBH params
"fR": -10.0,
"aR": 0.7,
"fR_mini": -10.0,
"aR_mini": 0.7,
"Radio_Zmin": 0.0,
}

def __init__(
Expand All @@ -846,6 +877,8 @@ def convert(self, key, val):
"L_X",
"L_X_MINI",
"X_RAY_Tvir_MIN",
"fR",
"fR_mini",
]:
return 10**val
else:
Expand Down Expand Up @@ -953,3 +986,11 @@ def validate_all_inputs(
logger.warning(
"USE_MINI_HALOS needs USE_RELATIVE_VELOCITIES to get the right evolution!"
)

if flag_options is not None:
# Some requirements for excess radio background
if flag_options.USE_RADIO_MCG and not flag_options.USE_MINI_HALOS:
raise ValueError("USE_RADIO_MCG requires USE_MINI_HALOS!")
if flag_options.Calibrate_EoR_feedback and not flag_options.USE_RADIO_MCG:
raise ValueError("Calibrate_EoR_feedback requires USE_RADIO_MCG!")

14 changes: 13 additions & 1 deletion src/py21cmfast/outputs.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ def _get_box_structures(self) -> dict[str, dict | tuple[int]]:
"x_e_box": shape,
"Tk_box": shape,
"J_21_LW_box": shape,
"Trad_box": shape,
"History_box": shape,
}

@cached_property
Expand All @@ -422,6 +424,14 @@ def global_Ts(self):
else:
return np.mean(self.Ts_box)

@cached_property
def global_Trad(self):
"""Global Radio Temp."""
if "Trad_box" not in self._computed_arrays:
raise AttributeError("Something went wrong, maybe Trad not computed?")
else:
return np.mean(self.Trad_box)

@cached_property
def global_Tk(self):
"""Global (mean) Tk."""
Expand Down Expand Up @@ -457,6 +467,8 @@ def get_required_input_arrays(self, input_box: _BaseOutputStruct) -> list[str]:
required += [
"Tk_box",
"x_e_box",
"Trad_box",
"History_box",
]
if self.flag_options.USE_MINI_HALOS:
required += ["J_21_LW_box"]
Expand Down Expand Up @@ -567,7 +579,7 @@ def get_required_input_arrays(self, input_box: _BaseOutputStruct) -> list[str]:
elif isinstance(input_box, PerturbedField):
required += ["density"]
elif isinstance(input_box, TsBox):
required += ["J_21_LW_box", "x_e_box", "Tk_box"]
required += ["J_21_LW_box", "x_e_box", "Tk_box", "Trad_box", "History_box"]
elif isinstance(input_box, IonizedBox):
required += ["z_re_box", "Gamma12_box"]
if self.flag_options.INHOMO_RECO:
Expand Down