2
votes

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
Does your typo misisngValue make a difference?Spencer Hill

1 Answers

4
votes

_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.