[SciPy-User] Scipy.io.netcdf: does nc.close release memory?

Julien Salort lists at juliensalort.org
Tue Jul 8 09:24:24 EDT 2014


Hello,

Consider the following simple code snipet:

---8<------8<------8<------8<------8<------8<------8<------8<------
import numpy as np
from scipy.io.netcdf import netcdf_file

ncfile = 'bos-00008.nc'
nc = netcdf_file(ncfile)
grid_X = np.reshape(nc.variables['vec2_patch_X'].data, (ny, nx))
grid_Y = np.reshape(nc.variables['vec2_patch_Y'].data, (ny, nx))
grid_U = np.reshape(nc.variables['vec2_patch_U'].data, (ny, nx))
grid_V = np.reshape(nc.variables['vec2_patch_V'].data, (ny, nx))
nc.close()
---8<------8<------8<------8<------8<------8<------8<------8<------

It is not clear to me whether or not it is safe to use grid_X, grid_Y,
grid_U and grid_V beyond the nc.close(). Does nc.close() release any
memory?

I am asking because I have one system where I get a segmentation fault
when I do the following code, *after* nc.close(). If I remove the
nc.close() then I get the proper plot.
---8<------8<------8<------8<------8<------8<------8<------8<------
grid_Module = np.sqrt(grid_U**2 + grid_V**2)
plt.streamplot(grid_X, grid_Y, grid_U, grid_V, density=2,
color=grid_Module)
---8<------8<------8<------8<------8<------8<------8<------8<------

System where I get the segmentation fault:
Mac OS X 10.9.4 running MacPorts Python 2.7.8 with Scipy 0.14.0.

No such problem with this system:
Debian 7 running Python 2.7.3 with Scipy 0.10.1

So, I wonder if I have a problem with my Mac OS X system, or if it was
unsafe to call nc.close anyway.

Thanks for any pointers,

Julien

-- 
http://www.juliensalort.org




More information about the SciPy-User mailing list