Skip to content

Commit

Permalink
Refactor bandpass implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
MetinSa committed May 1, 2024
1 parent 79aa169 commit 37366c9
Show file tree
Hide file tree
Showing 16 changed files with 531 additions and 302 deletions.
2 changes: 1 addition & 1 deletion tests/_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def get_obs_dist(obs: str, obs_time: time.Time) -> u.Quantity[u.AU]:
return u.Quantity(np.linalg.norm(obs_pos.value), u.AU)

los_dist_cut = min(
[COMPONENT_CUTOFFS[comp][1] for comp in model._ipd_model.comps],
[COMPONENT_CUTOFFS[comp][1] for comp in model._interplanetary_dust_model.comps],
)
if isinstance(los_dist_cut, dict):
los_dist_cut = min(list(los_dist_cut.values()))
Expand Down
42 changes: 21 additions & 21 deletions tests/test_get_emission.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@
DIRBE_START_DAY = Time("1990-01-01")


def test_compare_to_dirbe_idl() -> None:
"""Tests that ZodiPy reproduces the DIRBE software.
Zodipy should be able to reproduce the tabulated emission from the DIRBE Zoidacal Light
Prediction Software with a maximum difference of 0.1%.
"""
for frequency, tabulated_emission in TABULATED_DIRBE_EMISSION.items():
model = Zodipy(freq=frequency * u.micron, model="dirbe")
for idx, (day, lon, lat) in enumerate(zip(DAYS, LON, LAT)):
time = DIRBE_START_DAY + TimeDelta(day - 1, format="jd")

emission = model.get_emission_ang(
lon * u.deg,
lat * u.deg,
lonlat=True,
obs_pos="earth",
obs_time=time,
)
assert emission.value == pytest.approx(tabulated_emission[idx], rel=0.01)


@given(zodipy_models(), sky_coords(), data())
@settings(deadline=None)
def test_get_emission_skycoord(
Expand Down Expand Up @@ -176,27 +197,6 @@ def test_invalid_freq() -> None:
Zodipy(freq=1000 * u.micron, model="Planck2018", extrapolate=False)


def test_compare_to_dirbe_idl() -> None:
"""Tests that ZodiPy reproduces the DIRBE software.
Zodipy should be able to reproduce the tabulated emission from the DIRBE Zoidacal Light
Prediction Software with a maximum difference of 0.1%.
"""
for frequency, tabulated_emission in TABULATED_DIRBE_EMISSION.items():
model = Zodipy(freq=frequency * u.micron, model="dirbe")
for idx, (day, lon, lat) in enumerate(zip(DAYS, LON, LAT)):
time = DIRBE_START_DAY + TimeDelta(day - 1, format="jd")

emission = model.get_emission_ang(
lon * u.deg,
lat * u.deg,
lonlat=True,
obs_pos="earth",
obs_time=time,
)
assert emission.value == pytest.approx(tabulated_emission[idx], rel=0.01)


def test_multiprocessing() -> None:
"""Tests multiprocessing with for zodipy.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_reprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
def test_ipd_model_repr(model: Zodipy) -> None:
"""Tests that the IPD model has a userfriendly repr."""
repr(model)
repr(model._ipd_model)
repr(model._interplanetary_dust_model)
194 changes: 194 additions & 0 deletions tests/test_source_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
import pytest
from astropy import units

from zodipy.blackbody import N_TEMPS, tabulate_center_wavelength_bnu

CENTER_WAVELENGTHS = [20, 40, 10] * units.micron
CENTER_FREQUENCIES = [900, 1100, 500] * units.GHz


@pytest.mark.parametrize("center_wavelength", CENTER_WAVELENGTHS)
def test_tabulate_center_wavelength_bnu(
center_wavelength: units.Quantity,
) -> None:
"""Tests that the blackbody specific intensity is tabulated correctly."""
assert tabulate_center_wavelength_bnu(center_wavelength).shape == (2, N_TEMPS)


@pytest.mark.parametrize("center_frequency", CENTER_FREQUENCIES)
def test_tabulate_center_frequency_bnu(
center_frequency: units.Quantity,
) -> None:
"""Tests that the blackbody specific intensity is tabulated correctly."""
assert tabulate_center_wavelength_bnu(center_frequency).shape == (2, N_TEMPS)


DIRBE_25UM_BP_WAVELENGTHS = [
15.543,
15.664,
15.787,
15.910,
16.034,
16.160,
16.286,
16.413,
16.541,
16.670,
16.801,
16.932,
17.064,
17.198,
17.332,
17.467,
17.604,
17.741,
17.880,
18.019,
18.160,
18.302,
18.445,
18.589,
18.734,
18.881,
19.028,
19.177,
19.327,
19.477,
19.630,
19.783,
19.938,
20.093,
20.250,
20.408,
20.568,
20.728,
20.890,
21.054,
21.218,
21.384,
21.551,
21.719,
21.889,
22.060,
22.232,
22.406,
22.581,
22.757,
22.935,
23.114,
23.295,
23.477,
23.660,
23.845,
24.031,
24.219,
24.408,
24.599,
24.791,
24.984,
25.180,
25.376,
25.574,
25.774,
25.976,
26.178,
26.383,
26.589,
26.797,
27.006,
27.217,
27.430,
27.644,
27.860,
28.077,
28.297,
28.518,
28.741,
28.965,
29.191,
] * units.micron

DIRBE_25UM_BP_WEIGHTS = [
0.01,
0.02,
0.04,
0.05,
0.08,
0.16,
0.21,
0.34,
0.45,
0.55,
0.67,
0.79,
0.85,
0.89,
0.92,
0.93,
0.91,
0.88,
0.84,
0.82,
0.88,
0.94,
1.00,
0.99,
0.93,
0.87,
0.81,
0.68,
0.56,
0.46,
0.51,
0.60,
0.69,
0.70,
0.64,
0.60,
0.58,
0.63,
0.66,
0.70,
0.75,
0.80,
0.80,
0.69,
0.59,
0.53,
0.57,
0.61,
0.66,
0.74,
0.83,
0.83,
0.78,
0.73,
0.70,
0.68,
0.67,
0.79,
0.90,
0.95,
0.94,
0.93,
0.77,
0.62,
0.48,
0.35,
0.24,
0.18,
0.14,
0.09,
0.08,
0.07,
0.08,
0.08,
0.07,
0.05,
0.04,
0.03,
0.02,
0.02,
0.01,
0.01,
]
2 changes: 1 addition & 1 deletion tests/test_tabulated_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_tabulated_density(
grid = random.choice([grid_array, grid_regular])

assert tabulate_density(grid, model="DIRBE").shape == (
len(model._ipd_model.comps),
len(model._interplanetary_dust_model.comps),
n_grid_points,
n_grid_points,
n_grid_points,
Expand Down
28 changes: 14 additions & 14 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ def test_validate_frequencies(model: Zodipy) -> None:
with pytest.raises(TypeError):
get_validated_freq(
freq=BANDPASS_FREQUENCIES.value,
model=model._ipd_model,
model=model._interplanetary_dust_model,
extrapolate=False,
)
with pytest.raises(TypeError):
get_validated_freq(
freq=25,
model=model._ipd_model,
model=model._interplanetary_dust_model,
extrapolate=False,
)
with pytest.raises(units.UnitsError):
get_validated_freq(
freq=BANDPASS_FREQUENCIES.value * units.g,
model=model._ipd_model,
model=model._interplanetary_dust_model,
extrapolate=False,
)
with pytest.raises(units.UnitsError):
get_validated_freq(
freq=25 * units.g,
model=model._ipd_model,
model=model._interplanetary_dust_model,
extrapolate=False,
)

Expand Down Expand Up @@ -119,19 +119,19 @@ def test_extrapolate_raises_error() -> None:
model.get_emission_pix([1, 4, 5], nside=32, obs_time=OBS_TIME)


def test_interp_kind() -> None:
"""Tests that the interpolation kind can be passed in."""
model = Zodipy(freq=27 * units.micron, model="dirbe", interp_kind="linear")
linear = model.get_emission_pix([1, 4, 5], nside=32, obs_time=OBS_TIME)
# def test_interp_kind() -> None:
# """Tests that the interpolation kind can be passed in."""
# model = Zodipy(freq=27 * units.micron, model="dirbe", interp_kind="linear")
# linear = model.get_emission_pix([1, 4, 5], nside=32, obs_time=OBS_TIME)

model = Zodipy(freq=27 * units.micron, model="dirbe", interp_kind="quadratic")
quadratic = model.get_emission_pix([1, 4, 5], nside=32, obs_time=OBS_TIME)
# model = Zodipy(freq=27 * units.micron, model="dirbe", interp_kind="quadratic")
# quadratic = model.get_emission_pix([1, 4, 5], nside=32, obs_time=OBS_TIME)

assert not np.allclose(linear, quadratic)
# assert not np.allclose(linear, quadratic)

with pytest.raises(NotImplementedError):
model = Zodipy(freq=27 * units.micron, model="dirbe", interp_kind="sdfs")
model.get_emission_pix(pixels=[1, 4, 5], nside=32, obs_time=OBS_TIME)
# with pytest.raises(NotImplementedError):
# model = Zodipy(freq=27 * units.micron, model="dirbe", interp_kind="sdfs")
# model.get_emission_pix(pixels=[1, 4, 5], nside=32, obs_time=OBS_TIME)


def test_wrong_frame() -> None:
Expand Down
Loading

0 comments on commit 37366c9

Please sign in to comment.