I have a 3000x6000
2D grid (from a tiff image). I want to regrid it into a lower resolution grid using griddata
method from scipy.interpolate
library. First, I need to form a 18000000x2
numpy array
as the input for griddata
based on what I read here. Here's what I do:
import numpy as np
from scipy.interpolate import griddata
x_length = 6000
y_length = 3000
def func(x, y):
return x*(1-x)*np.cos(4*np.pi*x) * np.sin(4*np.pi*y**2)**2
grid_x, grid_y = np.meshgrid(np.linspace(0,1,x_length),np.linspace(0,1,y_length))
points = np.random.rand(x_length*y_length, 2)
values = func(points[:,0], points[:,1])
grid_z0 = griddata(points, values, (grid_x, grid_y), method='nearest')
I get a MemoryError
when doing griddata
. I have 8 gb of RAM and I shouldn't get this error based on the first answer to this question.
Overall, regriding a 3000x6000
grid into a lower resolution grid shouldn't be that hard and I guess I am doing something funny here. Should I get e MemoryError
doing these liens of codes with 8 gb RAM?
P.S: Although I have a 64-bit
operating system (Windows 7), I use the following Python version:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32