├── .coveragerc ├── .github └── workflows │ └── test_suite.yaml ├── .gitignore ├── .readthedocs.yaml ├── CITATION ├── LICENSE ├── README.md ├── ares ├── __init__.py ├── analysis │ ├── Animation.py │ ├── BlobFactory.py │ ├── DerivedQuantities.py │ ├── GalaxyPopulation.py │ ├── Global21cm.py │ ├── MetaGalacticBackground.py │ ├── ModelSet.py │ ├── MultiPhaseMedium.py │ ├── PowerSpectrum.py │ ├── RaySegment.py │ ├── TurningPoints.py │ └── __init__.py ├── data │ └── __init__.py ├── inference │ ├── CalibrateModel.py │ ├── FitGalaxyPopulation.py │ ├── FitGlobal21cm.py │ ├── GridND.py │ ├── ModelFit.py │ ├── ModelGrid.py │ ├── ModelSample.py │ └── __init__.py ├── obs │ ├── DustCorrection.py │ ├── MagnitudeSystem.py │ ├── OpticalDepth.py │ ├── Photometry.py │ ├── Survey.py │ └── __init__.py ├── phenom │ ├── Gaussian21cm.py │ ├── ParameterizedQuantity.py │ ├── Parametric21cm.py │ ├── Tanh21cm.py │ └── __init__.py ├── physics │ ├── Constants.py │ ├── Cosmology.py │ ├── CrossSections.py │ ├── DustEmission.py │ ├── ExcursionSet.py │ ├── HaloMassFunction.py │ ├── HaloModel.py │ ├── Hydrogen.py │ ├── InitialConditions.py │ ├── NebularEmission.py │ ├── RateCoefficients.py │ ├── SecondaryElectrons.py │ └── __init__.py ├── populations │ ├── BlackHoleAggregate.py │ ├── ClusterPopulation.py │ ├── Composite.py │ ├── GalaxyAggregate.py │ ├── GalaxyCohort.py │ ├── GalaxyEnsemble.py │ ├── GalaxyHOD.py │ ├── GalaxyPopulation.py │ ├── Halo.py │ ├── Parameterized.py │ ├── Population.py │ ├── Toy.py │ └── __init__.py ├── simulations │ ├── GasParcel.py │ ├── Global21cm.py │ ├── MetaGalacticBackground.py │ ├── MultiPhaseMedium.py │ ├── PowerSpectrum21cm.py │ ├── RaySegment.py │ ├── Simulation.py │ └── __init__.py ├── solvers │ ├── Chemistry.py │ ├── OpticalDepth.py │ ├── RadialField.py │ ├── UniformBackground.py │ └── __init__.py ├── sources │ ├── BlackHole.py │ ├── Composite.py │ ├── Source.py │ ├── Star.py │ ├── StarQS.py │ ├── SynthesisModel.py │ ├── SynthesisModelHybrid.py │ ├── SynthesisModelSBS.py │ ├── SynthesisModelToy.py │ ├── Toy.py │ ├── UserDefined.py │ └── __init__.py ├── static │ ├── ChemicalNetwork.py │ ├── Fluctuations.py │ ├── Grid.py │ ├── IntegralTables.py │ ├── InterpolationTables.py │ ├── SpectralSynthesis.py │ ├── VolumeGlobal.py │ ├── VolumeLocal.py │ └── __init__.py └── util │ ├── Aesthetics.py │ ├── BackwardCompatibility.py │ ├── BlobBundles.py │ ├── MPIPool.py │ ├── Math.py │ ├── Misc.py │ ├── ParameterBundles.py │ ├── ParameterFile.py │ ├── Pickling.py │ ├── PrintInfo.py │ ├── ProblemTypes.py │ ├── ProgressBar.py │ ├── ReadData.py │ ├── RestrictTimestep.py │ ├── SetDefaultParameterValues.py │ ├── Stats.py │ ├── Warnings.py │ ├── WriteData.py │ └── __init__.py ├── codecov.yml ├── docs ├── Makefile ├── acknowledgements.rst ├── conf.py ├── contributing.rst ├── example_adv_RT_w_He.rst ├── example_crb_br.rst ├── example_crb_ion.rst ├── example_crb_uv.rst ├── example_crb_xr.rst ├── example_edges.rst ├── example_embed_ares.rst ├── example_grid.rst ├── example_grid_analysis.rst ├── example_gs_hybrid.rst ├── example_gs_multipop.rst ├── example_gs_phenomenological.rst ├── example_gs_standard.rst ├── example_ham.rst ├── example_inline_analysis.rst ├── example_litdata.rst ├── example_mc_sampling.rst ├── example_mcmc_analysis.rst ├── example_mcmc_gs.rst ├── example_mcmc_lf.rst ├── example_popIII.rst ├── example_pop_cluster.rst ├── example_pop_dusty.rst ├── example_pop_galaxy.rst ├── example_pop_sps.rst ├── example_rt06_1.rst ├── example_rt06_2.rst ├── example_sedop.rst ├── examples.rst ├── examples │ ├── example_crb_uv.ipynb │ ├── example_crb_xr.ipynb │ ├── example_grid.ipynb │ ├── example_grid_analysis.ipynb │ ├── example_gs_multipop.ipynb │ ├── example_gs_phenomenological.ipynb │ ├── example_gs_standard.ipynb │ ├── example_litdata.ipynb │ ├── example_pop_dusty.ipynb │ ├── example_pop_galaxy.ipynb │ ├── example_pop_popIII.ipynb │ └── uth_pq.ipynb ├── fields.rst ├── generate_figures.py ├── history.rst ├── index.rst ├── inits_tables.rst ├── install.rst ├── methods_integration.rst ├── param_bundles.rst ├── params.rst ├── params_control.rst ├── params_cosmology.rst ├── params_grid.rst ├── params_hmf.rst ├── params_inference.rst ├── params_physics.rst ├── params_populations.rst ├── params_pq.rst ├── params_sources.rst ├── performance.rst ├── problem_types.rst ├── requirements.txt ├── scripts │ ├── generate_figures.py │ ├── run_example_crb_lw.py │ ├── run_example_crb_uv.py │ └── run_example_crb_xr.py ├── structure.rst ├── troubleshooting.rst ├── updates.rst ├── uth.rst ├── uth_litdata.rst ├── uth_mcmc.rst ├── uth_physics_constants.rst ├── uth_physics_cosmo.rst ├── uth_physics_esec.rst ├── uth_physics_hydrogen.rst ├── uth_physics_rcs.rst ├── uth_pop_bh.rst ├── uth_pop_halo.rst ├── uth_pop_new.rst ├── uth_pop_radiation.rst ├── uth_pop_sfrd.rst ├── uth_pop_stellar.rst ├── uth_pq.rst ├── uth_solver_chem.rst ├── uth_solver_igm.rst ├── uth_solver_rt1d.rst ├── uth_solver_rte.rst ├── uth_src.rst ├── uth_src_bh.rst ├── uth_src_galaxy.rst ├── uth_src_stellar.rst └── uth_src_toy.rst ├── examples ├── fits │ ├── test_abundance_matching.py │ ├── test_fitting_generic.py │ ├── test_fitting_lf.py │ ├── test_fitting_tanh.py │ ├── test_fitting_tanh_extrema.py │ ├── test_modelgrid.py │ ├── test_optimization_bb_n1.py │ └── test_optimization_bb_n4.py ├── gs │ ├── movie_21cm.py │ ├── test_cuvb.py │ ├── test_cxrb.py │ └── test_helium.py ├── lit │ ├── test_aird2015.py │ ├── test_atek2015.py │ ├── test_bouwens2015.py │ ├── test_eldridge2009.py │ ├── test_haardt2012.py │ ├── test_kroupa2001.py │ ├── test_leitherer1999.py │ ├── test_lf.py │ ├── test_robertson2015.py │ ├── test_sazonov2004.py │ ├── test_ueda2003.py │ └── test_ueda2014.py ├── rt06 │ ├── test_rt06_00.py │ ├── test_rt06_03.py │ ├── test_rt06_1.py │ ├── test_rt06_2.py │ ├── test_rt06_2_m12.py │ ├── test_rt06_2_w_he.py │ ├── test_rt06_2_w_he_adv_e.py │ └── test_rt06_3.py ├── sources │ ├── test_sed_agn.py │ ├── test_sed_apl.py │ ├── test_sed_bb.py │ ├── test_sed_mcd.py │ ├── test_sed_parameterized.py │ ├── test_sed_pl.py │ ├── test_sed_simpl.py │ ├── test_sed_zebra.py │ ├── test_src_bh.py │ └── test_src_star.py ├── test_bsd.py └── test_ps_density.py ├── input ├── bhseds │ ├── generate_simpl_seds.py │ └── plot_seds.py ├── bpass_v1 │ ├── degrade_bpass_seds.py │ └── pack_bpass.sh ├── hmf │ ├── generate_halo_histories.py │ ├── generate_hmf_tables.py │ ├── generate_ps_tables.py │ ├── pack_hmf.sh │ └── test_fcoll.py ├── inits │ ├── generate_inits_tables.py │ ├── pack_inits.sh │ ├── run_CosmoRec.py │ └── run_cosmologies.sh ├── litdata │ ├── aird2015.py │ ├── alavi2016.py │ ├── atek2015.py │ ├── behroozi2013.py │ ├── blue_tides.py │ ├── bouwens2014.py │ ├── bouwens2015.py │ ├── bouwens2017.py │ ├── bowler2020.py │ ├── bowman2018.py │ ├── bpass_v1.py │ ├── bpass_v2.py │ ├── calzetti1994.py │ ├── daddi2007.py │ ├── duncan2014.py │ ├── dunne2009.py │ ├── eldridge2009.py │ ├── eldridge2017.py │ ├── emma.py │ ├── ferland1980.py │ ├── ferland1980.txt │ ├── feulner2005.py │ ├── finkelstein2012.py │ ├── finkelstein2015.py │ ├── furlanetto2017.py │ ├── gonzalez2012.py │ ├── gruppioni2020.py │ ├── haardt2012.py │ ├── harikane2022.py │ ├── inoue2011.py │ ├── kajisawa2010.py │ ├── karim2011.py │ ├── kroupa2001.py │ ├── kusakabe2020.py │ ├── lee2011.py │ ├── leitherer1999.py │ ├── madau2014.py │ ├── marchesini2009_10.py │ ├── mcbride2009.py │ ├── mclure2013.py │ ├── mesinger2016.py │ ├── mirocha2016.py │ ├── mirocha2017.py │ ├── mirocha2018.py │ ├── mirocha2019.py │ ├── mirocha2020.py │ ├── morishita2018.py │ ├── mortlock2011.py │ ├── moustakas2013.py │ ├── noeske2007.py │ ├── oesch2013.py │ ├── oesch2014.py │ ├── oesch2016.py │ ├── oesch2018.py │ ├── park2019.py │ ├── parsa2016.py │ ├── parsec.py │ ├── perez2008.py │ ├── reddy2009.py │ ├── robertson2015.py │ ├── rojasruiz2020.py │ ├── sanders2015.py │ ├── sazonov2004.py │ ├── schaerer2002.py │ ├── schneider.py │ ├── song2016.py │ ├── starburst99.py │ ├── stark2010.py │ ├── stark2011.py │ ├── stefanon2017.py │ ├── stefanon2019.py │ ├── sun2020.py │ ├── test_schaerer2002.py │ ├── tomczak2014.py │ ├── ueda2003.py │ ├── ueda2014.py │ ├── vanderburg2010.py │ ├── weisz2014.py │ └── whitaker2012.py ├── optical_depth │ ├── generate_optical_depth_tables.py │ └── pack_tau.sh ├── rctabs │ └── generate_rc_table.py └── secondary_electrons │ └── read_FJS10.py ├── perf ├── README ├── run_ares.sh ├── test_gs_basic.py ├── test_gs_lfcal.py ├── test_sam_hists.py ├── test_sam_synth.py ├── test_tabulation_speed_H.py └── test_tabulation_speed_He.py ├── remote.py ├── requirements.txt ├── run_tests_local.sh ├── setup.py └── tests ├── __init__.py ├── adv ├── README ├── test_gs_4par.py ├── test_gs_crt.py ├── test_gs_fcoll.py ├── test_gs_lfcal.py ├── test_mc_repeat.py ├── test_mc_repeat.sh ├── test_mc_repeat_results.py ├── test_parallel_grid.py ├── test_parallel_grid.sh ├── test_parallel_grid_results.py ├── test_physics_hmf.py ├── test_pop_cohort.py ├── test_pop_galaxy.py ├── test_pop_sfrd.py ├── test_sed_simpl.py ├── test_setup_pbundles.py ├── test_solver_chem_he.py ├── test_solver_crt_uvb_w_bpass.py ├── test_solver_crt_xrb.py └── test_src_bpass.py ├── broken ├── test_cxrb_helium.py ├── test_cxrb_mcd.py ├── test_generator_uvb_qso.py ├── test_gs_param_rates.py ├── test_inline_tau.py ├── test_mpm.py ├── test_mpm_w_mgb.py ├── test_patch_cgm.py ├── test_patch_igm.py ├── test_patch_igm_analytic.py └── test_tau_dynamic.py ├── test_analysis_blobs.py ├── test_analysis_gs_extrema.py ├── test_inference_grid.py ├── test_int_feedback_LW.py ├── test_obs_survey.py ├── test_phenom_pq.py ├── test_physics_HI_beta.py ├── test_physics_HI_cc.py ├── test_physics_HI_lya.py ├── test_physics_HI_tau.py ├── test_physics_HI_wf.py ├── test_physics_cosmology.py ├── test_physics_cross_sections.py ├── test_physics_excursion_set.py ├── test_physics_halo_mf.py ├── test_physics_halo_model.py ├── test_physics_heating_cooling.py ├── test_physics_nebula.py ├── test_physics_secondary_elec.py ├── test_populations_aggregate.py ├── test_populations_bh.py ├── test_populations_cohort_emissivity.py ├── test_populations_cohort_funcs.py ├── test_populations_cohort_mlf.py ├── test_populations_cohort_pqs.py ├── test_populations_cohort_sfe.py ├── test_populations_ensemble.py ├── test_populations_hod.py ├── test_populations_popIII.py ├── test_simulations_gs_4par.py ├── test_simulations_gs_fcoll.py ├── test_simulations_gs_lfcal.py ├── test_simulations_gs_multipop.py ├── test_simulations_gs_param_hist.py ├── test_simulations_gs_phenom.py ├── test_simulations_rt1d_const_flux.py ├── test_simulations_rt1d_const_ioniz.py ├── test_simulations_rt1d_ptsrc.py ├── test_solvers_chem_h.py ├── test_solvers_crte_delta.py ├── test_solvers_crte_uvb.py ├── test_solvers_crte_xrb.py ├── test_solvers_tau.py ├── test_sources_bh.py ├── test_sources_sps.py ├── test_static_phot_synth.py ├── test_static_spec_synth.py ├── test_util_math.py ├── test_util_misc.py ├── test_util_pbundle.py ├── test_util_readdata.py └── test_util_stats.py /.coveragerc: -------------------------------------------------------------------------------- 1 | # .coveragerc to control coverage.py 2 | [run] 3 | branch = False 4 | 5 | [report] 6 | precision = 2 7 | 8 | # Regexes for lines to exclude from consideration 9 | exclude_lines = 10 | # Have to re-enable the standard pragma 11 | pragma: no cover 12 | 13 | # Don't complain about missing debug-only code: 14 | def __repr__ 15 | if self\.pf['debug'] 16 | if self\.pf['verbose'] 17 | 18 | # Don't complain if tests don't hit defensive assertion code: 19 | raise ImportError 20 | raise NotImplementedError 21 | except ImportError 22 | except NotImplementedError 23 | 24 | # Don't worry about MPI 25 | from mpi4py import MPI 26 | rank = MPI.COMM_WORLD.rank 27 | size = MPI.COMM_WORLD.size 28 | rank = MPI.COMM_WORLD.Get_rank() 29 | size = MPI.COMM_WORLD.Get_size() 30 | 31 | # Don't complain if rank > 0 blocks aren't executed 32 | if rank > 0: 33 | if size > 1: 34 | 35 | # Don't complain if non-runnable code isn't run: 36 | if 0: 37 | if False: 38 | if __name__ == .__main__.: 39 | 40 | omit = 41 | ares/util/Aesthetics.py 42 | ares/util/BlobBundles.py 43 | ares/util/MPIPool.py 44 | ares/util/PrintInfo.py 45 | ares/util/Warnings.py 46 | ares/analysis/*.py 47 | ares/inference/*.py 48 | 49 | ignore_errors = True 50 | 51 | [html] 52 | directory = htmlcov 53 | -------------------------------------------------------------------------------- /.github/workflows/test_suite.yaml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: Tests 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | python-version: [3.9] 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Set up Python ${{ matrix.python-version }} 24 | uses: actions/setup-python@v2 25 | with: 26 | python-version: ${{ matrix.python-version }} 27 | - name: Install dependencies 28 | run: | 29 | python -m pip install --upgrade pip 30 | python -m pip install flake8 pytest 31 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 32 | #- name: Lint with flake8 33 | # run: | 34 | # # stop the build if there are Python syntax errors or undefined names 35 | # flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 36 | # # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 37 | # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 38 | - name: Build 39 | run: | 40 | pip install . 41 | python remote.py minimal 42 | - name: Test with pytest 43 | run: | 44 | pytest --cov-config=.coveragerc --cov=ares --cov-report=xml -v tests/*.py 45 | - name: Upload coverage to Codecov 46 | uses: codecov/codecov-action@v2 47 | with: 48 | token: ${{ secrets.CODECOV_TOKEN }} 49 | files: ./coverage.xml 50 | fail_ci_if_error: false 51 | name: codecov-ares 52 | verbose: true 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.c 3 | *.h 4 | *.hdf5 5 | ares.egg-info 6 | *.png 7 | *.tar.gz 8 | docs/_build 9 | docs/*.py 10 | docs/*.txt 11 | docs/*.pkl 12 | docs/examples/*.txt 13 | docs/examples/*.pkl 14 | docs/examples/.ipynb_checkpoints 15 | input/eos 16 | input/irac/*.txt 17 | input/roman 18 | input/planck/ 19 | input/secondary_electrons/x_int_tables/ 20 | input/inoue2011 21 | input/wfc/ 22 | input/wfc3/ 23 | input/starburst99 24 | input/inits/outputs/ 25 | input/bpass_v1/SEDS 26 | input/bpass_v1/*tar.gz 27 | input/bpass_v1_stars/* 28 | input/bpass_v2 29 | input/inits/*.txt 30 | input/nircam 31 | tests/.coverage 32 | .coverage 33 | coverage.xml 34 | htmlcov 35 | .DS_Store 36 | tests/*.pkl 37 | tests/*.txt 38 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yaml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Build documentation in the docs/ directory with Sphinx 9 | sphinx: 10 | configuration: docs/conf.py 11 | 12 | # Optionally build your docs in additional formats such as PDF 13 | #formats: 14 | # - pdf 15 | 16 | # Optionally set the version of Python and requirements required to build your docs 17 | python: 18 | version: "3.7" 19 | install: 20 | - requirements: docs/requirements.txt 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Jordan Mirocha 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /ares/__init__.py: -------------------------------------------------------------------------------- 1 | import os as _os 2 | import imp as _imp 3 | 4 | _HOME = _os.environ.get('HOME') 5 | 6 | # Load custom defaults 7 | if _os.path.exists('{!s}/.ares/defaults.py'.format(_HOME)): 8 | (_f, _filename, _data) =\ 9 | _imp.find_module('defaults', ['{!s}/.ares/'.format(_HOME)]) 10 | rcParams = _imp.load_module('defaults.py', _f, _filename, _data).pf 11 | else: 12 | rcParams = {} 13 | 14 | import ares.physics 15 | import ares.util 16 | import ares.analysis 17 | import ares.sources 18 | import ares.populations 19 | import ares.static 20 | import ares.solvers 21 | import ares.simulations 22 | import ares.inference 23 | -------------------------------------------------------------------------------- /ares/analysis/__init__.py: -------------------------------------------------------------------------------- 1 | from ares.analysis.ModelSet import ModelSet 2 | from ares.analysis.RaySegment import RaySegment 3 | from ares.analysis.Global21cm import Global21cm 4 | from ares.analysis.PowerSpectrum import PowerSpectrum 5 | from ares.analysis.GalaxyPopulation import GalaxyPopulation 6 | from ares.analysis.Animation import Animation, AnimationSet 7 | from ares.analysis.MultiPhaseMedium import MultiPhaseMedium 8 | from ares.analysis.MetaGalacticBackground import MetaGalacticBackground 9 | -------------------------------------------------------------------------------- /ares/data/__init__.py: -------------------------------------------------------------------------------- 1 | _ARES = __path__[0] 2 | ARES = _ARES[0:_ARES.rfind('ares/')] 3 | -------------------------------------------------------------------------------- /ares/inference/__init__.py: -------------------------------------------------------------------------------- 1 | from ares.inference.ModelFit import ModelFit 2 | from ares.inference.ModelGrid import ModelGrid 3 | from ares.inference.ModelSample import ModelSample 4 | from ares.inference.FitGlobal21cm import FitGlobal21cm 5 | #from ares.inference.ModelEmulator import ModelEmulator 6 | from ares.inference.CalibrateModel import CalibrateModel 7 | #from ares.inference.OptimizeSpectrum import SpectrumOptimization 8 | from ares.inference.FitGalaxyPopulation import FitGalaxyPopulation 9 | 10 | -------------------------------------------------------------------------------- /ares/obs/MagnitudeSystem.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | MagnitudeSystem.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Sat Sep 5 15:51:39 PDT 2015 8 | 9 | Description: Utilities for converting magnitudes to luminosities and such. 10 | 11 | """ 12 | 13 | import numpy as np 14 | from ..physics.Cosmology import Cosmology 15 | from ..physics.Constants import cm_per_pc, flux_AB 16 | 17 | class MagnitudeSystem(object): 18 | def __init__(self, cosm=None, **kwargs): 19 | if cosm is None: 20 | self.cosm = Cosmology(**kwargs) 21 | else: 22 | self.cosm = cosm 23 | 24 | def MAB_to_L(self, mag): 25 | """ 26 | Convert AB magnitude [ABSOLUTE] to rest-frame luminosity. 27 | 28 | Parameters 29 | ---------- 30 | mag : int, float 31 | Absolute magnitude in AB system. 32 | z : int, float 33 | Redshift of object 34 | dL : int, float 35 | Luminosity distance of object [cm] 36 | 37 | Currently this is dumb: doesn't need to depend on luminosity. 38 | 39 | Returns 40 | ------- 41 | Luminosity in erg / s / Hz. 42 | 43 | """ 44 | 45 | # Apparent magnitude 46 | d10 = 10 * cm_per_pc 47 | 48 | # Luminosity! 49 | return 10**(mag / -2.5) * flux_AB * 4. * np.pi * d10**2 50 | 51 | def L_to_MAB(self, L): 52 | d10 = 10 * cm_per_pc 53 | return -2.5 * np.log10(L / 4. / np.pi / d10**2 / flux_AB) 54 | 55 | def L_to_mab(self, L, z=None, dL=None): 56 | raise NotImplemented('do we ever use this?') 57 | 58 | # apparent magnitude 59 | assert (z is not None) or (dL is not None) 60 | 61 | if z is not None: 62 | dL = self.cosm.LuminosityDistance(z) 63 | # 64 | return -2.5 * np.log10(L / (flux_AB * 4. * np.pi * dL**2)) 65 | -------------------------------------------------------------------------------- /ares/obs/Photometry.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Photometry.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill 7 | Created on: Mon 27 Jan 2020 09:59:10 EST 8 | 9 | Description: 10 | 11 | """ 12 | 13 | def get_filters_from_waves(z, fset, wave_lo=1300., wave_hi=2600., picky=True): 14 | """ 15 | Given a redshift and a full filter set, return the filters that probe 16 | a given wavelength range (rest-UV continuum by default). 17 | 18 | Parameters 19 | ---------- 20 | z : int, float 21 | Redshift of interest. 22 | fset : dict 23 | A filter set, i.e., the kind of dictionary created by 24 | ares.obs.Survey.get_throughputs. 25 | wave_lo, wave_hi: int, float 26 | Rest wavelengths bounding range of interest [Angstrom]. 27 | picky : bool 28 | If True, will only return filters that lie entirely in the specified 29 | wavelength range. If False, returned list of filters will contain those 30 | that straddle the boundaries (if such cases exist). 31 | 32 | Returns 33 | ------- 34 | List of filters that cover the specified rest-wavelength range. 35 | 36 | """ 37 | 38 | # Compute observed wavelengths in microns 39 | l1 = wave_lo * (1. + z) * 1e-4 40 | l2 = wave_hi * (1. + z) * 1e-4 41 | 42 | out = [] 43 | for filt in fset.keys(): 44 | # Hack out numbers 45 | _x, _y, mid, dx, Tbar = fset[filt] 46 | 47 | fhi = mid + dx[0] 48 | flo = mid - dx[1] 49 | 50 | entirely_in = (flo >= l1) and (fhi <= l2) 51 | partially_in = (flo <= l1 <= fhi) or (flo <= l2 <= fhi) 52 | 53 | if picky and (partially_in and not partially_in): 54 | continue 55 | elif picky and entirely_in: 56 | pass 57 | elif not (partially_in or entirely_in): 58 | continue 59 | elif (partially_in or entirely_in): 60 | pass 61 | 62 | out.append(filt) 63 | 64 | return out 65 | -------------------------------------------------------------------------------- /ares/obs/__init__.py: -------------------------------------------------------------------------------- 1 | from ares.obs.Survey import Survey 2 | from ares.obs.OpticalDepth import Madau1995 3 | from ares.obs.DustCorrection import DustCorrection 4 | from ares.obs.MagnitudeSystem import MagnitudeSystem 5 | from ares.obs.Photometry import get_filters_from_waves 6 | -------------------------------------------------------------------------------- /ares/phenom/__init__.py: -------------------------------------------------------------------------------- 1 | from ares.phenom.Tanh21cm import Tanh21cm 2 | from ares.phenom.Gaussian21cm import Gaussian21cm 3 | from ares.phenom.Parametric21cm import Parametric21cm 4 | from ares.phenom.ParameterizedQuantity import ParameterizedQuantity 5 | -------------------------------------------------------------------------------- /ares/physics/__init__.py: -------------------------------------------------------------------------------- 1 | import ares.physics.Constants 2 | from ares.physics.Hydrogen import Hydrogen 3 | from ares.physics.Cosmology import Cosmology 4 | from ares.physics.HaloModel import HaloModel 5 | from ares.physics.ExcursionSet import ExcursionSet 6 | from ares.physics.DustEmission import DustEmission 7 | from ares.physics.NebularEmission import NebularEmission 8 | from ares.physics.HaloMassFunction import HaloMassFunction 9 | from ares.physics.RateCoefficients import RateCoefficients 10 | from ares.physics.SecondaryElectrons import SecondaryElectrons 11 | from ares.physics.CrossSections import PhotoIonizationCrossSection 12 | -------------------------------------------------------------------------------- /ares/populations/Toy.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | ToyPopulation.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Tue Apr 17 12:29:50 PDT 2018 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import numpy as np 14 | from ..physics import Cosmology 15 | from .Population import Population 16 | from ares.physics.Constants import c, erg_per_ev 17 | 18 | class Toy(Population): 19 | 20 | def Emissivity(self, z, E=None, Emin=None, Emax=None): 21 | return np.zeros_like(z) 22 | 23 | -------------------------------------------------------------------------------- /ares/populations/__init__.py: -------------------------------------------------------------------------------- 1 | from ares.populations.Halo import HaloPopulation 2 | from ares.populations.GalaxyPopulation import GalaxyPopulation 3 | -------------------------------------------------------------------------------- /ares/simulations/__init__.py: -------------------------------------------------------------------------------- 1 | from ares.simulations.GasParcel import GasParcel 2 | from ares.simulations.RaySegment import RaySegment 3 | from ares.simulations.Global21cm import Global21cm 4 | from ares.simulations.Simulation import Simulation 5 | from ares.simulations.MultiPhaseMedium import MultiPhaseMedium 6 | from ares.simulations.MetaGalacticBackground import MetaGalacticBackground 7 | -------------------------------------------------------------------------------- /ares/solvers/__init__.py: -------------------------------------------------------------------------------- 1 | from ares.solvers.Chemistry import Chemistry 2 | from ares.solvers.RadialField import RadialField 3 | from ares.solvers.OpticalDepth import OpticalDepth 4 | from ares.solvers.UniformBackground import UniformBackground 5 | 6 | -------------------------------------------------------------------------------- /ares/sources/UserDefined.py: -------------------------------------------------------------------------------- 1 | from .Source import Source 2 | from inspect import ismethod 3 | from types import FunctionType 4 | from ..util.Math import interp1d 5 | from ..util.SetDefaultParameterValues import SourceParameters 6 | try: 7 | # this runs with no issues in python 2 but raises error in python 3 8 | basestring 9 | except: 10 | # this try/except allows for python 2/3 compatible string type checking 11 | basestring = str 12 | 13 | class UserDefined(Source): 14 | def __init__(self, **kwargs): 15 | """ 16 | 17 | Parameters 18 | ---------- 19 | pf: dict 20 | Full parameter file. 21 | 22 | """ 23 | 24 | self.pf = SourceParameters() 25 | self.pf.update(kwargs) 26 | Source.__init__(self) 27 | 28 | self._name = 'user_defined' 29 | 30 | self._load() 31 | 32 | def _load(self): 33 | sed = self.pf['source_sed'] 34 | E = self.pf['source_E'] 35 | L = self.pf['source_L'] 36 | 37 | if sed is not None: 38 | 39 | if sed == 'user': 40 | pass 41 | elif type(sed) is FunctionType or ismethod(sed) or \ 42 | isinstance(sed, interp1d): 43 | self._func = sed 44 | return 45 | elif type(sed) is tuple: 46 | E, L = sed 47 | 48 | elif isinstance(sed, basestring): 49 | E, L = np.loadtxt(sed, unpack=True) 50 | elif (E is not None) and (L is not None): 51 | assert len(E) == len(L) 52 | else: 53 | raise NotImplemented('sorry, dont understand!') 54 | 55 | self._func = interp1d(E, L, kind='cubic', bounds_error=False) 56 | 57 | def _Intensity(self, E, t=0): 58 | return self._func(E) 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /ares/sources/__init__.py: -------------------------------------------------------------------------------- 1 | from ares.sources.Toy import Toy 2 | from ares.sources.Star import Star 3 | from ares.sources.StarQS import StarQS 4 | from ares.sources.Toy import DeltaFunction 5 | from ares.sources.BlackHole import BlackHole 6 | from ares.sources.Composite import Composite 7 | from ares.sources.SynthesisModel import SynthesisModel 8 | from ares.sources.SynthesisModelToy import SynthesisModelToy 9 | from ares.sources.SynthesisModelSBS import SynthesisModelSBS 10 | from ares.sources.SynthesisModelHybrid import SynthesisModelHybrid 11 | -------------------------------------------------------------------------------- /ares/static/__init__.py: -------------------------------------------------------------------------------- 1 | from ares.static.Grid import Grid 2 | from ares.static.VolumeLocal import LocalVolume 3 | from ares.static.VolumeGlobal import GlobalVolume 4 | from ares.static.IntegralTables import IntegralTable 5 | from ares.static.InterpolationTables import LookupTable 6 | from ares.static.ChemicalNetwork import ChemicalNetwork 7 | from ares.static.Fluctuations import Fluctuations 8 | from ares.static.SpectralSynthesis import SpectralSynthesis 9 | -------------------------------------------------------------------------------- /ares/util/ProgressBar.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | ProgressBar.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Thu Dec 27 16:27:51 2012 8 | 9 | Description: Wrapper for progressbar2. 10 | 11 | """ 12 | 13 | from .PrintInfo import width 14 | 15 | try: 16 | import progressbar 17 | pb = True 18 | except ImportError: 19 | pb = False 20 | 21 | try: 22 | from mpi4py import MPI 23 | rank = MPI.COMM_WORLD.rank 24 | size = MPI.COMM_WORLD.size 25 | except ImportError: 26 | rank = 0 27 | size = 1 28 | 29 | class ProgressBar(object): 30 | def __init__(self, maxval, name='ares', use=True): 31 | self.maxval = maxval 32 | self.use = use 33 | 34 | self.has_pb = False 35 | if pb and rank == 0 and use: 36 | self.widget = ["{!s}: ".format(name), progressbar.Percentage(), ' ', \ 37 | progressbar.Bar(marker='#'), ' ', \ 38 | progressbar.ETA(), ' '] 39 | 40 | def start(self): 41 | if pb and rank == 0 and self.use: 42 | self.pbar = progressbar.ProgressBar(widgets=self.widget, 43 | max_value=self.maxval, redirect_stdout=False, 44 | term_width=width+1).start() 45 | self.has_pb = True 46 | 47 | def update(self, value): 48 | if self.has_pb: 49 | self.pbar.update(value) 50 | 51 | def finish(self): 52 | if self.has_pb: 53 | self.pbar.finish() 54 | 55 | -------------------------------------------------------------------------------- /ares/util/__init__.py: -------------------------------------------------------------------------------- 1 | import ares.util.Pickling 2 | from ares.util.Pickling import read_pickle_file, write_pickle_file,\ 3 | delete_file, delete_file_if_clobber, overwrite_pickle_file 4 | 5 | from ares.util.Aesthetics import labels 6 | from ares.util.WriteData import CheckPoints 7 | from ares.util.BlobBundles import BlobBundle 8 | from ares.util.ProgressBar import ProgressBar 9 | from ares.util.ParameterFile import ParameterFile 10 | from ares.util.ReadData import read_lit, lit_options 11 | from ares.util.ParameterBundles import ParameterBundle 12 | from ares.util.RestrictTimestep import RestrictTimestep 13 | from ares.util.Misc import get_hash, get_cmd_line_kwargs 14 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | status: 3 | project: 4 | default: 5 | # basic 6 | target: auto 7 | threshold: 0.2% 8 | base: auto 9 | flags: 10 | - unit 11 | paths: 12 | - "ares" 13 | # advanced settings 14 | branches: 15 | - main 16 | if_ci_failed: error #success, failure, error, ignore 17 | informational: false 18 | only_pulls: false 19 | -------------------------------------------------------------------------------- /docs/acknowledgements.rst: -------------------------------------------------------------------------------- 1 | Acknowledgements 2 | ================ 3 | 4 | Main developer(s): 5 | 6 | - `Jordan Mirocha `_ 7 | 8 | Additional contributions / corrections / suggestions from: 9 | 10 | .. hlist:: 11 | :columns: 3 12 | 13 | * Geraint Harker 14 | * Jason Sun 15 | * Keith Tauscher 16 | * Jacob Jost 17 | * Greg Salvesen 18 | * Adrian Liu 19 | * Saurabh Singh 20 | * Rick Mebane 21 | * Krishma Singal 22 | * Donald Trinh 23 | * Omar Ruiz Macias 24 | * Arnab Chakraborty 25 | * Madhurima Choudhury 26 | * Saul Kohn 27 | * Aurel Schneider 28 | * Kristy Fu 29 | * Garett Lopez 30 | * Ranita Jana 31 | * Daniel Meinert 32 | * Henri Lamarre 33 | * Matteo Leo 34 | * Emma Klemets 35 | * Felix Bilodeau-Chagnon 36 | * Venno Vipp 37 | * Oscar Hernandez 38 | -------------------------------------------------------------------------------- /docs/example_adv_RT_w_He.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Including Helium in 1-D Radiative Transfer Calculations 4 | ======================================================= 5 | Test #2 from the Radiative Transfer Comparison Project (`Iliev et al. 2006 6 | `_). 7 | 8 | This problem investigates the growth of an HII region around a blackbody 9 | source of ionizing photons. The main parameters are: 10 | 11 | * Stellar ionizing photon production rate of :math:`\dot{Q} = 5 \times 10^{48} \ \text{s}^{-1}`. 12 | * Stellar spectrum is a :math:`10^5` K blackbody. 13 | * Medium composed of hydrogen only, with a density of :math:`n_{\text{H}} = 10^{-3} \ \text{cm}^{-3}`. 14 | * Gas temperature is able to evolve. It is initially set to :math:`T=100` K everywhere on the grid. 15 | 16 | The ionization and heating rates are computed treating the source's spectral 17 | energy distribution in full. A lengthy discussion of this can be found in 18 | `Mirocha et al. (2012) `_. 19 | 20 | Including helium for pre-existing problem types is as simple as adding 10 to 21 | the ``problem_type``, i.e., 22 | 23 | :: 24 | 25 | import ares 26 | 27 | sim = ares.simulations.RaySegment(problem_type=12) 28 | sim.run() 29 | 30 | Now, we initialize an instance of the appropriate analysis class: 31 | 32 | :: 33 | 34 | and have a look at the temperature profile at 10, 30, and 100 Myr, 35 | 36 | :: 37 | 38 | ax1 = sim.RadialProfile('Tk', t=[10, 30, 100]) 39 | 40 | radial profiles of the hydrogen species fractions, 41 | 42 | :: 43 | 44 | ax2 = sim.RadialProfile('h_1', t=[10, 30, 100], fig=2) 45 | sim.RadialProfile('h_2', t=[10, 30, 100], ax=ax2, ls='--') 46 | 47 | and the species fractions for helium: 48 | 49 | :: 50 | 51 | ax3 = sim.RadialProfile('he_1', t=[10, 30, 100], fig=3) 52 | sim.RadialProfile('he_2', t=[10, 30, 100], ax=ax3, ls='--') 53 | sim.RadialProfile('he_3', t=[10, 30, 100], ax=ax3, ls=':') 54 | 55 | 56 | -------------------------------------------------------------------------------- /docs/example_crb_br.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Broad-Band Metagalactic Backgrounds 4 | =================================== 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /docs/example_gs_hybrid.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Hybrid Models for the Global 21-cm Signal 4 | ========================================= 5 | By "hybrid" I mean part physical, part phenomenological. 6 | 7 | 8 | To begin, first import ares: 9 | 10 | :: 11 | 12 | import ares 13 | 14 | :: 15 | 16 | To generate a model of the global 21-cm signal, we need to use the 17 | ``ares.simulations.Global21cm`` class. With no arguments, default parameter 18 | values will be used: 19 | -------------------------------------------------------------------------------- /docs/example_rt06_1.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | RT06 Test #1 (Strömgren Sphere, isothermal) 4 | ============================================ 5 | Test #1 from the Radiative Transfer Comparison Project (`Iliev et al. 2006 `_). 6 | 7 | This problem investigates the growth of an HII region around a monochromatic 8 | source of ionizing photons. The main parameters are: 9 | 10 | * Stellar ionizing photon production rate of :math:`\dot{Q} = 5 \times 10^{48} \ \text{s}^{-1}`. 11 | * Medium composed of hydrogen only, with a density of :math:`n_{\text{H}} = 10^{-3} \ \text{cm}^{-3}`. 12 | * Medium is isothermal at :math:`T=10^4` K. 13 | 14 | :: 15 | 16 | import ares 17 | 18 | sim = ares.simulations.RaySegment(problem_type=1) 19 | sim.run() 20 | sim.PlotIonizationFrontEvolution() 21 | -------------------------------------------------------------------------------- /docs/example_rt06_2.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | RT06 Test #2 (Strömgren Sphere, thermal evolution allowed) 4 | ========================================================== 5 | Test #2 from the Radiative Transfer Comparison Project (`Iliev et al. 2006 6 | `_). 7 | 8 | This problem investigates the growth of an HII region around a blackbody 9 | source of ionizing photons. The main parameters are: 10 | 11 | * Stellar ionizing photon production rate of :math:`\dot{Q} = 5 \times 10^{48} \ \text{s}^{-1}`. 12 | * Stellar spectrum is a :math:`10^5` K blackbody. 13 | * Medium composed of hydrogen only, with a density of :math:`n_{\text{H}} = 10^{-3} \ \text{cm}^{-3}`. 14 | * Gas temperature is able to evolve. It is initially set to :math:`T=100` K everywhere on the grid. 15 | 16 | The ionization and heating rates are computed treating the source's spectral 17 | energy distribution in full. A lengthy discussion of this can be found in 18 | `Mirocha et al. (2012) `_. 19 | 20 | :: 21 | 22 | import ares 23 | 24 | sim = ares.simulations.RaySegment(problem_type=2) 25 | sim.run() 26 | 27 | sim.PlotIonizationFrontEvolution(fig=1) 28 | 29 | # Snapshots at 10 and 50 Myr 30 | ax = sim.RadialProfile('h_1', fig=2, t=[10, 50]) 31 | sim.RadialProfile('h_2', ax=ax, t=[10, 50], ls='--') 32 | sim.RadialProfile('Tk', fig=3, t=[10, 50]) 33 | 34 | 35 | -------------------------------------------------------------------------------- /docs/example_sedop.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Optimal SEDs for RT Calculations 4 | ================================ 5 | -------------------------------------------------------------------------------- /docs/examples.rst: -------------------------------------------------------------------------------- 1 | Examples 2 | ======== 3 | 4 | Running Individual Simulations for Reionization and Re-Heating 5 | -------------------------------------------------------------- 6 | 7 | .. toctree:: 8 | :maxdepth: 1 9 | 10 | examples/example_gs_standard 11 | examples/example_gs_multipop 12 | examples/example_gs_phenomenological 13 | 14 | Advanced Source Populations 15 | --------------------------- 16 | .. toctree:: 17 | :maxdepth: 1 18 | 19 | examples/example_pop_galaxy 20 | examples/example_pop_popIII 21 | examples/example_pop_dusty 22 | * :doc:`example_edges` 23 | 24 | Parameter Studies and Inference 25 | ------------------------------- 26 | .. toctree:: 27 | :maxdepth: 1 28 | 29 | examples/example_grid 30 | examples/example_grid_analysis 31 | example_mc_sampling 32 | example_ham 33 | example_mcmc_gs 34 | example_mcmc_lf 35 | example_mcmc_analysis 36 | example_inline_analysis 37 | 38 | The Meta-Galactic Radiation Background 39 | -------------------------------------- 40 | .. toctree:: 41 | :maxdepth: 1 42 | 43 | examples/example_crb_uv 44 | examples/example_crb_xr 45 | 46 | 1-D Radiative Transfer 47 | ---------------------- 48 | .. toctree:: 49 | :maxdepth: 1 50 | 51 | example_rt06_1 52 | example_rt06_2 53 | example_adv_RT_w_He 54 | 55 | Extensions 56 | ---------- 57 | .. toctree:: 58 | :maxdepth: 2 59 | 60 | examples/example_litdata 61 | example_embed_ares 62 | examples/uth_pq 63 | uth_pop_new 64 | -------------------------------------------------------------------------------- /docs/generate_figures.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | generate_figures.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Thu May 31 16:02:30 PDT 2018 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import os 14 | import sys 15 | 16 | try: 17 | fn = sys.argv[1] 18 | except IndexError: 19 | fn = None 20 | 21 | docs = \ 22 | [ 23 | 'example_grid.rst', 24 | 'example_gs_standard.rst', 25 | 'example_gs_multipop.rst', 26 | 'example_gs_phenomenological.rst', 27 | 'example_pop_galaxy.rst', 28 | 'example_crb_uv.rst', 29 | 'example_crb_xr.rst', 30 | 'example_pop_galaxy.rst', 31 | 'uth_pop_radiation.rst', 32 | 'uth_pq.rst', 33 | ] 34 | 35 | for fn_rst in docs: 36 | 37 | # Way to run single .rst file if we want 38 | if fn is not None: 39 | if fn_rst != fn: 40 | continue 41 | 42 | os.system('python $MODS/rst_to_py/rst_to_py.py {}'.format(fn_rst)) 43 | 44 | fn_py = fn_rst.replace('rst', 'py') 45 | 46 | print('Running {}...'.format(fn_py)) 47 | os.system('python {}'.format(fn_py)) 48 | print('') 49 | 50 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. ares documentation master file, created by 2 | sphinx-quickstart on Mon Jul 8 08:48:22 2013. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | .. mdinclude:: ../README.md 7 | 8 | Contents 9 | -------- 10 | .. toctree:: 11 | :maxdepth: 1 12 | 13 | Home 14 | install 15 | examples 16 | performance 17 | uth 18 | troubleshooting 19 | updates 20 | contributing 21 | history 22 | acknowledgements 23 | 24 | 25 | .. Indices and tables 26 | .. ================== 27 | .. * :ref:`genindex` 28 | .. * :ref:`modindex` 29 | .. * :ref:`search` 30 | -------------------------------------------------------------------------------- /docs/methods_integration.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Integrating the Cosmological Radiative Transfer Equation 4 | ======================================================== 5 | We implemented multiple methods for integrating the cosmological radiative transfer equation (C-RTE), which we outline here. The most important piece of this is computing the IGM optical depth, 6 | 7 | .. math:: 8 | 9 | \overline{\tau}_{\nu}(z, z^{\prime}) = \sum_j \int_{z}^{z^{\prime}} n_j(z^{\prime \prime}) \sigma_{j, \nu^{\prime\prime}} \frac{dl}{dz^{\prime\prime}}dz^{\prime\prime} 10 | 11 | 12 | ============== ============= ========= ======== 13 | Parameters Behavior 14 | ------------------------------------------ -------- 15 | frequency_bins redshift_bins tau_table xray-flux 16 | ============== ============= ========= ========= 17 | not None None None 2-D table 18 | None not None None generator 19 | None None not None generator 20 | None None None function 21 | ============== ============= ========= ========= 22 | 23 | CXRB Generator 24 | -------------- 25 | 26 | 27 | 28 | CXRB Tabulation 29 | --------------- 30 | -------------------------------------------------------------------------------- /docs/params_cosmology.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Cosmology Parameters 4 | ==================== 5 | The default cosmological parameters in *ARES* are from *Planck*. Specifically, we take values from the last column of Table 4 in `Planck XIII `_. 6 | 7 | .. note :: Several input files (e.g., lookup tables for the halo mass 8 | function, initial conditions, etc.) depend on these vales. There currently 9 | is not a system in place to make sure there is a match between the 10 | parameters you pass at run-time and the lookup tables read-in from disk. 11 | Beware! 12 | 13 | ``omega_m_0`` 14 | Matter density, relative to the critical density. 15 | 16 | Default: :math:`\Omega_{m,0} = 0.3089` 17 | 18 | ``omega_b_0`` 19 | Baryon density, relative to the critical density. 20 | 21 | Default: :math:`\Omega_{b,0} = 0.0486` 22 | 23 | ``omega_l_0`` 24 | Dark energy density, relative to the critical density. 25 | 26 | Default :math:`\Omega_{\Lambda,0} = 0.6911` 27 | 28 | ``hubble_0`` 29 | Hubble parameter today. 30 | 31 | Default: 0.6774 :math:`[100 \ \text{km} \ \text{s}^{-1} \ \text{Mpc}^{-1}]` 32 | 33 | ``helium_by_mass`` 34 | Fractional helium abundance by mass. 35 | 36 | Default: 0.2453 37 | 38 | ``cmb_temp_0`` 39 | Temperature of the cosmic microwave blackbody, today. 40 | 41 | Default: 2.7255 :math:`[\text{K}]` 42 | 43 | ``sigma_8`` 44 | Default: 0.8159 45 | 46 | ``primordial_index`` 47 | Default: 0.9667 48 | 49 | -------------------------------------------------------------------------------- /docs/params_grid.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Grid Parameters 4 | =============== 5 | 6 | 7 | ``grid_cells`` 8 | Number of resolution elements in the grid (i.e., number of concentric 9 | spherical shells to consider in 1-D calculation). 10 | 11 | ``logarithmic_grid`` 12 | If True, discretize space logarithmically, rather than linearly. 13 | 14 | Default: False 15 | 16 | ``start_radius`` 17 | Ignore radiative transfer within this distance from the origin [length_units] 18 | Must be done in order to avoid divergence in flux as :math:`r\rightarrow 0` 19 | 20 | ``density_units`` 21 | Hydrogen number density in units of :math:`\text{cm}^{-3}` 22 | Default: :math:`1 \ \text{cm}^{-3}` 23 | 24 | ``length_units`` 25 | Default: :math:`10 \times 3.08568 \times 10^{21} \ \text{cm}` (i.e., 10 kilo-parsec) [centimeters] 26 | 27 | ``time_units`` 28 | Default: :math:`3.15576 \times 10^{13} \ \text{s}` (i.e., 1 Myr) [seconds] 29 | 30 | ``initial_ionization`` 31 | 32 | 33 | ``initial_temperature`` 34 | 35 | ``include_igm`` 36 | Include IGM phase in the model? 37 | 38 | Default: ``True`` 39 | 40 | ``include_cgm`` 41 | Include CGM phase in the model? 42 | 43 | Default: ``True`` -------------------------------------------------------------------------------- /docs/params_inference.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Parameter Estimation Parameters 4 | =============================== 5 | 6 | 7 | ``blob_names`` 8 | 9 | ``blob_ivars`` 10 | 11 | ``blob_funcs`` 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx 2 | numpydoc 3 | nbsphinx 4 | m2r2 5 | docutils<0.17 6 | -------------------------------------------------------------------------------- /docs/scripts/generate_figures.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | generate_figures.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Mon Jun 29 16:32:22 MDT 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import matplotlib.pyplot as pl 14 | 15 | scripts = \ 16 | [ 17 | 'example_galaxypop.rst' 18 | ] 19 | 20 | 21 | for script in scripts: 22 | with open(script) as script_file: 23 | exec(compile(script_file.read(), script, 'exec')) 24 | 25 | -------------------------------------------------------------------------------- /docs/scripts/run_example_crb_lw.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | run_example_crb_lw.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Mon Jun 29 17:17:37 MDT 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | from ares.physics.Constants import erg_per_ev, c, ev_per_hz 17 | 18 | pars = \ 19 | { 20 | 'pop_type': 'galaxy', 21 | 'pop_sfrd': lambda z: 0.1, 22 | 'pop_sed': 'pl', 23 | 'pop_alpha': 0.0, 24 | 'pop_Emin': 1., 25 | 'pop_Emax': 41.8, 26 | 'pop_EminNorm': 13.6, 27 | 'pop_EmaxNorm': 1e2, 28 | 'pop_yield': 1e57, 29 | 'pop_yield_units': 'photons/msun', 30 | 31 | # Solution method 32 | 'pop_solve_rte': True, 33 | 'pop_tau_Nz': 400, 34 | 'include_H_Lya': False, 35 | 36 | 'initial_redshift': 40., 37 | 'final_redshift': 10., 38 | } 39 | 40 | # First calculation: no sawtooth 41 | mgb = ares.simulations.MetaGalacticBackground(**pars) 42 | mgb.run() 43 | 44 | z, E, flux = mgb.get_history(flatten=True) 45 | pl.semilogy(E, flux[-1] * E * erg_per_ev, color='k', ls=':') 46 | 47 | # Now, turn on sawtooth 48 | pars2 = pars.copy() 49 | pars2['pop_sawtooth'] = True 50 | 51 | mgb2 = ares.simulations.MetaGalacticBackground(**pars2) 52 | mgb2.run() 53 | 54 | z2, E2, flux2 = mgb2.get_history(flatten=True) 55 | pl.semilogy(E2, flux2[-1] * E2 * erg_per_ev, color='k', ls='--') 56 | 57 | # Grab GalaxyPopulation 58 | pop = mgb.pops[0] 59 | 60 | # Cosmologically-limited solution to the RTE 61 | # [Equation A1 in Mirocha (2014)] 62 | zi, zf = 40., 10. 63 | e_nu = np.array([pop.Emissivity(zf, EE) for EE in E]) 64 | e_nu *= (1. + zf)**4.5 / 4. / np.pi / pop.cosm.HubbleParameter(zf) / -1.5 65 | e_nu *= ((1. + zi)**-1.5 - (1. + zf)**-1.5) 66 | e_nu *= c * ev_per_hz 67 | 68 | # Plot it 69 | pl.semilogy(E, e_nu, color='k', ls='-') 70 | pl.xlabel(ares.util.labels['E']) 71 | pl.ylabel(ares.util.labels['flux_E']) 72 | pl.savefig('example_crb_lw.png') 73 | -------------------------------------------------------------------------------- /docs/scripts/run_example_crb_uv.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | run_example_crb_uv.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Thu Jul 2 17:20:11 MDT 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | from ares.physics.Constants import erg_per_ev 17 | 18 | # Initialize radiation background 19 | pars = \ 20 | { 21 | # Source properties 22 | 'pop_type': 'galaxy', 23 | 'pop_sfrd': lambda z: 0.1, 24 | 'pop_sed': 'pl', 25 | 'pop_alpha': 1.0, 26 | 'pop_Emin': 13.6, 27 | 'pop_Emax': 1e2, 28 | 'pop_EminNorm': 13.6, 29 | 'pop_EmaxNorm': 1e2, 30 | 'pop_yield': 1e57, 31 | 'pop_yield_units': 'photons/msun', 32 | 33 | # Solution method 34 | 'pop_solve_rte': True, 35 | 'pop_tau_Nz': 400, 36 | 'include_H_Lya': False, 37 | 38 | 'sawtooth_nmax': 8, 39 | 'pop_sawtooth': True, 40 | 41 | 'initial_redshift': 7., 42 | 'final_redshift': 3., 43 | } 44 | 45 | 46 | mgb = ares.simulations.MetaGalacticBackground(**pars) 47 | mgb.run() 48 | 49 | """ 50 | First, look at background flux itself. 51 | """ 52 | 53 | z, E, flux = mgb.get_history(flatten=True) 54 | 55 | pl.semilogy(E, flux[-1] * E * erg_per_ev, color='k') 56 | pl.xlabel(ares.util.labels['E']) 57 | pl.ylabel(ares.util.labels['flux_E']) 58 | pl.savefig('example_crb_uv.png') 59 | 60 | 61 | -------------------------------------------------------------------------------- /docs/structure.rst: -------------------------------------------------------------------------------- 1 | Code Structure 2 | ============== 3 | *ARES* is organized hierarchically, with particularly heavy use of Python 4 | `generators `_. This makes for a code 5 | whose behavior can be easily adapted during run-time. 6 | 7 | The top level submodule of `ares` is the :py:mod:`ares.simulations` submodule. 8 | 9 | -------------------------------------------------------------------------------- /docs/uth.rst: -------------------------------------------------------------------------------- 1 | Under the Hood 2 | ============== 3 | Super incomplete, sorry! 4 | 5 | Parameters, Fields, and Data Structures 6 | --------------------------------------- 7 | * :doc:`params` 8 | * :doc:`fields` 9 | * :doc:`inits_tables` 10 | * :doc:`uth_pq` 11 | 12 | .. Radiation Sources 13 | .. ----------------- 14 | .. 15 | .. * :doc:`uth_src_stellar` 16 | .. * :doc:`uth_src_bh` 17 | .. * :doc:`uth_src_galaxy` 18 | .. * :doc:`uth_src_toy` 19 | 20 | Source Populations 21 | ------------------ 22 | * :doc:`uth_pop_halo` 23 | * :doc:`uth_pop_sfrd` 24 | * :doc:`uth_pop_radiation` 25 | * :doc:`example_pop_sps` 26 | 27 | .. * :doc:`uth_pop_sam` 28 | .. * :doc:`uth_pop_new` 29 | 30 | 31 | .. * :doc:`uth_pop_stellar` 32 | .. * :doc:`uth_pop_bh` 33 | .. * :doc:`uth_pop_analysis` 34 | 35 | Physics 36 | ------- 37 | * :doc:`uth_physics_cosmo` 38 | 39 | .. * :doc:`uth_physics_hydrogen` 40 | .. * :doc:`uth_physics_constants` 41 | .. * :doc:`uth_physics_rcs` 42 | .. * :doc:`uth_physics_esec` 43 | 44 | .. Data from the literature 45 | .. ------------------------ 46 | .. * :doc:`uth_litdata` 47 | 48 | Solvers 49 | ------- 50 | * :doc:`uth_solver_chem` 51 | .. * :doc:`uth_solver_rte` 52 | 53 | 54 | .. Inference 55 | .. --------- 56 | .. * :doc:`uth_mcmc` 57 | 58 | 59 | .. Simulation Drivers 60 | .. ------------------ 61 | .. NotImplemented 62 | 63 | 64 | -------------------------------------------------------------------------------- /docs/uth_physics_constants.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Physical Constants 4 | ================== -------------------------------------------------------------------------------- /docs/uth_physics_cosmo.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Cosmology 4 | ========= 5 | One quick note about cosmology: the convention in *ARES* is to eliminate all factors of "little h," i.e., the Hubble parameter in units of :math:`100 \ \mathrm{km} \ \mathrm{s}^{-1} \ \mathrm{Mpc}^{-3}`. The most noticeable place where this happens is in the ``ares.physics.HaloMassFunction`` class. For example, whereas the *hmf* code yields the halo mass function with implicit h's, *ARES* "undoes" these factors, meaning, e.g., that the halo mass function stored in ``ares.physics.HaloMassFunction.tab_dndm`` is simply in units of :math:`\mathrm{Mpc}^{-3}`, not :math:`h^4 \mathrm{Mpc}^{-3}`, so the user need not multiply `tab_dndm` by :math:`h^4` to obtain the "true" mass function. The same goes for halo masses themselves (no need to divide by :math:`h`) and the cumulative mass function (no need to multiply by :math:`h^3` or :math:`h^2` for :math:`n(>m)` and :math:`m(>m)`, respectively). 6 | 7 | For a nice discussion of little h check out `this paper by Darren Croton `_. -------------------------------------------------------------------------------- /docs/uth_physics_esec.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Secondary Ionization & Heating 4 | ============================== -------------------------------------------------------------------------------- /docs/uth_physics_hydrogen.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | The Hydrogen Atom 4 | ================= 5 | -------------------------------------------------------------------------------- /docs/uth_physics_rcs.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Rate Coefficients 4 | ================= 5 | -------------------------------------------------------------------------------- /docs/uth_pop_bh.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Black Hole Populations 4 | ====================== 5 | In these examples, we will initialize a stellar population object, defined 6 | by the minimum virial temperature of halos in which stars form, ``Tmin``, 7 | the star formation efficiency, ``fstar``, and other optional keyword arguments. 8 | 9 | To begin, import ares and initialize an instance of the BlackHolePopulation class: 10 | 11 | :: 12 | 13 | import ares 14 | pop = ares.populations.BlackHolePopulation(Tmin=1e4, fstar=0.1) 15 | 16 | Once initialized, there are several class methods available to compute the star-formation rate density (SFRD) and emissivity (in the UV and X-ray): 17 | 18 | :: 19 | 20 | z = 20. 21 | pop.AccretionRateDensity(z) # [g / ccm**3 / s] 22 | pop.XrayLuminosityDensity(z) # [erg / ccm**3 / s] 23 | pop.LymanWernerLuminosityDensity(z) # [erg / ccm**3 / s] 24 | 25 | Class methods always return values in cgs units, and when applicable, volume densities are assumed to be in comoving units (in the comments above, ccm stands for co-moving centimeters). 26 | 27 | To convert to more recognizable units, use conversion factors from ``ares``: 28 | 29 | :: 30 | 31 | from ares.physics.Constants import rhodot_cgs 32 | pop.SFRD(z) * rhodot_cgs # [Msun / cMpc**3 / yr] 33 | pop.XrayLuminosityDensity(z) * cm_per_mpc**3 # [erg / cMpc**3 / s] 34 | 35 | where Msun is solar masses, and cMpc is used to denote co-moving Megaparsecs. 36 | 37 | 38 | Black hole models have a wider variety of behaviors available than stellar models. 39 | 40 | To investigate the X-ray background that arises from a BH population, 41 | see :doc:`example_cxrb`. 42 | -------------------------------------------------------------------------------- /docs/uth_solver_igm.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | The Intergalactic Medium 4 | ======================== 5 | We've seen so far that you can initialize stellar and BH populations and 6 | radiation backgrounds independently, i.e., without doing a full blown 7 | 21-cm calculation. However, 8 | the radiation background will in general modify the 9 | properties of the intergalactic medium, which will then influence the subsequent 10 | evolution of the radiation background (and so on). Coupling radiation from 11 | stars and BHs to the IGM requires use of the ``ares.solvers.IntergalacticMedium`` 12 | module: 13 | 14 | :: 15 | 16 | import ares 17 | 18 | igm = ares.solvers.IGM() 19 | 20 | # Optical depth between 10 <= z <= 12 at 500 eV. 21 | # By default, assumes IGM is neutral 22 | tau_neutral = igm.OpticalDepth(10, 12, 500) 23 | 24 | # Can supply ionized fraction as constant 25 | tau_xconst = igm.OpticalDepth(10, 12, 500, xavg=0.5) 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /docs/uth_solver_rt1d.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | 1-D Radiative Transfer 4 | ====================== -------------------------------------------------------------------------------- /docs/uth_solver_rte.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Cosmological Radiative Transfer 4 | =============================== 5 | We've seen so far that you can initialize stellar and BH populations and 6 | radiation backgrounds independently, i.e., without doing a full blown 7 | 21-cm calculation. However, 8 | the radiation background will in general modify the 9 | properties of the intergalactic medium, which will then influence the subsequent 10 | evolution of the radiation background (and so on). Coupling radiation from 11 | stars and BHs to the IGM requires use of the ``ares.solvers.IntergalacticMedium`` 12 | module: 13 | 14 | :: 15 | 16 | import ares 17 | 18 | igm = ares.solvers.IGM() 19 | 20 | # Optical depth between 10 <= z <= 12 at 500 eV. 21 | # By default, assumes IGM is neutral 22 | tau_neutral = igm.OpticalDepth(10, 12, 500) 23 | 24 | # Can supply ionized fraction as constant 25 | tau_xconst = igm.OpticalDepth(10, 12, 500, xavg=0.5) 26 | -------------------------------------------------------------------------------- /docs/uth_src.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | The ``Source`` Class 4 | -------------------- 5 | All types of radiation sources inherit from one master class: the Source 6 | class. This class has numerous routines that are broadly applicable, e.g., 7 | integration of an SED over some band, computing spectrum-weighted 8 | cross-sections, etc. 9 | -------------------------------------------------------------------------------- /docs/uth_src_bh.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Black Hole Sources 4 | ================== 5 | Black hole sources currently have a wider array of potential behaviors than 6 | stellar sources. For example, their spectra can be quite a bit more complicated. 7 | *ARES* supports several standard SEDs for BHs: 8 | 9 | * Power-law (see ``source_alpha`` parameter to set slope) 10 | * Absorbed power-law (see ``source_logN`` to set absorbing column) 11 | * The multi-color disk spectrum 12 | 13 | BHs are also normalized differently. 14 | 15 | 16 | -------------------------------------------------------------------------------- /docs/uth_src_galaxy.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Galaxy Sources 4 | ============== -------------------------------------------------------------------------------- /docs/uth_src_stellar.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Stellar Sources 4 | =============== 5 | Stellar sources are those characterized by a 6 | 7 | 8 | They 9 | 10 | -------------------------------------------------------------------------------- /docs/uth_src_toy.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | Toy Sources 4 | ----------- 5 | Monochromatic or polychromatic sources. 6 | 7 | -------------------------------------------------------------------------------- /examples/fits/test_fitting_tanh.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_fitting_tanh.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Mon May 12 14:19:33 MDT 2014 8 | 9 | Description: Can run this in parallel. 10 | 11 | """ 12 | 13 | import time, ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | # These go to every calculation 18 | base_pars = \ 19 | { 20 | 'problem_type': 101, 21 | 'tanh_model': True, 22 | 'blob_names': [['tau_e', 'z_C', 'z_D'], ['cgm_h_2', 'igm_Tk', 'igm_dTb']], 23 | 'blob_ivars': [None, np.arange(6, 31)], 24 | 'blob_funcs': None, 25 | } 26 | 27 | # Initialize fitter 28 | fitter = ares.inference.FitGlobal21cm(**base_pars) 29 | 30 | fitter.frequencies = np.arange(40, 150) 31 | 32 | # Assume default parameters: will automatically be interpolated onto 33 | # frequencies (defined above) 34 | fitter.noise = 10. # Will add Gaussian random noise 35 | fitter.data = base_pars # Will generate input signal from these pars 36 | 37 | # Set axes of parameter space 38 | fitter.parameters = ['tanh_xz0', 'tanh_xdz', 'tanh_Tz0', 'tanh_Tdz'] 39 | fitter.is_log = [False]*4 40 | 41 | # Set priors on model parameters (uninformative except for tau_e) 42 | ps = ares.inference.PriorSet() 43 | ps.add_prior(ares.inference.Priors.UniformPrior(5., 20.), 'tanh_xz0') 44 | ps.add_prior(ares.inference.Priors.UniformPrior(0.1, 20.), 'tanh_xdz') 45 | ps.add_prior(ares.inference.Priors.UniformPrior(5., 20.), 'tanh_Tz0') 46 | ps.add_prior(ares.inference.Priors.UniformPrior(0.1, 20.), 'tanh_Tdz') 47 | ps.add_prior(ares.inference.Priors.GaussianPrior(0.066, 0.012), 'tau_e') 48 | fitter.prior_set = ps 49 | 50 | # Assumed errors 51 | fitter.error = 10. * np.ones_like(fitter.xdata) 52 | 53 | fitter.nwalkers = 128 54 | 55 | # Run it! 56 | t1 = time.time() 57 | fitter.run(prefix='test_tanh', burn=10, steps=50, clobber=True, 58 | save_freq=10) 59 | t2 = time.time() 60 | 61 | print("Run complete in {:.4g} minutes.\n".format((t2 - t1) / 60.)) 62 | 63 | -------------------------------------------------------------------------------- /examples/fits/test_fitting_tanh_extrema.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_fitting_tanh.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Mon May 12 14:19:33 MDT 2014 8 | 9 | Description: Can run this in parallel. 10 | 11 | """ 12 | 13 | import time, ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | # These go to every calculation 18 | base_pars = \ 19 | { 20 | 'problem_type': 101, 21 | 'tanh_model': True, 22 | 'blob_names': [['tau_e', 'z_B', 'z_C', 'z_D', 'igm_dTb_C', 'igm_dTb_D'], 23 | ['cgm_h_2', 'igm_Tk', 'igm_dTb']], 24 | 'blob_ivars': [None, np.arange(6, 21)], 25 | 'blob_funcs': None, 26 | } 27 | 28 | # Initialize fitter 29 | fitter = ares.inference.FitGlobal21cm(**base_pars) 30 | 31 | fitter.turning_points = list('BCD') 32 | 33 | # Assume default parameters 34 | fitter.data = base_pars 35 | 36 | # Set axes of parameter space 37 | fitter.parameters = ['tanh_xz0', 'tanh_xdz', 'tanh_Tz0', 'tanh_Tdz'] 38 | fitter.is_log = [False]*4 39 | 40 | # Set priors on model parameters (uninformative) 41 | ps = ares.inference.PriorSet() 42 | ps.add_prior(ares.inference.Priors.UniformPrior(5., 20.), 'tanh_xz0') 43 | ps.add_prior(ares.inference.Priors.UniformPrior(0.1, 20.), 'tanh_xdz') 44 | ps.add_prior(ares.inference.Priors.UniformPrior(5., 20.), 'tanh_Tz0') 45 | ps.add_prior(ares.inference.Priors.UniformPrior(0.1, 20.), 'tanh_Tdz') 46 | ps.add_prior(ares.inference.Priors.GaussianPrior(0.066, 0.012), 'tau_e') 47 | fitter.prior_set = ps 48 | 49 | # Set errors 50 | fitter.error = {tp:[1.0, 5.] for tp in list('BCD')} 51 | 52 | fitter.nwalkers = 128 53 | 54 | # Run it! 55 | t1 = time.time() 56 | fitter.run(prefix='test_tanh_extrema', burn=10, steps=50, clobber=True, 57 | save_freq=10) 58 | t2 = time.time() 59 | 60 | print("Run complete in {:.4g} minutes.\n".format((t2 - t1) / 60.)) 61 | 62 | -------------------------------------------------------------------------------- /examples/fits/test_modelgrid.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_modelgrid.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Sun Jun 15 12:59:04 MDT 2014 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares, time 14 | import numpy as np 15 | 16 | # 17 | ## 18 | z0 = np.arange(6, 12, 1.) 19 | dz = np.arange(0.1, 8.1, 1.) 20 | grid_axes = {'tanh_xz0': z0, 'tanh_xdz': dz} 21 | ## 22 | # 23 | 24 | base_pars = \ 25 | { 26 | 'problem_type': 101, 27 | 'tanh_model': True, 28 | 'blob_names': [['tau_e', 'z_C', 'z_D', 'dTb_C', 'dTb_D'], 29 | ['cgm_h_2', 'igm_Tk', 'dTb']], 30 | 'blob_ivars': [None, np.arange(5, 21)], 31 | 'blob_funcs': None, 32 | } 33 | 34 | mg = ares.inference.ModelGrid(**base_pars) 35 | 36 | mg.axes = grid_axes 37 | mg.LoadBalance(0) 38 | 39 | t1 = time.time() 40 | mg.run('test_grid', clobber=True, save_freq=10) 41 | t2 = time.time() 42 | 43 | print("Run complete in {:.4g} minutes.\n".format((t2 - t1) / 60.)) 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /examples/gs/test_cxrb.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_21cm_cxrb.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Mon Nov 11 13:02:00 MST 2013 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import matplotlib.pyplot as pl 15 | 16 | pars1 = \ 17 | { 18 | 'pop_solve_rte{1}': True, 19 | 'pop_tau_Nz{1}': 400, 20 | 'pop_approx_tau{1}': True, 21 | 'problem_type': 101.2, 22 | } 23 | 24 | pars2 = pars1.copy() 25 | pars2['pop_approx_tau{1}'] = 'neutral' 26 | 27 | ax = None 28 | 29 | # Examine effects of realistic CXRB (limits of neutral medium and optically thin) 30 | for p in [pars1, pars2, {'problem_type': 101}]: 31 | sim = ares.simulations.Global21cm(**p) 32 | sim.run() 33 | 34 | ax = sim.GlobalSignature(ax=ax) 35 | 36 | pl.show() 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /examples/lit/test_atek2015.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_atek2015.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Fri Nov 6 13:33:37 PST 2015 8 | 9 | Description: Compare to their Figure 8. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | # Remember: they are stored as the log10! 18 | atek15 = ares.util.read_lit('atek2015') 19 | 20 | for z in atek15.redshifts: 21 | data = atek15.data['lf'][z] 22 | 23 | pl.errorbar(data['M'], np.array(data['phi']), yerr=data['err'], 24 | fmt='o', label=r'$z={:.2g}$ (Atek)'.format(z)) 25 | 26 | pl.xlabel(r'$M_{\mathrm{UV}}$') 27 | pl.ylabel(r'$\log_{10} \phi \ (\mathrm{cMpc}^{-3} \ \mathrm{mag}^{-1})$') 28 | -------------------------------------------------------------------------------- /examples/lit/test_bouwens2015.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_bouwens2015.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Fri Nov 6 13:33:37 PST 2015 8 | 9 | Description: Compare to their Figure 8. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | b15 = ares.util.read_lit('bouwens2015') 18 | 19 | for z in b15.redshifts: 20 | data = b15.data['lf'][z] 21 | 22 | pl.errorbar(data['M'], data['phi'], yerr=data['err'], 23 | fmt='o', label=r'$z={:.2g}$'.format(z)) 24 | 25 | -------------------------------------------------------------------------------- /examples/lit/test_eldridge2009.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_eldridge2009.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Mon Apr 11 11:25:01 PDT 2016 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | # Stellar SED at 1,50 Myr 18 | fig1 = pl.figure(1); ax1 = fig1.add_subplot(111) 19 | 20 | ls = ['-', '--'] 21 | colors = ['k', 'g'] 22 | for i, binaries in enumerate([False, True]): 23 | 24 | pop = ares.populations.SynthesisModel(pop_sed='eldridge2009', 25 | pop_binaries=binaries) 26 | 27 | if binaries: 28 | bin = 'binary' 29 | else: 30 | bin = 'single' 31 | 32 | for j, t in enumerate([1, 50]): 33 | 34 | k = np.argmin(np.abs(pop.times - t)) 35 | 36 | ax1.loglog(pop.wavelengths, pop.data[:,k], color=colors[j], 37 | label=r'$t={0}$ Myr, {1!s}'.format(pop.times[k], bin), ls=ls[i]) 38 | 39 | ax1.set_xlabel(ares.util.labels['lambda_AA']) 40 | ax1.set_ylabel(ares.util.labels['intensity_AA']) 41 | ax1.legend(loc='lower left', fontsize=14) 42 | ax1.set_ylim(1e35, 1e42) 43 | pl.draw() 44 | 45 | # Compare to Leitherer et al. at t=10 Myr 46 | fig2 = pl.figure(2); ax2 = fig2.add_subplot(111) 47 | 48 | for j, model in enumerate(['eldridge2009', 'leitherer1999']): 49 | pop = ares.populations.SynthesisModel(pop_sed=model, 50 | pop_binaries=False) 51 | 52 | k = np.argmin(np.abs(pop.times - 10.)) 53 | ax2.loglog(pop.wavelengths, pop.data[:,k], color=colors[j], 54 | label=model) 55 | 56 | ax2.set_xlabel(ares.util.labels['lambda_AA']) 57 | ax2.set_ylabel(ares.util.labels['intensity_AA']) 58 | ax2.legend(loc='upper right', fontsize=14) 59 | ax2.set_ylim(1e35, 1e42) 60 | pl.draw() 61 | -------------------------------------------------------------------------------- /examples/lit/test_haardt2012.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_haardt2012.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Sun Jun 21 14:14:45 MDT 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | hm12 = ares.util.read_lit('haardt2012') 18 | 19 | z, E, flux = hm12.MetaGalacticBackground() 20 | 21 | for redshift in [0, 3, 4, 5]: 22 | i = np.argmin(np.abs(redshift - z)) 23 | pl.loglog(E, flux[i], label=r'$z={:.3g}$'.format(z[i])) 24 | 25 | pl.xlim(1e-1, 1e5) 26 | pl.ylim(1e-28, 1e-18) 27 | pl.xlabel(ares.util.labels['E']) 28 | pl.ylabel(ares.util.labels['flux_E']) 29 | pl.legend(loc='upper right', fontsize=14) 30 | -------------------------------------------------------------------------------- /examples/lit/test_kroupa2001.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_kroupa2001.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Thu Jun 11 14:05:10 MDT 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | k01 = ares.util.read_lit('kroupa2001') 18 | imf = k01.InitialMassFunction() 19 | 20 | m = np.logspace(-2, 2) 21 | 22 | pl.loglog(m, list(map(imf, m))) 23 | 24 | -------------------------------------------------------------------------------- /examples/lit/test_lf.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_lf.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Thu Jan 28 12:37:32 PST 2016 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | 15 | lf = ares.analysis.ObservedLF() 16 | 17 | ax = lf.Plot(6.9, sources=['bouwens2015', 'atek2015'], round_z=0.1) 18 | 19 | mp = lf.MultiPlot([3.8, 4.9, 5.9, 6.9, 7.9, 9.0], ncols=3, round_z=0.3, fig=2) 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/lit/test_sazonov2004.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sazonov2004.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Wed Jun 10 17:37:50 MDT 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | s04 = ares.util.read_lit('sazonov2004') 18 | 19 | E = np.logspace(0., 6., 100) 20 | F = list(map(s04.Spectrum, E)) 21 | 22 | pl.loglog(E, F) 23 | pl.xlabel(ares.util.labels['E']) 24 | pl.ylabel('Relative intensity') 25 | -------------------------------------------------------------------------------- /examples/rt06/test_rt06_03.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_rt06_03.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Fri Jan 18 09:35:35 2013 8 | 9 | Description: Single zone ionization/recombination + heating/cooling test. 10 | 11 | """ 12 | 13 | import ares 14 | from ares.analysis.MultiPlot import MultiPanel 15 | 16 | sim = ares.simulations.RaySegment(problem_type=0, optically_thin=1, 17 | secondary_ionization=0) 18 | sim.run() 19 | 20 | anl = ares.analysis.RaySegment(sim.checkpoints) 21 | 22 | t, xHI = anl.CellEvolution(field='h_1') 23 | t, T = anl.CellEvolution(field='Tk') 24 | 25 | mp = MultiPanel(dims=(2, 1), panel_size=(1, 0.5)) 26 | 27 | s_per_yr = ares.physics.Constants.s_per_yr 28 | mp.grid[0].loglog(t / s_per_yr, xHI, color = 'k') 29 | mp.grid[1].loglog(t / s_per_yr, T, color = 'k') 30 | 31 | mp.grid[0].set_xlim(1e-6, 1e7) 32 | mp.grid[1].set_xlim(1e-6, 1e7) 33 | mp.grid[0].set_ylim(1e-8, 1.5) 34 | mp.grid[1].set_ylim(1e2, 1e5) 35 | 36 | mp.grid[0].set_ylabel(r'$x_{\mathrm{HI}}$') 37 | mp.grid[1].set_ylabel(r'$T \ (\mathrm{K})$') 38 | mp.grid[0].set_xlabel(r'$t \ (\mathrm{yr})$') 39 | 40 | for ax in mp.grid: 41 | ax.loglog([sim.pf['source_lifetime'] * 1e6]*2, ax.get_ylim(), 42 | color='k', ls=':') 43 | 44 | ax.annotate('source OFF', (sim.pf['source_lifetime'] * 1e6, 2e2), ha='right', 45 | va='bottom', rotation=90) 46 | 47 | mp.fix_ticks() 48 | 49 | -------------------------------------------------------------------------------- /examples/rt06/test_rt06_1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_rt06_1.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Wed Dec 26 18:37:48 2012 8 | 9 | Description: This is Test problem #1 from the Radiative Transfer 10 | Comparison Project (Iliev et al. 2006; RT06). 11 | 12 | """ 13 | 14 | import ares 15 | 16 | sim = ares.simulations.RaySegment(problem_type=1) 17 | sim.run() 18 | 19 | anl = ares.analysis.RaySegment(sim) 20 | 21 | ax1 = anl.PlotIonizationFrontEvolution() 22 | 23 | ax2 = anl.RadialProfile('h_1', t=[10, 100, 500], fig=2) 24 | ax2 = anl.RadialProfile('h_2', t=[10, 100, 500], ax=ax2, ls='--') 25 | -------------------------------------------------------------------------------- /examples/rt06/test_rt06_2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_rt06_2.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Wed Dec 26 18:37:48 2012 8 | 9 | Description: This is Test problem #2 from the Radiative Transfer 10 | Comparison Project (Iliev et al. 2006; RT06). 11 | 12 | """ 13 | 14 | import ares 15 | 16 | sim = ares.simulations.RaySegment(problem_type=2) 17 | sim.run() 18 | 19 | anl = ares.analysis.RaySegment(sim) 20 | 21 | ax2 = anl.RadialProfile('Tk', t=[10, 30, 100]) 22 | 23 | ax2 = anl.RadialProfile('h_1', t=[10, 30, 100], fig=2) 24 | ax2 = anl.RadialProfile('h_2', t=[10, 30, 100], ax=ax2, ls='--') 25 | 26 | -------------------------------------------------------------------------------- /examples/rt06/test_rt06_2_m12.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_rt06_2.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Wed Dec 26 18:37:48 2012 8 | 9 | Description: This is Test problem #2 from the Radiative Transfer 10 | Comparison Project (Iliev et al. 2006; RT06), run using three different 11 | solution methods. 12 | 13 | """ 14 | 15 | import ares 16 | import matplotlib.pyplot as pl 17 | 18 | ax1 = None 19 | ax2 = None 20 | c = ['k', 'b','r'] 21 | for i, ptype in enumerate([2, 2.1, 2.2]): 22 | sim = ares.simulations.RaySegment(problem_type=ptype) 23 | sim.run() 24 | 25 | anl = ares.analysis.RaySegment(sim) 26 | 27 | ax1 = anl.RadialProfile('Tk', t=[10, 30, 100], ax=ax1, color=c[i]) 28 | 29 | ax2 = anl.RadialProfile('h_1', t=[10, 30, 100], ax=ax2, fig=2, color=c[i]) 30 | ax2 = anl.RadialProfile('h_2', t=[10, 30, 100], ax=ax2, ls='--', color=c[i]) 31 | 32 | pl.draw() 33 | -------------------------------------------------------------------------------- /examples/rt06/test_rt06_2_w_he.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_rt06_2.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Wed Dec 26 18:37:48 2012 8 | 9 | Description: This is Test problem #2 from the Radiative Transfer 10 | Comparison Project (Iliev et al. 2006; RT06). 11 | 12 | """ 13 | 14 | import ares 15 | 16 | sim = ares.simulations.RaySegment(problem_type=12, tables_dlogN=[0.1]*3, 17 | tables_discrete_gen=True, tables_energy_bins=250, epsilon_dt=0.05, 18 | initial_timestep=1e-6) 19 | #sim.save_tables('bb_He_0.1_250') 20 | sim.run() 21 | 22 | anl = ares.analysis.RaySegment(sim) 23 | 24 | ax1 = anl.RadialProfile('Tk', t=[10, 30, 100]) 25 | 26 | ax2 = anl.RadialProfile('h_1', t=[10, 30, 100], fig=2) 27 | anl.RadialProfile('h_2', t=[10, 30, 100], ax=ax2, ls='--') 28 | 29 | ax3 = anl.RadialProfile('he_1', t=[10, 30, 100], fig=3) 30 | anl.RadialProfile('he_2', t=[10, 30, 100], ax=ax3, ls='--') 31 | anl.RadialProfile('he_3', t=[10, 30, 100], ax=ax3, ls=':') 32 | 33 | 34 | -------------------------------------------------------------------------------- /examples/rt06/test_rt06_2_w_he_adv_e.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_rt06_2.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Wed Dec 26 18:37:48 2012 8 | 9 | Description: This is Test problem #2 from the Radiative Transfer 10 | Comparison Project (Iliev et al. 2006; RT06). 11 | 12 | """ 13 | 14 | import ares 15 | 16 | pars = \ 17 | { 18 | 'problem_type': 12, 19 | 'tables_dlogN': [0.2]*3, 20 | 'tables_discrete_gen': True, 21 | 'secondary_ionization': 3, 22 | } 23 | 24 | sim = ares.simulations.RaySegment(**pars) 25 | 26 | sim.run() 27 | 28 | anl = ares.analysis.RaySegment(sim) 29 | 30 | ax1 = anl.RadialProfile('Tk', t=[10, 30, 100]) 31 | 32 | ax2 = anl.RadialProfile('h_1', t=[10, 30, 100], fig=2) 33 | anl.RadialProfile('h_2', t=[10, 30, 100], ax=ax2, ls='--') 34 | 35 | ax3 = anl.RadialProfile('he_1', t=[10, 30, 100], fig=3) 36 | anl.RadialProfile('he_2', t=[10, 30, 100], ax=ax2, ls='--') 37 | anl.RadialProfile('he_3', t=[10, 30, 100], ax=ax2, ls=':') -------------------------------------------------------------------------------- /examples/rt06/test_rt06_3.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_slab.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Sun May 10 13:51:54 MDT 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import matplotlib.pyplot as pl 15 | 16 | sim = ares.simulations.RaySegment(problem_type=3, initial_timestep=1e-6) 17 | sim.run() 18 | 19 | anl = ares.analysis.RaySegment(sim) 20 | 21 | ax1 = anl.RadialProfile('Tk', t=[0], color='k') 22 | anl.RadialProfile('Tk', t=[1,3,5,15], ax=ax1, color='b', ls='--', lw=4) 23 | ax1.set_yscale('log') 24 | 25 | ax2 = anl.RadialProfile('h_1', t=[0], fig=2, color='k') 26 | anl.RadialProfile('h_1', t=[1,3,5,15], color='b', ax=ax2, ls='--', lw=4) 27 | ax2.set_yscale('log') 28 | 29 | pl.draw() 30 | -------------------------------------------------------------------------------- /examples/sources/test_sed_agn.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sed_agn.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Thu May 2 10:46:44 2013 8 | 9 | Description: Plot Sazonov et al. (2004) AGN template SED. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | pars = \ 18 | { 19 | 'source_type': 'bh', 20 | 'source_sed': 'sazonov2004', 21 | 'source_Emin': 1, 22 | 'source_Emax': 3e4, 23 | } 24 | 25 | src = ares.sources.BlackHole(init_tabs=False, **pars) 26 | bh = ares.analysis.Source(src) 27 | 28 | ax = bh.PlotSpectrum() 29 | 30 | ax.set_ylim(1e-6, 1e-3) 31 | pl.draw() 32 | 33 | -------------------------------------------------------------------------------- /examples/sources/test_sed_apl.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sed_apl.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Thu May 2 10:46:44 2013 8 | 9 | Description: Plot an absorbed power-law spectrum. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | pars = \ 18 | { 19 | 'source_type': 'bh', 20 | 'source_sed': 'pl', 21 | 'source_Emin': 2e2, 22 | 'source_Emax': 3e4, 23 | 'source_EminNorm': 5e2, 24 | 'source_EmaxNorm': 8e3, 25 | } 26 | 27 | colors = 'k', 'b', 'g' 28 | ls = ['-.', ':', '--', '-', '-.'] 29 | for i, alpha in enumerate([-0.5, -1.5, -2.5]): 30 | for j, logN in enumerate([-np.inf, 20, 21, 22, 23]): 31 | pars.update({'source_alpha': alpha, 'source_logN': logN}) 32 | 33 | src = ares.sources.BlackHole(init_tabs=False, **pars) 34 | bh = ares.analysis.Source(src) 35 | 36 | if j == 2: 37 | label = r'$\alpha = {:.2g}$'.format(alpha) 38 | else: 39 | label = None 40 | 41 | ax = bh.PlotSpectrum(color=colors[i], ls=ls[j], label=label) 42 | 43 | ax.fill_between([5e2, 8e3], 1e-8, 1, alpha=0.3, color='r') 44 | ax.legend(loc='upper right', fontsize=14) 45 | ax.set_ylim(1e-8, 1) 46 | pl.draw() 47 | 48 | 49 | -------------------------------------------------------------------------------- /examples/sources/test_sed_bb.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sed_mcd.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Thu May 2 10:46:44 2013 8 | 9 | Description: Plot a simple multi-color disk accretion spectrum. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | pars = \ 18 | { 19 | 'source_temperature': 1e4, 20 | 'source_Emin': 1., 21 | 'source_Emax': 1e2, 22 | 'source_qdot': 1e50, 23 | } 24 | 25 | ls = [':', '--', '-'] 26 | for i, logT in enumerate([4, 4.5, 5]): 27 | pars.update({'source_temperature': 10**logT}) 28 | 29 | src = ares.sources.Star(init_tabs=False, **pars) 30 | bh = ares.analysis.Source(src) 31 | 32 | ax = bh.PlotSpectrum(ls=ls[i], 33 | label=r'$T_{{\ast}} = 10^{{{:.2g}}} \mathrm{{K}}$'.format(logT)) 34 | 35 | ax.plot([10.2]*2, [1e-8, 1], color='r', ls='--') 36 | ax.plot([13.6]*2, [1e-8, 1], color='r', ls='--') 37 | 38 | ax.legend(loc='lower left') 39 | ax.set_ylim(1e-8, 1) 40 | pl.draw() 41 | 42 | 43 | -------------------------------------------------------------------------------- /examples/sources/test_sed_mcd.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sed_mcd.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Thu May 2 10:46:44 2013 8 | 9 | Description: Plot a simple multi-color disk accretion spectrum. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | bh_pars = \ 18 | { 19 | 'source_type': 'bh', 20 | 'source_mass': 10., 21 | 'source_rmax': 1e3, 22 | 'source_sed': 'mcd', 23 | 'source_Emin': 10., 24 | 'source_Emax': 1e4, 25 | 'source_logN': 18., 26 | } 27 | 28 | src = ares.sources.BlackHole(init_tabs=False, **bh_pars) 29 | bh = ares.analysis.Source(src) 30 | 31 | ax = bh.PlotSpectrum() 32 | pl.draw() 33 | 34 | 35 | -------------------------------------------------------------------------------- /examples/sources/test_sed_parameterized.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sed_parameterized.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Wed Oct 2 16:57:01 MDT 2013 8 | 9 | Description: See if passing spectrum_function parameter works. 10 | 11 | """ 12 | 13 | import ares 14 | import matplotlib.pyplot as pl 15 | 16 | BBfunc = rt1d.sources.Star._Planck 17 | 18 | # First, use StellarSource class 19 | sim = rt1d.run.Simulation(problem_type=2, stop_time=30) 20 | sim.run() 21 | 22 | # Now, use ParameterizedSource class 23 | sim2 = rt1d.run.Simulation(problem_type=2, source_type='parameterized', 24 | spectrum_function=lambda E: BBfunc(E, 1e5), stop_time=30, 25 | source_Lbol=sim.rs.src[0].Lbol) 26 | sim2.run() 27 | 28 | anl1 = rt1d.analyze.Simulation(sim.checkpoints) 29 | anl2 = rt1d.analyze.Simulation(sim2.checkpoints) 30 | 31 | ax = anl1.TemperatureProfile(t=[10, 30]) 32 | anl2.TemperatureProfile(t=[10, 30], ax=ax, marker='o', color='b') 33 | -------------------------------------------------------------------------------- /examples/sources/test_sed_pl.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sed_mcd.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Thu May 2 10:46:44 2013 8 | 9 | Description: Plot a simple power-law spectrum. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | pars = \ 18 | { 19 | 'source_type': 'bh', 20 | 'source_sed': 'pl', 21 | 'source_Emin': 2e2, 22 | 'source_Emax': 3e4, 23 | } 24 | 25 | ls = [':', '--', '-'] 26 | for i, alpha in enumerate([-0.5, -1.5, -2.5]): 27 | pars.update({'source_alpha': alpha}) 28 | 29 | src = ares.sources.BlackHole(init_tabs=False, **pars) 30 | bh = ares.analysis.Source(src) 31 | 32 | ax = bh.PlotSpectrum(ls=ls[i], 33 | label=r'$\alpha = {:.2g}$'.format(alpha)) 34 | 35 | ax.legend(loc='upper right') 36 | ax.set_ylim(1e-8, 1) 37 | pl.draw() 38 | 39 | 40 | -------------------------------------------------------------------------------- /examples/sources/test_sed_simpl.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sed_mcd.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Thu May 2 10:46:44 2013 8 | 9 | Description: Plot a simple multi-color disk accretion spectrum. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | rmax = 1e2 18 | mass = 10. 19 | f_scatter = [0.1, 0.5] 20 | gamma = [-2.5] 21 | Emin = 10. 22 | 23 | simpl = \ 24 | { 25 | 'source_type': 'bh', 26 | 'source_mass': mass, 27 | 'source_rmax': rmax, 28 | 'source_sed': 'simpl', 29 | 'source_Emin': Emin, 30 | 'source_Emax': 5e4, 31 | 'source_EminNorm': 500., 32 | 'source_EmaxNorm': 8e3, 33 | 'source_alpha': -0.5, 34 | 'source_fsc': 1.0, 35 | 'source_logN': 22., 36 | } 37 | 38 | mcd = \ 39 | { 40 | 'source_type': 'bh', 41 | 'source_sed': 'mcd', 42 | 'source_mass': mass, 43 | 'source_rmax': rmax, 44 | 'source_Emin': Emin, 45 | 'source_Emax': 5e4, 46 | 'source_EminNorm': 500., 47 | 'source_EmaxNorm': 8e3, 48 | } 49 | 50 | bh_mcd = ares.sources.BlackHole(init_tabs=False, **mcd) 51 | bh1 = ares.analysis.Source(bh_mcd) 52 | ax = bh1.PlotSpectrum(color='k') 53 | 54 | ls = ['-', '--', ':'] 55 | colors = ['b', 'g', 'r', 'm'] 56 | for i, fsc in enumerate(f_scatter): 57 | simpl.update({'source_fsc': fsc}) 58 | for j, alpha in enumerate(gamma): 59 | simpl.update({'source_alpha': alpha}) 60 | 61 | bh_simpl = ares.sources.BlackHole(init_tabs=False, **simpl) 62 | bh2 = ares.analysis.Source(bh_simpl) 63 | 64 | if j == 0: 65 | label = r'$f_{{\mathrm{{sc}}}} = {:g}$'.format(fsc) 66 | else: 67 | label = None 68 | 69 | ax = bh2.PlotSpectrum(color=colors[i], ls=ls[j], label=label) 70 | pl.draw() 71 | 72 | ax.legend(loc='lower left') 73 | ax.set_ylim(1e-8, 1e-3) 74 | ax.set_xlim(1e2, 6e4) 75 | ax.fill_betweenx([1e-8, 1e-3], 5e2, 8e3, alpha=0.5, color='gray') 76 | pl.draw() 77 | 78 | -------------------------------------------------------------------------------- /examples/sources/test_src_bh.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sed_mcd.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Thu May 2 10:46:44 2013 8 | 9 | Description: Plot a simple multi-color disk accretion spectrum. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | pars = \ 18 | { 19 | 'source_Emin': 10., 20 | 'source_Emax': 1e4, 21 | 'source_sed': 'mcd', 22 | 'source_mass': 10, 23 | } 24 | 25 | ls = [':', '--', '-'] 26 | for i, logM in enumerate([0, 1, 2]): 27 | pars.update({'source_mass': 10**logM}) 28 | 29 | src = ares.sources.BlackHole(init_tabs=False, **pars) 30 | bh = ares.analysis.Source(src) 31 | 32 | ax = bh.PlotSpectrum(ls=ls[i], 33 | label=r'$M_{\bullet} = {} \ M_{\odot}$'.format(int(10**logM))) 34 | 35 | ax.plot([10.2]*2, [1e-8, 1], color='r', ls='--') 36 | ax.plot([13.6]*2, [1e-8, 1], color='r', ls='--') 37 | 38 | ax.legend(loc='lower left') 39 | ax.set_ylim(1e-8, 1e-3) 40 | pl.draw() 41 | 42 | 43 | -------------------------------------------------------------------------------- /examples/sources/test_src_star.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sed_mcd.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Thu May 2 10:46:44 2013 8 | 9 | Description: Plot a simple multi-color disk accretion spectrum. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | pars = \ 18 | { 19 | 'source_temperature': 1e4, 20 | 'source_Emin': 1., 21 | 'source_Emax': 1e2, 22 | 'source_qdot': 1e50, 23 | } 24 | 25 | ls = [':', '--', '-'] 26 | for i, logT in enumerate([4, 4.5, 5]): 27 | pars.update({'source_temperature': 10**logT}) 28 | 29 | src = ares.sources.Star(init_tabs=False, **pars) 30 | bh = ares.analysis.Source(src) 31 | 32 | ax = bh.PlotSpectrum(ls=ls[i], 33 | label=r'$T_{{\ast}} = 10^{{{.2g}}} \mathrm{{K}}$'.format(logT)) 34 | 35 | ax.plot([10.2]*2, [1e-8, 1], color='r', ls='--') 36 | ax.plot([13.6]*2, [1e-8, 1], color='r', ls='--') 37 | 38 | ax.legend(loc='lower left') 39 | ax.set_ylim(1e-8, 1) 40 | pl.draw() 41 | 42 | 43 | -------------------------------------------------------------------------------- /input/bhseds/generate_simpl_seds.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | generate_simpl_seds.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Thu May 11 10:03:29 CDT 2017 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import os 14 | import ares 15 | import time 16 | import numpy as np 17 | from mpi4py import MPI 18 | 19 | rank = MPI.COMM_WORLD.rank 20 | size = MPI.COMM_WORLD.size 21 | 22 | # 23 | ## INPUT 24 | mass = 10. 25 | E = 10**np.arange(1, 5.1, 0.1) 26 | ## 27 | # 28 | 29 | simpl = \ 30 | { 31 | 'source_type': 'bh', 32 | 'source_mass': mass, 33 | 'source_rmax': 1e2, 34 | 'source_sed': 'simpl', 35 | 'source_Emin': 1, 36 | 'source_Emax': 5e4, 37 | 'source_EminNorm': 500., 38 | 'source_EmaxNorm': 8e3, 39 | 'source_alpha': -1.5, 40 | 'source_fsc': 0.1, 41 | 'source_dlogE': 0.025, 42 | } 43 | 44 | for i, alpha in enumerate([-2.5, -2, -1.5, -1, -0.5, -0.25]): 45 | for j, fsc in enumerate([0.1, 0.5, 0.9]): 46 | 47 | k = i * 3 + j 48 | 49 | if k % size != rank: 50 | continue 51 | 52 | fn = 'simpl_M_{0}_fsc_{1:.2f}_alpha_{2:.2f}.txt'.format(mass, fsc, alpha) 53 | 54 | if os.path.exists(fn): 55 | print("{!s} already exists.".format(fn)) 56 | continue 57 | 58 | simpl['source_alpha'] = alpha 59 | simpl['source_fsc'] = fsc 60 | 61 | src = ares.sources.BlackHole(**simpl) 62 | src.dump(fn, E) 63 | 64 | -------------------------------------------------------------------------------- /input/bhseds/plot_seds.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | plot_seds.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Thu May 11 13:30:52 CDT 2017 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | mass = 10 18 | 19 | ls = [':', '--', '-'] 20 | colors = ['m', 'c', 'b', 'g', 'k'] 21 | 22 | for i, alpha in enumerate([-1.5, -1, -0.5]): 23 | for j, fsc in enumerate([0.1, 0.5, 0.9]): 24 | 25 | k = i * 3 + j 26 | 27 | fn = 'simpl_M_{0}_fsc_{1:.2f}_alpha_{2:.2f}.txt'.format(mass, fsc, alpha) 28 | 29 | x, y = np.loadtxt(fn, unpack=True) 30 | 31 | pl.loglog(x, y, color=colors[i], ls=ls[j]) 32 | 33 | # A pure MCD 34 | mcd = ares.sources.BlackHole(source_sed='mcd', source_mass=10, 35 | source_Emin=1, source_Emax=5e4, source_EminNorm=500, source_EmaxNorm=8e3) 36 | pl.loglog(x, list(map(mcd.Spectrum, x)), color='k', lw=3) 37 | 38 | # A few power-laws 39 | for logNHI in [20, 21, 22]: 40 | src = ares.sources.BlackHole(source_sed='pl', source_mass=10, 41 | source_Emin=1, source_Emax=5e4, source_EminNorm=500, source_EmaxNorm=8e3, 42 | source_alpha=-1.5, source_logN=logNHI) 43 | 44 | pl.loglog(x, list(map(src.Spectrum, x)), color='k', ls='--', lw=3) 45 | 46 | pl.xlim(1e2, 3e4) 47 | pl.ylim(1e-6, 5e-3) 48 | pl.xlabel(r'$h\nu / \mathrm{eV}$') 49 | pl.ylabel(r'$I_{\nu}$') 50 | pl.savefig('mcd_vs_simpl.png') 51 | 52 | -------------------------------------------------------------------------------- /input/bpass_v1/degrade_bpass_seds.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | degrade_bpass_seds.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill 7 | Created on: Fri 12 Apr 2019 15:51:48 EDT 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import os 14 | import sys 15 | import numpy as np 16 | import matplotlib.pyplot as pl 17 | from ares.util.Math import smooth 18 | 19 | try: 20 | degrade_to = int(sys.argv[1]) 21 | except IndexError: 22 | degrade_to = 10 23 | 24 | try: 25 | single_fn = sys.argv[2] 26 | except IndexError: 27 | single_fn = None 28 | 29 | for fn in os.listdir('SEDS'): 30 | 31 | if single_fn is not None: 32 | if fn != single_fn.replace('SEDS/', ''): 33 | continue 34 | 35 | if fn.split('.')[-1].startswith('deg'): 36 | continue 37 | 38 | if 'readme' in fn: 39 | continue 40 | 41 | full_fn = 'SEDS/{}'.format(fn) 42 | out_fn = full_fn+'.deg{}'.format(degrade_to) 43 | 44 | if os.path.exists(out_fn): 45 | print("File {} exists! Moving on...".format(out_fn)) 46 | continue 47 | 48 | print("Loading {}...".format(full_fn)) 49 | data = np.loadtxt(full_fn) 50 | wave = data[:,0] 51 | 52 | ok = wave % degrade_to == 0 53 | new_dims = data.shape[0] // degrade_to 54 | 55 | if new_dims == ok.sum() - 1: 56 | new_dims += 1 57 | 58 | new_wave = wave[ok==1] 59 | new_data = np.zeros((new_dims, data.shape[1])) 60 | new_data[:,0] = new_wave 61 | 62 | for i in range(data.shape[1]): 63 | if i == 0: 64 | continue 65 | 66 | ys = smooth(data[:,i], degrade_to+1)[ok==1] 67 | 68 | new_data[:,i] = ys 69 | 70 | np.savetxt(out_fn, new_data) 71 | print("Wrote {}".format(out_fn)) 72 | 73 | del data, wave 74 | 75 | 76 | -------------------------------------------------------------------------------- /input/bpass_v1/pack_bpass.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | me=$(whoami) 4 | degrade=100 5 | 6 | echo '' 7 | echo '################################ HMF ################################' 8 | 9 | if [ $me = 'jordanmirocha' ] 10 | then 11 | echo \# Hey, J.M., right this way. 12 | else 13 | printf '# Are you sure you want to proceed [yes/no]: ' 14 | read -r areyousure 15 | 16 | if [ $areyousure = 'yes' ] 17 | then 18 | echo \# OK, hope you know what you are doing. 19 | else 20 | exit 1 21 | fi 22 | fi 23 | 24 | echo \# Generating BPASS tables at $degrade x lower resolution. 25 | 26 | python degrade_bpass_seds.py $degrade 27 | 28 | tar -czvf sed_degraded.tar.gz \ 29 | SEDS/sed.bpass.constant.nocont.sin.z020.deg$degrade \ 30 | SEDS/sed.bpass.instant.nocont.sin.z020.deg$degrade \ 31 | SEDS/sed.bpass.constant.cloudy.sin.z020.deg$degrade 32 | 33 | echo Created tarball sed_degraded.tar.gz. 34 | 35 | # Copy to dropbox 36 | FILE=$DROPBOX/ares 37 | if [ -d "$FILE" ] 38 | then 39 | : 40 | else 41 | mkdir $FILE 42 | echo "Created $FILE." 43 | fi 44 | 45 | if [ -d "$FILE/input" ] 46 | then 47 | : 48 | else 49 | mkdir $FILE/input 50 | echo "Created $FILE/input." 51 | fi 52 | 53 | if [ -d "$FILE/input/bpass_v1" ] 54 | then 55 | : 56 | else 57 | mkdir $FILE/input/bpass_v1 58 | echo "Created $FILE/input/bpass_v1." 59 | fi 60 | 61 | cp sed_degraded.tar.gz $FILE/input/bpass_v1/ 62 | echo Copied sed_degraded.tar.gz to $FILE/input/bpass_v1/ 63 | 64 | echo '#####################################################################' 65 | echo '' -------------------------------------------------------------------------------- /input/hmf/generate_hmf_tables.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | generate_hmf_tables.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Wed May 8 11:33:48 2013 8 | 9 | Description: Create lookup tables for collapsed fraction. Can be run in 10 | parallel, e.g., 11 | 12 | mpirun -np 4 python generate_hmf_tables.py 13 | 14 | """ 15 | 16 | import sys 17 | import ares 18 | 19 | def_kwargs = \ 20 | { 21 | "hmf_model": 'PS', 22 | "hmf_logMmin": 4, 23 | "hmf_logMmax": 18, 24 | "hmf_dlogM": 0.01, 25 | 26 | "hmf_fmt": 'hdf5', 27 | "hmf_table": None, 28 | "hmf_wdm_mass": None, 29 | 30 | #"hmf_window": 'sharpk', 31 | 32 | # Redshift sampling 33 | "hmf_zmin": 0., 34 | "hmf_zmax": 60., 35 | "hmf_dz": 0.05, 36 | 37 | # Can do constant timestep instead of constant dz 38 | #"hmf_dt": 1, 39 | #"hmf_tmin": 30., 40 | #"hmf_tmax": 1000., 41 | 42 | # Cosmology 43 | "cosmology_id": 'best', 44 | "cosmology_name": 'planck_TTTEEE_lowl_lowE', 45 | 46 | #HMF params and filter params are for doing Aurel Schneider's 2015 paper WDM. 47 | #"hmf_params" : {'a' : 1.0}, 48 | #"filter_params" : {'c' : 2.5} 49 | 50 | #"cosmology_id": 'paul', 51 | #"cosmology_name": 'user', 52 | #"sigma_8": 0.8159, 53 | #'primordial_index': 0.9652, 54 | #'omega_m_0': 0.315579, 55 | #'omega_b_0': 0.0491, 56 | #'hubble_0': 0.6726, 57 | #'omega_l_0': 1. - 0.315579, 58 | 59 | } 60 | 61 | ## 62 | 63 | kwargs = def_kwargs.copy() 64 | kwargs.update(ares.util.get_cmd_line_kwargs(sys.argv)) 65 | 66 | hmf = ares.physics.HaloMassFunction(hmf_analytic=False, 67 | hmf_load=False, **kwargs) 68 | 69 | hmf.info 70 | 71 | try: 72 | hmf.SaveHMF(fmt=kwargs['hmf_fmt'], clobber=False) 73 | except IOError as err: 74 | print(err) 75 | -------------------------------------------------------------------------------- /input/hmf/generate_ps_tables.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | generate_hmf_tables.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Wed May 8 11:33:48 2013 8 | 9 | Description: Create lookup tables for collapsed fraction. Can be run in 10 | parallel, e.g., 11 | 12 | mpirun -np 4 python generate_hmf_tables.py 13 | 14 | """ 15 | 16 | import ares 17 | import numpy as np 18 | 19 | ## INPUT 20 | fit = 'ST' 21 | fmt = 'hdf5' 22 | ## 23 | 24 | pars = \ 25 | { 26 | "hmf_model": fit, 27 | # Should add halo concentration model here. 28 | "hmf_dlogM": 0.01, 29 | "hmf_logMmin": 4, 30 | "hmf_logMmax": 18, 31 | "hmf_zmin": 5, 32 | "hmf_zmax": 30, 33 | "hmf_dz": 0.05, 34 | 35 | "hps_zmin": 6, 36 | "hps_zmax": 30, 37 | "hps_dz": 0.5, 38 | 39 | 'hps_dlnk': 0.001, 40 | 'hps_dlnR': 0.001, 41 | 'hps_lnk_min': -10., 42 | 'hps_lnk_max': 10., 43 | 'hps_lnR_min': -10., 44 | 'hps_lnR_max': 10., 45 | } 46 | 47 | kwargs = \ 48 | { 49 | 'split_by_scale': True, 50 | 'epsrel': 1e-8, 51 | 'epsabs': 1e-8, 52 | } 53 | 54 | ## 55 | 56 | hmf = ares.physics.HaloModel(hmf_load=True, hmf_load_ps=False, 57 | **pars) 58 | 59 | hmf.SavePS(format=fmt, clobber=False, checkpoint=True, **kwargs) 60 | -------------------------------------------------------------------------------- /input/hmf/test_fcoll.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_hmf.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Thu Jul 7 15:29:10 PDT 2016 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | from scipy.integrate import simps 17 | 18 | pop = ares.populations.HaloPopulation(pop_sfr_model='fcoll', pop_Mmin=1e8, 19 | hmf_interp='linear') 20 | 21 | zarr = np.arange(10, 50, 0.1) 22 | 23 | pl.semilogy(zarr, pop.fcoll(zarr), color='k', lw=3, alpha=0.5) 24 | 25 | new_fcoll = [] 26 | 27 | j = np.argmin(np.abs(pop.halos.tab_M - 1e8)) 28 | 29 | for z in zarr: 30 | i = np.argmin(np.abs(pop.halos.z - z)) 31 | fcoll_mgtm1 = pop.halos.tab_mgtm[i,j] / pop.halos.MF.mean_density0 32 | 33 | dndm = pop.halos.tab_dndm[i,j] 34 | M = pop.halos.tab_M 35 | 36 | ok = M >= 1e8 37 | 38 | dndlnm = dndm * M 39 | 40 | #fcoll_mgtm2 = np.trapz(dndlnm, x=np.log(M)) / pop.halos.MF.mean_density0 41 | fcoll_mgtm2 = simps(dndlnm[ok], x=np.log(M[ok])) / pop.halos.MF.mean_density0 42 | 43 | print('{0!s} {1!s} {2!s}'.format(z, fcoll_mgtm1, fcoll_mgtm2))#, fcoll 44 | 45 | new_fcoll.append(fcoll_mgtm2) 46 | 47 | pl.semilogy(zarr, new_fcoll, color='b', lw=1) 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /input/inits/generate_inits_tables.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | generate_inits_tables.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill 7 | Created on: Mon 23 Mar 2020 13:29:43 EDT 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import sys 14 | import ares 15 | 16 | try: 17 | cosmorec_path = sys.argv[1] 18 | except IndexError: 19 | raise IndexError("Must supply path to CosmoRec executable!") 20 | 21 | cosm = ares.physics.Cosmology(cosmology_name='planck_TTTEEE_lowl_lowE', 22 | cosmology_id='best', cosmorec_path=cosmorec_path) 23 | 24 | cosm.get_inits() 25 | -------------------------------------------------------------------------------- /input/inits/pack_inits.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | me=$(whoami) 4 | 5 | echo '' 6 | echo '############################### inits ###############################' 7 | 8 | if [ $me = 'jordanmirocha' ] 9 | then 10 | echo \# Hey, J.M., right this way. 11 | else 12 | printf '# Are you sure you want to proceed [yes/no]: ' 13 | read -r areyousure 14 | 15 | if [ $areyousure = 'yes' ] 16 | then 17 | echo \# OK, hope you know what you are doing. 18 | else 19 | exit 1 20 | fi 21 | fi 22 | 23 | printf '# Please specify the path (up to but not including) your CosmoRec executable: ' 24 | read -r cosmorec 25 | 26 | echo \# Generating initial conditions with $cosmorec 27 | 28 | python generate_inits_tables.py $cosmorec 29 | 30 | 31 | tar -czvf inits.tar.gz inits_planck_TTTEEE_lowl_lowE_best.txt 32 | 33 | # Copy to dropbox 34 | echo Created tarball inits.tar.gz. 35 | 36 | # Copy to dropbox 37 | FILE=$DROPBOX/ares 38 | if [ -d "$FILE" ] 39 | then 40 | : 41 | else 42 | mkdir $FILE 43 | echo "Created $FILE." 44 | fi 45 | 46 | if [ -d "$FILE/input" ] 47 | then 48 | : 49 | else 50 | mkdir $FILE/input 51 | echo "Created $FILE/input." 52 | fi 53 | 54 | if [ -d "$FILE/input/inits" ] 55 | then 56 | : 57 | else 58 | mkdir $FILE/input/inits 59 | echo "Created $FILE/input/inits." 60 | fi 61 | 62 | cp inits.tar.gz $FILE/input/inits 63 | echo Copied inits.tar.gz to $FILE/input/inits 64 | 65 | echo '#####################################################################' 66 | echo '' -------------------------------------------------------------------------------- /input/inits/run_cosmologies.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################################################ 3 | # This script will execute run_CosmoRec.py for a bunch of different cosmologies. 4 | # Pass three arguments to this script: 5 | # (i) path to your CosmoRec executable (not including executable itself) 6 | # (ii) Planck likelihood to use, e.g., 7 | # plikHM_TTTEEE_lowl_lowE_lensing/base_plikHM_TTTEEE_lowl_lowE_lensing_4 8 | # (iii) Number of models to run in total. 9 | ################################################################################ 10 | 11 | CR=$1 12 | like=$2 13 | num=$3 14 | start=${4:-0} 15 | 16 | ctr=$start 17 | while [ $ctr -le $3 ] 18 | do 19 | python run_CosmoRec.py $1 $2 $ctr 20 | ((ctr++)) 21 | done 22 | 23 | -------------------------------------------------------------------------------- /input/litdata/atek2015.py: -------------------------------------------------------------------------------- 1 | """ 2 | Atek et al., 2015, arxiv 3 | 4 | Their Tables 2 and 5 5 | """ 6 | 7 | import numpy as np 8 | 9 | redshifts = [7.] 10 | 11 | wavelength = 1500. 12 | ULIM = -1e10 13 | 14 | info = \ 15 | { 16 | 'reference': 'Atek et al., 2015, ApJ, 814, 69', 17 | 'data': 'Table 2', 18 | 'fits': 'Table 5', 19 | 'label': 'Atek+ (2015)', 20 | } 21 | 22 | 23 | fits = {} 24 | 25 | fits['lf'] = {} 26 | 27 | # Table 5 28 | fits['lf']['pars'] = \ 29 | { 30 | 'Mstar': [-20.89], 31 | 'pstar': [10**3.54], 32 | 'alpha': [-2.04], 33 | } 34 | 35 | fits['lf']['err'] = \ 36 | { 37 | 'Mstar': [0.66], 38 | 'pstar': [0.15], 39 | 'alpha': [0.465], 40 | } 41 | 42 | # Table 4 43 | tmp_data = {} 44 | tmp_data['lf'] = \ 45 | { 46 | 7.: {'M': list(np.arange(-20.25, -14.75, 0.5)), 47 | 'phi': [-3.4184, -3.0263, -2.9044, -2.7418, -2.3896, -2.1032, 48 | -1.8201, -1.7548, -1.6044, -1.4012, -1.4012], 49 | 'err': [ 0.1576, 0.1658, 0.1431, 0.1332, 0.1401, 0.1990, 50 | 0.1940, 0.1893, 0.2117, 0.3123, 0.3122], 51 | }, 52 | } 53 | 54 | 55 | units = {'lf': 'log10'} 56 | 57 | data = {} 58 | data['lf'] = {} 59 | for key in tmp_data['lf']: 60 | #mask = np.array(tmp_data['lf'][key]['err']) == ULIM 61 | N = len(tmp_data['lf'][key]['M']) 62 | mask = np.array([tmp_data['lf'][key]['err'][i] == ULIM for i in range(N)]) 63 | 64 | data['lf'][key] = {} 65 | data['lf'][key]['M'] = np.ma.array(tmp_data['lf'][key]['M'], mask=mask) 66 | data['lf'][key]['phi'] = np.ma.array(tmp_data['lf'][key]['phi'], mask=mask) 67 | data['lf'][key]['err'] = tmp_data['lf'][key]['err'] 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /input/litdata/behroozi2013.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | behroozi2013.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Thu Mar 2 13:31:44 PST 2017 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import numpy as np 14 | 15 | redshifts = [7.] 16 | 17 | wavelength = 1500. 18 | 19 | fits = {} 20 | 21 | fits['lf'] = {} 22 | 23 | # Table 5 24 | fits['lf']['pars'] = \ 25 | { 26 | 'Mstar': [-20.89], 27 | 'pstar': [10**3.54], 28 | 'alpha': [-2.04], 29 | } 30 | 31 | fits['lf']['err'] = \ 32 | { 33 | 'Mstar': [0.66], 34 | 'pstar': [0.15], 35 | 'alpha': [0.465], 36 | } 37 | 38 | # Table 4 39 | data = {} 40 | data['lf'] = \ 41 | { 42 | 7.: {'M': list(np.arange(-20.25, -14.75, 0.5)), 43 | 'phi': [-3.4184, -3.0263, -2.9044, -2.7418, -2.3896, -2.1032, 44 | -1.8201, -1.7548, -1.6044, -1.4012, -1.4012], 45 | 'err': [ 0.1576, 0.1658, 0.1431, 0.1332, 0.1401, 0.1990, 46 | 0.1940, 0.1893, 0.2117, 0.3123, 0.3122], 47 | }, 48 | } 49 | 50 | 51 | units = {'lf': 'log10'} 52 | 53 | 54 | -------------------------------------------------------------------------------- /input/litdata/bouwens2017.py: -------------------------------------------------------------------------------- 1 | """ 2 | Bouwens et al., 2017, ApJ, 843, 129 3 | 4 | Table 4 and volume estimate from text. 5 | """ 6 | 7 | info = \ 8 | { 9 | 'reference': 'Bouwens et al., 2017, ApJ, 843, 129', 10 | 'data': 'Table 5', 11 | 'label': 'Bouwens+ (2017)' 12 | } 13 | 14 | import numpy as np 15 | 16 | redshifts = [6.] 17 | 18 | wavelength = 1600. # I think? 19 | 20 | ULIM = -1e10 21 | 22 | tmp_data = {} 23 | tmp_data['lf'] = \ 24 | { 25 | 6.0: {'M': list(np.arange(-20.75, -12.25, 0.5)), 26 | 'phi': [0.0002, 0.0009, 0.0007, 0.0018, 0.0036, 27 | 0.0060, 0.0071, 0.0111, 0.0170, 0.0142, 28 | 0.0415, 0.0599, 0.0817, 0.1052, 0.1275, 29 | 0.1464, 0.1584], 30 | 'err': [(0.0002, 0.0002), (0.0004, 0.0004), 31 | (0.0004, 0.0004), (0.0006, 0.0006), 32 | (0.0009, 0.0009), (0.0012, 0.0012), 33 | (0.0066, 0.0014), (0.0101, 0.0022), 34 | (0.0165, 0.0039), (0.0171, 0.0054), 35 | (0.0354, 0.0069), (0.0757, 0.0106), 36 | (0.1902, 0.0210), (0.5414, 0.0434), 37 | (1.6479, 0.0747), (5.4369, 0.1077), 38 | (19.8047, 0.1343)], 39 | }, 40 | } 41 | 42 | units = {'lf': 1.} 43 | 44 | 45 | 46 | data = {} 47 | data['lf'] = {} 48 | for key in tmp_data['lf']: 49 | #mask = np.array(tmp_data['lf'][key]['err']) == ULIM 50 | N = len(tmp_data['lf'][key]['M']) 51 | mask = np.array([tmp_data['lf'][key]['err'][i] == ULIM for i in range(N)]) 52 | 53 | data['lf'][key] = {} 54 | data['lf'][key]['M'] = np.ma.array(tmp_data['lf'][key]['M'], mask=mask) 55 | data['lf'][key]['phi'] = np.ma.array(tmp_data['lf'][key]['phi'], mask=mask) 56 | data['lf'][key]['err'] = tmp_data['lf'][key]['err'] 57 | 58 | -------------------------------------------------------------------------------- /input/litdata/bowler2020.py: -------------------------------------------------------------------------------- 1 | """ 2 | Bowler et al., 2020, MNRAS 3 | 4 | Table 6. 5 | """ 6 | 7 | import numpy as np 8 | 9 | info = \ 10 | { 11 | 'reference': 'Bowler et al., 2020, MNRAS', 12 | 'data': 'Table 6', 13 | 'fits': 'Table 7', 14 | 'label': 'Bowler+ (2020)', 15 | } 16 | 17 | redshifts = np.array([8., 9.]) 18 | wavelength = 1500. 19 | 20 | ULIM = -1e10 21 | 22 | # Table 6 23 | tmp_data = {} 24 | tmp_data['lf'] = \ 25 | { 26 | 8.: {'M': [-21.65, -22.15, -22.90], 27 | 'phi': [2.95e-6, 0.58e-6, 0.14e-6], 28 | 'err': [0.98e-6, 0.33e-6, 0.06e-6], 29 | }, 30 | 9.: {'M': [-21.9, -22.9], 31 | 'phi': [0.84e-6, 0.16e-6], 32 | 'err': [0.49e-6, 0.11e-6], 33 | }, 34 | } 35 | 36 | units = {'lf': 1.} 37 | 38 | data = {} 39 | data['lf'] = {} 40 | for key in tmp_data['lf']: 41 | #mask = np.array(tmp_data['lf'][key]['err']) == ULIM 42 | N = len(tmp_data['lf'][key]['M']) 43 | mask = np.array([tmp_data['lf'][key]['err'][i] == ULIM for i in range(N)]) 44 | 45 | data['lf'][key] = {} 46 | data['lf'][key]['M'] = np.ma.array(tmp_data['lf'][key]['M'], mask=mask) 47 | data['lf'][key]['phi'] = np.ma.array(tmp_data['lf'][key]['phi'], mask=mask) 48 | data['lf'][key]['err'] = tmp_data['lf'][key]['err'] 49 | -------------------------------------------------------------------------------- /input/litdata/bpass_v1.py: -------------------------------------------------------------------------------- 1 | from eldridge2009 import * 2 | from eldridge2009 import _load # Must load explicitly 3 | 4 | # To preserve backward compatibility. 5 | -------------------------------------------------------------------------------- /input/litdata/calzetti1994.py: -------------------------------------------------------------------------------- 1 | """ 2 | Calzetti et al., 1994, ApJ, 429, 582 3 | 4 | Table 2. 5 | """ 6 | 7 | import numpy as np 8 | 9 | info = \ 10 | { 11 | 'reference': 'Calzetti et al., 1994, ApJ, 429, 582', 12 | 'data': 'Table 2', 13 | 'label': 'Calzetti+ (1994)', 14 | } 15 | 16 | # Wavelength windows used to compute UV slope. 17 | windows = \ 18 | ((1268., 1284.), (1309., 1316.), (1342., 1371.), (1407., 1515.), 19 | (1562., 1583.), (1677., 1740.), (1760., 1833.), (1866., 1890.), 20 | (1930., 1950.), (2400., 2580.)) 21 | 22 | 23 | -------------------------------------------------------------------------------- /input/litdata/daddi2007.py: -------------------------------------------------------------------------------- 1 | """ 2 | Daddi, E., et al. 2007, ApJ, 670, 156 3 | https://arxiv.org/abs/0705.2831v2 4 | 5 | For ssfr, values are corrected as seen in Behroozi et al. 2013 (http://arxiv.org/abs/1207.6105), Table 5, for I (Initial Mass Function) corrections. 6 | 7 | """ 8 | 9 | import numpy as np 10 | 11 | info = \ 12 | { 13 | 'reference':'Daddi, E., et al. 2007, ApJ, 670, 156', 14 | 'data': 'Behroozi, Table 5', 15 | 'imf': ('chabrier, 2003', (0.1, 100.)), 16 | } 17 | 18 | redshifts = [2.0] 19 | wavelength = 1600. 20 | 21 | ULIM = -1e10 22 | 23 | fits = {} 24 | 25 | # Table 1 26 | tmp_data = {} 27 | tmp_data['ssfr'] = \ 28 | { 29 | 2.0: {'M': [5.8823529E+09, 1.7647059E+10, 5.8823529E+10], 30 | 'phi': [-8.60205999132796, -8.65, -8.69897000433602], 31 | 'err': [(0.3, 0.3), (0.3, 0.3), (0.3, 0.3)] 32 | }, 33 | } 34 | 35 | 36 | units = {'ssfr': '1.'} 37 | 38 | data = {} 39 | data['ssfr'] = {} 40 | 41 | for group in ['ssfr']: 42 | 43 | for key in tmp_data[group]: 44 | 45 | if key not in tmp_data[group]: 46 | continue 47 | 48 | subdata = tmp_data[group] 49 | 50 | mask = [] 51 | for element in subdata[key]['err']: 52 | if element == ULIM: 53 | mask.append(1) 54 | else: 55 | mask.append(0) 56 | 57 | mask = np.array(mask) 58 | 59 | data[group][key] = {} 60 | data[group][key]['M'] = np.ma.array(subdata[key]['M'], mask=mask) 61 | data[group][key]['phi'] = np.ma.array(subdata[key]['phi'], mask=mask) 62 | data[group][key]['err'] = tmp_data[group][key]['err'] 63 | -------------------------------------------------------------------------------- /input/litdata/ferland1980.py: -------------------------------------------------------------------------------- 1 | import os 2 | import numpy as np 3 | 4 | info = \ 5 | { 6 | 'reference': 'Ferland 1980', 7 | 'data': 'Table 1' 8 | } 9 | 10 | def _load(): 11 | from ares.data import ARES 12 | E, T10, T20 = np.loadtxt('{}/input/litdata/ferland1980.txt'.format(ARES), 13 | delimiter=',') 14 | 15 | return E, T10, T20 16 | -------------------------------------------------------------------------------- /input/litdata/ferland1980.txt: -------------------------------------------------------------------------------- 1 | # rows: E/E_ryd, T=10,000, T=20,000 2 | 1.00, 0.25, 0.25, 0.11, 0.11, 0.0625, 0.0625, 0.04, 0.04,0.0278, 0.0278, 0.0204, 0.0204,0.0156, 0.0156, 0.0123, 0.0123,0.0100, 0.0100, 0.0083, 0.0083, 0.0069 3 | 2.11e-44, 2.48e-39, 1.37e-40, 1.15e-39, 4.26e-40, 9.04e-40, 5.93e-40, 8.51e-40, 6.90e-40, 8.50e-40, 7.56e-40, 8.66e-40, 8.06e-40, 8.87e-40, 8.47e-40, 9.11e-40, 8.82e-40, 9.34e-40, 9.14e-40, 9.58e-40, 9.42e-40, 9.80e-40 4 | 3.29e-42, 1.06e-39, 2.32e-40, 6.78e-40, 4.23e-40, 6.31e-40, 5.21e-40, 6.41e-40, 5.84e-40, 6.65e-40, 6.31e-40, 6.90e-40, 6.69e-40, 7.16e-40, 7.02e-40, 7.41e-40, 7.31e-40, 7.64e-40, 7.57e-40, 7.87e-40, 7.81e-40, 8.08e-40 5 | -------------------------------------------------------------------------------- /input/litdata/finkelstein2012.py: -------------------------------------------------------------------------------- 1 | """ 2 | Finkelstein et al., 2012, ApJ, 756, 164 3 | 4 | Table 5. 5 | """ 6 | 7 | import numpy as np 8 | 9 | info = \ 10 | { 11 | 'reference': 'Finkelstein et al., 2012, ApJ, 756, 164', 12 | 'data': 'Table 5', 13 | 'label': 'Finkelstein+ (2012)', 14 | } 15 | 16 | redshifts = [4, 5, 6, 7, 8] 17 | wavelength = 1500. 18 | 19 | ULIM = -1e10 20 | 21 | # Table 5 22 | tmp_data = {} 23 | tmp_data['beta'] = \ 24 | { 25 | 4: {'beta': [-2.22, -2.03, -1.88], 26 | 'Ms': [7.5, 8.5, 9.5], 27 | 'err': [(0.13, 0.05), (0.02, 0.04), (0.02, 0.02)]}, 28 | 5: {'beta': [-2.4, -2.15, -1.79], 29 | 'Ms': [7.5, 8.5, 9.5], 30 | 'err': [(0.22, 0.1), (0.06, 0.04), (0.09, 0.03)]}, 31 | 6: {'beta': [-2.59, -2.20, -1.78], 32 | 'Ms': [7.5, 8.5, 9.5], 33 | 'err': [(0.23, 0.1), (0.05, 0.16), (0.19, 0.1)]}, 34 | 7: {'beta': [-2.68, -2.42, -1.76], 35 | 'Ms': [7.5, 8.5, 9.5], 36 | 'err': [(0.15, 0.24), (0.31, 0.11), (0.23, 0.33)]}, 37 | 8: {'beta': [-2.5, -2.35, -1.6], 38 | 'Ms': [7.5, 8.5, 9.5], 39 | 'err': [(1.26, 0.43), (0.46, 0.16), (0.32, 0.54)]}, 40 | } 41 | 42 | data = {} 43 | data['beta'] = {} 44 | for key in tmp_data['beta']: 45 | data['beta'][key] = {} 46 | data['beta'][key]['Ms'] = np.array(tmp_data['beta'][key]['Ms']) 47 | data['beta'][key]['beta'] = np.array(tmp_data['beta'][key]['beta']) 48 | data['beta'][key]['err'] = np.array(tmp_data['beta'][key]['err']) 49 | 50 | data['slope_wrt_mass'] = \ 51 | { 52 | 4: {'slope': 0.17, 'err': 0.03}, 53 | 5: {'slope': 0.30, 'err': 0.06}, 54 | 6: {'slope': 0.40, 'err': 0.1}, 55 | 7: {'slope': 0.46, 'err': 0.1}, 56 | 8: {'slope': 0.45, 'err': 0.37}, 57 | } 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /input/litdata/furlanetto2017.py: -------------------------------------------------------------------------------- 1 | from numpy import inf 2 | 3 | # Calibration set! 4 | energy = \ 5 | { 6 | 7 | 'pop_fstar': None, 8 | 'pop_fstar_max': 0.1, # fstar <= this value 9 | 10 | # SFE (through mass loading factor) 11 | 'pop_sfr_model': 'mlf-func', 12 | 'pop_mlf': 'pq[0]', 13 | 'pq_func[0]': 'pl_evolN', 14 | 'pq_func_var[0]': 'Mh', 15 | 'pq_func_var2[0]': '1+z', 16 | 17 | ## 18 | # Steve's Equation 13. 19 | ## 20 | 'pq_func_par0[0]': 1., 21 | 'pq_func_par1[0]': 10**11.5, 22 | 'pq_func_par2[0]': -2./3., 23 | 'pq_func_par3[0]': 9., 24 | 'pq_func_par4[0]': -1., 25 | 26 | 'pop_lum_per_sfr': 1e-28, 27 | 28 | } 29 | 30 | ereg = energy 31 | 32 | momentum = energy.copy() 33 | momentum['pop_fstar_max'] = 0.2 34 | momentum['pq_func_par0[0]'] = 5. # actually not sure what Steve uses here. 35 | momentum['pq_func_par2[0]'] = -1./3. 36 | momentum['pq_func_par4[0]'] = -0.5 37 | 38 | mreg = momentum 39 | 40 | fshock = \ 41 | { 42 | # Massive end 43 | 'pop_fshock': 'pq[1]', 44 | 'pq_func[1]': 'pl_evolN', 45 | 'pq_func_var[1]': 'Mh', 46 | 'pq_func_var2[1]': '1+z', 47 | 48 | 'pq_val_ceil[1]': 1.0, # fshock <= 1 49 | 50 | # Steve's Equation 6 (from Faucher-Giguere+ 2011) 51 | 'pq_func_par0[1]': 0.47, 52 | 'pq_func_par1[1]': 1e12, 53 | 'pq_func_par2[1]': -0.25, 54 | 'pq_func_par3[1]': 4., 55 | 'pq_func_par4[1]': 0.38, 56 | } 57 | -------------------------------------------------------------------------------- /input/litdata/gonzalez2012.py: -------------------------------------------------------------------------------- 1 | """ 2 | Gonzalez, V., et al., 2012, arXiv:1208.4362 3 | http://arxiv.org/abs/1208.4362 4 | 5 | For ssfr, values are corrected as seen in Behroozi et al. 2013 (http://arxiv.org/abs/1207.6105), Table 5, for I (Initial Mass Function) corrections. 6 | 7 | """ 8 | 9 | import numpy as np 10 | 11 | info = \ 12 | { 13 | 'reference':'Gonzalez, V., et al., 2012, arXiv:1208.4362', 14 | 'data': 'Behroozi, Table 5', 15 | 'imf': ('chabrier, 2003', (0.1, 100.)), 16 | } 17 | 18 | redshifts = [4.0, 5.0, 6.0] 19 | wavelength = 1600. 20 | 21 | ULIM = -1e10 22 | 23 | fits = {} 24 | 25 | # Table 1 26 | tmp_data = {} 27 | tmp_data['ssfr'] = \ 28 | { 29 | 4.0: {'M': [2.9481602E+09, 5.8823529E+08], 30 | 'phi': [-8.49, -8.33], 31 | 'err': [(0.3, 0.3), (0.3, 0.3)] 32 | }, 33 | 5.0: {'M': [2.9481602E+09, 5.8823529E+08], 34 | 'phi': [-8.48, -8.21], 35 | 'err': [(0.3, 0.3), (0.3, 0.3)] 36 | }, 37 | 6.0: {'M': [2.9481602E+09, 5.8823529E+08], 38 | 'phi': [-7.9, -7.91], 39 | 'err': [(0.3, 0.3), (0.3, 0.3)] 40 | }, 41 | } 42 | 43 | 44 | units = {'ssfr': '1.'} 45 | 46 | data = {} 47 | data['ssfr'] = {} 48 | 49 | for group in ['ssfr']: 50 | 51 | for key in tmp_data[group]: 52 | 53 | if key not in tmp_data[group]: 54 | continue 55 | 56 | subdata = tmp_data[group] 57 | 58 | mask = [] 59 | for element in subdata[key]['err']: 60 | if element == ULIM: 61 | mask.append(1) 62 | else: 63 | mask.append(0) 64 | 65 | mask = np.array(mask) 66 | 67 | data[group][key] = {} 68 | data[group][key]['M'] = np.ma.array(subdata[key]['M'], mask=mask) 69 | data[group][key]['phi'] = np.ma.array(subdata[key]['phi'], mask=mask) 70 | data[group][key]['err'] = tmp_data[group][key]['err'] 71 | -------------------------------------------------------------------------------- /input/litdata/haardt2012.py: -------------------------------------------------------------------------------- 1 | """ 2 | Haardt, F., & Madau, P. 2012, ApJ, 746, 125 3 | 4 | Notes 5 | ----- 6 | 7 | """ 8 | 9 | import os 10 | import numpy as np 11 | from ares.physics.Constants import h_p, c, erg_per_ev 12 | 13 | _input = os.getenv('ARES') + '/input/hm12' 14 | 15 | pars_ml = \ 16 | { 17 | 'a': 6.9e-3, 18 | 'b': 0.14, 19 | 'c': 2.2, 20 | 'd': 5.29, 21 | } 22 | 23 | pars_err = \ 24 | { 25 | 'a': 0.001, 26 | 'b': 0.21, 27 | 'c': 0.14, 28 | 'd': 0.19, 29 | } 30 | 31 | def _read_UVB(): 32 | 33 | fn = 'UVB.out' 34 | skip = 20 35 | 36 | f = open('{0!s}/{1!s}'.format(_input, fn), 'r') 37 | 38 | data = [] 39 | for i, line in enumerate(f): 40 | if i < skip: 41 | continue 42 | 43 | if i == 20: 44 | z = np.array(list(map(float, line.split()))) 45 | continue 46 | 47 | data.append(list(map(float, line.split()))) 48 | 49 | return z, np.array(data) 50 | 51 | def MetaGalacticBackground(): 52 | z, data = _read_UVB() 53 | 54 | # Reshape data so this function looks like an 55 | # ares.simulations.MetaGalacticBackground object 56 | 57 | dT = data.T 58 | wavelengths = dT[0] 59 | E = h_p * c / (wavelengths / 1e8) / erg_per_ev 60 | fluxes = dT[1:] 61 | 62 | return z[-1::-1], E[-1::-1], fluxes[-1::-1,-1::-1] 63 | 64 | def SFRD(z, **kwargs): 65 | return (6.9e-3 + 0.14 * (z / 2.2)**1.5) / (1. + (z / 2.7)**4.1) 66 | 67 | def _qso_sed_uv(): 68 | pass 69 | 70 | def _qso_emissivity_uv(): 71 | pass 72 | 73 | def _qso_sed_xray(): 74 | pass 75 | 76 | def _qso_emissivity_xray(): 77 | pass 78 | -------------------------------------------------------------------------------- /input/litdata/kroupa2001.py: -------------------------------------------------------------------------------- 1 | """ 2 | Kroupa P., 2001, MNRAS, 322, 231 3 | """ 4 | 5 | import numpy as np 6 | 7 | m_0 = (0.01, 0.08) 8 | m_1 = (0.08, 0.5) 9 | m_2 = (0.5, 1.0) 10 | m_3 = (1.0, np.inf) 11 | 12 | imf_pars = \ 13 | { 14 | 'alpha_0': 0.3, 15 | 'alpha_1': 1.3, 16 | 'alpha_2': 2.3, 17 | 'alpha_3': 3.3, 18 | } 19 | 20 | imf_err = \ 21 | { 22 | 'alpha_0': 0.7, 23 | 'alpha_1': 0.5, 24 | 'alpha_2': 0.3, 25 | 'alpha_3': 0.7, 26 | } 27 | 28 | class InitialMassFunction(object): 29 | def __init__(self, **kwargs): 30 | 31 | if not kwargs: 32 | kwargs = imf_pars 33 | else: 34 | kw = imf_pars.copy() 35 | kw.update(kwargs) 36 | kwargs = kw 37 | 38 | self.kwargs = kwargs 39 | 40 | self._norm() 41 | 42 | def __call__(self, m): 43 | 44 | if m_0[0] <= m < m_0[1]: 45 | return self._n0 * m**-self.kwargs['alpha_0'] 46 | elif m_1[0] <= m < m_1[1]: 47 | return self._n1 * m**-self.kwargs['alpha_1'] 48 | elif m_2[0] <= m < m_2[1]: 49 | return self._n2 * m**-self.kwargs['alpha_2'] 50 | elif m_3[0] <= m < m_3[1]: 51 | return self._n3 * m**-self.kwargs['alpha_3'] 52 | 53 | def _norm(self): 54 | self._n0 = 1.0 55 | self._n1 = self._n0 * m_0[1]**-self.kwargs['alpha_0'] \ 56 | / m_1[0]**-self.kwargs['alpha_1'] 57 | self._n2 = self._n1 * m_1[1]**-self.kwargs['alpha_1'] \ 58 | / m_2[0]**-self.kwargs['alpha_2'] 59 | self._n3 = self._n2 * m_2[1]**-self.kwargs['alpha_2'] \ 60 | / m_3[0]**-self.kwargs['alpha_3'] 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /input/litdata/kusakabe2020.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | kusakabe2020.py 4 | 5 | Tables 3 and 4, last chunk. 6 | Figures 6 and 8 7 | 8 | """ 9 | 10 | import numpy as np 11 | 12 | info = \ 13 | { 14 | 'reference': 'Kusakabe et al., 2020, A&A submitted', 15 | 'data': 'Figures 6 and 8', 16 | 'label': 'Kusakabe+ (2020)', 17 | } 18 | 19 | 20 | redshifts = 3.3, 4.1, 4.7, 5.6 21 | 22 | # EW > 55 vs. redshift in -20.25 <= M1500 <= -18.75 23 | faint = (-20.25, -18.75) 24 | _x_55 = 0.06, 0.1, 0.18, 0.13 25 | _e_55 = (0.04, 0.03), (0.09, 0.04), (0.13, 0.07), (0.12, 0.05) 26 | 27 | _z_25 = 3.3, 4.1, 4.7, 5.6 28 | _x_25 = 0.13, 0.25, 0.32, 0.13 29 | _e_25 = (0.07, 0.05), (0.14, 0.09), (0.22, 0.11), (0.13, 0.05) 30 | 31 | _mags = (-20.75, -19.50, -18.50) 32 | _x_50 = [0.12, 0.04, 0.17] 33 | _e_50 = (0.23, 0.06), (0.09, 0.02), (0.12, 0.05) 34 | 35 | 36 | # vs. M1500 at z=4.1 37 | data_vs_M = \ 38 | { 39 | 'mags': _mags, 'x_LAE': np.array(_x_50), 'err': np.array(_e_50), 'EW': 50, 40 | 'z': 4.1, 41 | } 42 | 43 | data_vs_z = \ 44 | { 45 | 'EW25': {'x_LAE': np.array(_x_25), 'err': np.array(_e_25)}, 46 | 'EW55': {'x_LAE': np.array(_x_55), 'err': np.array(_e_55)}, 47 | } 48 | 49 | -------------------------------------------------------------------------------- /input/litdata/lee2011.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | info = \ 4 | { 5 | 'reference': 'Lee et al., 2011', 6 | 'data': 'Section 5.3, Figure 5' 7 | } 8 | 9 | redshifts = [4] 10 | wavelength = 1700. 11 | units = {'beta': 1.} 12 | 13 | 14 | _data = \ 15 | { 16 | # Really z~3.7, samples 1, 3, 6 17 | 4: {'M': [-23.3, -22.18, -21.43], 18 | 'beta': [-1.16, -1.37, -1.78], 19 | 'err': [0.31, 0.14, 0.28], 20 | }, 21 | } 22 | 23 | 24 | data = {} 25 | data['beta'] = {} 26 | for key in _data: 27 | data['beta'][key] = {} 28 | for element in _data[key]: 29 | data['beta'][key][element] = np.array(_data[key][element]) -------------------------------------------------------------------------------- /input/litdata/madau2014.py: -------------------------------------------------------------------------------- 1 | """ 2 | Madau, P., & Dickinson, M. 2014, ARA&A, 52, 415 3 | """ 4 | 5 | pars_ml = \ 6 | { 7 | 'a': 0.015, 8 | 'b': 2.7, 9 | 'c': 2.9, 10 | 'd': 5.6, 11 | } 12 | 13 | #pars_err = \ 14 | #{ 15 | # 'a': 0.001, 16 | # 'b': 0.21, 17 | # 'c': 0.14, 18 | # 'd': 0.19, 19 | #} 20 | 21 | def _SFRD(z, a=None, b=None, c=None, d=None): 22 | return a * (1. + z)**b / (1 + ((1 + z) / c)**d) 23 | 24 | def SFRD(z): 25 | return _SFRD(z, **pars_ml) 26 | 27 | info = \ 28 | { 29 | 'Lmin': '0.03 * Lstar', 30 | } 31 | 32 | -------------------------------------------------------------------------------- /input/litdata/mcbride2009.py: -------------------------------------------------------------------------------- 1 | """ 2 | McBride et al. 2009. 3 | """ 4 | 5 | #def MAR(z, Mh): 6 | # """ 7 | # Equation 8 from McBride et al. (2009), in high-z limit. 8 | # 9 | # ..note:: This is the *DM* accretion rate, not the baryon accretion rate. 10 | # """ 11 | # return 42. * (Mh / 1e12)**1.127 * (1. + 1.17 * z) * (1. + z)**1.5 12 | 13 | def MAR(z, Mh): 14 | """ 15 | Equation 9 from McBride et al. (2009). 16 | 17 | ..note:: This is the *median* MAH, not the mean. 18 | 19 | """ 20 | 21 | return 24.1 * (Mh / 1e12)**1.094 * (1. + 1.75 * z) * (1. + z)**1.5 22 | 23 | 24 | -------------------------------------------------------------------------------- /input/litdata/mclure2013.py: -------------------------------------------------------------------------------- 1 | """ 2 | McLure et al., 2013, MNRAS, 432, 2696 3 | 4 | Table 2. 5 | """ 6 | 7 | import numpy as np 8 | 9 | info = \ 10 | { 11 | 'reference': 'McLure et al., 2013, MNRAS, 432, 2696', 12 | 'data': 'Table 2', 13 | 'fits': 'Table 3', 14 | 'label': 'McLure+ (2013)', 15 | } 16 | 17 | redshifts = np.array([7., 8.]) 18 | wavelength = 1500. 19 | 20 | ULIM = -1e10 21 | 22 | # Table 6 23 | tmp_data = {} 24 | tmp_data['lf'] = \ 25 | { 26 | 7.: {'M': list(np.arange(-21, -16.5, 0.5)), 27 | 'phi': [0.00003, 0.00012, 0.00033, 0.00075, 0.0011, 0.0021, 0.0042, 28 | 0.0079, 0.011], 29 | 'err': [0.000001, 0.00002, 0.00005, 0.00009, 0.0002, 0.0006, 0.0009, 30 | 0.0019, 0.0025], 31 | }, 32 | 8.: {'M': list(np.arange(-21.25, -16.75, 0.5)), 33 | 'phi': [0.000008, 0.00003, 0.0001, 0.0003, 0.0005, 0.0012, 0.0018, 34 | 0.0028, 0.0050], 35 | 'err': [0.000003, 0.000009, 0.00003, 0.00006, 0.00012, 0.0004, 36 | 0.0006, 0.0008, 0.0025], 37 | }, 38 | } 39 | 40 | units = {'lf': 1.} 41 | 42 | data = {} 43 | data['lf'] = {} 44 | for key in tmp_data['lf']: 45 | #mask = np.array(tmp_data['lf'][key]['err']) == ULIM 46 | N = len(tmp_data['lf'][key]['M']) 47 | mask = np.array([tmp_data['lf'][key]['err'][i] == ULIM for i in range(N)]) 48 | 49 | data['lf'][key] = {} 50 | data['lf'][key]['M'] = np.ma.array(tmp_data['lf'][key]['M'], mask=mask) 51 | data['lf'][key]['phi'] = np.ma.array(tmp_data['lf'][key]['phi'], mask=mask) 52 | data['lf'][key]['err'] = tmp_data['lf'][key]['err'] 53 | -------------------------------------------------------------------------------- /input/litdata/morishita2018.py: -------------------------------------------------------------------------------- 1 | """ 2 | Morishita et al., 2018, ApJ 3 | 4 | Table 6. 5 | """ 6 | 7 | import numpy as np 8 | 9 | info = \ 10 | { 11 | 'reference': 'Morishita et al., 2018, MNRAS', 12 | 'data': 'Table 3', 13 | 'label': 'Morishita+ (2018)', 14 | } 15 | 16 | redshifts = np.array([9., 10.]) 17 | wavelength = 1500. 18 | 19 | ULIM = -50. 20 | 21 | # Table 6 22 | tmp_data = {} 23 | tmp_data['lf'] = \ 24 | { 25 | 10.: {'M': [-23., -22., -21.], 26 | 'phi': [-6.1, -5.9, -4.6], 27 | 'err': [(0.5, 0.8), ULIM, ULIM], 28 | }, 29 | 9.: {'M': [-23., -22., -21.], 30 | 'phi': [-5.9, -5.9, -5.4], 31 | 'err': [ULIM, (0.5, 0.8), (0.5, 0.8)], 32 | }, 33 | } 34 | 35 | units = {'lf': 'log10'} 36 | 37 | data = {} 38 | data['lf'] = {} 39 | for key in tmp_data['lf']: 40 | #mask = np.array(tmp_data['lf'][key]['err']) == ULIM 41 | N = len(tmp_data['lf'][key]['M']) 42 | mask = np.array([tmp_data['lf'][key]['err'][i] == ULIM for i in range(N)]) 43 | 44 | data['lf'][key] = {} 45 | data['lf'][key]['M'] = np.ma.array(tmp_data['lf'][key]['M'], mask=mask) 46 | data['lf'][key]['phi'] = np.ma.array(tmp_data['lf'][key]['phi'], mask=mask) 47 | data['lf'][key]['err'] = tmp_data['lf'][key]['err'] 48 | -------------------------------------------------------------------------------- /input/litdata/oesch2013.py: -------------------------------------------------------------------------------- 1 | """ 2 | Oesch et al., 2013, ApJ, 773, 75 3 | 4 | Table 6. 4 the last 5 rows. 5 | """ 6 | 7 | import numpy as np 8 | 9 | info = \ 10 | { 11 | 'reference': 'Oesch et al., 2013, ApJ, 773, 75', 12 | 'data': 'Table 4', 13 | } 14 | 15 | wavelength = 1600. 16 | redshifts = [9, 10] 17 | 18 | ULIM = -1e10 19 | 20 | fits = {} 21 | 22 | fits['lf'] = {} 23 | 24 | #fits['lf']['pars'] = \ 25 | #{ 26 | # 'Mstar': [-20.88, -21.17, -20.94, -20.87, -20.63], 27 | # 'pstar': [1.97e-3, 0.74e-3, 0.5e-3, 0.29e-3, 0.21e-3], 28 | # 'alpha': [-1.64, -1.76, -1.87, -2.06, -2.02], 29 | #} 30 | # 31 | #fits['lf']['err'] = \ 32 | #{ 33 | # 'Mstar': [0.08, 0.12, 0.2, 0.26, 0.36], 34 | # 'pstar': [0.315e-3, 0.16e-3, 0.19e-3, 0.165e-3, 0.17e-3], # should be asymmetric! 35 | # 'alpha': [0.04, 0.05, 0.1, 0.13, 0.23], 36 | #} 37 | 38 | # Table 4 39 | # Note: not currently including any of the upper limits 40 | tmp_data = {} 41 | tmp_data['lf'] = \ 42 | { 43 | 9.: {'M': [-20.66, -19.66, -18.66, -17.66], 44 | 'phi': [0.18e-3, 0.15e-3, 0.35e-3, 1.6e-3], 45 | 'err': [ULIM, (0.15e-3, 0.13e-3), 0.24e-3, 0.9e-3], 46 | }, 47 | 10.: {'M': [-20.78, -20.28, -19.78, -19.28, -18.78, -18.28, -17.78], 48 | 'phi': [0.0077e-3, 0.013e-3, 0.027e-3, 0.083e-3, 0.17e-3, 0.34e-3, 0.58e-3], 49 | 'err': [ULIM, ULIM, ULIM, ULIM, ULIM, ULIM, (0.58e-3, 0.5e-3)], 50 | }, 51 | } 52 | 53 | units = {'lf': 1.} 54 | 55 | data = {} 56 | data['lf'] = {} 57 | for key in tmp_data['lf']: 58 | #mask = np.array(tmp_data['lf'][key]['err']) == ULIM 59 | N = len(tmp_data['lf'][key]['M']) 60 | mask = np.array([tmp_data['lf'][key]['err'][i] == ULIM for i in range(N)]) 61 | 62 | data['lf'][key] = {} 63 | data['lf'][key]['M'] = np.ma.array(tmp_data['lf'][key]['M'], mask=mask) 64 | data['lf'][key]['phi'] = np.ma.array(tmp_data['lf'][key]['phi'], mask=mask) 65 | data['lf'][key]['err'] = tmp_data['lf'][key]['err'] 66 | -------------------------------------------------------------------------------- /input/litdata/oesch2014.py: -------------------------------------------------------------------------------- 1 | """ 2 | Oesch et al., 2014, ApJ, 786, 108 3 | 4 | Table 6. 4 the last 5 rows. 5 | """ 6 | 7 | import numpy as np 8 | 9 | info = \ 10 | { 11 | 'reference': 'Oesch et al., 2014, ApJ, 786, 108', 12 | 'data': 'Table 5', 13 | } 14 | 15 | redshifts = [10.] 16 | wavelength = 1600. # I think? 17 | 18 | ULIM = -1e10 19 | 20 | tmp_data = {} 21 | tmp_data['lf'] = \ 22 | { 23 | 10.: {'M': [-21.28, -20.78, -20.28, -19.78, -19.28, -18.78, -18.28, -17.78], 24 | 'phi': [0.0027e-3, 0.01e-3, 0.0078e-3, 0.02e-3, 0.089e-3, 0.25e-3, 0.68e-3, 1.3e-3], 25 | 'err': [(0.0027e-3, 0.0023e-3), (0.006e-3, 0.005e-3), ULIM, ULIM, 26 | ULIM, ULIM, ULIM, (1.3e-3, 1.1e-3)], 27 | }, 28 | } 29 | 30 | units = {'lf': 1.} 31 | 32 | data = {} 33 | data['lf'] = {} 34 | for key in tmp_data['lf']: 35 | #mask = np.array(tmp_data['lf'][key]['err']) == ULIM 36 | N = len(tmp_data['lf'][key]['M']) 37 | mask = np.array([tmp_data['lf'][key]['err'][i] == ULIM for i in range(N)]) 38 | 39 | data['lf'][key] = {} 40 | data['lf'][key]['M'] = np.ma.array(tmp_data['lf'][key]['M'], mask=mask) 41 | data['lf'][key]['phi'] = np.ma.array(tmp_data['lf'][key]['phi'], mask=mask) 42 | data['lf'][key]['err'] = tmp_data['lf'][key]['err'] 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /input/litdata/oesch2016.py: -------------------------------------------------------------------------------- 1 | """ 2 | Oesch et al., 2016, arxiv 3 | 4 | Table 2 and volume estimate from text. 5 | """ 6 | 7 | import numpy as np 8 | 9 | #info = \ 10 | #{ 11 | # 'reference': 'Oesch et al., 2016, ApJ, 786, 108', 12 | # 'data': 'Table 5', 13 | #} 14 | 15 | redshifts = [11.1] 16 | 17 | wavelength = 1600. # I think? 18 | 19 | ULIM = -1e10 20 | 21 | tmp_data = {} 22 | tmp_data['lf'] = \ 23 | { 24 | 11.1: {'M': [-22.1], 25 | 'phi': [1. / 1.2e6], 26 | 'err': [None], 27 | }, 28 | } 29 | 30 | units = {'lf': 1.} 31 | 32 | data = {} 33 | data['lf'] = {} 34 | for key in tmp_data['lf']: 35 | #mask = np.array(tmp_data['lf'][key]['err']) == ULIM 36 | N = len(tmp_data['lf'][key]['M']) 37 | mask = np.array([tmp_data['lf'][key]['err'][i] == ULIM for i in range(N)]) 38 | 39 | data['lf'][key] = {} 40 | data['lf'][key]['M'] = np.ma.array(tmp_data['lf'][key]['M'], mask=mask) 41 | data['lf'][key]['phi'] = np.ma.array(tmp_data['lf'][key]['phi'], mask=mask) 42 | data['lf'][key]['err'] = tmp_data['lf'][key]['err'] 43 | -------------------------------------------------------------------------------- /input/litdata/oesch2018.py: -------------------------------------------------------------------------------- 1 | """ 2 | Oesch et al., 2017, arxiv 3 | 4 | Table 4 and volume estimate from text. 5 | """ 6 | 7 | import numpy as np 8 | 9 | info = \ 10 | { 11 | 'reference': 'Oesch et al., 2018, arXiv', 12 | 'data': 'Table 4', 13 | 'label': 'Oesch+ (2018)' 14 | } 15 | 16 | redshifts = np.array([10.]) 17 | 18 | wavelength = 1600. # I think? 19 | 20 | ULIM = -1e10 21 | 22 | tmp_data = {} 23 | tmp_data['lf'] = \ 24 | { 25 | 10.0: {'M': [-22.25, -21.25, -20.25, -19.25, -18.25,-17.25], 26 | 'phi': [0.017e-4, 0.01e-4, 0.1e-4, 0.34e-4, 1.9e-4, 6.3e-4], 27 | 'err': [ULIM, (0.022e-4, 0.008e-4), (0.1e-4, 0.05e-4), 28 | (0.45e-4, 0.22e-4), (2.5e-4, 1.2e-4), (14.9e-4, 5.2e-4)], 29 | }, 30 | } 31 | 32 | units = {'lf': 1.} 33 | 34 | data = {} 35 | data['lf'] = {} 36 | for key in tmp_data['lf']: 37 | N = len(tmp_data['lf'][key]['M']) 38 | mask = np.array([tmp_data['lf'][key]['err'][i] == ULIM for i in range(N)]) 39 | 40 | data['lf'][key] = {} 41 | data['lf'][key]['M'] = np.ma.array(tmp_data['lf'][key]['M'], mask=mask) 42 | data['lf'][key]['phi'] = np.ma.array(tmp_data['lf'][key]['phi'], mask=mask) 43 | data['lf'][key]['err'] = tmp_data['lf'][key]['err'] 44 | -------------------------------------------------------------------------------- /input/litdata/park2019.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | park2019.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill University 7 | Created on: Fri 31 Dec 2021 12:43:15 EST 8 | 9 | Description: 10 | 11 | """ 12 | 13 | from mirocha2017 import dpl 14 | 15 | base = dpl.copy() 16 | base['pop_sfr_model'] = '21cmfast' 17 | 18 | _updates = \ 19 | { 20 | # SFE 21 | 'pop_fstar{0}': 'pq[0]', 22 | 'pq_func[0]{0}': 'pl', 23 | 'pq_func_var[0]{0}': 'Mh', 24 | 25 | 'pop_tstar{0}': 0.5, # 0.5 in Park et al. 26 | 27 | # PL parameters 28 | 'pq_func_par0[0]{0}': 0.05, # Table 1 in Park et al. (2019) 29 | 'pq_func_par1[0]{0}': 1e10, 30 | 'pq_func_par2[0]{0}': 0.5, 31 | 'pq_func_par3[0]{0}': -0.61, 32 | 33 | 'pop_calib_wave{0}': 1600, 34 | 'pop_calib_lum{0}': None, 35 | 'pop_lum_per_sfr{0}': 1. / 1.15e-28, # Park et al. (2019); Eq. 12 36 | 37 | # Mturn stuff 38 | 'pop_Mmin{0}': 1e5, # Let focc do the work. 39 | 'pop_focc{0}': 'pq[40]', 40 | "pq_func[40]{0}": 'exp-', 41 | 'pq_func_var[40]{0}': 'Mh', 42 | 'pq_func_par0[40]{0}': 1., 43 | 'pq_func_par1[40]{0}': 5e8, 44 | 'pq_func_par2[40]{0}': -1., 45 | 46 | } 47 | 48 | base.update(_updates) 49 | -------------------------------------------------------------------------------- /input/litdata/reddy2009.py: -------------------------------------------------------------------------------- 1 | """ 2 | Reddy & Steidel, 2009, ApJ, 692, 778 3 | 4 | Table 1. 5 | """ 6 | 7 | import numpy as np 8 | 9 | info = \ 10 | { 11 | 'reference': 'Reddy & Steidel, 2009, ApJ, 692, 778', 12 | 'data': 'Table 2', 13 | } 14 | 15 | # u, g, and r dropouts, respectively 16 | redshifts = [2.3, 3.05] 17 | wavelength = 1700. 18 | 19 | ULIM = -1e10 20 | 21 | tmp_data = {} 22 | tmp_data['lf'] = \ 23 | {# has h70's built-in 24 | 2.3: {'M': list(np.arange(-22.58, -18.33+0.5, 0.5)), 25 | 'phi': [0.004e-3, 0.035e-3, 0.142e-3, 0.341e-3, 1.246e-3, 2.030e-3, 26 | 3.583e-3, 7.171e-3, 8.188e-3, 12.62e-3], 27 | 'err': [0.003e-3, 0.007e-3, 0.016e-3, 0.058e-3, 0.083e-3, 0.196e-3, 28 | 0.319e-3, 0.552e-3, 0.777e-3, 1.778e-3], 29 | }, 30 | 3.05: {'M': list(np.arange(-22.77, -18.77+0.5, 0.5)), 31 | 'phi': [0.003e-3, 0.030e-3, 0.085e-3, 0.240e-3, 0.686e-3, 1.530e-3, 32 | 2.934e-3, 4.296e-3, 5.536e-3], 33 | 'err': [0.001e-3, 0.013e-3, 0.032e-3, 0.104e-3, 0.249e-3, 0.273e-3, 34 | 0.333e-3, 0.432e-3, 0.601e-3], 35 | }, 36 | } 37 | 38 | units = {'lf': 1., 'wavelength': 1500.} 39 | 40 | 41 | data = {} 42 | data['lf'] = {} 43 | for key in tmp_data['lf']: 44 | #mask = np.array(tmp_data['lf'][key]['err']) == ULIM 45 | N = len(tmp_data['lf'][key]['M']) 46 | mask = np.array([tmp_data['lf'][key]['err'][i] == ULIM for i in range(N)]) 47 | 48 | data['lf'][key] = {} 49 | data['lf'][key]['M'] = np.ma.array(tmp_data['lf'][key]['M'], mask=mask) 50 | data['lf'][key]['phi'] = np.ma.array(tmp_data['lf'][key]['phi'], mask=mask) 51 | data['lf'][key]['err'] = tmp_data['lf'][key]['err'] 52 | -------------------------------------------------------------------------------- /input/litdata/robertson2015.py: -------------------------------------------------------------------------------- 1 | """ 2 | Robertson, B. E., Ellis, R. S., Furlanetto, S. R., & Dunlop, J. S. 2015, ApJ, 3 | 802, L19 4 | 5 | Notes 6 | ----- 7 | 8 | """ 9 | 10 | sfrd_pars = \ 11 | { 12 | 'a': 0.01376, 13 | 'b': 3.26, 14 | 'c': 2.59, 15 | 'd': 5.68, 16 | } 17 | 18 | sfrd_err = \ 19 | { 20 | 'a': 0.001, 21 | 'b': 0.21, 22 | 'c': 0.14, 23 | 'd': 0.19, 24 | } 25 | 26 | def _SFRD(z, a=None, b=None, c=None, d=None): 27 | return a * (1. + z)**b / (1. + ((1. + z) / c)**d) 28 | 29 | def SFRD(z, **kwargs): 30 | if not kwargs: 31 | kwargs = sfrd_pars 32 | 33 | return _SFRD(z, **kwargs) 34 | 35 | -------------------------------------------------------------------------------- /input/litdata/rojasruiz2020.py: -------------------------------------------------------------------------------- 1 | """ 2 | Rojas-Ruiz et al., 2020, ApJ accepted 3 | 4 | https://arxiv.org/abs/2002.06209 5 | 6 | Table 2 7 | """ 8 | 9 | import numpy as np 10 | 11 | info = \ 12 | { 13 | 'reference': 'Rojas-Ruiz et al., 2020, ApJ', 14 | 'data': 'Table 2', 15 | 'label': 'Rojas-Ruiz+ (2020)' 16 | } 17 | 18 | redshifts = np.array([8., 9.]) 19 | zrange = np.array([(7., 8.4), (8.4, 11.)]) 20 | wavelength = 1500. 21 | 22 | ULIM = -1e10 23 | 24 | # Table 6 25 | tmp_data = {} 26 | tmp_data['lf'] = \ 27 | { 28 | 8.: {'M': [-23, -22, -21], 29 | 'phi': [1.0175e-6, 2.9146e-6, 17.932e-6], 30 | 'err': [(2.752e-6, 0.253e-6), (6.39e-6, 0.969e-6), (36.767e-6, 7.298e-6)], 31 | }, 32 | 9.: {'M': [-23, -22, -21], 33 | 'phi': [5.6904e-6, 7.0378e-6, 40.326e-6], 34 | 'err': [(11.184e-6, 2.413e-6), (13.413e-6, 3.037e-6), (81.276e-6, 18.802e-6)], 35 | }, 36 | } 37 | 38 | units = {'lf': 1.} 39 | 40 | data = {} 41 | data['lf'] = {} 42 | for key in tmp_data['lf']: 43 | #mask = np.array(tmp_data['lf'][key]['err']) == ULIM 44 | N = len(tmp_data['lf'][key]['M']) 45 | mask = np.array([tmp_data['lf'][key]['err'][i] == ULIM for i in range(N)]) 46 | 47 | data['lf'][key] = {} 48 | data['lf'][key]['M'] = np.ma.array(tmp_data['lf'][key]['M'], mask=mask) 49 | data['lf'][key]['phi'] = np.ma.array(tmp_data['lf'][key]['phi'], mask=mask) 50 | data['lf'][key]['err'] = tmp_data['lf'][key]['err'] 51 | -------------------------------------------------------------------------------- /input/litdata/sanders2015.py: -------------------------------------------------------------------------------- 1 | """ 2 | Sanders et al. 2015 3 | 4 | Table 1. 5 | """ 6 | 7 | import numpy as np 8 | 9 | info = \ 10 | { 11 | 'reference': 'Sanders et al. 2015', 12 | 'data': 'Table 1', 13 | 'label': 'Sanders+ (2015)' 14 | } 15 | 16 | # u, g, and r dropouts, respectively 17 | redshifts = [2.3] 18 | 19 | ULIM = -1e10 20 | 21 | data = {} 22 | data['mzr'] = \ 23 | { 24 | 2.3: {'M': [10**9.45, 10**9.84, 10**10.11, 10**10.56], 25 | 'Mr': 10**np.array([[9.15, 9.68], [9.68, 9.94], [9.99, 10.27], [10.29, 11.11]]), 26 | 'phi': [8.18, 8.30, 8.44, 8.52], 27 | 'err': [(0.10, 0.07), (0.05, 0.04), (0.04, 0.04), (0.02, 0.02)], 28 | }, 29 | } 30 | 31 | units = {'mzr': 1.} 32 | 33 | -------------------------------------------------------------------------------- /input/litdata/starburst99.py: -------------------------------------------------------------------------------- 1 | from leitherer1999 import * 2 | 3 | -------------------------------------------------------------------------------- /input/litdata/stark2010.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | stark2010.py 4 | 5 | """ 6 | 7 | import numpy as np 8 | 9 | info = \ 10 | { 11 | 'reference': 'Stark et al., 2010, MNRAS, 408, 1628', 12 | 'data': 'Figure 13', 13 | 'label': 'Stark+ (2010)', 14 | } 15 | 16 | redshifts = np.array([7., 8.]) 17 | _mags1 = np.arange(-22, -18, 0.5) 18 | _mags2 = np.arange(-22, -18, 1) 19 | 20 | 21 | # Fig. 13a 22 | x_13a = (0.0885, 0.0658, 0.0695, 0.1035, 0.1729, 0.3024, 0.4655, 0.6021) 23 | e_13a = (0.1752-0.0885,0.0885), (0.1083-0.0658, 0.0658-0.0339), \ 24 | (0.0944-0.0695, 0.0695-0.0448), (0.1372-0.1035,0.1035-0.0717), \ 25 | (0.2153-0.1729, 0.1729-0.141), (0.382-0.3024,0.3024-0.2316), \ 26 | (0.6265-0.4655, 0.4655-0.3096), (0.8037-0.6021,0.6021-0.3968) 27 | 28 | # Fig 13b 29 | # blue = 3.5 <= z <= 4.5 30 | m_st_blue = np.arange(-22, -18, 1) 31 | x_st_blue = (0.053, 0.063, 0.151, 0.4526) 32 | e_st_blue = (0.096-0.053,0.053), (0.0856-0.063, 0.063-0.0391),\ 33 | (0.1815-0.151,0.151-0.1218), (0.5615-0.4526, 0.4526-0.3477) 34 | 35 | # red = 4.5 <= z <= 6.0 36 | m_st_red = np.arange(-22, -18, 1) 37 | x_st_red = (0.1968, 0.1016, 0.2174, 0.5549) 38 | e_st_red = (0.3256-0.1968, 0.1968-0.0694), (0.1348-0.1016, 0.1016-0.0684),\ 39 | (0.2638-0.2174,0.2174-0.1723), (0.7221-0.5549, 0.5549-0.389) 40 | 41 | 42 | data_all = {'mags': _mags1, 'x_LAE': np.array(x_13a), 'err': np.array(e_13a)} 43 | 44 | data_split = \ 45 | { 46 | 'low': {'mags': _mags2, 'x_LAE': np.array(x_st_blue), 'err': np.array(e_st_blue)}, 47 | 'high': {'mags': _mags2, 'x_LAE': np.array(x_st_blue), 'err': np.array(e_st_blue)}, 48 | 'z': {'low': (3.5, 4.5), 'high': (4.5, 6.0)} 49 | } 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /input/litdata/stark2011.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | stark2011.py 4 | 5 | """ 6 | 7 | import numpy as np 8 | 9 | info = \ 10 | { 11 | 'reference': 'Stark et al., 2010, ApJL, 728, L2', 12 | 'data': 'Figure 2', 13 | 'label': 'Stark+ (2011)', 14 | } 15 | 16 | redshifts = (4, 4.9, 5.9) 17 | 18 | # Top right, EW>25, -20.25 <= MUV <= -18.75 19 | _x_25_f = (0.3453, 0.4764, 0.5415) 20 | _e_25_f = (0.4015-0.3453,0.3453-0.2927), (0.5718-0.4764,0.4764-0.3847), \ 21 | (0.6516-0.5415, 0.5415-0.4327) 22 | 23 | 24 | # Top right, EW>55, -20.25 <= MUV <= -18.75 25 | _x_55_f = (0.2224, 0.2214, 0.2684) 26 | _e_55_f = (0.2702-0.2224,0.2224-0.1807), (0.2913-0.2214,0.2214-0.154), \ 27 | (0.3481-0.2684,0.2684-0.1886) 28 | 29 | 30 | # Bottom right, EW > 25, -21.75 <= MUV <= -20.25 31 | _x_25_b = (0.124, 0.2444, 0.1998) 32 | _e_25_b = (0.1499-0.124,0.124-0.0982), (0.2961-0.2444,0.2444-0.1935), \ 33 | (0.2841-0.1998,0.1998-0.117) 34 | 35 | # Bottom right, EW > 55, -21.75 <= MUV <= -20.25 36 | _x_55_b = (0.0549, 0.0719, 0.0735) 37 | _e_55_b = (0.0739-0.0549,0.0549-0.03882), (0.1016-0.0719, 0.0719-0.0423), \ 38 | (0.1261-0.0735, 0.0735-0.0212) 39 | 40 | bright = (-21.75, -20.25) 41 | faint = (-20.25, -18.75) 42 | 43 | data_EW25 = \ 44 | { 45 | 'faint': {'x_LAE': _x_25_f, 'err': _e_25_f}, 46 | 'bright': {'x_LAE': _x_25_b, 'err': _e_25_b}, 47 | } 48 | 49 | data_EW55 = \ 50 | { 51 | 'faint': {'x_LAE': _x_55_f, 'err': _e_55_f}, 52 | 'bright': {'x_LAE': _x_55_b, 'err': _e_55_b}, 53 | } 54 | -------------------------------------------------------------------------------- /input/litdata/stefanon2019.py: -------------------------------------------------------------------------------- 1 | """ 2 | Stefanon et al., 2019, ApJ, 883, 99 3 | 4 | Table 6. 5 | """ 6 | 7 | import numpy as np 8 | 9 | info = \ 10 | { 11 | 'reference': 'Stefanon et al., 2019, ApJ, 883, 99', 12 | 'data': 'Table 6', 13 | 'label': 'Stefanon+ (2019)', 14 | } 15 | 16 | redshifts = np.array([8., 9.]) 17 | wavelength = 1500. 18 | 19 | ULIM = -1e10 20 | 21 | # Table 6 22 | tmp_data = {} 23 | tmp_data['lf'] = \ 24 | { 25 | 8.: {'M': [-22.55, -22.05, -21.55], 26 | 'phi': [0.76e-6, 1.38e-6, 4.87e-6], 27 | 'err': [(0.74e-6, 0.41e-6), (1.09e-6, 0.66e-6), (2.01e-6, 1.41e-6)], 28 | }, 29 | 9.: {'M': [-22.35, -22.00, -21.60, -21.20], 30 | 'phi': [0.43e-6, 0.43e-6, 1.14e-6, 1.64e-6], 31 | 'err': [(0.99e-6, 0.36e-6), (0.98e-6, 0.36e-6), (1.5e-6, 0.73e-6), 32 | (2.16e-6, 1.06e-6)], 33 | }, 34 | } 35 | 36 | units = {'lf': 1.} 37 | 38 | data = {} 39 | data['lf'] = {} 40 | for key in tmp_data['lf']: 41 | #mask = np.array(tmp_data['lf'][key]['err']) == ULIM 42 | N = len(tmp_data['lf'][key]['M']) 43 | mask = np.array([tmp_data['lf'][key]['err'][i] == ULIM for i in range(N)]) 44 | 45 | data['lf'][key] = {} 46 | data['lf'][key]['M'] = np.ma.array(tmp_data['lf'][key]['M'], mask=mask) 47 | data['lf'][key]['phi'] = np.ma.array(tmp_data['lf'][key]['phi'], mask=mask) 48 | data['lf'][key]['err'] = tmp_data['lf'][key]['err'] 49 | -------------------------------------------------------------------------------- /input/litdata/weisz2014.py: -------------------------------------------------------------------------------- 1 | """ 2 | Weisz, Johnson, & Conroy, 2014, ApJ, 794, L3 3 | 4 | Table 1. 5 | """ 6 | 7 | import numpy as np 8 | 9 | info = \ 10 | { 11 | 'reference': 'Reddy & Steidel, 2009, ApJ, 692, 778', 12 | 'data': 'Table 1', 13 | } 14 | 15 | # u, g, and r dropouts, respectively 16 | redshifts = [3, 4, 5] 17 | wavelength = 1700. 18 | 19 | ULIM = -1e10 20 | 21 | tmp_data = {} 22 | tmp_data['lf'] = \ 23 | {# has h70's built-in 24 | #0.75: {'M': list(np.arange(-13.44, -1.44+3, 3)), 25 | # 'phi': [], 26 | # 'err': [], 27 | # }, 28 | #1.25: {'M': list(np.arange(-15.53, -3.53+3, 3)), 29 | # 'phi': [], 30 | # 'err': [], 31 | # }, 32 | #2: {'M': list(np.arange(-11.75, -2.75+3, 3)), 33 | # 'phi': [], 34 | # 'err': [], 35 | # }, 36 | 3: {'M': list(np.arange(-13.92, -4.92+3, 3)), 37 | 'phi': [0.0333, 0.0956, 0.2162, 1.4591], 38 | 'err': [0.0189, 0.0454, 0.0899, 0.8935], 39 | }, 40 | 41 | 4: {'M': list(np.arange(-13.82, -4.82+3, 3)), 42 | 'phi': [0.3184, 1.8523, 5.9041, 4.5149], 43 | 'err': [0.1510, 0.7706, 2.6702, 3.91], 44 | }, 45 | 5: {'M': [-15.66, -12.16, -8.66, -5.16], 46 | 'phi': [0.1608, 1.1793, 3.8774, 2.573], 47 | 'err': [0.1206, 0.5334, 1.4540, 2.1117], 48 | }, 49 | } 50 | 51 | units = {'lf': 1., 'wavelength': 1500.} 52 | 53 | data = {} 54 | data['lf'] = {} 55 | for key in tmp_data['lf']: 56 | #mask = np.array(tmp_data['lf'][key]['err']) == ULIM 57 | N = len(tmp_data['lf'][key]['M']) 58 | mask = np.array([tmp_data['lf'][key]['err'][i] == ULIM for i in range(N)]) 59 | 60 | data['lf'][key] = {} 61 | data['lf'][key]['M'] = np.ma.array(tmp_data['lf'][key]['M'], mask=mask) 62 | data['lf'][key]['phi'] = np.ma.array(tmp_data['lf'][key]['phi'], mask=mask) 63 | data['lf'][key]['err'] = tmp_data['lf'][key]['err'] 64 | 65 | -------------------------------------------------------------------------------- /input/optical_depth/generate_optical_depth_tables.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | generate_optical_depth_tables.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Fri Jun 14 09:20:22 2013 8 | 9 | Description: Generate optical depth lookup table. 10 | 11 | Note: This can be run in parallel, e.g., 12 | 13 | mpirun -np 4 python generate_optical_depth_tables.py 14 | 15 | """ 16 | 17 | import sys 18 | import ares 19 | 20 | # Initialize radiation background 21 | def_kwargs = \ 22 | { 23 | 'tau_Emin': 2e2, 24 | 'tau_Emax': 3e4, 25 | 'tau_Emin_pin': True, 26 | 'tau_fmt': 'hdf5', 27 | 'tau_redshift_bins': 400, 28 | 'approx_He': 1, 29 | 'include_He': 1, 30 | 'initial_redshift': 60, 31 | 'final_redshift': 5, 32 | 'first_light_redshift': 60, 33 | } 34 | 35 | kwargs = def_kwargs.copy() 36 | kwargs.update(ares.util.get_cmd_line_kwargs(sys.argv)) 37 | 38 | # Create OpticalDepth instance 39 | igm = ares.solvers.OpticalDepth(**kwargs) 40 | 41 | # Impose an ionization history: neutral for all times 42 | igm.ionization_history = lambda z: 0.0 43 | 44 | # Tabulate tau and save 45 | tau = igm.TabulateOpticalDepth() 46 | igm.save(suffix=kwargs['tau_fmt'], clobber=False) 47 | 48 | 49 | -------------------------------------------------------------------------------- /input/rctabs/generate_rc_table.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | generate_rc_table.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Tue May 12 20:54:21 MDT 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | 15 | # 16 | ## INPUT 17 | helium = 0 18 | dlogN = 0.05 19 | NE = 100 20 | ## 21 | # 22 | 23 | ptype = 2 + 10 * helium 24 | 25 | sim = ares.simulations.RaySegment(problem_type=ptype, 26 | tables_discrete_gen=True, tables_energy_bins=NE, tables_dlogN=[dlogN]*3) 27 | sim.save_tables(prefix='bb_He_NE_{0}_dlogN_{1:.2g}'.format(NE, dlogN)) 28 | 29 | 30 | -------------------------------------------------------------------------------- /perf/README: -------------------------------------------------------------------------------- 1 | Performance Testing 2 | ------------------- 3 | 4 | :: 5 | 6 | python -m cProfile -o output.pstats test_whatever.py 7 | gprof2dot -f pstats output.pstats | dot -Teps -o output.eps 8 | 9 | Then, have a look at ``output.png`` to see where time is being spent. 10 | 11 | 12 | -------------------------------------------------------------------------------- /perf/run_ares.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | scriptname=$1 4 | Niter=$2 5 | fnout=${scriptname/py/eps} 6 | 7 | python -m cProfile -o output.pstats $scriptname $Niter 8 | gprof2dot -f pstats output.pstats | dot -Teps -o $fnout 9 | 10 | -------------------------------------------------------------------------------- /perf/test_gs_basic.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_speed_gs_basic.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill 7 | Created on: Thu 8 Aug 2019 18:30:02 EDT 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import sys 14 | import ares 15 | 16 | N = int(sys.argv[1]) 17 | 18 | for i in range(N): 19 | print("Running iteration {}/{}".format(i+1, N)) 20 | sim = ares.simulations.Global21cm(verbose=False, progress_bar=False) 21 | sim.run() 22 | 23 | 24 | -------------------------------------------------------------------------------- /perf/test_gs_lfcal.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_speed_gs_lfcal.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill 7 | Created on: Thu 8 Aug 2019 18:30:02 EDT 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import sys 14 | import ares 15 | 16 | N = int(sys.argv[1]) 17 | pars = ares.util.ParameterBundle('mirocha2017:base') 18 | pars['verbose'] = False 19 | pars['progress_bar'] = False 20 | 21 | for i in range(N): 22 | print("Running iteration {}/{}".format(i+1, N)) 23 | sim = ares.simulations.Global21cm(**pars) 24 | sim.run() 25 | 26 | 27 | -------------------------------------------------------------------------------- /perf/test_sam_hists.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sam_histories.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill 7 | Created on: Thu 8 Aug 2019 18:38:06 EDT 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import sys 14 | import ares 15 | 16 | N = int(sys.argv[1]) 17 | pars = ares.util.ParameterBundle('in_prep:base').pars_by_pop(0, 1) 18 | pars['verbose'] = False 19 | pars['progress_bar'] = False 20 | 21 | for i in range(N): 22 | print("Running iteration {}/{}".format(i+1, N)) 23 | pop = ares.populations.GalaxyPopulation(**pars) 24 | hist = pop.histories 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /perf/test_sam_synth.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sam_synth.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill 7 | Created on: Thu 8 Aug 2019 18:38:13 EDT 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import sys 14 | import ares 15 | 16 | N = int(sys.argv[1]) 17 | pars = ares.util.ParameterBundle('in_prep:base').pars_by_pop(0, 1) 18 | pars['verbose'] = False 19 | pars['progress_bar'] = False 20 | 21 | for i in range(N): 22 | print("Running iteration {}/{}".format(i+1, N)) 23 | pop = ares.populations.GalaxyPopulation(**pars) 24 | L = pop.Luminosity(z=6., wave=1600.) 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /perf/test_tabulation_speed_H.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_tabulation_speed_H.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Tue May 12 15:26:39 MDT 2015 8 | 9 | Description: How fast can we make look-up tables for Phi and Psi? 10 | 11 | """ 12 | 13 | import ares 14 | import time 15 | 16 | t1 = time.time() 17 | sim1 = ares.simulations.RaySegment(problem_type=2, tables_discrete_gen=False) 18 | t2 = time.time() 19 | 20 | t3 = time.time() 21 | sim2 = ares.simulations.RaySegment(problem_type=2, tables_discrete_gen=True) 22 | t4 = time.time() 23 | 24 | print "Discrete tabulation is %.2gx faster than quad." % ((t2 - t1) / (t4 - t3)) 25 | 26 | sim1.run() 27 | sim2.run() 28 | 29 | anl1 = ares.analysis.RaySegment(sim1) 30 | anl2 = ares.analysis.RaySegment(sim2) 31 | 32 | ax = anl1.RadialProfile('h_2', color='k') 33 | anl2.RadialProfile('h_2', color='b', ls='--', lw=4, ax=ax) 34 | 35 | -------------------------------------------------------------------------------- /perf/test_tabulation_speed_He.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_tabulation_speed_He.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Tue May 12 15:26:39 MDT 2015 8 | 9 | Description: How fast can we make look-up tables for Phi and Psi? 10 | 11 | """ 12 | 13 | import ares 14 | import time 15 | 16 | sim = ares.simulations.RaySegment(problem_type=12, tables_discrete_gen=True, 17 | source_table='bb_He.npz') 18 | #sim.save_tables(prefix='bb_He') 19 | 20 | sim.run() 21 | 22 | anl = ares.analysis.RaySegment(sim) 23 | 24 | ax1 = anl.RadialProfile('h_1', color='k', ls='-', fig=1) 25 | anl.RadialProfile('h_2', color='k', ls='--', ax=ax1) 26 | 27 | ax2 = anl.RadialProfile('he_1', color='b', ls='-', fig=2) 28 | anl.RadialProfile('he_2', color='b', ls='--', ax=ax2) 29 | anl.RadialProfile('he_3', color='b', ls=':', ax=ax2) 30 | 31 | anl.RadialProfile('Tk', color='b', ls='-', fig=3) 32 | 33 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy>=1.22.2 2 | matplotlib==2.2.4 3 | scipy>=1.10 4 | h5py>=3 5 | coveralls==1.11.1 6 | pytest==3.6.4 7 | pytest-cov==2.8.1 8 | pyyaml==5.4 9 | emcee==2.2.1 10 | docutils==0.17.1 11 | cached_property>=1.5.2<2.0 12 | camb>=1.3<2.0 13 | hmf>=3.1<4.0 14 | -e git+https://bitbucket.org/ktausch/distpy/#egg=distpy 15 | -------------------------------------------------------------------------------- /run_tests_local.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Can never remember all the flags 4 | pytest --cov-config=.coveragerc --cov=ares --cov-report=html -v tests/*.py 5 | 6 | rm -f test_*.pkl test_*.txt test_*.hdf5 hmf*.pkl hmf*.hdf5 7 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import print_function 3 | import os 4 | 5 | try: 6 | from setuptools import setup 7 | except ImportError: 8 | from distutils.core import setup 9 | 10 | setup(name='ares', 11 | version='0.1', 12 | description='Accelerated Reionization Era Simulations', 13 | author='Jordan Mirocha', 14 | author_email='mirochaj@gmail.com', 15 | url='https://github.com/mirochaj/ares', 16 | packages=['ares', 'ares.analysis', 'ares.data', 'ares.simulations', 'ares.obs', 17 | 'ares.populations', 'ares.util', 'ares.solvers', 'ares.static', 18 | 'ares.sources', 'ares.physics', 'ares.inference', 'ares.phenom'], 19 | ) 20 | 21 | # Try to set up $HOME/.ares 22 | HOME = os.getenv('HOME') 23 | if not os.path.exists('{!s}/.ares'.format(HOME)): 24 | try: 25 | os.mkdir('{!s}/.ares'.format(HOME)) 26 | except: 27 | pass 28 | 29 | # Create files for defaults and labels in HOME directory 30 | for fn in ['defaults', 'labels']: 31 | if not os.path.exists('{0!s}/.ares/{1!s}.py'.format(HOME, fn)): 32 | try: 33 | f = open('{0!s}/.ares/{1!s}.py'.format(HOME, fn), 'w') 34 | print("pf = {}", file=f) 35 | f.close() 36 | except: 37 | pass 38 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirochaj/ares/fd77c4a86982d25fdad790d717f8bf5eecff4eb8/tests/__init__.py -------------------------------------------------------------------------------- /tests/adv/README: -------------------------------------------------------------------------------- 1 | Note about 'advanced' tests 2 | --------------------------- 3 | Scripts in this folder are either (i) a little expensive, or (ii) rely on non-standard dependencies or lookup tables, which may complicate or lengthen the build. As a result, they are not included in the standard test suite. 4 | -------------------------------------------------------------------------------- /tests/adv/test_gs_4par.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_gs_4par.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Thu May 26 15:53:18 PDT 2016 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | def test(): 17 | 18 | # Use N* parameters 19 | sim_N = ares.simulations.Global21cm(fstar=0.1, fesc=0.1, 20 | Nlw=9690, Nion=4e3, fX=1, problem_type=101) 21 | sim_N.run() 22 | 23 | # Use xi* parameters 24 | sim_x = ares.simulations.Global21cm(xi_UV=40., 25 | xi_LW=969, xi_XR=1e-1, problem_type=101) 26 | sim_x.run() 27 | 28 | for field in sim_N.history: 29 | assert np.allclose(sim_N.history[field], sim_x.history[field]), \ 30 | "Backward compatibility issue w/ field '{!s}'.".format(field) 31 | 32 | if __name__ == '__main__': 33 | test() 34 | -------------------------------------------------------------------------------- /tests/adv/test_gs_crt.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_gs_crt.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Wed May 11 09:46:05 PDT 2016 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | pars = \ 18 | { 19 | 20 | 'pop_sed{1}': 'mcd', 21 | 'pop_alpha{1}': -1.5, 22 | 'pop_Emin{1}': 2e2, 23 | 'pop_Emax{1}': 3e4, 24 | 'pop_EminNorm{1}': 5e2, 25 | 'pop_EmaxNorm{1}': 8e3, 26 | #'pop_logN{1}': -np.inf, 27 | 28 | 'pop_solve_rte{1}': True, 29 | 'pop_tau_Nz{1}': 1e3, 30 | 'pop_approx_tau{1}': 'neutral', 31 | 32 | # Force optically thin to overestimate heating/ionization? 33 | 34 | 'final_redshift': 5, 35 | 'initial_redshift': 50, 36 | 'problem_type': 101.2 37 | } 38 | 39 | ax1 = None; ax2 = None 40 | labels = ['fidicual', 'fiducial+RT', 'fiducial+OTRT'] 41 | for i, solve_rte in enumerate([False, True, True]): 42 | 43 | pars['pop_solve_rte{1}'] = solve_rte 44 | 45 | if i == 2: 46 | pars['pop_approx_tau{1}'] = True 47 | 48 | sim = ares.simulations.Global21cm(**pars) 49 | sim.run() 50 | 51 | ax1 = sim.GlobalSignature(fig=1, label=labels[i], ax=ax1) 52 | ax2 = sim.IonizationHistory(fig=2, ax=ax2) 53 | 54 | ax1.legend(loc='lower right') 55 | pl.show() 56 | 57 | for i in range(1,3): 58 | pl.figure(i) 59 | pl.savefig('{0!s}_{1}.png'.format(__file__.rstrip('.py'), i)) 60 | #pl.close() 61 | -------------------------------------------------------------------------------- /tests/adv/test_gs_fcoll.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_21cm_basic.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Mon Oct 1 15:23:53 2012 8 | 9 | Description: Make sure the global 21-cm signal calculator works. 10 | 11 | """ 12 | 13 | import ares 14 | import matplotlib.pyplot as pl 15 | 16 | def test(): 17 | 18 | sim = ares.simulations.Global21cm(verbose=False, progress_bar=False) 19 | sim.run() 20 | sim.GlobalSignature() 21 | 22 | pl.savefig('{!s}.png'.format(__file__.rstrip('.py'))) 23 | pl.close() 24 | 25 | assert True 26 | 27 | if __name__ == '__main__': 28 | test() 29 | 30 | -------------------------------------------------------------------------------- /tests/adv/test_gs_lfcal.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_gs_lfcal.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Thu Feb 23 15:54:29 PST 2017 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import matplotlib.pyplot as pl 15 | 16 | def test(): 17 | pars = ares.util.ParameterBundle('mirocha2016:dpl') 18 | 19 | # minimal build doesn't include 1000-element tau table, need to downgrade 20 | pars['initial_redshift'] = 50 21 | pars['pop_tau_Nz{0}'] = 400 22 | 23 | sim = ares.simulations.Global21cm(**pars) 24 | sim.run() 25 | sim.GlobalSignature() 26 | 27 | pl.savefig('{!s}.png'.format(__file__.rstrip('.py'))) 28 | pl.close() 29 | 30 | assert True 31 | 32 | if __name__ == '__main__': 33 | test() 34 | -------------------------------------------------------------------------------- /tests/adv/test_mc_repeat.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_parallel_grid.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Fri Jul 7 15:02:45 PDT 2017 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import sys 14 | import ares 15 | import numpy as np 16 | from mpi4py import MPI 17 | 18 | rank = MPI.COMM_WORLD.rank 19 | size = MPI.COMM_WORLD.size 20 | 21 | prefix = sys.argv[1] 22 | seed = int(sys.argv[2]) 23 | 24 | blobs = ares.util.BlobBundle('gs:basics') 25 | base_kwargs = {'tanh_model': True, 'problem_type': 101} 26 | base_kwargs.update(blobs) 27 | 28 | ps = ares.inference.PriorSet() 29 | ps.add_prior(ares.inference.Priors.UniformPrior(0, 3), 'tanh_T0') 30 | ps.add_prior(ares.inference.Priors.UniformPrior(6, 20.), 'tanh_Tz0') 31 | ps.add_prior(ares.inference.Priors.UniformPrior(0.1, 10.), 'tanh_Tdz') 32 | 33 | mc = ares.inference.ModelSample(**base_kwargs) 34 | 35 | mc.prior_set = ps 36 | mc.N = 1e2 # Number of models to run 37 | mc.save_by_proc = True 38 | mc.is_log = {'tanh_T0': True} 39 | mc.seed = seed 40 | 41 | mc.run(prefix, clobber=True, restart=False) 42 | 43 | # Should also test restart etc. 44 | # If seed is provided, restart should run *up to* N models, not N more. 45 | 46 | 47 | -------------------------------------------------------------------------------- /tests/adv/test_mc_repeat.sh: -------------------------------------------------------------------------------- 1 | mpirun -np 4 python test_mc_repeat.py test_mc_1 1234 2 | mpirun -np 4 python test_mc_repeat.py test_mc_2 1234 3 | mpirun -np 4 python test_mc_repeat.py test_mc_3 2468 4 | python test_mc_repeat_results.py 5 | -------------------------------------------------------------------------------- /tests/adv/test_mc_repeat_results.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_parallel_grid_results.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Tue Jul 11 13:01:19 PDT 2017 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | files = ['test_mc_1', 'test_mc_2', 'test_mc_3'] 17 | 18 | for i, prefix in enumerate(files): 19 | anl = ares.analysis.ModelSet(prefix) 20 | 21 | z_C_now = anl.ExtractData('z_C')['z_C'].data 22 | if i > 0: 23 | z_C_pre = z_C_now 24 | z_C_now = anl.ExtractData('z_C')['z_C'].data 25 | else: 26 | continue 27 | 28 | if i <= 1: 29 | assert np.allclose(z_C_pre, z_C_now), \ 30 | "Detected difference between {!s}*.pkl and previous!".format(prefix) 31 | else: 32 | assert np.allclose(z_C_pre, z_C_now), \ 33 | "{!s}*.pkl should be different!".format(prefix) 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /tests/adv/test_parallel_grid.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_parallel_grid.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Fri Jul 7 15:02:45 PDT 2017 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import sys 14 | import ares 15 | import numpy as np 16 | from mpi4py import MPI 17 | 18 | rank = MPI.COMM_WORLD.rank 19 | size = MPI.COMM_WORLD.size 20 | 21 | 22 | prefix = sys.argv[1] 23 | exit = int(sys.argv[2]) 24 | 25 | blobs = ares.util.BlobBundle('gs:basics') 26 | 27 | base_kwargs = {'tanh_model': True, 'problem_type': 101} 28 | base_kwargs.update(blobs) 29 | 30 | mg = ares.inference.ModelGrid(**base_kwargs) 31 | 32 | z0 = np.arange(6, 13, 1) 33 | dz = np.arange(1, 9, 1) 34 | 35 | mg.axes = {'tanh_xz0': z0, 'tanh_xdz': dz} 36 | 37 | mg.checkpoint_by_proc = True 38 | mg.LoadBalance() 39 | 40 | freq = int((mg.grid.size * 0.5) / size) 41 | 42 | mg.run(prefix, clobber=False, restart=True, save_freq=freq, exit_after=exit) 43 | 44 | 45 | -------------------------------------------------------------------------------- /tests/adv/test_parallel_grid.sh: -------------------------------------------------------------------------------- 1 | mpirun -np 2 python test_parallel_grid.py order_2_4 1 2 | mpirun -np 4 python test_parallel_grid.py order_2_4 1000 3 | 4 | mpirun -np 4 python test_parallel_grid.py order_4_2 1 5 | mpirun -np 2 python test_parallel_grid.py order_4_2 1000 6 | 7 | mpirun -np 2 python test_parallel_grid.py order_2_2 1 8 | mpirun -np 2 python test_parallel_grid.py order_2_2 1000 9 | 10 | mpirun -np 4 python test_parallel_grid.py order_4_4 1 11 | mpirun -np 4 python test_parallel_grid.py order_4_4 1000 12 | 13 | mpirun -np 4 python test_parallel_grid.py order_4 1000 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/adv/test_parallel_grid_results.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_parallel_grid_results.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Tue Jul 11 13:01:19 PDT 2017 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | files = ['order_2_2', 'order_4_4', 'order_2_4', 'order_4_2', 'order_4'] 17 | 18 | for i, prefix in enumerate(files): 19 | anl = ares.analysis.ModelSet(prefix) 20 | 21 | 22 | z_C_now = anl.ExtractData('z_C')['z_C'].data 23 | if i > 0: 24 | z_C_pre = z_C_now 25 | z_C_now = anl.ExtractData('z_C')['z_C'].data 26 | else: 27 | continue 28 | 29 | assert np.allclose(z_C_pre, z_C_now), \ 30 | "Detected difference between {!s}*.pkl and previous!".format(prefix) 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /tests/adv/test_physics_hmf.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_hmf_PS.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Fri May 3 16:03:57 2013 8 | 9 | Description: Use Press-Schechter mass function to test numerical integration, 10 | since PS has an analytic solution for the collapsed fraction. 11 | 12 | """ 13 | 14 | import ares 15 | import numpy as np 16 | 17 | def test(rtol=1e-2): 18 | 19 | # Two HMFs: one analytic, one numerical 20 | hmf_a = ares.populations.HaloPopulation(hmf_model='PS', hmf_analytic=True, 21 | pop_Mmin=1e8) 22 | hmf_n = ares.populations.HaloPopulation(hmf_model='PS', hmf_analytic=False, 23 | hmf_load=True, pop_Mmin=1e8) 24 | 25 | ok = True 26 | for i, z in enumerate([5, 10, 15, 20]): 27 | 28 | fcoll_a = hmf_a.halos.fcoll_tab[np.argmin(np.abs(z-hmf_a.halos.z))] 29 | 30 | try: 31 | fcoll_n = hmf_n.halos.fcoll_tab[np.argmin(np.abs(z-hmf_a.halos.z))] 32 | except AttributeError: 33 | fcoll_n = hmf_n.halos.fcoll(z, hmf_a.halos.logM) 34 | 35 | # Limit to intermediate mass range 36 | mask = np.logical_and(hmf_a.halos.M >= 1e8, hmf_a.halos.M <= 1e11) 37 | 38 | ok_z = np.allclose(fcoll_n[mask], fcoll_a[mask], rtol=rtol, atol=0) 39 | 40 | if not ok_z: 41 | ok = False 42 | break 43 | 44 | assert ok, "Relative error between analytical and numerical solutions exceeds {:.3g}.".format(rtol) 45 | 46 | if __name__ == '__main__': 47 | test() 48 | 49 | -------------------------------------------------------------------------------- /tests/adv/test_pop_galaxy.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_galaxy.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Tue May 26 14:32:20 MDT 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | from ares.physics.Constants import cm_per_mpc, erg_per_ev, s_per_yr 17 | 18 | def test(): 19 | 20 | z = np.arange(10, 25) 21 | 22 | # Initialize a GalaxyPopulation 23 | pop = ares.populations.GalaxyPopulation(pop_sed='pl', pop_Emin=2e2, 24 | pop_Emax=1e4, pop_EminNorm=5e2, pop_EmaxNorm=8e3, pop_fX=1.0, 25 | pop_yield=2.6e39, pop_yield_units='erg/s/SFR') 26 | 27 | # Compute the luminosity density in two bands 28 | Lx1 = np.array(list(map(pop.LuminosityDensity, z))) * cm_per_mpc**3 29 | Lx2 = np.array([pop.LuminosityDensity(zz, 2e2, 5e2) for zz in z]) * cm_per_mpc**3 30 | 31 | # Plot 'em 32 | pl.semilogy(z, Lx1, color='k') 33 | pl.semilogy(z, Lx2, color='b') 34 | 35 | # Try again with different units 36 | erg_per_phot = pop.src.AveragePhotonEnergy(500., 8e3) * erg_per_ev 37 | y = 2.6e39 * s_per_yr / erg_per_phot 38 | pop = ares.populations.GalaxyPopulation(pop_sed='pl', pop_Emin=2e2, 39 | pop_Emax=1e4, pop_EminNorm=5e2, pop_EmaxNorm=8e3, pop_fX=1.0, 40 | pop_yield=y, pop_yield_units='photons/Msun') 41 | 42 | # Compute the luminosity density in two bands 43 | Lx1 = np.array(list(map(pop.LuminosityDensity, z))) * cm_per_mpc**3 44 | Lx2 = np.array([pop.LuminosityDensity(zz, 2e2, 5e2) for zz in z]) * cm_per_mpc**3 45 | 46 | # Plot 'em 47 | pl.scatter(z, Lx1, s=100, facecolors='none', color='k') 48 | pl.scatter(z, Lx2, s=100, facecolors='none', color='b') 49 | 50 | assert True 51 | 52 | if __name__ == '__main__': 53 | test() 54 | 55 | -------------------------------------------------------------------------------- /tests/adv/test_pop_sfrd.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_pop_models.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Fri Jul 15 15:23:11 PDT 2016 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import matplotlib.pyplot as pl 15 | 16 | PB = ares.util.ParameterBundle 17 | 18 | def test(): 19 | 20 | # Create a simple population 21 | pars_1 = PB('pop:fcoll') + PB('sed:bpass') 22 | pop_fcoll = ares.populations.GalaxyPopulation(**pars_1) 23 | #pop_fcoll_XR = ares.populations.GalaxyPopulation(**pars_1) 24 | 25 | # Mimic the above population to check our different SFRD/SED techniques 26 | sfrd_pars = {'pop_sfr_model': 'sfrd-func'} 27 | sfrd_pars['pop_sfrd'] = pop_fcoll.SFRD 28 | sfrd_pars['pop_sfrd_units'] = 'internal' 29 | 30 | sed = PB('sed:toy') 31 | sed['pop_Nion'] = pop_fcoll.src.Nion 32 | sed['pop_Nlw'] = pop_fcoll.src.Nlw 33 | # pop_Ex? 34 | sed['pop_ion_src_igm'] = False 35 | sed['pop_heat_src_igm'] = False 36 | 37 | pars_2 = sed + sfrd_pars 38 | 39 | pop_sfrd = ares.populations.GalaxyPopulation(**pars_2) 40 | 41 | assert pop_fcoll.SFRD(20.) == pop_sfrd.SFRD(20.), "Error in SFRD." 42 | 43 | # Check the emissivities too 44 | 45 | #print(pop_fcoll.PhotonLuminosityDensity(20., Emin=10.2, Emax=13.6)) 46 | #print(pop_sfrd.PhotonLuminosityDensity(20., Emin=10.2, Emax=13.6)) 47 | 48 | #assert pop_fcoll.PhotonLuminosityDensity(20., Emin=10.2, Emax=13.6) \ 49 | # == pop_sfrd.PhotonLuminosityDensity(20., Emin=10.2, Emax=13.6), \ 50 | # "Error in photon luminosity density." 51 | 52 | if __name__ == '__main__': 53 | test() 54 | 55 | 56 | -------------------------------------------------------------------------------- /tests/adv/test_sed_simpl.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sed_mcd.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Thu May 11 09:39:08 CDT 2017 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import time 15 | import numpy as np 16 | import matplotlib.pyplot as pl 17 | 18 | mcd = \ 19 | { 20 | 'source_type': 'bh', 21 | 'source_mass': 10, 22 | 'source_rmax': 1e2, 23 | 'source_sed': 'mcd', 24 | 'source_Emin': 10, 25 | 'source_Emax': 5e4, 26 | 'source_EminNorm': 500., 27 | 'source_EmaxNorm': 8e3, 28 | 'source_alpha': -1.5, 29 | 'source_fsc': 0.9, 30 | } 31 | 32 | simpl = mcd.copy() 33 | simpl['source_sed'] = 'simpl' 34 | 35 | E = np.logspace(0, 4.5) 36 | 37 | src = ares.sources.BlackHole(**mcd) 38 | pl.loglog(E, list(map(src.Spectrum, E)), color='k') 39 | 40 | ls = [':', '--', '-'] 41 | colors = ['m', 'c', 'b', 'k'] 42 | for i, alpha in enumerate([-1, 0., 0.5]): 43 | for j, fsc in enumerate([0.1, 0.5, 0.9]): 44 | 45 | simpl['source_alpha'] = alpha 46 | simpl['source_fsc'] = fsc 47 | 48 | src2 = ares.sources.BlackHole(**simpl) 49 | 50 | t1 = time.time() 51 | pl.loglog(E, list(map(src2.Spectrum, E)), color=colors[j], ls=ls[i]) 52 | t2 = time.time() 53 | print('simpl took {:.2g} sec'.format(t2 - t1)) 54 | 55 | pl.xlim(10, 3e4) 56 | pl.ylim(1e-6, 1e-3) 57 | pl.xlabel(r'$h\nu / \mathrm{eV}$') 58 | pl.ylabel(r'$I_{\nu}$') 59 | pl.savefig('mcd_vs_simpl.png') 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /tests/adv/test_setup_pbundles.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_setup_pbundles.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Mon Jun 13 11:59:46 PDT 2016 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | 15 | pop1 = ares.util.ParameterBundle('pop:sfe') 16 | pop2 = ares.util.ParameterBundle('pop:fcoll') 17 | 18 | pop1.num = 0 19 | pop2.num = 1 20 | 21 | sed = ares.util.ParameterBundle('sed:bpass') 22 | 23 | pf = pop1 + sed 24 | 25 | assert pf - pop1 == sed, 'Error in subtraction of ParameterBundle.' 26 | -------------------------------------------------------------------------------- /tests/adv/test_solver_chem_he.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_chemistry_hydrogen.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Mon Feb 16 12:50:43 MST 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | def test(): 18 | pf = \ 19 | { 20 | 'grid_cells': 64, 21 | 'include_He': True, 22 | 'isothermal': True, 23 | 'stop_time': 1e2, 24 | 'radiative_transfer': False, 25 | 'density_units': 1.0, 26 | 'initial_timestep': 1, 27 | 'max_timestep': 1e2, 28 | 'initial_temperature': np.logspace(4, 6, 64), 29 | 'initial_ionization': [1.-1e-8, 1e-8, 1-2e-8, 1e-8, 1e-8], # neutral 30 | } 31 | 32 | sim = ares.simulations.GasParcel(**pf) 33 | sim.run() 34 | 35 | data = sim.history 36 | 37 | # Plot last time snapshot 38 | pl.loglog(data['Tk'][0], data['h_1'][-1,:], color='k') 39 | pl.loglog(data['Tk'][0], data['h_2'][-1,:], color='k', ls='--') 40 | 41 | pl.loglog(data['Tk'][0], data['he_1'][-1,:], color='b') 42 | pl.loglog(data['Tk'][0], data['he_2'][-1,:], color='b', ls='--') 43 | pl.loglog(data['Tk'][0], data['he_3'][-1,:], color='b', ls=':') 44 | pl.ylim(1e-8, 1) 45 | 46 | pl.savefig('{!s}.png'.format(__file__.rstrip('.py'))) 47 | pl.close() 48 | 49 | if __name__ == '__main__': 50 | test() 51 | -------------------------------------------------------------------------------- /tests/adv/test_src_bpass.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sed_bpass.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Wed Jun 22 16:57:19 PDT 2016 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | # Test metallicity interpolation, energy interpolation at fixed tsf 17 | def test(): 18 | # Test metallicity interpolation 19 | pop1 = ares.sources.SynthesisModel(source_sed='eldridge2009', source_Z=0.02) 20 | pop2 = ares.sources.SynthesisModel(source_sed='eldridge2009', source_Z=0.03) 21 | pop3 = ares.sources.SynthesisModel(source_sed='eldridge2009', source_Z=0.04) 22 | 23 | for i, E in enumerate([1,5,10,20]): 24 | fnu = np.array([pop1.Spectrum(E), pop3.Spectrum(E)]) 25 | mi, ma = min(fnu), max(fnu) 26 | assert mi <= pop2.Spectrum(E) <= ma, \ 27 | 'Error in spectrum/metallicity interpolation!' 28 | 29 | if __name__ == '__main__': 30 | test() 31 | -------------------------------------------------------------------------------- /tests/broken/test_cxrb_helium.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_cxrb_helium.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Fri May 24 13:07:09 2013 8 | 9 | Description: Include helium opacity. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | # Redshift regime 18 | zi, zf = (10, 40) 19 | 20 | # Initialize radiation background 21 | pars = \ 22 | { 23 | 'pop_sfrd': lambda z: 1e-2 / (1. + z)**3., 24 | 'pop_sfrd_units': 'msun/yr/mpc^3', 25 | 'source_type': 'bh', 26 | 'spectrum_type': 'pl', 27 | 'spectrum_alpha': -1.5, 28 | 'spectrum_Emin': 2e2, 29 | 'spectrum_Emax': 3e4, 30 | 'spectrum_EminNorm': 2e2, 31 | 'spectrum_EmaxNorm': 3e4, 32 | 'approx_xrb': False, 33 | 'initial_redshift': zi, 34 | 'final_redshift': zf, 35 | 'redshift_bins': 400, 36 | } 37 | 38 | pars2 = pars.copy(); pars2.update({'approx_He': 1, 'include_He': 1}) 39 | 40 | rad_h = ares.solvers.UniformBackground(**pars) 41 | rad_he = ares.solvers.UniformBackground(**pars2) 42 | 43 | E = np.logspace(2, 4) 44 | 45 | flux_h = list(map(lambda E: rad_h.AngleAveragedFlux(10, E, xavg=lambda z: 0.0), E)) 46 | flux_he = list(map(lambda E: rad_he.AngleAveragedFlux(10, E, xavg=lambda z: 0.0), E)) 47 | 48 | pl.loglog(E, flux_h, color='k', label='H-only') 49 | pl.loglog(E, flux_he, color='b', label='H+He') 50 | pl.xlabel(ares.util.labels['E']) 51 | pl.ylabel(ares.util.labels['flux']) 52 | pl.legend(loc='best', frameon=False) 53 | pl.title('X-ray Background at z = {:g}'.format(zi)) 54 | pl.ylim(1e-30, 1e-18) 55 | -------------------------------------------------------------------------------- /tests/broken/test_generator_uvb_qso.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_generator_xrb.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Fri Jun 14 09:20:22 2013 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import numpy as np 14 | import os, sys, ares 15 | import matplotlib.pyplot as pl 16 | from ares.physics.Constants import erg_per_ev 17 | 18 | zi, zf = (6, 3.) 19 | 20 | # Initialize radiation background 21 | src_pars = \ 22 | { 23 | # Source properties 24 | 'pop_type': 'galaxy', 25 | 'pop_sed': 'sazonov2004', 26 | 'pop_rhoL': 'ueda2003', 27 | 'pop_kwargs': {'evolution': 'ple'}, 28 | 29 | #'pop_alpha': 1.0, 30 | 'pop_Emin': 1.0, 31 | 'pop_Emax': 5e4, 32 | 'pop_EminNorm': 2e3, 33 | 'pop_EmaxNorm': 1e4, 34 | 35 | # Solution method 36 | 'pop_solve_rte': True, 37 | 'pop_tau_Nz': 100, 38 | 'include_H_Lya': False, 39 | 40 | 'sawtooth_nmax': 8, 41 | 42 | 'initial_redshift': zi, 43 | 'final_redshift': zf, 44 | } 45 | 46 | rad1 = ares.simulations.MetaGalacticBackground(pop_sawtooth=True, 47 | approx_tau=True, **src_pars) 48 | 49 | # Compute background flux 50 | rad1.run() 51 | 52 | # Grab background flux from Haardt & Madau (2012) 53 | hm12 = ares.util.read_lit('haardt2012') 54 | z, E, flux = hm12.MetaGalacticBackground() 55 | 56 | # Plot it at z=3 57 | ax = None 58 | colors = 'k', 'b', 'r' 59 | for i, rad in enumerate([rad1]): 60 | anl = ares.analysis.MetaGalacticBackground(rad) 61 | ax = anl.PlotBackground(z=3, ax=ax, color=colors[i]) 62 | 63 | j = np.argmin(np.abs(z - 3.)) 64 | ax.plot(E, flux[j] / 1e-21, color='c') 65 | 66 | ax.set_xlim(1, 4e3) 67 | ax.set_ylim(1e-5, 2e2) 68 | ax.set_title(r'$z=3$') 69 | pl.draw() 70 | 71 | -------------------------------------------------------------------------------- /tests/broken/test_mpm.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_multi_phase.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Sat Feb 21 11:55:00 MST 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | pars = \ 18 | { 19 | 'pop_type': 'galaxy', 20 | 'pop_sfrd': 'robertson2015', 21 | 'pop_sed': 'pl', 22 | 'pop_alpha': 1.0, 23 | 'pop_Emin': 13.6, 24 | 'pop_Emax': 24.6, 25 | 'pop_EminNorm': 13.6, 26 | 'pop_EmaxNorm': 24.6, 27 | 'pop_fesc': 0.2, 28 | 'pop_yield': 1e57, 29 | 'pop_yield_units': 'photons/msun', 30 | 'photon_counting': True, 31 | 32 | 'include_igm': False, 33 | 'initial_redshift': 40., 34 | 'final_redshift': 5., 35 | } 36 | 37 | sim = ares.simulations.MultiPhaseMedium(**pars) 38 | sim.run() 39 | 40 | pl.semilogy(sim.history['z'], sim.history['cgm_h_2']) 41 | pl.xlim(5, 50) 42 | -------------------------------------------------------------------------------- /tests/broken/test_mpm_w_mgb.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_mpm_w_mgb.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Mon Mar 23 09:35:41 MDT 2015 8 | 9 | Description: Test the evolution of a MultiPhaseMedium using ionization and 10 | heating rates induced by a MetaGalacticBackground (hence, mpm_w_mgb). 11 | 12 | """ 13 | 14 | import ares 15 | import numpy as np 16 | import matplotlib.pyplot as pl 17 | 18 | pars = \ 19 | { 20 | 'pop_type': 'galaxy', 21 | 'pop_sed': 'pl', 22 | 'pop_alpha': -1.5, 23 | 'pop_Emin': 2e2, 24 | 'pop_Emax': 3e4, 25 | 'pop_EminNorm': 5e2, 26 | 'pop_EmaxNorm': 8e3, 27 | 'pop_yield': 2.6e39, 28 | 'pop_yield_units': 'erg/s/sfr', 29 | 30 | 'pop_solve_rte': True, 31 | 'pop_tau_Nz': 400, 32 | 33 | 'include_cgm': False, 34 | 'initial_redshift': 40., 35 | 'final_redshift': 10., 36 | 'secondary_ionization': 1, 37 | 38 | #'is_ion_src_cgm': False, 39 | #'include_He': False, 40 | } 41 | 42 | ax1 = None; ax2 = None 43 | labels = ['optically thin', 'neutral IGM'] 44 | for i, tau_approx in enumerate([True, 'neutral']): 45 | 46 | pars['pop_approx_tau'] = tau_approx 47 | 48 | sim = ares.simulations.MultiPhaseMedium(**pars) 49 | sim.run() 50 | 51 | anl = ares.analysis.MultiPhaseMedium(sim) 52 | ax1 = anl.TemperatureHistory(ax=ax1, label=labels[i]) 53 | 54 | ax2 = anl.IonizationHistory(zone='igm', element='h', fig=2, 55 | label=labels[i], ax=ax2) 56 | 57 | pl.legend() 58 | pl.show() 59 | -------------------------------------------------------------------------------- /tests/broken/test_patch_cgm.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_multi_phase.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Sat Feb 21 11:55:00 MST 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | pars = \ 18 | { 19 | 'pop_type': 'galaxy', 20 | 'pop_sfrd': 'robertson2015', 21 | 'pop_Emin': 13.6, 22 | 'pop_Emax': 24.6, 23 | 'pop_EminNorm': 13.6, 24 | 'pop_EmaxNorm': 24.6, 25 | 'pop_yield': 1e54, 26 | 'pop_yield_units': 'photons/s/sfr', 27 | 'pop_heat_src_igm': False, 28 | 'pop_ion_src_igm': False, 29 | 'initial_redshift': 30., 30 | 'final_redshift': 4., 31 | 'include_igm': False, 32 | 'cgm_initial_temperature': 2e4, 33 | 'clumping_factor': 3., 34 | } 35 | 36 | sim = ares.simulations.MultiPhaseMedium(**pars) 37 | sim.run() 38 | 39 | pl.plot(sim.history['z'], sim.history['cgm_h_1']) 40 | pl.xlim(4.5, 30) 41 | pl.ylim(1e-4, 1) 42 | pl.ylabel(r'$1 - Q_{\mathrm{HII}}$') 43 | pl.xlabel(r'$z$') 44 | 45 | -------------------------------------------------------------------------------- /tests/broken/test_patch_igm.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_multi_phase.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Sat Feb 21 11:55:00 MST 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | pars = \ 18 | { 19 | 'pop_type': 'galaxy', 20 | 'pop_sfrd': 'robertson2015', 21 | 'pop_sed': 'pl', 22 | 'pop_alpha': -1.5, 23 | 'pop_Emin': 2e2, 24 | 'pop_Emax': 3e4, 25 | 'pop_EminNorm': 5e2, 26 | 'pop_EmaxNorm': 8e3, 27 | 'pop_yield': 2.6e39, 28 | 'pop_yield_units': 'erg/s/sfr', 29 | 'pop_heat_src_igm': True, 30 | 'pop_ion_src_igm': True, 31 | 32 | 'initial_redshift': 40., 33 | 'final_redshift': 6., 34 | 'include_cgm': False, 35 | } 36 | 37 | sim = ares.simulations.MultiPhaseMedium(**pars) 38 | sim.run() 39 | 40 | mp = ares.analysis.MultiPanel(dims=(2,1)) 41 | 42 | mp.grid[0].semilogy(sim.history['z'], sim.history['igm_Tk']) 43 | mp.grid[1].semilogy(sim.history['z'], sim.history['igm_h_2']) 44 | 45 | for i in range(2): 46 | mp.grid[i].set_xlim(4.5, 50) 47 | 48 | mp.grid[1].set_ylim(1e-10, 1.) 49 | mp.fix_ticks() 50 | pl.draw() 51 | -------------------------------------------------------------------------------- /tests/broken/test_tau_dynamic.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_tau_dynamic.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Mon Jul 13 12:46:56 MDT 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | import matplotlib.pyplot as pl 16 | 17 | pars = \ 18 | { 19 | 'pop_type': 'galaxy', 20 | 'pop_sed': 'pl', 21 | 'pop_alpha': -1.5, 22 | 'pop_Emin': 2e2, 23 | 'pop_Emax': 3e4, 24 | 'pop_EminNorm': 5e2, 25 | 'pop_EmaxNorm': 8e3, 26 | 'pop_yield': 2.6e39, 27 | 'pop_yield_units': 'erg/s/sfr', 28 | 29 | 'pop_solve_rte': True, 30 | 'pop_tau_Nz': 400, 31 | 32 | 'include_cgm': False, 33 | 'initial_redshift': 40., 34 | 'final_redshift': 10., 35 | 'secondary_ionization': 1, 36 | 37 | } 38 | 39 | ax1 = None; ax2 = None 40 | labels = ['optically thin', 'neutral IGM', 'evolving IGM'] 41 | for i, tau_approx in enumerate([True, 'neutral', False]): 42 | 43 | pars['approx_tau'] = tau_approx 44 | 45 | sim = ares.simulations.MultiPhaseMedium(**pars) 46 | sim.run() 47 | 48 | anl = ares.analysis.MultiPhaseMedium(sim) 49 | ax1 = anl.TemperatureHistory(ax=ax1, label=labels[i]) 50 | 51 | ax2 = anl.IonizationHistory(zone='igm', element='h', fig=2, 52 | label=labels[i], ax=ax2) 53 | 54 | pl.legend() 55 | pl.show() 56 | -------------------------------------------------------------------------------- /tests/test_analysis_gs_extrema.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_21cm_extrema.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Tue May 6 18:10:46 MDT 2014 8 | 9 | Description: Make sure our extrema-finding routines work. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | from ares.physics.Constants import nu_0_mhz 16 | 17 | def test(): 18 | 19 | sim = ares.simulations.Global21cm(gaussian_model=True, gaussian_nu=70., 20 | gaussian_A=-100.) 21 | sim.run() 22 | 23 | # In this case, we know exactly where C happens 24 | absorption_OK = np.allclose(nu_0_mhz / (1. + sim.turning_points['C'][0]), 25 | sim.pf['gaussian_nu']) 26 | absorption_OK = np.allclose(sim.turning_points['C'][1], 27 | sim.pf['gaussian_A'], rtol=1e-3, atol=1e-3) 28 | 29 | no_nonsense = 1 30 | 31 | # Check to make sure no turning points are absurd 32 | things = ['redshift', 'amplitude', 'curvature'] 33 | for tp in list('BCD'): 34 | if tp not in sim.turning_points: 35 | continue 36 | 37 | for i, element in enumerate(sim.turning_points[tp]): 38 | 39 | if -500 <= element <= 100: 40 | continue 41 | 42 | print('Absurd turning point! {0!s} of {1!s}'.format(things[i], element)) 43 | no_nonsense *= 0 44 | 45 | # Now, check the turning-point-finding on the tanh model 46 | # Test sensitivity to frequency sampling 47 | for dnu in [0.05, 0.1, 0.5, 1]: 48 | freq = np.arange(40, 120+dnu, dnu) 49 | sim = ares.simulations.Global21cm(tanh_model=True, 50 | output_frequencies=freq) 51 | 52 | # Everything good? 53 | assert absorption_OK and no_nonsense 54 | 55 | if __name__ == "__main__": 56 | test() 57 | -------------------------------------------------------------------------------- /tests/test_obs_survey.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | tests/test_obs_survey.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill University 7 | Created on: Tue 21 Dec 2021 14:38:11 EST 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import numpy as np 14 | from ares.obs import Survey, get_filters_from_waves 15 | 16 | def test(): 17 | hst = Survey(cam='hst') 18 | 19 | zarr = [4, 5, 6, 7, 8, 10] 20 | drops = ['F435W', 'F606W', 'F775W', 'F850LP', 'F105W', 'F125W'] 21 | for (z, drop) in zip(zarr, drops): 22 | 23 | fred, fblu = hst.get_dropout_filter(z, 24 | drop_wave=912. if z < 6 else 1216., skip=['F110W']) 25 | 26 | assert fred == drop, \ 27 | "Dropout filter at z={} should be {}, got {}".format(z, drop, fred) 28 | 29 | # Make sure we can recover filters over range in wavelength. 30 | hst_filt = hst.read_throughputs(filters='all') 31 | filt_p = get_filters_from_waves(z, hst_filt, picky=True) 32 | filt_np = get_filters_from_waves(z, hst_filt, picky=False) 33 | 34 | assert len(filt_p) <= len(filt_np), "{}, {}".format(filt_p, filt_np) 35 | 36 | if __name__ == '__main__': 37 | test() 38 | -------------------------------------------------------------------------------- /tests/test_physics_HI_beta.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_physics_HI_beta.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Fri Sep 23 15:58:34 PDT 2016 8 | 9 | Description: Make a plot like in Furlanetto, Oh, & Briggs (2006) 10 | Figure 9. Just use a tanh model because it's fast. 11 | 12 | """ 13 | 14 | import ares 15 | import numpy as np 16 | 17 | def test(): 18 | 19 | hydr = ares.physics.Hydrogen() 20 | 21 | # Just to get reasonable histories 22 | sim = ares.simulations.Global21cm(tanh_model=True, 23 | output_redshifts=np.linspace(4, 100), interp_cc='linear') 24 | 25 | z = sim.history['z'] 26 | Tk = sim.history['igm_Tk'] 27 | xHI = 1. - sim.history['cgm_h_2'] 28 | Ja = sim.history['Ja'] 29 | ne = (1. - sim.history['igm_h_1']) * hydr.cosm.nH(z) 30 | 31 | beta_d = hydr.beta_d(z, Tk, 1.-xHI, ne, Ja) 32 | beta_x = hydr.beta_x(z, Tk, 1.-xHI, ne, Ja) 33 | beta_z = hydr.beta_a(z, Tk, 1.-xHI, ne, Ja) 34 | beta_T = hydr.beta_T(z, Tk, 1.-xHI, ne, Ja) 35 | 36 | assert True 37 | 38 | if __name__ == '__main__': 39 | test() 40 | -------------------------------------------------------------------------------- /tests/test_physics_HI_cc.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_physics_collisional_coupling.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Fri Nov 9 16:01:47 2012 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import numpy as np 14 | from ares.physics import Hydrogen 15 | 16 | def test(): 17 | 18 | hydr = Hydrogen(interp_cc='cubic') 19 | hydr2 = Hydrogen(interp_cc='linear') 20 | 21 | # Relevant temperature range + a little bit to make sure our interpolation 22 | # bounds are obeyed. 23 | T = np.logspace(-0.5, 4.5, 500) 24 | 25 | ok = 1 26 | for suffix in ['H', 'e']: 27 | 28 | tab = hydr.tabulated_coeff['kappa_{!s}'.format(suffix)] 29 | 30 | if suffix == 'H': 31 | interp = hydr.kappa_H(hydr.tabulated_coeff['T_{!s}'.format(suffix)]) 32 | else: 33 | interp = hydr.kappa_e(hydr.tabulated_coeff['T_{!s}'.format(suffix)]) 34 | 35 | # Numbers small so ignore absolute tolerance 36 | ok *= np.allclose(tab, interp, atol=0.0) 37 | 38 | assert ok, "Error in computation of coupling coefficients." 39 | 40 | # Also check extrapolation 41 | # If off, should just use last value in table 42 | Tlo = hydr.tabulated_coeff['T_H'].min() 43 | assert hydr.kappa_H(Tlo) == hydr.kappa_H(Tlo / 2.) 44 | assert hydr.kappa_e(Tlo) == hydr.kappa_e(Tlo / 2.) 45 | 46 | hydr_e = Hydrogen(extrapolate_coupling=True) 47 | assert hydr_e.kappa_H(Tlo) > hydr_e.kappa_H(Tlo / 2.) 48 | assert hydr_e.kappa_H(Tlo) > hydr_e.kappa_H(Tlo / 2.) 49 | 50 | if __name__ == '__main__': 51 | test() 52 | -------------------------------------------------------------------------------- /tests/test_physics_HI_lya.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_physics_HI_lya.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill University 7 | Created on: Mon 14 Feb 2022 15:24:50 EST 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import numpy as np 14 | from ares.physics import Hydrogen 15 | from ares.simulations import Global21cm 16 | 17 | def test(): 18 | 19 | Tarr = np.logspace(-1, 2) 20 | 21 | hydr = Hydrogen(approx_Salpha=0) 22 | 23 | z = 22. 24 | Tk = 10. 25 | xHII = 2.19e-4 26 | x = np.arange(-100, 100) 27 | 28 | Jc = np.array([hydr.get_lya_profile(z, Tk, xx, continuum=1, xHII=xHII) \ 29 | for xx in x]) 30 | Ji = np.array([hydr.get_lya_profile(z, Tk, xx, continuum=0, xHII=xHII) \ 31 | for xx in x]) 32 | 33 | Ji_norm = Ji * Jc[x==0] 34 | Ji_norm[x < 0] = Jc[x < 0] 35 | 36 | Ic = hydr.get_lya_EW(z, Tk, continuum=1) 37 | Ii = hydr.get_lya_EW(z, Tk, continuum=0) 38 | 39 | # Compare to Mittal & Kulkarni (2021) who actually quote numbers :) 40 | # Be lenient since we have different cosmologies. 41 | assert abs(Ic - 20.11) < 1 42 | assert abs(Ii - -5.75) < 1 43 | 44 | heat = hydr.get_lya_heating(z, Tk, Jc=1e-12, Ji=1e-13) 45 | 46 | # Compare to FP06 approximation, eventually Chuzhoy & Shapiro 47 | hydr_fp06 = Hydrogen(approx_Salpha=3) 48 | hydr_mk21 = Hydrogen(approx_Salpha=5) 49 | 50 | heat_fp06 = hydr_fp06.get_lya_heating(z, Tk, Jc=1e-12, Ji=1e-13) 51 | heat_mk21 = hydr_mk21.get_lya_heating(z, Tk, Jc=1e-12, Ji=1e-13) 52 | 53 | assert abs(heat_fp06 - heat) / heat < 0.1 54 | assert abs(heat_mk21 - heat) / heat < 0.1 55 | 56 | Ii_fp06 = hydr_fp06.get_lya_EW(z, Tk, continuum=0) 57 | Ii_mk21 = hydr_mk21.get_lya_EW(z, Tk, continuum=0) 58 | 59 | assert abs(Ii - Ii_fp06) / Ii < 0.1 60 | assert abs(Ii - Ii_mk21) / Ii < 0.1 61 | 62 | if __name__ == '__main__': 63 | test() 64 | -------------------------------------------------------------------------------- /tests/test_physics_HI_tau.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_physics_HI_tau.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill University 7 | Created on: Fri 11 Feb 2022 12:06:01 EST 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import numpy as np 14 | from ares.physics import Hydrogen 15 | 16 | def test(rtol=1e-1): 17 | hydr_approx = Hydrogen(approx_tau_21cm=True) 18 | hydr_general = Hydrogen(approx_tau_21cm=False) 19 | 20 | for i, z in enumerate([10, 20, 30]): 21 | dTb_a = hydr_approx.get_21cm_adiabatic_floor(z) 22 | dTb_g = hydr_general.get_21cm_adiabatic_floor(z) 23 | 24 | err_r = np.abs((dTb_a - dTb_g) / dTb_g) 25 | 26 | assert np.all(err_r < rtol) 27 | 28 | if __name__ == '__main__': 29 | test() 30 | -------------------------------------------------------------------------------- /tests/test_physics_HI_wf.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_physics_lya_coupling.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Wed Sep 25 10:01:27 MDT 2013 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | def test(): 17 | Tarr = np.logspace(-1, 2) 18 | 19 | res = [] 20 | for i, method in enumerate([2,3,3.5,4,5]): 21 | hydr = ares.physics.Hydrogen(approx_Salpha=method) 22 | 23 | Sa = np.array([hydr.Sa(20., Tarr[k]) for k in range(Tarr.size)]) 24 | res.append(Sa) 25 | 26 | if method == 5: 27 | # Mittal & Kulkarni (2021) quote a value in the text for 28 | # (z, x_e, Tk) = (22, 0, 10) 29 | assert abs(hydr.Sa(z=22., Tk=10.) - 0.7) < 1e-2 30 | 31 | # Check Ts while we're here 32 | Ts = hydr.get_Ts(20., hydr.cosm.Tgas(20.), 1, 0., 0.) 33 | 34 | # Compare at T > 1 K 35 | ok = Tarr > 1. 36 | diff = np.abs(np.diff(res, axis=1)) 37 | 38 | # Just set to a level that I know is tight enough to pickup 39 | # any errors we might accidentally introduce later. 40 | assert np.all(diff.ravel() < 0.3) 41 | 42 | # Check frec 43 | for n in range(2, 31): 44 | frec = hydr.frec(n) 45 | 46 | assert hydr.Tbg is None 47 | 48 | # Check various limits 49 | dTb_sat = hydr.get_21cm_saturated_limit(10.) 50 | dTb_low = hydr.get_21cm_adiabatic_floor(10.) 51 | dTb_phy = hydr.get_21cm_dTb_no_astrophysics(10.) 52 | 53 | assert 0 <= dTb_sat <= 50 54 | assert -350 <= dTb_low <= -200 55 | assert abs(dTb_phy) < 1 56 | 57 | if __name__ == '__main__': 58 | test() 59 | -------------------------------------------------------------------------------- /tests/test_physics_cosmology.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_physics_cosm.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Wed Sep 24 15:39:44 MDT 2014 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import numpy as np 14 | from ares.physics import Cosmology 15 | from ares.physics.Constants import s_per_gyr, m_H, m_He, cm_per_mpc 16 | 17 | def test(rtol=1e-3): 18 | 19 | cosm = Cosmology() 20 | 21 | # Check some high-z limits 22 | cosm_appr = Cosmology(approx_highz=True) 23 | 24 | # Check critical density 25 | assert cosm.CriticalDensity(0.) == cosm.CriticalDensityNow 26 | 27 | # Make sure energy densities sum to unity 28 | assert np.allclose(cosm.omega_m_0, 1. - cosm.omega_l_0) 29 | 30 | # Make sure the age of the Universe is OK 31 | assert 13.5 <= cosm.t_of_z(0.) / s_per_gyr <= 14. 32 | 33 | # Check high-z limit for Hubble parameter. Better than 1%? 34 | H_n = cosm.HubbleParameter(30.) 35 | H_a = cosm_appr.HubbleParameter(30.) 36 | assert abs(H_n - H_a) / H_a < rtol, \ 37 | "Hubble parameter @ high-z not accurate to < {:.3g}%.".format(rtol) 38 | 39 | # Check high-z limit for comoving radial distance 40 | R_n = cosm_appr.ComovingRadialDistance(20., 30.) / cm_per_mpc 41 | R_a = cosm.ComovingRadialDistance(20., 30.) / cm_per_mpc 42 | 43 | assert abs(R_a - R_n) / R_a < rtol, \ 44 | "Comoving radial distance @ high-z not accurate to < {:.3g}%.".format(rtol) 45 | 46 | # Test a user-supplied cosmology and one that grabs a row from Planck chain 47 | # Remember: test suite doesn't have CosmoRec, so don't use get_inits_rec. 48 | cosm = Cosmology(cosmology_name='user', cosmology_id='jordan') 49 | 50 | cosm = Cosmology(cosmology_id=100) 51 | 52 | if __name__ == '__main__': 53 | test() 54 | 55 | -------------------------------------------------------------------------------- /tests/test_physics_cross_sections.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_physics_cross_sections.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Mon Apr 22 10:54:18 2013 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import numpy as np 14 | from ares.physics.CrossSections import PhotoIonizationCrossSection, \ 15 | ApproximatePhotoIonizationCrossSection 16 | 17 | def test(): 18 | 19 | E = np.logspace(np.log10(13.6), 4) 20 | 21 | sigma = PhotoIonizationCrossSection 22 | sigma_approx = ApproximatePhotoIonizationCrossSection 23 | 24 | for species in [0, 1]: 25 | _sigma = np.array([sigma(EE, species) for EE in E]) 26 | _sigma_approx = np.array([sigma_approx(EE, species) for EE in E]) 27 | 28 | assert np.allclose(_sigma, _sigma_approx, rtol=3e-1) 29 | 30 | if __name__ == '__main__': 31 | test() 32 | -------------------------------------------------------------------------------- /tests/test_physics_halo_model.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_halo_model.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Fri Jul 8 12:24:24 PDT 2016 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | def test(rtol=1e-3): 17 | 18 | hm = ares.physics.HaloModel() 19 | 20 | # Just check large k range, k < 1 / Mpc 21 | k = np.logspace(-2, 0, 10) 22 | 23 | # Compare linear matter power spectrum to 2-h term of halo model 24 | for z in [6, 10, 20]: 25 | 26 | iz = np.argmin(np.abs(hm.tab_z - z)) 27 | plin = np.exp(np.interp(np.log(k), np.log(hm.tab_k_lin), 28 | np.log(hm.tab_ps_lin[iz,:]))) 29 | 30 | # Will default to using k-values used for plin if nothing supplied 31 | ps2h = hm.get_ps_2h(z, k) 32 | 33 | rerr = np.abs((plin - ps2h) / plin) 34 | assert np.allclose(plin, ps2h, rtol=rtol), \ 35 | "2h term != linear matter PS at z={}. err_rel(k)={}".format(z, 36 | rerr) 37 | 38 | if __name__ == '__main__': 39 | test() 40 | -------------------------------------------------------------------------------- /tests/test_physics_heating_cooling.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_physics_rates.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Sun Apr 13 16:38:44 MDT 2014 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares, sys 14 | import numpy as np 15 | 16 | def test(): 17 | species = 0 18 | dims = 32 19 | T = np.logspace(3.5, 6, 500) 20 | 21 | colors = list('kb') 22 | for i, src in enumerate(['fk94']): 23 | 24 | # Initialize grid object 25 | grid = ares.static.Grid(grid_cells=dims) 26 | 27 | # Set initial conditions 28 | grid.set_physics(isothermal=True) 29 | grid.set_chemistry() 30 | grid.set_density(1) 31 | grid.set_ionization(x=[1. - 1e-8, 1e-8]) 32 | grid.set_temperature(T) 33 | 34 | coeff = coeffB = ares.physics.RateCoefficients(grid=grid, rate_src=src, T=T) 35 | coeffA = ares.physics.RateCoefficients(grid=grid, rate_src=src, T=T, 36 | recombination='A') 37 | 38 | # First: collisional ionization, recombination 39 | CI = [coeff.CollisionalIonizationRate(species, TT) for TT in T] 40 | RRB = [coeff.RadiativeRecombinationRate(species, TT) for TT in T] 41 | RRA = [coeffA.RadiativeRecombinationRate(species, TT) for TT in T] 42 | 43 | # Second: Cooling processes 44 | CIC = [coeff.CollisionalIonizationCoolingRate(species, TT) for TT in T] 45 | CEC = [coeff.CollisionalExcitationCoolingRate(species, TT) for TT in T] 46 | RRC = [coeff.RecombinationCoolingRate(species, TT) for TT in T] 47 | 48 | assert True 49 | 50 | if __name__ == '__main__': 51 | test() 52 | -------------------------------------------------------------------------------- /tests/test_physics_secondary_elec.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_secondary_electrons.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Thu Apr 3 16:58:43 MDT 2014 8 | 9 | Description: Reproduce Figures 1-3 (kind of) in Furlanetto & Stoever (2010). 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | # First, compare at fixed ionized fraction 17 | xe = [1e-4, 1e-3, 1e-2, 1e-1, 0.5, 0.9] 18 | E = np.logspace(1, 4, 400) 19 | channels = ['heat', 'h_1', 'exc', 'lya'] 20 | 21 | def test(): 22 | 23 | esec1 = ares.physics.SecondaryElectrons(method=1) 24 | esec2 = ares.physics.SecondaryElectrons(method=2) 25 | esec3 = ares.physics.SecondaryElectrons(method=3) 26 | 27 | for channel in ['heat', 'h_1', 'he_1', 'lya', 'exc']: 28 | func = lambda EE: esec3.DepositionFraction(E=EE, channel=channel, xHII=0.01) 29 | f = list(map(func, E)) 30 | 31 | 32 | results = {channel: [] for channel in channels} 33 | 34 | elements = [3, 2, 0, 1] 35 | for j, channel in enumerate(channels): 36 | 37 | l = elements[j] 38 | 39 | for k, x in enumerate(xe): 40 | 41 | if channel == 'lya' and x >= 0.5: 42 | continue 43 | 44 | # Compare to high-energy limit from Ricotti et al. 45 | if channel not in ['exc', 'lya']: 46 | f2 = list(map(lambda EE: esec2.DepositionFraction(xHII=x, E=EE, 47 | channel=channel), E)) 48 | 49 | f3 = np.array(list(map(lambda EE: esec3.DepositionFraction(xHII=x, E=EE, 50 | channel=channel), E))) 51 | 52 | if channel == 'lya': 53 | last = np.array(results['exc'][k]) 54 | else: 55 | pass 56 | 57 | # Just need this to do flya/fexc 58 | results[channel].append(np.array(f3)) 59 | 60 | assert True 61 | 62 | if __name__ == '__main__': 63 | test() 64 | -------------------------------------------------------------------------------- /tests/test_populations_aggregate.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_populations_bh.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill 7 | Created on: Fri 3 Apr 2020 12:54:41 EDT 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | from ares.physics.Constants import rhodot_cgs 16 | 17 | def test(): 18 | pop = ares.populations.GalaxyPopulation() 19 | 20 | zarr = np.arange(5, 40) 21 | 22 | sfrd = pop.SFRD(zarr) * rhodot_cgs 23 | 24 | pop2 = ares.populations.GalaxyPopulation(pop_sfr_model='sfrd-tab', 25 | pop_sfrd=(zarr, sfrd), pop_sfrd_units='internal') 26 | 27 | assert abs(sfrd[5] - pop2.SFRD(zarr[5])) < 1e-8, \ 28 | "{:.3e} {:.3e}".format(sfrd[5], pop2.SFRD(zarr[5])) 29 | 30 | pop3 = ares.populations.GalaxyPopulation(pop_sfr_model='sfrd-func', 31 | pop_sfrd=lambda z: np.interp(z, zarr, sfrd), pop_sfrd_units='internal') 32 | 33 | assert abs(sfrd[5] - pop3.SFRD(zarr[5])) < 1e-8, \ 34 | "{:.3e} {:.3e}".format(sfrd[5], pop3.SFRD(zarr[5])) 35 | 36 | 37 | if __name__ == '__main__': 38 | test() 39 | -------------------------------------------------------------------------------- /tests/test_populations_bh.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_populations_bh.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill 7 | Created on: Fri 3 Apr 2020 12:54:41 EDT 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | from ares.physics.Constants import rhodot_cgs, rho_cgs 16 | 17 | def test(): 18 | bh_pars = \ 19 | { 20 | 'pop_sfr_model': 'bhmd', 21 | 'pop_Tmin': 2e3, 22 | 'pop_Tmax': 1e4, 23 | 'pop_bh_seed_eff': 1e-4, 24 | 'pop_eta': 0.1, 25 | 'pop_fduty': 1., 26 | 'pop_rad_yield': 0.1, # in this case, fraction of Lbol in (EminNorm, EmaxNorm) 27 | 'pop_Emin': 2e2, 28 | 'pop_Emax': 3e4, 29 | 'pop_EminNorm': 2e3, 30 | 'pop_EmaxNorm': 1e4, 31 | 'pop_ion_src_cgm': False, 32 | 'pop_solve_rte': True, 33 | 'pop_sed': 'pl', 34 | 'pop_alpha': -1.5, 35 | 'hmf_dt': 1., 36 | #'sam_dz': 0.05, 37 | #'sam_atol': 1e-6, 38 | #'sam_rtol': 1e-8, 39 | } 40 | 41 | pop = ares.populations.GalaxyPopulation(**bh_pars) 42 | pop.info 43 | pop.halos.info 44 | 45 | zarr = np.arange(5, 40) 46 | 47 | frd = pop.FRD(zarr) * rhodot_cgs 48 | ard = pop.ARD(zarr) * rhodot_cgs 49 | bhmd = pop.BHMD(zarr) * rho_cgs 50 | 51 | 52 | # Crude checks 53 | assert 1e-9 <= np.mean(frd) <= 1e-1, "BH FRD unreasonable!" 54 | assert 1 <= np.interp(10, zarr, bhmd) <= 1e9, "BHMD unreasonable!" 55 | 56 | 57 | if __name__ == '__main__': 58 | test() 59 | -------------------------------------------------------------------------------- /tests/test_populations_cohort_pqs.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_pq_gen.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Thu Dec 15 14:31:54 PST 2016 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | def test(): 17 | # Make sure we can parameterize a bunch of things 18 | 19 | pars = ares.util.ParameterBundle('pop:sfe-dpl') 20 | 21 | pop = ares.populations.GalaxyPopulation(**pars) 22 | 23 | base_kwargs = \ 24 | { 25 | 'pq_func': 'dpl', 26 | 'pq_func_var': 'Mh', 27 | 'pq_func_par0': 0.1, 28 | 'pq_func_par1': 3e11, 29 | 'pq_func_par2': 0.6, 30 | 'pq_func_par3': -0.6, 31 | 'pq_func_par4': 1e10, 32 | } 33 | 34 | val = [] 35 | parameterizable_things = \ 36 | ['fstar', 'fshock', 'fpoll', 'fstall', 'rad_yield', 'fduty', 'fesc_LW'] 37 | 38 | for par in parameterizable_things: 39 | 40 | pars = base_kwargs.copy() 41 | pars['pop_{!s}'.format(par)] = 'pq' 42 | 43 | pop = ares.populations.GalaxyPopulation(**pars) 44 | 45 | func = pop.__getattr__(par) 46 | val.append(func(z=6, Mh=1e12)) 47 | 48 | print('{!s}'.format(val)) 49 | assert np.unique(val).size == 1, "Error in building ParameterizedQuantity!" 50 | 51 | if __name__ == '__main__': 52 | test() 53 | -------------------------------------------------------------------------------- /tests/test_populations_hod.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | test_populations_hod.py 4 | Author: Emma Klemets 5 | Affiliation: McGill 6 | Created on: Aug 7, 2020 7 | 8 | Description: Test the main functions of GalaxyHOD.py. 9 | """ 10 | 11 | import ares 12 | import numpy as np 13 | 14 | def test(): 15 | #set up basic pop 16 | pars = ares.util.ParameterBundle('emma:model2') 17 | pop = ares.populations.GalaxyPopulation(**pars) 18 | 19 | z = 5 20 | mags = np.linspace(-24, -12) 21 | 22 | #test LF for high Z 23 | x, LF = pop.get_lf(z, mags) 24 | assert all(1e-8 <= i <= 10 for i in LF), "LF unreasonable" 25 | 26 | log_HM = 0 27 | SM = pop.SMHM(2, log_HM) 28 | 29 | #test SMF 30 | z = 1.75 31 | logbins = np.linspace(7, 12, 60) 32 | 33 | SMF_tot = pop.StellarMassFunction(z, logbins) 34 | 35 | assert all(1e-19 <= i <= 1 for i in SMF_tot), "SMF unreasonable" 36 | 37 | SMF_sf = pop.StellarMassFunction(z, logbins, sf_type='smf_sf') 38 | SMF_q = pop.StellarMassFunction(z, logbins, sf_type='smf_q') 39 | 40 | assert all(np.less(SMF_sf, SMF_tot)), "Sf-fraction of SMF bigger than total" 41 | assert all(np.less(SMF_q, SMF_tot)), "Q-fraction of SMF bigger than total" 42 | 43 | SM = np.linspace(8, 11.1) 44 | #test SFR 45 | SFR = pop.SFR(z, SM) 46 | assert all(-2 <= i <= 3 for i in SFR), "SFR unreasonable" 47 | 48 | #test SSFR 49 | SSFR = pop.SSFR(z, SM) 50 | assert all(-10 <= i <= -7 for i in SSFR), "SSFR unreasonable" 51 | 52 | #test SFRD 53 | Zs = np.linspace(0, 6, 50) 54 | SFRD = pop.SFRD(Zs) 55 | assert all(1e-6 <= i <= 1 for i in SFRD), "SFRD unreasonable" 56 | 57 | if __name__ == '__main__': 58 | test() 59 | -------------------------------------------------------------------------------- /tests/test_populations_popIII.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_populations_popIII.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill 7 | Created on: Tue 7 Apr 2020 21:18:13 EDT 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | from ares.physics.Constants import rhodot_cgs, s_per_myr 16 | 17 | def test(): 18 | 19 | mags = np.arange(-25, -5, 0.1) 20 | zarr = np.arange(6, 30, 0.1) 21 | 22 | pars = ares.util.ParameterBundle('mirocha2017:base') \ 23 | + ares.util.ParameterBundle('mirocha2018:high') 24 | 25 | updates = ares.util.ParameterBundle('testing:galaxies') 26 | updates.num = 0 27 | pars.update(updates) 28 | 29 | # Just testing: speed this up. 30 | pars['feedback_LW'] = True 31 | pars['feedback_LW_maxiter'] = 3 32 | pars['tau_redshift_bins'] = 400 33 | pars['hmf_dt'] = 1 34 | pars['hmf_tmax'] = 1000 35 | 36 | # Use sam_dz? 37 | 38 | sim = ares.simulations.Global21cm(**pars) 39 | sim.run() 40 | 41 | assert sim.pops[2].is_sfr_constant 42 | 43 | sfrd_II = sim.pops[0].SFRD(zarr) * rhodot_cgs 44 | sfrd_III = sim.pops[2].SFRD(zarr) * rhodot_cgs 45 | # Check for reasonable values 46 | assert np.all(sfrd_II < 1) 47 | assert 1e-6 <= np.mean(sfrd_II) <= 1e-1 48 | 49 | assert np.all(sfrd_III < 1) 50 | assert 1e-8 <= np.mean(sfrd_III) <= 1e-3 51 | 52 | x, phi_M = sim.pops[0].get_lf(zarr[0], mags, use_mags=True, 53 | wave=1600.) 54 | 55 | assert 60 <= sim.nu_C <= 115, "Global signal unreasonable!" 56 | assert -250 <= sim.dTb_C <= -150, "Global signal unreasonable!" 57 | 58 | # Make sure L_per_sfr works 59 | assert sim.pops[2].src.L_per_sfr() > sim.pops[0].src.L_per_sfr() 60 | 61 | # Duration of PopIII 62 | zform, zfin, Mfin, duration = sim.pops[2].get_duration(6) 63 | 64 | hubble_time = sim.pops[2].cosm.HubbleTime(z=6) 65 | assert np.all(duration <= hubble_time / s_per_myr) 66 | 67 | 68 | if __name__ == '__main__': 69 | test() 70 | -------------------------------------------------------------------------------- /tests/test_simulations_gs_4par.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_gs_basic.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Thu Jan 19 10:35:33 PST 2017 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | def test(): 17 | sim = ares.simulations.Global21cm() 18 | 19 | sim.info 20 | pf = sim.pf 21 | sim.pf._check_for_conflicts() 22 | assert sim.pf.Npops == 3 23 | 24 | sim.run() 25 | 26 | # 27 | # Make sure it's not a null signal. 28 | z = sim.history['z'] 29 | dTb = sim.history['dTb'][z < 50] 30 | assert len(np.unique(np.sign(dTb))) == 2 31 | assert max(dTb) > 5 and min(dTb) < -5 32 | 33 | # Test that the turning points are there, that tau_e is reasonable, etc. 34 | assert 80 <= sim.z_A <= 90 35 | assert 10 <= sim.nu_A <= 20 36 | assert -50 <= sim.dTb_A <= -40 37 | 38 | assert 25 <= sim.z_B <= 35 39 | assert -15 <= sim.dTb_B <= 0 40 | 41 | assert 10 <= sim.z_C <= 25 42 | assert -250 <= sim.dTb_C <= 0 43 | 44 | assert 6 <= sim.z_D <= 15 45 | assert 0 <= sim.dTb_D <= 30 46 | 47 | assert 0.04 <= sim.tau_e <= 0.15 48 | 49 | fwhm = sim.Width() 50 | hwhm = sim.Width(peak_relative=True) 51 | 52 | assert 10 <= fwhm <= 50 53 | assert 0 <= hwhm <= 3 54 | 55 | k = sim.kurtosis 56 | s = sim.skewness 57 | 58 | slope1 = sim.dTbdz 59 | slope2 = sim.dTbdnu 60 | curv1 = sim.dTb2dz2 61 | curv2 = sim.dTb2dnu2 62 | 63 | if __name__ == '__main__': 64 | test() 65 | -------------------------------------------------------------------------------- /tests/test_simulations_gs_lfcal.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_simulations_gs_lfcal.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill 7 | Created on: Sat 28 Mar 2020 14:59:01 EDT 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | from ares.physics.Constants import rhodot_cgs 16 | 17 | def test(): 18 | 19 | mags = np.arange(-25, -5, 0.1) 20 | zarr = np.arange(6, 30, 0.1) 21 | 22 | pars = ares.util.ParameterBundle('mirocha2017:base') 23 | # Test suite only carries solar metallicity, heavily degraded, BPASS SEDs 24 | pars['pop_sed_degrade{0}'] = 100 25 | pars['pop_Z{0}'] = 0.02 26 | 27 | sim = ares.simulations.Global21cm(**pars) 28 | sim.run() 29 | 30 | sfrd = sim.pops[0].SFRD(zarr) * rhodot_cgs 31 | 32 | # Check for reasonable values 33 | assert np.all(sfrd < 1) 34 | assert 1e-6 <= np.mean(sfrd) <= 1e-1 35 | 36 | x, phi_M = sim.pops[0].get_lf(zarr[0], mags, use_mags=True, 37 | wave=1600.) 38 | 39 | assert 90 <= sim.nu_C <= 115, \ 40 | "Global signal unreasonable! nu_min={:.1f} MHz".format(sim.nu_C) 41 | assert -250 <= sim.dTb_C <= -150, \ 42 | "Global signal unreasonable! dTb_min={:.1f} mK".format(sim.dTb_C) 43 | 44 | if __name__ == '__main__': 45 | test() 46 | -------------------------------------------------------------------------------- /tests/test_simulations_gs_multipop.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_gs_multipop.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: UCLA 7 | Created on: Fri Jul 1 15:42:30 PDT 2016 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | 15 | def test(): 16 | 17 | fcoll = ares.util.ParameterBundle('pop:fcoll') 18 | popIII = ares.util.ParameterBundle('sed:uv') 19 | 20 | pop = fcoll + popIII 21 | 22 | # Restrict to halos below the atomic cooling threshold 23 | pop['pop_fstar'] = 1e-3 24 | pop['pop_Tmin'] = 300 25 | pop['pop_Tmax'] = 1e4 26 | 27 | # Tag with ID number 28 | pop.num = 3 29 | 30 | sim1 = ares.simulations.Global21cm() 31 | sim2 = ares.simulations.Global21cm(**pop) 32 | 33 | sim1.run() 34 | sim2.run() 35 | 36 | 37 | if __name__ == '__main__': 38 | test() 39 | -------------------------------------------------------------------------------- /tests/test_simulations_gs_param_hist.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_21cm_parameterized.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Wed Aug 6 08:54:15 MDT 2014 8 | 9 | Description: 21-cm signal in absence of astrophysical sources. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | def test(): 17 | 18 | # Create instance of Hydrogen class 19 | hydr = ares.physics.Hydrogen(approx_thermal_history='piecewise') 20 | 21 | # Analytic approximation to thermal history 22 | Tk = lambda z: hydr.cosm.Tgas(z) 23 | 24 | # Spin temperature (arguments: z, Tk, Ja, xHII, ne) 25 | Ts = lambda z: hydr.SpinTemperature(z, Tk(z), 0.0, 0.0, 0.0) 26 | 27 | # Brightness temperature (arguments: z, Ts, xavg optional) 28 | dTb = lambda z: hydr.get_21cm_dTb(z, Ts(z)) 29 | 30 | # Define redshift interval of interest 31 | z = np.linspace(10, 1e3, 500) 32 | 33 | # Get CosmoRec recombination history 34 | CR = hydr.cosm._ics.get_inits_rec() 35 | 36 | # Assume neutral medium for simplicity 37 | Ts_CR = hydr.SpinTemperature(CR['z'], CR['Tk'], 0.0, 0.0, 0.0) 38 | dTb_CR = hydr.get_21cm_dTb(CR['z'], Ts_CR) 39 | 40 | if __name__ == '__main__': 41 | test() 42 | -------------------------------------------------------------------------------- /tests/test_simulations_gs_phenom.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_21cm_tanh.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Tue Sep 9 20:03:58 MDT 2014 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | def test(): 17 | 18 | sim = ares.simulations.Global21cm(tanh_model=True) 19 | sim.run() 20 | 21 | sim2 = ares.simulations.Global21cm(gaussian_model=True) 22 | sim2.run() 23 | 24 | p = \ 25 | { 26 | 'parametric_model': True, 27 | 'pop_Ja': lambda z: 1e-2 * ((1. + z) / 10.)**-4., 28 | 'pop_Tk': lambda z: 1e2 * (1. - np.exp(-(15. / z)**4)), 29 | 'pop_xi': lambda z: 1. - np.exp(-(10. / z)**4), 30 | } 31 | 32 | sim3 = ares.simulations.Global21cm(**p) 33 | sim3.run() 34 | 35 | if __name__ == "__main__": 36 | test() 37 | -------------------------------------------------------------------------------- /tests/test_simulations_rt1d_const_flux.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_const_ionization.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Thu Oct 16 14:46:48 MDT 2014 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | from ares.physics.CrossSections import PhotoIonizationCrossSection as sigma 16 | 17 | s_per_yr = ares.physics.Constants.s_per_yr 18 | 19 | pars = \ 20 | { 21 | 'problem_type': 0, 22 | 'grid_cells': 1, 23 | 'initial_ionization': [1.-1e-6, 1e-6], 24 | #'initial_temperature': 1e4,# make cold so collisional ionization is negligible 25 | 'isothermal': False, 26 | 27 | 'stop_time': 10.0, 28 | 'plane_parallel': True, 29 | 'recombination': False, # To match analytical solution 30 | 31 | 'source_type': 'toy', 32 | 'source_qdot': 1e4, # solver fails when this is large (like 1e10) 33 | 'source_lifetime': 1e10, 34 | 'source_E': [13.60000001], 35 | 'source_LE': [1.0], 36 | 'secondary_ionization': 0, 37 | 'collisional_ionization': 0, 38 | 'logdtDataDump': 0.5, 39 | 'initial_timestep': 1e-15, 40 | } 41 | 42 | def test(rtol=1e-2): 43 | 44 | # Numerical solution 45 | sim = ares.simulations.RaySegment(**pars) 46 | sim.run() 47 | 48 | t, xHII = sim.get_cell_evolution(field='h_2') 49 | 50 | # Analytic solution: exponential time evolution 51 | sigma0 = sigma(pars['source_E'][0]) 52 | qdot = pars['source_qdot'] 53 | Gamma = qdot * sigma0 54 | 55 | xi0 = pars['initial_ionization'][1] 56 | C = 1. - xi0 57 | def xi(t, Gamma=Gamma): 58 | return 1. - C * np.exp(-Gamma * t) 59 | 60 | xHII_anyl = np.array(list(map(xi, t))) 61 | 62 | # Only test accuracy at somewhat later times 63 | mask = t > 0 64 | 65 | err = np.abs(xHII[mask] - xHII_anyl[mask]) / xHII_anyl[mask] 66 | 67 | assert np.allclose(xHII[mask], xHII_anyl[mask], rtol=rtol, atol=0) 68 | 69 | if __name__ == '__main__': 70 | test() 71 | -------------------------------------------------------------------------------- /tests/test_simulations_rt1d_const_ioniz.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_const_ionization.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Wed Feb 18 10:30:47 MST 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | pf = \ 17 | { 18 | 'grid_cells': 64, 19 | 'isothermal': True, 20 | 'stop_time': 1e2, 21 | 'secondary_ionization': False, 22 | 'density_units': 1.0, 23 | 'initial_timestep': 1, 24 | 'max_timestep': 1e2, 25 | 'initial_temperature': np.logspace(3, 5, 64), 26 | 'initial_ionization': [1. - 1e-4, 1e-4], # neutral 27 | } 28 | 29 | def test(): 30 | 31 | sim = ares.simulations.GasParcel(radiative_transfer=True, **pf) 32 | 33 | # Set constant ionization rate (coefficient) by hand 34 | k_ion = np.ones([sim.grid.dims,1]) * 1e-14 35 | 36 | # Initialize all rate coefficients 37 | sim.update_rate_coefficients(sim.grid.data) 38 | sim.set_radiation_field() 39 | 40 | # Evolve in time 41 | all_data = [] 42 | for t, dt, data in sim.step(): 43 | 44 | sim.update_rate_coefficients(sim.grid.data, k_ion=k_ion) 45 | 46 | all_data.append(data) 47 | 48 | # Re-run without radiative transfer for comparison 49 | sim2 = ares.simulations.GasParcel(radiative_transfer=False, **pf) 50 | sim2.run() 51 | 52 | 53 | if __name__ == "__main__": 54 | test() 55 | -------------------------------------------------------------------------------- /tests/test_simulations_rt1d_ptsrc.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_simulations_rt1d.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill University 7 | Created on: Mon 20 Dec 2021 11:54:45 EST 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | def test(): 17 | 18 | # Uniform density, isothermal, point source Q=5e48 19 | sim = ares.simulations.RaySegment(problem_type=1, 20 | stop_time=100, grid_cells=32) 21 | sim.run() 22 | 23 | # Make sure I-front is made over time 24 | assert np.mean(sim.history['h_2'][-1]) > sim.history['h_2'][0,0] 25 | 26 | # Same thing but now isothermal=False 27 | sim = ares.simulations.RaySegment(problem_type=2, 28 | stop_time=100, grid_cells=32) 29 | sim.run() 30 | 31 | # Make sure heating happens! 32 | assert np.mean(sim.history['Tk'][-1]) > sim.history['Tk'][0,0] 33 | 34 | # This run will have generated a lookup table for Gamma. Write to disk. 35 | sim.save_tables(prefix='test_rt1d') 36 | 37 | # Eventually, test read capability. Currently broken. 38 | 39 | # Same thing but now w/ secondary ionization/heating 40 | sim = ares.simulations.RaySegment(problem_type=2, 41 | stop_time=100, grid_cells=32, secondary_ionization=1) 42 | sim.run() 43 | 44 | # Make sure heating happens! 45 | assert np.mean(sim.history['Tk'][-1]) > sim.history['Tk'][0,0] 46 | 47 | if __name__ == "__main__": 48 | test() 49 | -------------------------------------------------------------------------------- /tests/test_solvers_chem_h.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_chemistry_hydrogen.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Mon Feb 16 12:50:43 MST 2015 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | def test(): 17 | 18 | pf = \ 19 | { 20 | 'grid_cells': 64, 21 | 'isothermal': True, 22 | 'stop_time': 1e2, 23 | 'radiative_transfer': False, 24 | 'density_units': 1.0, 25 | 'initial_timestep': 1, 26 | 'max_timestep': 1e2, 27 | 'restricted_timestep': None, 28 | 'initial_temperature': np.logspace(3, 5, 64), 29 | 'initial_ionization': [1.-1e-8, 1e-8], # neutral 30 | } 31 | 32 | sim = ares.simulations.GasParcel(**pf) 33 | sim.run() 34 | 35 | data = sim.history 36 | 37 | # Test last time snapshot 38 | x_HI = data['h_1'][-1,:] 39 | x_HII = data['h_2'][-1,:] 40 | 41 | 42 | if __name__ == '__main__': 43 | test() 44 | -------------------------------------------------------------------------------- /tests/test_sources_bh.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sed_mcd.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: University of Colorado at Boulder 7 | Created on: Thu May 2 10:46:44 2013 8 | 9 | Description: Plot a simple multi-color disk accretion spectrum. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | def test(): 17 | rmax = 1e2 18 | mass = 10. 19 | fsc = 0.1 20 | alpha = -1.5 21 | Emin = 1e2 22 | Emax = 1e4 23 | 24 | simpl = \ 25 | { 26 | 'source_type': 'bh', 27 | 'source_mass': mass, 28 | 'source_rmax': rmax, 29 | 'source_sed': 'simpl', 30 | 'source_Emin': Emin, 31 | 'source_Emax': Emax, 32 | 'source_EminNorm': Emin, 33 | 'source_EmaxNorm': Emax, 34 | 'source_alpha': alpha, 35 | 'source_fsc': fsc, 36 | 'source_logN': 22., 37 | } 38 | 39 | mcd = \ 40 | { 41 | 'source_type': 'bh', 42 | 'source_sed': 'mcd', 43 | 'source_mass': mass, 44 | 'source_rmax': rmax, 45 | 'source_Emin': Emin, 46 | 'source_Emax': Emax, 47 | 'source_EminNorm': Emin, 48 | 'source_EmaxNorm': Emax, 49 | } 50 | 51 | agn = \ 52 | { 53 | 'source_type': 'bh', 54 | 'source_sed': 'sazonov2004', 55 | 'source_Emin': Emin, 56 | 'source_Emax': Emax, 57 | 'source_EminNorm': Emin, 58 | 'source_EmaxNorm': Emax, 59 | } 60 | 61 | bh_mcd = ares.sources.BlackHole(init_tabs=False, **mcd) 62 | bh_sim = ares.sources.BlackHole(init_tabs=False, **simpl) 63 | bh_s04 = ares.sources.BlackHole(init_tabs=False, **agn) 64 | 65 | Earr = np.logspace(2, 4, 100) 66 | 67 | for src in [bh_mcd, bh_sim, bh_s04]: 68 | sed = bh_mcd.Spectrum(Earr) 69 | 70 | 71 | if __name__ == '__main__': 72 | test() 73 | -------------------------------------------------------------------------------- /tests/test_sources_sps.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_sources_sps.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill 7 | Created on: Wed 29 Apr 2020 17:54:05 EDT 8 | 9 | Description: Test basic functionality of SynthesisModel class. 10 | 11 | """ 12 | 13 | import ares 14 | import numpy as np 15 | 16 | def test(): 17 | 18 | src = ares.sources.SynthesisModel(source_sed='eldridge2009', 19 | source_sed_degrade=100, source_Z=0.02) 20 | 21 | Ebar = src.AveragePhotonEnergy(13.6, 1e2) 22 | assert 13.6 <= Ebar <= 1e2 23 | 24 | nu = src.frequencies 25 | ehat = src.emissivity_per_sfr 26 | 27 | beta = src.get_beta() 28 | assert -3 <= np.mean(beta) <= 2 29 | 30 | # Check caching and Z-interpolation. 31 | source_sps_data = src.pf['source_Z'], src.pf['source_ssp'], \ 32 | src.wavelengths, src.times, src.data 33 | 34 | src2 = ares.sources.SynthesisModel(source_sed='eldridge2009', 35 | source_sed_degrade=100, source_Z=0.02, source_sps_data=source_sps_data) 36 | 37 | assert np.allclose(src.data, src2.data) 38 | 39 | # Can't test Z interpolation until we download more than Z=0.02 tables 40 | # for test suite. 41 | #src3 = ares.sources.SynthesisModel(source_sed='eldridge2009', 42 | # source_sed_degrade=100, source_Z=0.015) 43 | # 44 | #assert src3.Nion > src.Nion 45 | #assert src3.Nion > src2.Nion 46 | 47 | if __name__ == '__main__': 48 | test() 49 | -------------------------------------------------------------------------------- /tests/test_util_math.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_util_stats.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill 7 | Created on: Tue 24 Mar 2020 22:11:31 EDT 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import numpy as np 14 | from scipy.interpolate import interp1d 15 | from ares.util.Math import interp1d_wrapper, forward_difference, \ 16 | central_difference, five_pt_stencil, LinearNDInterpolator, smooth 17 | 18 | def test(): 19 | 20 | # First, test my dumb wrapper around interp1d 21 | x = np.linspace(0, 4 * np.pi, 100) 22 | y = np.sin(x) 23 | 24 | func1 = interp1d(x, y, kind='cubic') 25 | func2 = interp1d_wrapper(x, y, kind='cubic') 26 | func3 = LinearNDInterpolator(x, y) 27 | 28 | x2 = np.linspace(0, 4 * np.pi, 50) 29 | 30 | f1 = func1(x2) 31 | f2 = func2(x2) 32 | f3 = func3(x2) 33 | 34 | assert np.array_equal(f1, f2) 35 | 36 | # Test derivative routines 37 | x1, dydx1 = forward_difference(x, y) 38 | x2, dydx2 = central_difference(x, y) 39 | x3, dydx3 = five_pt_stencil(x, y) 40 | 41 | # Smoothing 42 | d = y + np.random.normal(scale=0.5, size=y.size) 43 | std = np.std(d - y) 44 | ds_b = smooth(d, 5, kernel='boxcar') 45 | ds_g = smooth(d, 5, kernel='gaussian') 46 | 47 | assert np.std(ds_b - y) < std 48 | assert np.std(ds_g - y) < std 49 | 50 | # Next, test LinearNDInterpolator 51 | _x = _y = np.linspace(0, 5, 100) 52 | xx, yy = np.meshgrid(_x, _y) 53 | f = np.sin(xx) + np.cos(yy) 54 | 55 | func2d = LinearNDInterpolator([_x, _y], f) 56 | f0 = func2d(np.array([0.5, 1.3])) 57 | 58 | _x = _y = _z = np.linspace(0, 5, 100) 59 | xx, yy, zz = np.meshgrid(_x, _y, _z) 60 | g = np.sin(xx) + np.cos(yy) + + np.tan(zz) 61 | 62 | func3d = LinearNDInterpolator([_x, _y, _z], g) 63 | g0 = func3d(np.array([0.5, 1.3, 1.5])) 64 | 65 | if __name__ == '__main__': 66 | test() 67 | -------------------------------------------------------------------------------- /tests/test_util_misc.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | test_util_misc.py 4 | 5 | Author: Jordan Mirocha 6 | Affiliation: McGill University 7 | Created on: Sun 19 Dec 2021 18:52:05 EST 8 | 9 | Description: 10 | 11 | """ 12 | 13 | import numpy as np 14 | from ares.util.Misc import get_cmd_line_kwargs, get_attribute, split_by_sign 15 | 16 | def test(): 17 | 18 | sys_argv = ['scriptname', 'int_var=3', 'str_var=hello', 19 | 'mix_var=ax323', 'bool_var=True', 'None_var=None', 20 | 'float_var=12.3', 'special_var=23_45', 'list_var=[1,2,3]'] 21 | 22 | kwargs = get_cmd_line_kwargs(sys_argv) 23 | 24 | assert kwargs['int_var'] == 3 25 | assert kwargs['str_var'] == 'hello' 26 | assert kwargs['mix_var'] == 'ax323' 27 | assert kwargs['bool_var'] is True 28 | assert kwargs['None_var'] is None 29 | assert kwargs['float_var'] == 12.3 30 | assert np.all(kwargs['list_var'] == np.array([1,2,3])) 31 | 32 | x = np.arange(0, 6 * np.pi, 500) 33 | y = np.sin(x) 34 | 35 | xch, ych = split_by_sign(x, y) 36 | for i, (xc, yc) in enumerate(zip(xch, ych)): 37 | assert np.all(np.sign(xc) == np.sign(xc[0])) 38 | assert np.all(np.sign(yc) == np.sign(yc[0])) 39 | 40 | # Test if all same sign 41 | xch, ych = split_by_sign(xc, yc) 42 | assert np.all(np.sign(xch) == np.sign(xch[0])) 43 | assert np.all(np.sign(ych) == np.sign(ych[0])) 44 | 45 | 46 | if __name__ == '__main__': 47 | test() 48 | -------------------------------------------------------------------------------- /tests/test_util_pbundle.py: -------------------------------------------------------------------------------- 1 | import ares 2 | 3 | 4 | def test(): 5 | pars = ares.util.ParameterBundle('mirocha2017:base') 6 | 7 | orph = pars.orphans 8 | bkw = pars.get_base_kwargs() 9 | 10 | assert pars.pqids == [0] 11 | assert pars.pqs == ['pop_fstar{0}'] 12 | 13 | sfe_pars = pars.pars_by_pq(0) 14 | 15 | if __name__ == '__main__': 16 | test() 17 | 18 | -------------------------------------------------------------------------------- /tests/test_util_readdata.py: -------------------------------------------------------------------------------- 1 | import ares 2 | 3 | 4 | def test(): 5 | for src in ['mirocha2017', 'bouwens2015', 'finkelstein2015']: 6 | data = ares.util.read_lit(src) 7 | 8 | if __name__ == '__main__': 9 | test() 10 | 11 | --------------------------------------------------------------------------------