cas3ymau3 / netcdf4-python

Automatically exported from code.google.com/p/netcdf4-python
Other
0 stars 0 forks source link

Error when reading data from a netcdf file #214

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a file with a variable which has an attribute missing_value=-99.9f
2. Try to read this file
3.

What is the expected output? What do you see instead?
Did not expect the exception.

What version of the product are you using? On what operating system?
In [12]: netCDF4.__version__
Out[12]: '1.0.5'

System: x86_64 GNU/Linux

Please provide any additional information below.

Here is the code snippet and the error message:

In [8]: imd_ds.variables.keys()
Out[8]: [u'lon', u'lat', u'timeObs', u'var']

In [9]: imd_data = imd_ds.variables["var"][:]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-9-d7897cf0a03a> in <module>()
----> 1 imd_data = imd_ds.variables["var"][:]

/skynet3_rech1/huziy/virtualenv_cython/lib/python2.7/site-packages/netCDF4.so 
in netCDF4.Variable.__getitem__ (netCDF4.c:34558)()

/skynet3_rech1/huziy/virtualenv_cython/lib/python2.7/site-packages/netCDF4.so 
in netCDF4.Variable._toma (netCDF4.c:34897)()

ValueError: invalid literal for float(): -99.9f

The var part in the ncdump output:

    float precip(time, latitude, longitude) ;
        precip:long_name = "daily precipitation analysis interpolated onto 0.5deg grids [mm/day]" ;
        precip:units = "mm/day" ;
        precip:_FillValue = -99.9f ;
        precip:missing_value = -99.9f ;
        precip:level_description = "Earth surface" ;

Original issue reported on code.google.com by guziy.sa...@gmail.com on 7 Jan 2014 at 2:14

GoogleCodeExporter commented 8 years ago
The var part is here, the previous one from a different file

    double var(timeObs, lon, lat) ;
        var:long_name = "daily precipitation analysis interpolated onto 1deg grids mm/day" ;
        var:units = "mm/day" ;
        var:missing_value = "-99.9f" ;

Original comment by guziy.sa...@gmail.com on 7 Jan 2014 at 2:16

GoogleCodeExporter commented 8 years ago
Could you please upload the file?

Original comment by whitaker.jeffrey@gmail.com on 7 Jan 2014 at 2:16

GoogleCodeExporter commented 8 years ago
I think that the problem is in quotes:

var:missing_value = "-99.9f" ;  <- get exception

precip:missing_value = -99.9f ; <- everything works fine

Original comment by guziy.sa...@gmail.com on 7 Jan 2014 at 2:18

GoogleCodeExporter commented 8 years ago
Ah, I see.  The missing value attribute is a string!  I consider this a bug in 
the file, not the software.  I suggest contacting the data provider and ask 
them to use numbers for missing values, at least for numeric data type 
variables.

Original comment by whitaker.jeffrey@gmail.com on 7 Jan 2014 at 2:19

GoogleCodeExporter commented 8 years ago
OK, thank you Jeff and Happy New Year))

Original comment by guziy.sa...@gmail.com on 7 Jan 2014 at 2:22

GoogleCodeExporter commented 8 years ago

Original comment by whitaker.jeffrey@gmail.com on 26 Feb 2014 at 2:04