CCI-Tools / cate

ESA CCI Toolbox (Cate)
MIT License
50 stars 15 forks source link

AttributeError "cannot write attribute with reserved name '_NCProperties' " when using make_local #900

Closed AliceBalfanz closed 4 years ago

AliceBalfanz commented 4 years ago

When using cate python api for some datasets the following error occurs: AttributeError "cannot write attribute with reserved name '_NCProperties' "

This happens for some datasets which have not problem when opening from remote. this happens e.g. for

esacci.SST.satellite-orbit-frequency.L3U.SSTskin.AVHRR-3.Metop-A.AVHRRMTA_G.2-1.r1 time range ('2006-11-21', '2006-11-23') region "-49.8, 13.1,-49.7, 13.2" variables ['sst_dtime', 'sea_surface_temperature_depth']

Expected behavior

I would expect no error occurring, as the dataset collection does not fail when opening from remote.

EDIT: This issue occurs when executing

data_source = data_store.query('esacci.SST.satellite-orbit-frequency.L3U.SSTskin.AVHRR-3.Metop-A.AVHRRMTA_G.2-1.r1')[0]
ds_from_local = data_source.make_local('local_ds_sst', time_range=('2006-11-21', '2006-11-23'), var_names=['sst_dtime', 'sea_surface_temperature_depth'], region='-49.8, 13.1,-49.7, 13.2' )

Stacktrace:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-291fe64864a3> in <module>
----> 1 das = data_source.make_local('local_name_10', time_range=time_range, var_names=variables, region=region )

~/Desktop/projects/cate/cate/ds/esa_cci_odp.py in make_local(self, local_name, local_id, time_range, region, var_names, monitor)
   1321                     if local_ds.is_empty:
   1322                         local_store.remove_data_source(local_ds)
-> 1323                     raise e
   1324 
   1325             if local_ds.is_empty:

~/Desktop/projects/cate/cate/ds/esa_cci_odp.py in make_local(self, local_name, local_id, time_range, region, var_names, monitor)
   1314             if not local_ds.is_complete:
   1315                 try:
-> 1316                     self._update_local_ds(local_ds, time_range, region, var_names, monitor=monitor)
   1317                 except Cancellation as c:
   1318                     local_store.remove_data_source(local_ds)

~/Desktop/projects/cate/cate/ds/esa_cci_odp.py in _update_local_ds(self, local_ds, time_range, region, var_names, monitor)
   1117         if region or var_names:
   1118             self._update_ds_using_opendap(local_path, local_ds, selected_file_list, time_range, var_names, region,
-> 1119                                           monitor)
   1120         else:
   1121             self._update_ds_using_http(local_path, local_ds, selected_file_list, time_range, region, var_names, monitor)

~/Desktop/projects/cate/cate/ds/esa_cci_odp.py in _update_ds_using_opendap(self, local_path, local_ds, selected_file_list, time_range, var_names, region, monitor)
   1175                             # Probably related to https://github.com/pydata/xarray/issues/2560.
   1176                             # And probably fixes Cate issues #823, #822, #818, #816, #783.
-> 1177                             remote_dataset.to_netcdf(local_filepath, format='NETCDF4', engine='h5netcdf')
   1178                             child_monitor.progress(work=75)
   1179 

~/miniconda3/envs/cate-env/lib/python3.7/site-packages/xarray/core/dataset.py in to_netcdf(self, path, mode, format, group, engine, encoding, unlimited_dims, compute, invalid_netcdf)
   1545             unlimited_dims=unlimited_dims,
   1546             compute=compute,
-> 1547             invalid_netcdf=invalid_netcdf,
   1548         )
   1549 

~/miniconda3/envs/cate-env/lib/python3.7/site-packages/xarray/backends/api.py in to_netcdf(dataset, path_or_file, mode, format, group, engine, encoding, unlimited_dims, compute, multifile, invalid_netcdf)
   1071         # to be parallelized with dask
   1072         dump_to_store(
-> 1073             dataset, store, writer, encoding=encoding, unlimited_dims=unlimited_dims
   1074         )
   1075         if autoclose:

~/miniconda3/envs/cate-env/lib/python3.7/site-packages/xarray/backends/api.py in dump_to_store(dataset, store, writer, encoder, encoding, unlimited_dims)
   1117         variables, attrs = encoder(variables, attrs)
   1118 
-> 1119     store.store(variables, attrs, check_encoding, writer, unlimited_dims=unlimited_dims)
   1120 
   1121 

~/miniconda3/envs/cate-env/lib/python3.7/site-packages/xarray/backends/common.py in store(self, variables, attributes, check_encoding_set, writer, unlimited_dims)
    293         variables, attributes = self.encode(variables, attributes)
    294 
--> 295         self.set_attributes(attributes)
    296         self.set_dimensions(variables, unlimited_dims=unlimited_dims)
    297         self.set_variables(

~/miniconda3/envs/cate-env/lib/python3.7/site-packages/xarray/backends/common.py in set_attributes(self, attributes)
    310         """
    311         for k, v in attributes.items():
--> 312             self.set_attribute(k, v)
    313 
    314     def set_variables(self, variables, check_encoding_set, writer, unlimited_dims=None):

~/miniconda3/envs/cate-env/lib/python3.7/site-packages/xarray/backends/h5netcdf_.py in set_attribute(self, key, value)
    178 
    179     def set_attribute(self, key, value):
--> 180         self.ds.attrs[key] = value
    181 
    182     def encode_variable(self, variable):

~/miniconda3/envs/cate-env/lib/python3.7/site-packages/h5netcdf/attrs.py in __setitem__(self, key, value)
     22         if key in _HIDDEN_ATTRS:
     23             raise AttributeError('cannot write attribute with reserved name %r'
---> 24                                  % key)
     25         if hasattr(value, 'dtype'):
     26             dtype = value.dtype

AttributeError: cannot write attribute with reserved name '_NCProperties'
AliceBalfanz commented 4 years ago

closed by https://github.com/CCI-Tools/cate/pull/901