Changing or Turning off _FillValues

ぐ巨炮叔叔 提交于 2019-12-10 12:30:50

问题


I want to either turn off the filling or change the _FillValue to None/NaN in the NetCDF file. How do you do this? I have tried looking it up and nobody talks about it. When I output a variable such as longitude, this is what I get:

float32 lons(lons) units: degree_east unlimited dimensions: current shape = (720,) filling on, default _FillValue of 9.969209968386869e+36 used

I have also tried masking, but it still gives me the information above.

Here is some code I have:

  lati = numpy.arange(-89.75,90.25,0.5)
  long = numpy.arange(-179.75,180.25,0.5)

  row = 360
  column = 720

  dataset = netCDF4.Dataset(r'Y://Projects//ToriW//NC Files//April2.nc', 'w', format = 'NETCDF4_CLASSIC')

  dataset.misisngValue = None
  dataset.filling = "off"
  dataset.createDimension('lats',row)
  dataset.createDimension('lons',column)

  lats = dataset.createVariable('lats', 'f4',('lats'))
  lats.units = 'degree_north'

  lons = dataset.createVariable('lons','f4',('lons'))
  lons.units = 'degree_east'

  print (lons)

  lats[:] = lati
  lons[:] = long     
  Pre = dataset.createVariable ('Pre',numpy.float64, ('lats','lons'))

  Pre[:,:] = total

  dataset.close()

}


回答1:


_Fill_Value is the proper name for the attribute you want.

dateset.set_fill_off()

should work.

dataset.setncattr("_Fill_Value", None)

might work. I'm not sure, but will work to change the _Fill_Value.



来源:https://stackoverflow.com/questions/38599252/changing-or-turning-off-fillvalues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!