0

I'm trying to read a global attribute within python using xarray from a netcdf4 file. I can see the global attribute in nc_dump from the linux command line. I've tried:

print(ds['global_attribute'])
print(ds.attrs['global_attribute'])

Within python, I note that when I use print(ds.variables.keys()), the global attributes don't show up.

Appreciate the help.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
SP00N
  • 25
  • 7
  • 1
    https://stackoverflow.com/questions/41794956/adding-global-attribute-using-xarray – Robert Davy May 24 '21 at 01:16
  • Thanks. That link is where I obtained the commands I tried above. Didn't work for me. Where there other methods or some way I can check the validity of the file? Seeing the global attributes in "ncdump" was my naive way of doing a check. – SP00N May 24 '21 at 02:21
  • 3
    It should work if you use `ds.attrs['global_attribute']` rather than `ds.attrs('global_attribute')`. Also, `ds.attrs.keys()` . – Robert Davy May 24 '21 at 02:57
  • Thanks Robert, you caught my mistake. I was using the wrong parantheses. Dang it! Greatly appreciate your help – SP00N May 24 '21 at 04:32

0 Answers0