Closed emiliano-gelati closed 5 years ago
@emiliano-gelati
Hi Emiliano, Any update on this? should we merge that commit into master and close this issue?
@domeniconappo Hi Domenico, Yes, if changes look OK to you, please proceed with merging. Thank you, Emiliano
super! I'm doing some tests and will merge if no problems come up
merged. Thanks!
Using input NetCDF files created via xarray.Dataset.to_netcdf, which creates a "_FillValue" attribute for all variables (including those corresponding to the spatial dimensions x,y/lon,lat) causes an error when writing the attributes of the spatial dimensions of output NetCDF files: NetCDF4 does not allow setting the "_FillValue" attribute after the variable has been created. See the bold lines in the Traceback at the bottom.
I propose a bug-fix (59a8407637c8791af6fc330af157459ac08088ec) to skip creating the "_FillValue" attribute for spatial dimensions. In addition, a loop over the spatial dimensions replaces 4 nearly identical code blocks.
I could not find any way to prevent xarray.Dataset.to_netcdf from setting the "_FillValue" attribute.
Traceback (most recent call last): File "lisvap/lisvap1.py", line 122, in
sys.exit(main())
File "lisvap/lisvap1.py", line 118, in main
lisvapexe(lissettings)
File "lisvap/lisvap1.py", line 70, in lisvapexe
dynfmw.run()
File "/opt/pcraster-4.1.0_x86-64/python/pcraster/framework/dynamicFramework.py", line 65, in run
self._runDynamic()
File "/opt/pcraster-4.1.0_x86-64/python/pcraster/framework/frameworkBase.py", line 362, in _runDynamic
self._userModel().dynamic()
File "/home/gelatem/BMI_lisflood/lisvap/src/lisvap/lisvapdynamic.py", line 358, in dynamic
self.output_module.dynamic()
File "/home/gelatem/BMI_lisflood/lisvap/src/lisvap/utils/output.py", line 153, in dynamic
self.settings.report_maps_all[maps].unit, 'f4', self.var.calendar_date)
File "/home/gelatem/BMI_lisflood/lisvap/src/lisvap/utils/writers.py", line 49, in writenet
setattr(latitude, i, metadata_ncdf['lat'][i])
File "netCDF4/_netCDF4.pyx", line 3869, in netCDF4._netCDF4.Variable.setattr
AttributeError: _FillValue attribute must be set when variable is created (using fill_value keyword to createVariable)