Skip to content

Commit

Permalink
support for pre-beam
Browse files Browse the repository at this point in the history
  • Loading branch information
zonca committed Oct 16, 2024
1 parent be07014 commit 5e2d339
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/pysm3/data/presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ input_units = "uK_RJ"
freqs = [5.0, 18.7, 24.5, 44.0, 70.0, 100.0, 143.0, 217.0, 353.0, 545.0, 643.0, 729.0, 857.0, 906.0]
path = "websky/0.4/radio_catalog/{nside}"
interpolation_kind = "linear"
available_nside = [2048, 4096, 8192]
pre_applied_beam = {2048=5.1, 4096=2.6, 8192=0.9}
pre_applied_beam_units = "arcmin"
max_nside = 8192
[ksz1]
class = "WebSkySZ"
Expand Down
67 changes: 63 additions & 4 deletions tests/test_interpolating.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@
from pysm3 import InterpolatingComponent
from pysm3 import units as u

nside = 4
nside = 64
shape = (3, hp.nside2npix(nside))


@pytest.fixture
def interp(tmp_path):
"""Setup the interpolating component"""
def create_maps(tmp_path):
hp.write_map(tmp_path / "10.fits", np.ones(shape, dtype=np.float32))
hp.write_map(tmp_path / "20.fits", 2 * np.ones(shape, dtype=np.float32))
return tmp_path


@pytest.fixture
def interp(create_maps):
"""Setup the interpolating component"""

return InterpolatingComponent(tmp_path, "uK_RJ", nside, interpolation_kind="linear")
return InterpolatingComponent(
create_maps, "uK_RJ", nside, interpolation_kind="linear"
)


def test_interpolating(interp):
Expand Down Expand Up @@ -44,3 +51,55 @@ def test_interpolating_bandpass_boundary_below(interp):
np.testing.assert_allclose(
1.118 * np.ones(shape) * u.uK_RJ, interpolated_map, rtol=1e-2
)


@pytest.fixture
def interp_pre_smoothed(tmp_path):
"""Setup the interpolating component"""
m = np.zeros(shape, dtype=np.float32)
m[0] += 10

m[0, hp.ang2pix(nside, np.pi / 2, 0)] = 100
hp.write_map(tmp_path / "10.fits", m)

return m, InterpolatingComponent(
tmp_path,
"uK_RJ",
nside,
interpolation_kind="linear",
available_nside=[nside],
pre_applied_beam={nside: 5},
pre_applied_beam_units="deg",
)


def test_presmoothed_null(interp_pre_smoothed):
input_map, interp_pre_smoothed = interp_pre_smoothed
output_map = interp_pre_smoothed.get_emission(
10 * u.GHz,
fwhm=5 * u.deg,
lmax=1.5 * nside,
)
np.testing.assert_allclose(input_map, output_map.value)


def test_presmoothed(tmp_path):
"""Setup the interpolating component"""
m = np.ones(shape, dtype=np.float32) * 10
m[0, hp.ang2pix(nside, np.pi / 2, 0)] = 100
m_smoothed = hp.smoothing(m, fwhm=np.radians(3))
hp.write_map(tmp_path / "10.fits", m_smoothed)

c = InterpolatingComponent(
tmp_path,
"uK_RJ",
nside,
interpolation_kind="linear",
available_nside=[nside],
pre_applied_beam={nside: 3},
pre_applied_beam_units="deg",
)

input_map = hp.smoothing(m, fwhm=np.radians(5))
output_map = c.get_emission(10 * u.GHz, fwhm=5 * u.deg, lmax=1.5 * nside)
np.testing.assert_allclose(input_map, output_map.value, rtol=1e-3, atol=1e-4)
2 changes: 1 addition & 1 deletion tests/test_smoothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from astropy.tests.helper import assert_quantity_allclose

import pysm3.units as u
from pysm3.models import apply_smoothing_and_coord_transform
from pysm3 import apply_smoothing_and_coord_transform

FWHM = (5 * u.deg).to_value(u.radian)
NSIDE = 128
Expand Down

0 comments on commit 5e2d339

Please # to comment.