Re: [netcdfgroup] reading netcdf file: problem with float conversion

Martin:  I would venture to guess that you have either a missing_value
or a _Fill_Value attribute in your dataset set to a string
'3.402823466e+38F'. ncdump -h will tell you if this is the case.  The
python module is probably trying to convert that to a float and failing.
  You can either reset that attribute to an actual floating point number
(or something castable to a float), or shut off the automatic conversion
of missing_values to masked array elements using the Dataset
set_auto_maskandscale method (i.e. ds= netCDF4.Dataset(filename);
ds.set_automaskandscale(False)).

Regards, Jeff


On Tue, Jun 30, 2015, at 01:42 AM, martin_r wrote:
> Hello netcdf-experts,
> currently i am working on a data analysis program which requires reading
> different netcdf files (version 3 and 4).
> To keep the installation requirements slim (the python script should run
> on
> various machines) it would be desirable to use as few libraries as
> possible. 
> 
> If the Scientific.IO.NetCDF library is used everything works fine.
> With the netCDF4 python library (version 1.1.5), the following error
> occurs:
> Traceback (most recent call last):
>   File "advection.py", line 157, in <module>
>     profile = wp_advect("wpl_20150602_002408.nc")
>   File "advection.py", line 143, in __init__
>     self.u_vel = self.f.variables["WP_U"][:]
>   File "netCDF4.pyx", line 3097, in netCDF4.Variable.__getitem__
> (netCDF4.c:42713)
>   File "netCDF4.pyx", line 3118, in netCDF4.Variable._toma
>   (netCDF4.c:43134)
> ValueError: invalid literal for float(): 3.402823466e+38F
> 
> The relevant code snippet:
> def __init__(self, filename):
>     """ """
>     self.filename = filename
>     #self.f = netCDF4.Dataset(filename, 'r', format='NETCDF4_CLASSIC')
>     self.f = NetCDF.NetCDFFile(filename, 'r')
>     self.time_list = self.f.variables["Timestamp"][:]
>     self.height = self.f.variables["WP_Height"][:]
>     self.u_vel = self.f.variables["WP_U"][:]
>     self.v_vel = self.f.variables["WP_V"][:]
> 
> Thank you for your help.
> Kind regards 
> Martin Radenz
> 
> 
> 
> --
> View this message in context:
> http://netcdf-group.1586084.n2.nabble.com/reading-netcdf-file-problem-with-float-conversion-tp7575845.html
> Sent from the NetCDF Group mailing list archive at Nabble.com.
> 
> _______________________________________________
> netcdfgroup mailing list
> netcdfgroup@xxxxxxxxxxxxxxxx
> For list information or to unsubscribe,  visit:
> http://www.unidata.ucar.edu/mailing_lists/ 


-- 
------
Jeffrey S. Whitaker
Phone: (303)497-6313
FAX: (303)497-6449
NOAA/OAR/CDC  R/CDC1         
325 Broadway, Boulder, CO, USA 80305-3328                             
http://www.cdc.noaa.gov/people/jeffrey.s.whitaker



  • 2015 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: