我有阵列与A和B相关联,它们存储每个网格点的(x,y)位置。
在这种情况下,答案应该是相当简单的...
是两个网格严格在同一网格化方案?假如是这样,你可以这样做:
np.argwhere((Ax == Bx.min()) & (Ay == By.min()))
假设两个网格的世界坐标增加在相同的方向网格的indicies,这给子集化的网格的左下角。 (如果他们没有在同一方向(即负dx
或dy
)增加,它只是给对方一个角)
在下面的例子中,我们可以明显才算从ix = (Bxmin - Axmin)/dx
等适当indicies ,但假设你有一个更复杂的网格系统,这仍然有效。但是,这是假定两个网格处于相同的网格方案!它稍微复杂,如果他们不...
import numpy as np
# Generate grids of coordinates from a min, max, and spacing
dx, dy = 0.5, 0.5
# For the larger grid...
Axmin, Axmax = -180, 180
Aymin, Aymax = -90, 90
# For the smaller grid...
Bxmin, Bxmax = -5, 10
Bymin, Bymax = 30, 40
# Generate the indicies on a 2D grid
Ax = np.arange(Axmin, Axmax+dx, dx)
Ay = np.arange(Aymin, Aymax+dy, dy)
Ax, Ay = np.meshgrid(Ax, Ay)
Bx = np.arange(Bxmin, Bxmax+dx, dx)
By = np.arange(Bymin, Bymax+dy, dy)
Bx, By = np.meshgrid(Bx, By)
# Find the corner of where the two grids overlap...
ix, iy = np.argwhere((Ax == Bxmin) & (Ay == Bymin))[0]
# Assert that the coordinates are identical.
assert np.all(Ax[ix:ix+Bx.shape[0], iy:iy+Bx.shape[1]] == Bx)
assert np.all(Ay[ix:ix+Bx.shape[0], iy:iy+Bx.shape[1]] == By)
这个问题的答案真的取决于你有的网格类型。它是一个等距的笛卡尔网格吗? – 2010-11-11 09:07:02
对于A和B的网格点的位置,坐标是否在水平和垂直方向上升?如果是这样,那么只需做一些二进制搜索。 – 2010-11-13 03:57:42
如果这是全球气候图,B是否与非洲等地理区域相对应(即形状不完全是矩形)还是只是一个矩形子区域? – 2010-11-22 19:40:45