coecms / xmhw

Xarray version of Marine Heatwaves code by Eric Olivier
https://xmhw.readthedocs.io/en/latest/
Apache License 2.0
21 stars 10 forks source link

xmhw struggles with 2d data #66

Open erikbehrens opened 1 year ago

erikbehrens commented 1 year ago

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:

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:

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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