Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xmhw struggles with 2d data #66

Open
erikbehrens opened this issue Mar 28, 2023 · 3 comments
Open

xmhw struggles with 2d data #66

erikbehrens opened this issue Mar 28, 2023 · 3 comments

Comments

@erikbehrens
Copy link

erikbehrens commented Mar 28, 2023

Hey,
I am using a subset of NOAA OISST.

ds=xr.open_dataset('sst.day.mean.1982_2019.v2.nc')
sst=ds['sst']
<xarray.DataArray 'sst' (time: 13879, lat: 720, lon: 1440)>
[14389747200 values with dtype=float32]
Coordinates:

  • time (time) datetime64[ns] 1982-01-01 1982-01-02 ... 2019-12-31
  • lat (lat) float32 -89.88 -89.62 -89.38 -89.12 ... 89.38 89.62 89.88
  • lon (lon) float32 0.125 0.375 0.625 0.875 ... 359.1 359.4 359.6 359.9
    Attributes:

with a subset
In [123]: sst_select
Out[123]:
<xarray.DataArray 'sst' (time: 13879, lat: 4, lon: 4)>
array([[[26.949999, 27.029999, 27.07 , 27.14 ],
[26.8 , 26.869999, 27.109999, 27.26 ],
[26.98 , 27.109999, 27.23 , 27.39 ],
[27.17 , 27.32 , 27.47 , 27.66 ]],

   [[27.24    , 27.199999, 27.119999, 27.01    ],
    [27.23    , 27.15    , 27.22    , 27.17    ],
    [27.38    , 27.33    , 27.33    , 27.269999],
    [27.359999, 27.42    , 27.46    , 27.55    ]],

   ...,

   [[27.849998, 27.76    , 27.65    , 27.57    ],
    [27.92    , 27.779999, 27.68    , 27.66    ],
    [28.06    , 27.98    , 27.859999, 27.82    ],
    [28.32    , 28.24    , 28.09    , 27.92    ]],

   [[27.849998, 27.859999, 27.8     , 27.699999],
    [27.89    , 27.89    , 27.9     , 27.769999],
    [28.119999, 28.07    , 27.99    , 27.88    ],
    [28.349998, 28.289999, 28.15    , 28.05    ]]], dtype=float32)

Coordinates:

  • time (time) datetime64[ns] 1982-01-01 1982-01-02 ... 2019-12-31
  • lat (lat) float32 -0.875 -0.625 -0.375 -0.125
  • lon (lon) float32 0.125 0.375 0.625 0.875

clim=threshold(sst_select)
breaks with
File ~/.conda/envs/def39x/lib/python3.9/site-packages/xmhw/xmhw.py:138 in threshold
ts = land_check(temp, tdim=tdim, anynans=anynans)

File ~/.conda/envs/def39x/lib/python3.9/site-packages/xmhw/identify.py:521 in land_check
ts = temp.stack(cell=(sorted(dims)), create_index=False)

File ~/.conda/envs/def39x/lib/python3.9/site-packages/xarray/core/dataarray.py:2138 in stack
ds = self._to_temp_dataset().stack(dimensions, **dimensions_kwargs)

File ~/.conda/envs/def39x/lib/python3.9/site-packages/xarray/core/dataset.py:3929 in stack
result = result._stack_once(dims, new_dim)

File ~/.conda/envs/def39x/lib/python3.9/site-packages/xarray/core/dataset.py:3865 in _stack_once
if ... in dims:

TypeError: argument of type 'bool' is not iterable

Something does not behave when stacking into 'one long vector'
ts = temp.stack(cell=(sorted(dims)), create_index=False)

Best regards
Erik

PS: Works fine when only applied as a timeseries

@paolap
Copy link
Member

paolap commented Mar 28, 2023

Hi Erik,

I recently updated the land_check function to keep into account changes within xarray concat which were breaking the previous versions. Could you tell me what version of xarray, numpy etc are you using?

It might be possible that the changes introduced break with older version, I didn't;'t have time to test it, so it's just speculation on my part

thanks

@erikbehrens
Copy link
Author

Hey,
thanks for looking into it;
xarray 2022.3.0 pyhd8ed1ab_0 conda-forge
numpy 1.24.2 py39h7360e5f_0 conda-forge

Best
Erik

Do not mind using a different version if that is an issue.

@paolap
Copy link
Member

paolap commented Mar 30, 2023

Yes the changes introduced with 0.9 versions requires newer versions of xarray, or at least they were introduced to work with changes within xarray. Try 0.8.1 that should work with the packages you listed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants