Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions litebird_sim/input_sky.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,32 +840,21 @@ def _generate_dipole_frequencies(self) -> HealpixMap | SphericalHarmonics:
band_integration=False,
)

m_dip = HealpixMap(
values=dipole_map_val * conv_factor,
nside=self.params.nside,
units=self.lbs_unit,
coordinates=self.coords,
nest=False,
)

alm_dip = estimate_alm(
m_dip,
lmax=self.params.lmax,
nthreads=self.params.nthreads,
)

fwhm = None if self.fwhm_rad is None else float(self.fwhm_rad[i])
self._apply_smoothing_and_windows_to_alm(alm_dip, fwhm)

if self.params.output_type == "map":
m = pixelize_alm(
alm_dip,
out[i] = dipole_map_val * conv_factor
else:
m_dip = HealpixMap(
values=dipole_map_val * conv_factor,
nside=self.params.nside,
units=self.lbs_unit,
coordinates=self.coords,
nest=False,
)
alm_dip = estimate_alm(
m_dip,
lmax=self.params.lmax,
nthreads=self.params.nthreads,
)
out[i] = m.values
else:
out[i] = alm_dip.values

# Return multi-frequency object
Expand Down
45 changes: 45 additions & 0 deletions test/test_input_sky.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,48 @@ def test_skygenerator_frequency_mode_all_components():

assert result_multi.nfreqs == 2
assert result_multi.values.shape == (2, 3, 12 * 16**2) # (nfreqs, nstokes, npix)


def test_dipole_consistency_channel_vs_frequency():
"""
Tests that the dipole map is identical when generated via the channel path
and the frequency path, reproducing the bug reported in the issue.
The frequency path previously applied a map->alm->map round trip and beam
smoothing to the dipole that the channel path did not, causing discrepancies.
"""
nside = 64
fwhm_arcmin = 37.805193

channel_info = FreqChannelInfo(
bandcenter_ghz=140.0,
channel="L4-140",
bandwidth_ghz=1.0,
fwhm_arcmin=fwhm_arcmin,
)

sky_params = SkyGenerationParams(
make_cmb=False,
make_dipole=True,
make_fg=False,
output_type="map",
apply_beam=True,
bandpass_integration=False,
nside=nside,
units="K_CMB",
)

gen_sky_ch = SkyGenerator(parameters=sky_params, channels=channel_info)
input_maps_ch = gen_sky_ch.execute()["L4-140"]

gen_sky_freq = SkyGenerator(
parameters=sky_params,
frequencies_ghz=140.0,
fwhm_rad=np.radians(fwhm_arcmin / 60.0),
)
input_maps_freq = gen_sky_freq.execute()

npt.assert_array_almost_equal(
input_maps_ch.values,
input_maps_freq.values[0],
decimal=5,
)