Project

General

Profile

Printing global attribute

Added by Ilias Moysidis about 1 year ago

Suppose that we have a netcdf file with the following global attributes:

global attributes:
:CDI = "Climate Data Interface version 2.0.4 (https://mpimet.mpg.de/cdi)" ;
:Conventions = "CF-1.6" ;
:source = "SMHI-RCA4, driving experiment:MOHC-HadGEM2-ES, rcp26, r1i1p1" ;
:institution = "National Observatory of Athens, URL: http://www.noa.gr" ;
:creation_date = "2019-06-18-T15:47:14Z" ;
:Frequency = "Daily" ;
:contact = "" ;
:title = "Daily FWI Values" ;

How can I save and access a specific attribute, let's say "source" in python?


Replies (3)

RE: Printing global attribute - Added by Karin Meier-Fleischer about 1 year ago

Hi Ilias,

I don't know why showattribute is not working in Python to retrieve the global attributes but you can use xarray instead.

import xarray as xr

ds = xr.open_dataset('infile.nc')

print(ds.attrs['source'])

RE: Printing global attribute - Added by Ilias Moysidis about 1 year ago

How would you do it with showattribute?

    (1-3/3)