ihesp / IPART

Image-Process based Atmospheric River Tracking (IPART) algorithms
https://ipart.readthedocs.io/en/latest/
GNU General Public License v3.0
23 stars 8 forks source link

_FillValue attribute error #18

Closed khouakhi closed 3 years ago

khouakhi commented 3 years ago

_FillValue error when trying to save the nc files using funcs.saveNC () . It seems a _FillValue attribute needs to be set

funcs.saveNC(abpath_out, ivt.'w')

AttributeError                            Traceback (most recent call last)
<ipython-input-36-b3979129d066> in <module>
----> 1 funcs.saveNC(abpath_out, ivt)

c:\users\e806872\ipart\ipart\utils\funcs.py in saveNC(abpath_out, varNV, mode, dtype)
    816 
    817     with Dataset(abpath_out, mode) as fout:
--> 818         saveNCDims(fout, varNV.axislist)
    819         _saveNCVAR(fout, varNV, dtype)
    820 

c:\users\e806872\ipart\ipart\utils\funcs.py in saveNCDims(fout, axislist)
    896         for kk,vv in aa.attributes.items():
    897             if kk!='isunlimited':
--> 898                 axisvar.setncattr(kk, vv)
    899 
    900     return

netCDF4\_netCDF4.pyx in netCDF4._netCDF4.Variable.setncattr()

AttributeError: _FillValue attribute must be set when variable is created (using fill_value keyword to createVariable)

This happened also when the running the THR script

File "/usr/local/lib/python3.6/site-packages/ipart/thr.py", line 278, in rotatingTHR
    funcs.saveNC(abpath_out, var1, 'w')
  File "/usr/local/lib/python3.6/site-packages/ipart/utils/funcs.py", line 818, in saveNC
    saveNCDims(fout, varNV.axislist)
  File "/usr/local/lib/python3.6/site-packages/ipart/utils/funcs.py", line 898, in saveNCDims
    axisvar.setncattr(kk, vv)
  File "netCDF4/_netCDF4.pyx", line 4123, in netCDF4._netCDF4.Variable.setncattr

AttributeError: _FillValue attribute must be set when variable is created (using fill_value keyword to createVariable) 
Xunius commented 3 years ago

Hi @khouakhi , thanks for the report.

After a bit of searching I guess that the attribute it is trying to set is _FillValue, which should not be overwritten after variable creation (reference: https://github.com/ec-jrc/lisflood-lisvap/commit/59a8407637c8791af6fc330af157459ac08088ec). I tried to manually set a new _FillValue attribute and got the same error message.

I'm pushing a fix to the master branch, implementing this fix:

change line 897 in ipart/utils/funcs.py from

            if kk!='isunlimited':

to

            if kk!='isunlimited' and kk!='_FillValue':

Btw, how did you install IPART, via conda? I will update the conda version later this week (I need to refresh myself about how to maintain conda packages). So if you are in a hurry, could you help manually changing that line of code, and let me know whether that fixes your issue?

Hope that helps

khouakhi commented 3 years ago

Yes I installed IPART using conda. I modified the source funcs.saveNCDims and all works.