regionmask / regionmask

create masks of geospatial regions for arbitrary grids
https://regionmask.readthedocs.io/
MIT License
250 stars 23 forks source link

make non-dimension coords indexes for 3D mask #480

Open mathause opened 1 year ago

mathause commented 1 year ago

With the ongoing xarray index refactor we can now promote the "abbrevs" and "names" to indexes, which can then be selected directly (instead of needing to go via the numbers).

Implementing this is not difficult - but which xarray version supports this exactly? (Certainly after v2022.09.0)


import regionmask
import xarray as xr

air = xr.tutorial.open_dataset("air_temperature")
mask = regionmask.defined_regions.ar6.land.mask_3D(air)

mask = mask.set_xindex("abbrevs").set_xindex("names")

mask.sel(abbrevs="GIC")
mask.sel(names="Caribbean")
dcherian commented 1 year ago

It'd be nice to thrown in the geometry too so we can convert to a vector data cube easily: https://xvec.readthedocs.io/en/stable/

mathause commented 1 year ago

Thanks for pointing that out!

mathause commented 12 months ago

Just found out about pydata/xarray#7695, and with the xindexes air.air.weighted(mask).mean(["lat", "lon"]) raises an error so currently this is unfortunately not usable :disappointed: