You would be much better off with the Python xarray
library. Along with a bunch of other nice features, metadata stored via the attrs
attribute are OrderedDict
objects.
A quick example:
> import xarray as xr
> ds = xr.open_dataset('zonal_wind.nc')
> ds
<xarray.Dataset>
Dimensions: (lat: 240, lon: 240, rho_lvl: 50, time: 1)
Coordinates:
* time (time) datetime64[ns] 2011-08-11
* lat (lat) float32 -34.05 -34.1 -34.15 -34.2 -34.25 -34.3 -34.35 ...
* lon (lon) float32 139.0 139.05 139.1 139.15 139.2 139.25 139.3 ...
* rho_lvl (rho_lvl) float32 9.99777 50.0014 130.003 250.001 410.003 ...
Data variables:
seg_type (time) |S4 ...
...
zonal_wnd (time, rho_lvl, lat, lon) float64 ...
merid_wnd (time, rho_lvl, lat, lon) float64 ...
Attributes:
positive: up
convention: COARDS
source: Australian Bureau of Meteorology
modl_vrsn: ACCESS-V
expt_id: 0001
> ds.attrs
OrderedDict([('positive', 'up'),
('convention', 'COARDS'),
('source', 'Australian Bureau of Meteorology'),
('modl_vrsn', 'ACCESS-V'),
('expt_id', '0001')])
If you're working with spatial data as well, as an added bonus xarray has an open_rasterio
method to open spatial raster data built on rasterio
, which in turn is built on GDAL.