[SciPy-User] Can create, but not access, netCDF variables with no dimension

Oleksandr Huziy guziy.sasha at gmail.com
Sun Apr 13 20:12:46 EDT 2014


Can you share ncdump -h on the file in question with the variable in
question indicated?

Cheers


2014-04-13 17:16 GMT-04:00 Mannucci, Anthony J (335G) <
anthony.j.mannucci at jpl.nasa.gov>:

>   I am trying to read a netcdf file that has variables created without
> dimension (they are scalars). Since the file is obtained externally, and
> written without python, I cannot modify the file. So, the variable I am
> trying to access is not accessible using scipy.io.netcdf. (I can see the
> variable with ncdump).
>
>  I cannot fully reproduce the problem here, although I can reproduce
> something similar. Here is some code for discussion:
> ---
>  import scipy.io.netcdf as CDF
> f = CDF.netcdf_file('simple.nc', 'w')
> f.createDimension('time', 10)
> time = f.createVariable('time', 'i', ('time',))
> time[:] = np.arange(10)
> nodimvar = f.createVariable('nodimvar','f8',()) # Guessing this creates a
> scalar variable.
> nodimvar = 8.0 # nodimvar[:] fails with an error. Scalar not indexable.
> f.close()
>
>  f = CDF.netcdf_file('simple.nc', 'r')
> print f.variables.keys()
> print f.variables['time'][:]
> print f.variables['nodimvar'] # Does not print variable value, just the
> object.
> print f.variables['nodimvar'][:] # Error, scalar is not indexable.
> f.close()
>  -----
> The variable name shows up in f.variables.keys(). However, I do not know
> how to access the variable. Appending [:] to gives an error "IndexError:
> 0-d arrays can't be indexed.".
>
>  In the file I was provided, not included here because it's very large,
> the variable with no dimensions does not even show with up in keys().
>
>  I note that the package netCDF4 seems to handle this case correctly.
> Even zero-dimension variables are accessed via [:]. No error is generated
> and the value of the scalar is returned.
>
>  Thanks!
>
>  -Tony
>
>   --
>  Tony Mannucci
> Supervisor, Ionospheric and Atmospheric Remote Sensing Group
>  Mail-Stop 138-308,                     Tel > (818) 354-1699
>  Jet Propulsion Laboratory,              Fax > (818) 393-5115
>  California Institute of Technology,     Email >
> Tony.Mannucci at jpl.nasa.gov
>  4800 Oak Grove Drive,
> http://scienceandtechnology.jpl.nasa.gov/people/a_mannucci/
>  Pasadena, CA 91109
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>


-- 
Sasha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20140413/20a9f1c5/attachment.html>


More information about the SciPy-User mailing list