galsci / pysm

PySM 3: Sky emission simulations for Cosmic Microwave Background experiments
https://pysm3.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
33 stars 23 forks source link

Got TypeError using 'd11' model #145

Closed YJHelloWorld closed 1 year ago

YJHelloWorld commented 1 year ago

Hi,

I'm trying to use 'd11' model to generate different realizations of small scales as follows,

image

It comes out with following message and an error, which seems to relate with healpy: /global/homes/j/jianyao/my3.8/lib/python3.8/site-packages/healpy/fitsfunc.py:643: ComplexWarning: Casting complex values to real discards the imaginary part alm.real[i] = almr /global/homes/j/jianyao/my3.8/lib/python3.8/site-packages/healpy/fitsfunc.py:644: ComplexWarning: Casting complex values to real discards the imaginary part alm.imag[i] = almi No physical unit associated with file /global/project/projectdirs/cmb/www/pysm-data/dust_gnilc/raw/HFI_Mask_GalPlane-apo2_2048_R2.00_GAL080_noapo.fits.gz

TypeError Traceback (most recent call last) Cell In [13], line 1 ----> 1 sky11 = pysm3.Sky(nside=64, preset_strings=["d11"])

File ~/my3.8/lib/python3.8/site-packages/pysm3/sky.py:165, in Sky.init(self, nside, max_nside, preset_strings, component_config, component_objects, output_unit, map_dist) 163 component_config[string] = PRESET_MODELS[string] 164 if len(component_config) > 0: --> 165 self.components += create_components_from_config( 166 component_config, nside=nside, map_dist=map_dist 167 ) 168 self.output_unit = u.Unit(output_unit)

File ~/my3.8/lib/python3.8/site-packages/pysm3/sky.py:43, in create_components_from_config(config, nside, map_dist) 41 else: 42 component_class = globals()[class_name] ---> 43 output_component = component_class( 44 **remove_class_from_dict(model_config), nside=nside, map_dist=map_dist 45 ) 46 output_components.append(output_component) 47 return output_components

File ~/my3.8/lib/python3.8/site-packages/pysm3/models/dust_realization.py:130, in ModifiedBlackBodyRealization.init(self, largescale_alm, freq_ref, amplitude_modulation_temp_alm, amplitude_modulation_pol_alm, small_scale_cl, largescale_alm_mbb_index, small_scale_cl_mbb_index, largescale_alm_mbb_temperature, small_scale_cl_mbb_temperature, nside, galactic_mask, max_nside, galplane_fix, seeds, synalm_lmax, has_polarization, map_dist) 120 self.small_scale_cl_mbb_temperature = self.read_cl( 121 small_scale_cl_mbb_temperature 122 ).to(u.K**2) 123 self.nside = int(nside) 124 ( 125 self.I_ref, 126 self.Q_ref, 127 self.U_ref, 128 self.mbb_index, 129 self.mbb_temperature, --> 130 ) = self.draw_realization(synalm_lmax, seeds)

File ~/my3.8/lib/python3.8/site-packages/pysm3/models/dust_realization.py:142, in ModifiedBlackBodyRealization.draw_realization(self, synalm_lmax, seeds) 138 synalm_lmax = min(16384, 2.5 self.nside) 140 np.random.seed(seeds[0]) --> 142 alm_small_scale = hp.synalm( 143 list(self.small_scale_cl.value), 144 lmax=synalm_lmax, 145 new=True, 146 ) 148 alm_small_scale = [ 149 hp.almxfl(each, np.ones(int(min(synalm_lmax, 2.5 self.nside)))) 150 for each in alm_small_scale 151 ] 152 map_small_scale = hp.alm2map(alm_small_scale, nside=self.nside)

File ~/my3.8/lib/python3.8/site-packages/astropy/utils/decorators.py:546, in deprecated_renamed_argument..decorator..wrapper(*args, *kwargs) 543 msg += f'\n Use {alternative} instead.' 544 warnings.warn(msg, warning_type, stacklevel=2) --> 546 return function(args, **kwargs)

File ~/my3.8/lib/python3.8/site-packages/healpy/sphtfunc.py:599, in synalm(cls, lmax, mmax, new, verbose) 597 alms_list = [] 598 for i in range(Nspec): --> 599 alm = np.zeros(szalm, "D") 600 alm.real = np.random.standard_normal(szalm) 601 alm.imag = np.random.standard_normal(szalm)

TypeError: 'float' object cannot be interpreted as an integer

zonca commented 1 year ago

Thanks for reporting, Could you please check if also the main branch gives the same error?

YJHelloWorld commented 1 year ago

image

I tried to install pysm3 from source code in the github main branch, still find the same error.

BTW, the pysm3.4.0b5 version in the first post is installed from pip install pysm3==3.4.0b5 --pre.

YJHelloWorld commented 1 year ago

This problem is due to this line: https://github.com/galsci/pysm/blob/main/pysm3/models/dust_realization.py#L138

When we leave synalm_lmax undefined and set a nside of which 2.5 nside is < 16384, _synalm_lmax = 2.5nside_ which is not an integer, and when passing this float numer to the lmax of hp.synalm, the error occurs.

zonca commented 1 year ago

thanks for tracking it down! would you like to make a pull request to add a int() in that line?