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

Conflicting dimension in newer xarray version #49

Closed CapeHobbit closed 1 year ago

CapeHobbit commented 1 year ago

Not really an issue, just an FYI!

First; thanks for putting together this excellent toolkit! I have been using it for a couple of case studies for EUMETSAT (who I contract for; e.g. https://www.eumetsat.int/marine-heatwave-intensification-threatens-coral-reef-health), with associated Jupyter Notebooks.

However, I think some recent updates to the concat method in xarray break some of your methods. See here for an example. If I roll xarray back to 2022.3.0 everything is fine, but until they roll out a fix 2022.6.0 won't work and will give errors related to duplication of the ts.cell indices. You may want to update your build instructions in the interim. Hope this is useful.

Thanks again!

florianboergel commented 1 year ago

Same for me. I have not been able to solve the problem, however, downgrading to version 2022.3.0 helped.

paolap commented 1 year ago

Thanks for letting me know, I don't use it myself, and I'm drowning in work so didn't have time to check it. I will run some tests and see if I can fix it :-)

paolap commented 1 year ago

Thanks again, looks like the xarray bug has already been resolved, so I've temporarily updated the requirements files, hopefully they'll have a new release soon and then I'll check if this is still happening

bnjmnr commented 1 year ago

I stumbled into the same issue and after some digging, it seems that it comes from the xarray side and particularly in a difference of treatment between the methods mean and quantile. While the first one keeps all the coordinates, including the ones having only one element as is the case for the cell coordinate at that stage of the code, it is not the case for quantile which drops those coordinates for some unknown reason. This is the cause of an error when calling xr.concat at line 173 of the xmhw.py file, because there is no cell coordinate to concatenate anymore. So far, my workaround is to add a little method in the comprehensive list command of line 172 (thresh_results = [r[0] for r in results[0]]) to reassign the command: thresh_results = [r[0].assign_coords(r[1]['cell'].coords) for r in results[0]] It is ugly, but it works. Hopefully something better can be achieved, or the xarray methods will be homogenized soon. In any case, thanks a lot for doing this package, very complementary to the Oliver one.

paolap commented 1 year ago

thanks everyone, looks like I finally have a bit of time to look into this

paolap commented 1 year ago

After having a look, just re-assigning the coordinates doesn't work for me, as they aren't anymore a multi-index but. anomy object and I'm getting an error later when concatenating. After a bit of trial and error I managed to make it work by:

bnjmnr commented 1 year ago

Great, thanks @paolap!

florianboergel commented 1 year ago

Thanks for the effort, @bnjmnr and @paolap.

paolap commented 1 year ago

I had to do a bit of wrangling to make sure the coordinates were treated correctly everywhere. Now all tests are passing, I also used to chance to remove some annoying pandas warnings. Finger crossed this is it! :-) There's a new release 0.9.0