pyoceans / pocean-core

🐍 + 🌊 A python framework for working with met-ocean data
https://pyoceans.github.io/pocean-core/
MIT License
22 stars 16 forks source link

can't handle variable attributes that start with underscore (i.e. '_CoordinateAxisType') #45

Closed eldobbins closed 5 years ago

eldobbins commented 5 years ago

When I use OrthogonalMultidimensionalTimeseries with a dictionary of attributes that contain keys that start with an underscore, I get an error. For instance:

'latitude': {'_CoordinateAxisType': 'Lat', '_FillValue': -9999.9, ...}, Gives

RuntimeError Traceback (most recent call last) ~/anaconda3/envs/packrat36/lib/python3.6/site-packages/pocean/dsg/timeseries/om.py in from_dataframe(cls, df, output, **kwargs) 161 # Set global attributes --> 162 nc.update_attributes(attributes) 163

~/anaconda3/envs/packrat36/lib/python3.6/site-packages/pocean/dataset.py in upate_attributes(self, attributes) 268 L.warning('Could not set attribute {} on {}'.format(n, k)) --> 269 self.sync()

netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Dataset.sync()

netCDF4/_netCDF4.pyx in netCDF4._netCDF4._ensure_nc_success()

RuntimeError: NetCDF: Can't open HDF5 attribute

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last)

in () ---> 68 station_dataframe_to_netcdf(df, name, outfile, filename, **stations[name]) in station_dataframe_to_netcdf(stdf, code, output_path, filename, **kwargs) 54 output=output_path, 55 axes=axes, ---> 56 attributes=atts) 57 ncd.close() 58 ~/anaconda3/envs/packrat36/lib/python3.6/site-packages/pocean/dsg/timeseries/om.py in from_dataframe(cls, df, output, **kwargs) 160 161 # Set global attributes --> 162 nc.update_attributes(attributes) 163 164 return OrthogonalMultidimensionalTimeseries(output, **kwargs) netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Dataset.__exit__() ~/anaconda3/envs/packrat36/lib/python3.6/site-packages/pocean/dataset.py in close(self) 49 return 50 ---> 51 super(EnhancedDataset, self).close() 52 53 def vatts(self, vname): netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Dataset.close() netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Dataset._close() netCDF4/_netCDF4.pyx in netCDF4._netCDF4._ensure_nc_success() RuntimeError: NetCDF: Can't open HDF5 attribute

Is it this specific attribute? Is it reserved for something?

kwilcox commented 5 years ago

Fixed in https://github.com/pyoceans/pocean-core/commit/a1192115c9bbbd58e7df1ba093313f3545625d03