From 0f8d4b7c183f18e4d91d7aea160a55c53faf2c38 Mon Sep 17 00:00:00 2001 From: Andrea Zonca Date: Wed, 18 May 2022 20:39:37 -0700 Subject: [PATCH 1/5] smooth directly the small scales --- pysm3/models/dust_realization.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/pysm3/models/dust_realization.py b/pysm3/models/dust_realization.py index 1be4bee9..c1f4cf18 100644 --- a/pysm3/models/dust_realization.py +++ b/pysm3/models/dust_realization.py @@ -19,6 +19,7 @@ def __init__( largescale_alm_mbb_temperature, small_scale_cl_mbb_temperature, nside, + fwhm=None, galplane_fix=None, seeds=None, synalm_lmax=None, @@ -62,6 +63,9 @@ def __init__( excess power in the full sky spectra due to the generated small scales being too strong on the galactic plane. By default in d9,d10,d11 we use the input GNILC map with a resolution of 21.8' + fwhm: gaussian beam width + Produce small scales already smoothed with a gaussian beam, this makes the spherical + harmonics transforms more accurate compared to smoothing the outputs seeds: list of ints List of seeds used for generating the small scales, first is used for the template, the second for the spectral index, the third for the black body temperature. @@ -100,8 +104,7 @@ def __init__( else: self.galplane_fix_map = None self.largescale_alm_mbb_index = self.read_alm( - largescale_alm_mbb_index, - has_polarization=False, + largescale_alm_mbb_index, has_polarization=False ).to(u.dimensionless_unscaled) self.small_scale_cl_mbb_index = self.read_cl(small_scale_cl_mbb_index).to( u.dimensionless_unscaled @@ -112,6 +115,16 @@ def __init__( self.small_scale_cl_mbb_temperature = self.read_cl( small_scale_cl_mbb_temperature ).to(u.K ** 2) + self.fwhm = fwhm + if self.fwhm is not None: + self.fwhm = self.fwhm.to(u.rad) + self.small_scale_cl_mbb_temperature *= ( + hp.gauss_beam( + fwhm=self.fwhm.value, + lmax=len(self.small_scale_cl_mbb_temperature) - 1, + ) + ** 2 + ) self.nside = int(nside) ( self.I_ref, @@ -151,8 +164,7 @@ def draw_realization(self, synalm_lmax=None, seeds=None): map_small_scale[1:] *= hp.alm2map(self.modulate_alm[1].value, self.nside) map_small_scale += hp.alm2map( - self.template_largescale_alm.value, - nside=self.nside, + self.template_largescale_alm.value, nside=self.nside ) if self.galplane_fix_map is not None: @@ -177,11 +189,7 @@ def draw_realization(self, synalm_lmax=None, seeds=None): np.random.seed(seed) input_cl = getattr(self, f"small_scale_cl_{key}") output_unit = np.sqrt(1 * input_cl.unit).unit - alm_small_scale = hp.synalm( - input_cl.value, - lmax=synalm_lmax, - new=True, - ) + alm_small_scale = hp.synalm(input_cl.value, lmax=synalm_lmax, new=True) alm_small_scale = hp.almxfl( alm_small_scale, np.ones(min(3 * self.nside - 1, synalm_lmax + 1)) @@ -190,8 +198,7 @@ def draw_realization(self, synalm_lmax=None, seeds=None): output[key] *= modulate_map_I output[key] += ( hp.alm2map( - getattr(self, f"largescale_alm_{key}").value, - nside=self.nside, + getattr(self, f"largescale_alm_{key}").value, nside=self.nside ) * output_unit ) From be2238512cd7e3d5e92856e9efb3141b9e36c710 Mon Sep 17 00:00:00 2001 From: Andrea Zonca Date: Wed, 18 May 2022 21:19:44 -0700 Subject: [PATCH 2/5] fix: was smoothing the mbb temperature instead of the template --- pysm3/models/dust_realization.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pysm3/models/dust_realization.py b/pysm3/models/dust_realization.py index c1f4cf18..37979fa0 100644 --- a/pysm3/models/dust_realization.py +++ b/pysm3/models/dust_realization.py @@ -118,13 +118,13 @@ def __init__( self.fwhm = fwhm if self.fwhm is not None: self.fwhm = self.fwhm.to(u.rad) - self.small_scale_cl_mbb_temperature *= ( + B_ell_squared = ( hp.gauss_beam( - fwhm=self.fwhm.value, - lmax=len(self.small_scale_cl_mbb_temperature) - 1, + fwhm=self.fwhm.value, lmax=self.small_scale_cl.shape[-1] - 1 ) ** 2 ) + self.small_scale_cl *= B_ell_squared self.nside = int(nside) ( self.I_ref, From e84021e7353060040fed219043fd22ae1376dda7 Mon Sep 17 00:00:00 2001 From: Andrea Zonca Date: Wed, 18 May 2022 21:58:03 -0700 Subject: [PATCH 3/5] scale also index and mbb temperature --- pysm3/models/dust_realization.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pysm3/models/dust_realization.py b/pysm3/models/dust_realization.py index 37979fa0..0c6f3842 100644 --- a/pysm3/models/dust_realization.py +++ b/pysm3/models/dust_realization.py @@ -125,6 +125,12 @@ def __init__( ** 2 ) self.small_scale_cl *= B_ell_squared + self.small_scale_cl_mbb_temperature *= B_ell_squared[ + : len(self.small_scale_cl_mbb_temperature) + ] + self.small_scale_cl_mbb_index *= B_ell_squared[ + : len(self.small_scale_cl_mbb_index) + ] self.nside = int(nside) ( self.I_ref, From 50e72ed660b3c3c0b9d521d292904457fb954f69 Mon Sep 17 00:00:00 2001 From: Andrea Zonca Date: Wed, 18 May 2022 22:38:47 -0700 Subject: [PATCH 4/5] make pep8 happy --- pysm3/utils/__init__.py | 1 + pysm3/utils/logpoltens.py | 3 ++- tox.ini | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pysm3/utils/__init__.py b/pysm3/utils/__init__.py index f233ddd4..f9e207d7 100644 --- a/pysm3/utils/__init__.py +++ b/pysm3/utils/__init__.py @@ -11,6 +11,7 @@ from .logpoltens import log_pol_tens_to_map, map_to_log_pol_tens # noqa: F401 from .small_scales import sigmoid # noqa: F401 from .add_metadata import add_metadata # noqa: F401 +from .gauss_legendre import * # noqa: F401, F403 import logging diff --git a/pysm3/utils/logpoltens.py b/pysm3/utils/logpoltens.py index 9951f5a8..c02b1137 100644 --- a/pysm3/utils/logpoltens.py +++ b/pysm3/utils/logpoltens.py @@ -25,5 +25,6 @@ def log_pol_tens_to_map(log_pol_tens): m = np.empty_like(log_pol_tens) exp_i = np.exp(log_pol_tens[0]) m[0] = exp_i * np.cosh(P) - m[1:] = log_pol_tens[1:] / P * exp_i * np.sinh(P) + for pol in [1, 2]: + m[pol] = log_pol_tens[pol] / P * exp_i * np.sinh(P) return m diff --git a/tox.ini b/tox.ini index 6a710c20..7c0757c5 100644 --- a/tox.ini +++ b/tox.ini @@ -103,3 +103,4 @@ extend-ignore = per-file-ignores = pysm3/units.py:F405 pysm3/sky.py:F401,F403 + pysm3/tests/test_gl.py:F405,F403 From dfdb793a2d037fa201543aa6b2e07dd751892824 Mon Sep 17 00:00:00 2001 From: Andrea Zonca Date: Sun, 5 Jun 2022 17:27:47 -0700 Subject: [PATCH 5/5] remove import from other branch --- pysm3/utils/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pysm3/utils/__init__.py b/pysm3/utils/__init__.py index f9e207d7..f233ddd4 100644 --- a/pysm3/utils/__init__.py +++ b/pysm3/utils/__init__.py @@ -11,7 +11,6 @@ from .logpoltens import log_pol_tens_to_map, map_to_log_pol_tens # noqa: F401 from .small_scales import sigmoid # noqa: F401 from .add_metadata import add_metadata # noqa: F401 -from .gauss_legendre import * # noqa: F401, F403 import logging