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

Add axis metadata #393

Open
danlooo opened this issue May 15, 2024 · 1 comment
Open

Add axis metadata #393

danlooo opened this issue May 15, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed todo

Comments

@danlooo
Copy link
Member

danlooo commented May 15, 2024

The NetCDF data models allows storing attributes of dimensions.
This is helpful when it comes to store CF metadata of axis dimensions, e.g. unit and standard_name of axis air pressure. However, such attributes are currently ignored by open_dataset and savedataset:

using YAXArrays
using NetCDF
using Downloads

cf_example_file = Downloads.download("https://www.unidata.ucar.edu/software/netcdf/examples/sresa1b_ncar_ccsm3-example.nc", "example.nc")

ds_nc = NetCDF.open(cf_example_file)
ds_yax = open_dataset(cf_example_file)

ds_yax.plev # no metadata
# plev [100000.0, 92500.0, …, 2000.0, 1000.0]

ds_nc["plev"].atts # metadata
# Dict{Any, Any} with 5 entries:
#   "units"         => "Pa"
#   "long_name"     => "pressure"
#   "axis"          => "Z"
#   "standard_name" => "air_pressure"
#   "positive"      => "down"

This could be fixed by utilising the metadata field of the Lookup of the Dimension:

using DimensionalData.Lookups
plev_lookup = Sampled(ds_yax.axes[:plev].val; metadata=ds_nc["plev"].atts)
plev_dim = Dim{:plev}(plev_lookup)

ds_yax.axes[:plev] = plev_dim
metadata(plev_dim)

#Dict{Any, Any} with 5 entries:
#  "units"         => "Pa"
#  "long_name"     => "pressure"
#  "axis"          => "Z"
#  "standard_name" => "air_pressure"
#  "positive"      => "down"
@lazarusA
Copy link
Collaborator

PR?

@lazarusA lazarusA added enhancement New feature or request help wanted Extra attention is needed todo labels Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed todo
Projects
None yet
Development

No branches or pull requests

2 participants