xgcm / xgcm

python package for analyzing general circulation model output data
http://xgcm.readthedocs.org
MIT License
222 stars 80 forks source link

diff_2d_vector error in example code #531

Open yangleir opened 2 years ago

yangleir commented 2 years ago

Hi, I not sure if this is a bug or my wrong usage of xgcm. I try to run the example: https://github.com/pangeo-gallery/physical-oceanography/blob/master/04_eccov4.ipynb

Fails at diff_2d_vector:

diff_ADV_th = grid.diff_2d_vector({'X': advx_th_vint, 'Y': advy_th_vint}, boundary='fill')

The error messages are pretty long, finally show:

ValueError: The truth value of a Array is ambiguous. Use a.any() or a.all().

I have tried this example many times, each time I have the same issue.

I know the xgcm is developed quickly. Dose somethings progressed and the notebook is out of date? And how to make it work?

Thanks

andrewdelman commented 1 year ago

I have had the same issue with the most recent version (v0.8.1). The error seems to lie in padding.py:

if di not in arr_source:

where arr_source is a full xarray DataArray. Specifying arr_source.dims (a tuple) seems to fix this issue

if di not in arr_source.dims:

andrewdelman commented 1 year ago

Also had issue #581 with diff_2d_vector after fixing the above.

seamanticscience commented 1 year ago

+1, I had this issue in v0.8.1 (see too @jdldeauna's #595), and then #581 - the fixes mentioned both seemed to work for me! Thanks @andrewdelman!

jbusecke commented 1 year ago

Hi everyone, thanks for reporting this bug and also providing fixes. I have started #597 which includes a test covering this issue and the fix suggested above.

I am not sure if #581 is directly related to this as suggested above. Will investigate separately.

jbusecke commented 1 year ago

Can you try if this works from the main branch for you? I will release 0.9.0 soon then.

andrewdelman commented 1 year ago

Thanks @jbusecke the fix has resolved #531 for me. I do still encounter issue #581 when using diff_2d_vector.

jbusecke commented 1 year ago

Thanks for letting me know! Ill work on a fix when I get a minute. Thanks for the patience.