The Higher Education and Research forge

Home My Page Projects Code Snippets Project Openings ScientificPython
Summary Activity Forums Tracker Tasks Docs Surveys News Files

Forum: help

Monitor Forum | Start New Thread Start New Thread
RE: How to set _FillValue? [ Reply ]
By: Konrad Hinsen on 2010-08-23 15:27
[forum:12974]
There was indeed a bug in the Python interface to NetCDF, which prevented some netCDF errors from being converted into Python exceptions. This is fixed now (see http://www.python-science.org/ticket/2062).

RE: How to set _FillValue? [ Reply ]
By: Colin Brown on 2010-08-23 11:26
[forum:12973]
Perfect, thanks. Of course, Python requires explicit casting.

Colin

RE: How to set _FillValue? [ Reply ]
By: Konrad Hinsen on 2010-08-23 08:19
[forum:12972]
The problem is that your fill value is a double-precision value whereas your variables are single-precision. The netCDF specification says that the fill value must match the element type of the variable. I'll check why this doesn't raise an exception as I'd expect it to do.

To specify a single-precision fill value, use

v1._FillValue = numpy.float32(-9999.0)

Konrad.

How to set _FillValue? [ Reply ]
By: Colin Brown on 2010-08-21 06:00
[forum:12971]
When I set the _FillValue I cannot write data into the netCDF file?


from Scientific.IO.NetCDF import NetCDFFile

ncf = NetCDFFile('test1.nc','w')
ncf.createDimension('record', None)
v1 = ncf.createVariable('rdg1','f',('record',))
v1.long_name = 'Reading One'
v2 = ncf.createVariable('rdg2','f',('record',))
v2.missing_value = -9998.0
v3 = ncf.variables['rdg1']
v3[0] = 6.0
v3[1] = -9998.0
v4 = ncf.variables['rdg2']
v4[1] = 29.0
ncf.sync()
ncf.close()

ncf = NetCDFFile('test2.nc','w')
ncf.createDimension('record', None)
v1 = ncf.createVariable('rdg1','f',('record',))
v1.long_name = 'Reading One'
v1._FillValue = -9999.0
v2 = ncf.createVariable('rdg2','f',('record',))
v2.missing_value = -9998.0
v3 = ncf.variables['rdg1']
v3[0] = 6.0
v3[1] = -9998.0
v4 = ncf.variables['rdg2']
v4[1] = 29.0
ncf.sync()
ncf.close()


netcdf test1 {
dimensions:
record = UNLIMITED ; // (2 currently)
variables:
float rdg1(record) ;
rdg1:long_name = "Reading One" ;
float rdg2(record) ;
rdg2:missing_value = -9998. ;
data:

rdg1 = 6, -9998 ;

rdg2 = _, 29 ;
}


netcdf test2 {
dimensions:
record = UNLIMITED ; // (0 currently)
variables:
float rdg1(record) ;
rdg1:long_name = "Reading One" ;
rdg1:_FillValue = -9999. ;
float rdg2(record) ;
rdg2:missing_value = -9998. ;
data:
}