From be6502c37ec28d4c1f19136b732a5d1560beec6a Mon Sep 17 00:00:00 2001 From: Willow Smith Date: Tue, 21 Jan 2025 16:30:37 -0500 Subject: [PATCH] more tests --- tests/test_observation.py | 14 ++++++++++++++ tests/test_sensitivity.py | 3 +++ tests/test_theory.py | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/test_observation.py b/tests/test_observation.py index 5295565..e926742 100644 --- a/tests/test_observation.py +++ b/tests/test_observation.py @@ -92,12 +92,26 @@ def test_from_yaml(observatory): with pytest.raises(ValueError, match="yaml_file must be a string filepath"): Observation.from_yaml(3) +def test_huge_time_per_day_size(observatory: Observatory, wd): + tpd = 25 * units.hour if wd=="earth" else 682.5 * units.hour + with pytest.raises(ValueError, match="time_per_day should be between 0 and"): + Observation(observatory=observatory, time_per_day=tpd) + +def test_huge_track_size(observatory: Observatory, wd): + tck = 25 * units.hour if wd=="earth" else 682.5 * units.hour + with pytest.raises(ValueError, match="track should be between 0 and"): + Observation(observatory=observatory, track=tck) + def test_huge_lst_bin_size(observatory: Observatory, wd): lst = 23 * units.hour if wd=="earth" else 627.9 * units.hour with pytest.raises(ValueError, match="lst_bin_size must be <= time_per_day"): Observation(observatory=observatory, lst_bin_size=lst) + lst2 = 25 * units.hour if wd=="earth" else 682.5 * units.hour + with pytest.raises(ValueError, match="lst_bin_size should be between 0 and"): + Observation(observatory=observatory, lst_bin_size=lst2) + def test_huge_integration_time(observatory: Observatory): with pytest.raises(ValueError, match="integration_time must be <= lst_bin_size"): diff --git a/tests/test_sensitivity.py b/tests/test_sensitivity.py index 8b9ff01..c945c75 100644 --- a/tests/test_sensitivity.py +++ b/tests/test_sensitivity.py @@ -82,6 +82,9 @@ def test_sensitivity_optimistic(observation): ps = PowerSpectrum(observation=observation, foreground_model="optimistic") assert ps.horizon_limit(10.0) > ps.horizon_limit(5.0) +def test_sensitivity_foreground_free(observation): + ps = PowerSpectrum(observation=observation, foreground_model="foreground_free") + assert ps.horizon_limit(10.0) == 0 def test_infs_in_trms(observation): # default dumb layout should have lots of infs.. diff --git a/tests/test_theory.py b/tests/test_theory.py index 5c4e11a..07fd71d 100644 --- a/tests/test_theory.py +++ b/tests/test_theory.py @@ -3,7 +3,7 @@ import numpy as np import pytest -from py21cmsense.theory import EOS2021, EOS2016Bright, EOS2016Faint, Legacy21cmFAST +from py21cmsense.theory import EOS2021, EOS2016Bright, EOS2016Faint, Legacy21cmFAST, FarViewModel def test_eos_extrapolation(): @@ -38,3 +38,16 @@ def test_eos_2016(): bright = EOS2016Bright() assert faint.delta_squared(9.1, 1.0) != bright.delta_squared(9.1, 1.0) + +def test_FarView(): + theory = FarViewModel() + assert theory.delta_squared(29.6, 1.0) == theory.delta_squared(30.4, 1.0) + + with pytest.warns(UserWarning, match="Theory power corresponds to z=30, not z"): + theory.delta_squared(1.0, 1.0) + + with pytest.warns(UserWarning, match="Extrapolating above the simulated theoretical k"): + theory.delta_squared(30, np.array([0.1, 1e6])) + + with pytest.warns(UserWarning, match="Extrapolating below the simulated theoretical k"): + theory.delta_squared(30, np.array([0.0001, 0.1]))