pcmdi_metrics
pcmdi_metrics copied to clipboard
Error in loading 4d variables
While I was testing the new obs info catalogue, I noticed an error I was getting in a new pcmdi_metrics environment that I was not getting in my old environment. This error only happens to 4-D variables, and after doing some testing with cdms2 in ipython I think it might be related to the newest version of the numpy library (1.23.4). I haven’t pinned down exactly which version, but I get the error using numpy=1.23.4 but not with numpy =1.22.4.
Here is a snippet showing the error text:
INFO::2022-10-20 13:09::pcmdi_metrics::E3SM:: VAR: zg, REGION: TROPICS
INFO::2022-10-20 13:09::pcmdi_metrics::E3SM:: reference_data_set (given): ['all'], reference_data_set_is_obs: True, test_data_set_is_obs: False
INFO::2022-10-20 13:09::pcmdi_metrics::E3SM:: reference_data_set (adjusted): ['alternate1', 'default'], test_data_set: ['E3SM-1-0']
INFO::2022-10-20 13:09::pcmdi_metrics::E3SM:: alternate1 is an obs
INFO::2022-10-20 13:09::pcmdi_metrics::E3SM:: Could not figure out obs mask name from obs json file
INFO::2022-10-20 13:09::pcmdi_metrics::E3SM:: TEST DATA IS: E3SM-1-0
INFO::2022-10-20 13:09::pcmdi_metrics::E3SM:: E3SM-1-0 is a model
ERROR::2022-10-20 13:09::pcmdi_metrics::E3SM:: Failed opening 4D OBS zg alternate1 only integers, slices (:
), ellipsis (...
), numpy.newaxis (None
) and integer or boolean arrays are valid indices
Here are some ipython snippets showing the testing I've done.
Setup in ipython
import cdms2
filename="/p/user_pub/PCMDIobs/obs4MIPs_clims/hus/ERA-INT/v20210804/hus_mon_ERA-INT_PCMDI_gn.200301-201812.AC.v20210804.nc"
var_file=cdms2.open(filename,"r")
Numpy = 1.22.4 environment, slicing works as expected but with future warning
hus=var_file("hus",plev=100000)
/home/ordonez4/miniconda3/envs/test_pcmdi/lib/python3.8/site-packages/cdms2/fvariable.py:103: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
result = result[revlist]
hus.shape
Out[5]: (12, 1, 121, 240)
Numpy = 1.23.[2,3,4] environment, slicing does not work as before
hus=var_file("hus",plev=100000)
Out[25]:
…stack trace…
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
But the following does work with these versions:
hus=var_file("hus",plev=(100000,92500))
hus.shape
Out[28]: (12, 2, 121, 240)
Related to https://github.com/CDAT/cdms/issues/446
This issue is temporarily resolved by pinning numpy < 1.23.0 in meta.yaml on the pcmdi_metrics conda feedstock.