[Numpy-discussion] Transparently reading complex arrays from netcdf4

G Jones glenn.caltech at gmail.com
Sat Mar 29 21:13:37 EDT 2014


Hi,
I am using netCDF4 to store complex data using the recommended strategy of
creating a compound data type with the real and imaginary parts. This all
works well, but reading the data into a numpy array is a bit clumsy.

Typically I do:

nc = netCDF4.Dataset('my.nc')
cplx_data = nc.groups['mygroup'].variables['cplx_stuff'][:].view('complex')

which directly gives a nice complex numpy array. This is OK for small
arrays, but is wasteful if I only need some chunks of the array because it
reads all the data in, reducing the utility of the mmap feature of netCDF.

I'm wondering if there is a better way to directly make a numpy array view
that uses the netcdf variable's memory mapped buffer directly. Looking at
the Variable class, there is no access to this buffer directly which could
then be passed to np.ndarray(buffer=...).

Any ideas of simple solutions to this problem?

Thanks,
Glenn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140329/06e89bc2/attachment.html>


More information about the NumPy-Discussion mailing list