我正在使用numpy数组,在该数组中,对于不同的坐标(插值),我具有一定的地下水位。我想使数组中与我要检查的地理数据帧中不存在的点无效。我有一个有效的代码,但是循环的数量很大。如果有人可以提出更好的方法?我当前的代码如下:
x = np.array(SpatialTable['x'])
y = np.array(SpatialTable['y'])
z = np.array(SpatialTable['Difference'])
#identify the extreme points of the aquifer system for which data is available
lon_min = min(x)
lat_min = min(y)
lon_max = max(x)
lat_max = max(y)
#create grid points of defined spacing for interpolation, spacing in x and y=150
numcols, numrows = int((lon_max-lon_min)/150), int((lat_max-lat_min)/150)
xi = np.linspace(lon_min, lon_max, numcols)
yi = np.linspace(lat_min, lat_max, numrows)
xx, yy = np.meshgrid(xi, yi)
#interpolate the data available for all defined grid points
zi = griddata((x,y),z,(xx,yy),method='cubic')
for i in range(numcols):
for j in range(numrows):
if (np.isnan(zi[j][i])==False):
if (Point(xi[i],yi[j]).within(shape['geometry'][0]) or \Point(xi[i],yi[j]).within(shape['geometry'][1]) or Point(xi[i],yi[j]).within(shape['geometry'][2]) or \`enter code here`Point(xi[i],yi[j]).within(shape['geometry'][3])):
pass
else:
zi[j][i]=np.nan