galsci / pysm

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

Issue at NERSC (CORI) with PySM 3.2.0 (units conversion) #54

Closed jchamilton75 closed 4 years ago

jchamilton75 commented 4 years ago

Hi ! I'm running PySM at NERSC on CORI and I have an error that appeared with version 3.2.0 and was not there with 3.1.0. This is when converting units. The simple script below triggers the error on Cori with 3.2.0 and not with 3.1.0:

`import numpy as np import pysm import pysm.units as u from pysm import utils

print('PySM version:',pysm.version) nus = np.linspace(130., 170., 12) print('nus: ',nus) filter_uK_CMB = np.ones(len(nus), dtype=np.double) print('filter Init: ', filter_uK_CMB) filter_uK_CMB_normalized = utils.normalize_weights(nus * u.GHz, filter_uK_CMB) print('filter Normalized: ', filter_uK_CMB_normalized) print ('All done') `

With 3.1.0: PySM version: 3.1.0 nus: [130. 133.63636364 137.27272727 140.90909091 144.54545455 148.18181818 151.81818182 155.45454545 159.09090909 162.72727273 166.36363636 170. ] filter Init: [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] filter Normalized: [0.01866534 0.01972416 0.02081219 0.02192942 0.02307587 0.02425152 0.02545639 0.02669046 0.02795374 0.02924623 0.03056793 0.03191884] All done

while with 3.2.0: PySM version: 3.2.0 nus: [130. 133.63636364 137.27272727 140.90909091 144.54545455 148.18181818 151.81818182 155.45454545 159.09090909 162.72727273 166.36363636 170. ] filter Init: [1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] Traceback (most recent call last): File "simpletest.py", line 11, in <module> filter_uK_CMB_normalized = utils.normalize_weights(nus * u.GHz, filter_uK_CMB) File "/global/homes/h/hamilton/.conda/envs/qubic_env/lib/python3.8/site-packages/pysm/utils/__init__.py", line 38, in normalize_weights (u.Jy / u.sr), equivalencies=u.cmb_equivalencies(freqs * u.GHz) File "/global/homes/h/hamilton/.conda/envs/qubic_env/lib/python3.8/site-packages/astropy/units/decorators.py", line 229, in wrapper _validate_arg_value(param.name, wrapped_function.__name__, File "/global/homes/h/hamilton/.conda/envs/qubic_env/lib/python3.8/site-packages/astropy/units/decorators.py", line 79, in _validate_arg_value raise UnitsError("Argument '{}' to function '{}' must be in units" astropy.units.core.UnitsError: Argument 'spec' to function 'cmb_equivalencies' must be in units convertible to 'GHz'.

Am I doing something wrong ?

Thanks in advance

zonca commented 4 years ago

my bad @jchamilton75 , it was missing a docstring. I am not using units anymore for that function. because it is mostly used internally by the models and there we are always working in GHz anyway.