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

when grouping by a flag array, set output coordinate using flag_meanings #472

Open
dcherian opened this issue Oct 10, 2023 · 1 comment
Open

Comments

@dcherian
Copy link
Contributor

This would be cool and particularly useful with regionmask

cc @mathause

@mathause
Copy link
Contributor

That would be super cool! Would need to decide if the flag_values are kept as well. I assume you would add this in da.cf.groupby(groups)?

A short example (using regionmask - could of course be simplified to only using xarray):

import cf_xarray
import regionmask
import xarray as xr

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

regional_mean = air.air.groupby(mask).mean()

regional_mean = regional_mean.assign_coords({mask.name: mask.attrs["flag_values"]})
regional_mean = regional_mean.assign_coords({"flags": mask.attrs["flag_meanings"]})

# or
regional_mean = regional_mean.assign_coords({mask.name: mask.attrs["flag_meanings"]})

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