add `flag_values` and `flag_meanings` to 2D masks?
See original GitHub issueThis would allow to indicate which region corresponds to which number via attrs
and would work nicely with cf_xarray
.
import cf_xarray
import xarray as xr
da = xr.DataArray(
[[1, 2, 1], [1, 2, np.NaN]],
dims=("lat", "lon"),
attrs={
"flag_values": [1, 2],
"flag_meanings": "atlantic_ocean pacific_ocean",
"standard_name": "region",
},
name="mask",
)
print(da.cf)
print(da.cf == "atlantic_ocean")
print(da.cf.isin(["indian_ocean", "pacific_ocean"]))
See
- https://cf-xarray.readthedocs.io/en/latest/flags.html
- xarray-contrib/cf-xarray#199
- http://cfconventions.org/Data/cf-conventions/cf-conventions-1.8/cf-conventions.html#flags
Open questions:
- do we add
abbrevs
ornames
(probablyabbrevs
) - does it work for
float
arrays (as I encode “not belonging to any region” withNaN
)?
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
How to Mask Graphics in Unity. 2D Sprite Mask ... - YouTube
How to mask graphics in Unity? In this tutorial we will have a look at how we can create and use sprite masks....
Read more >Masking BGR image using a 2D mask - python - Stack Overflow
Try to use a mask with the same shape as the image (actually, this will be a 3D mask). After generating your image_mask...
Read more >Blue KF94 2D Mask (Large Black - Adult Size) - Be Healthy
Approved by KFDA (KF94 / KF80) · Premium 4 layers of filters · Blocks over 94% of 0.4µm size particles. · Ultra-light and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Each region has 3 “indices” - a number, an abbreviation, and a name, e.g.:
But we can only attach one of the “abbreviation” and “name” to
flag_meanings
- but which one should it be?Currently I am tempted to just assign the abbreviation.
Alternatively we could make it an option:
The code would then (more or less) just be:
Another open question - if some regions are missing from the mask - do we still list them under
"flag_values"
and"flag_meanings"
? I’d also need to test this with cf_xarray.But overall I think this whole thing should be relatively straight-forward…
As long as we have some set way to do it, that seems totally fine to me. But there might be some spec that I am missing here?