python中输入数组的数据_从输入数组python中选择网格数据

关于您的要求有点不清楚,但是如果您有一个经度、纬度对数组,并且希望从网格数据集中找到最接近的值,可以使用下面的方法。这是一个Python函数,用于从网格数据集(矩形数据)中提取站点数据,其中每个站点都是经纬度对。可以指定要提取其索引的距桩号最近的点的数量。一旦有了周围点的索引列表,就可以将值插值到桩号。在def getStationIndices(longitude,latitude,st_lon,st_lat,numberOfPoints):

"""

This is a function that takes longitude and latitude as

decimal input, and returns the index values closest to

the longitude and latitude. This is an iterative process for finding the best

index pair.

"""

if st_lon<0: st_lon=st_lon+360.0; NEG=True

else: NEG=False

"""Input longitude should go from 0-360"""

longitude=np.where(longitude<0,longitude+360,longitude)

distance = np.zeros((longitude.shape),dtype=np.float64)

listd=[]

"""First, create a list of distances from the station of interest, while

also save the matrix of distances that contains the info to get the index pair that the distance of interest corresponds to"""

for eta in range(len(latitude[:,0])):

for xi in range(len(latitude[0,:])):

distance[eta,xi] = np.sqrt( (latitude[eta,xi]-st_lat)**2.0 + (longitude[eta, xi] - st_lon)**2.0 )

listd.append(distance[eta,xi])

listsIndexes=[]

listd.sort()

"""Now find the closest point to the station. When that point is found, remove the

closests pooint and find the next closests point, until you have found numberOfPoints

closests to station.

"""

for i in range(numberOfPoints):

value=listd[0]

itemindex=np.where(distance==value)

listsIndexes.append(itemindex)

listd.pop(0)

print ''

print '=====getStationIndices======'

if NEG is True:

print 'Looking for longitude [%3.3f] and latitude [%3.3f]'%(st_lon-360,st_lat)

else:

print 'Looking for longitude [%3.3f] and latitude [%3.3f]'%(st_lon,st_lat)

print 'Result ===>'

for i in range(numberOfPoints):

print 'Found index pair in gridfile',listsIndexes[i]

if NEG is True:

print 'Index corresponds to longitude [%3.3f] and latitude [%3.3f]'%(longitude[listsIndexes[i][0],listsIndexes[i][1]]-360,latitude[listsIndexes[i][0],listsIndexes[i][1]])

else:

print 'Index corresponds to longitude [%3.3f] and latitude [%3.3f]'%(longitude[listsIndexes[i][0],listsIndexes[i][1]],latitude[listsIndexes[i][0],listsIndexes[i][1]])

"""

We want to use data interpolated from the 4 surrounding points to get appropriate values at station point.

We do this by using relative weights determined by relative distance to total distance from all 4 points.

"""

dis=[]

for i in range(numberOfPoints):

dis.append(np.sqrt( (latitude[listsIndexes[i][0],listsIndexes[i][1]]-st_lat)**2.0 + (longitude[listsIndexes[i][0],listsIndexes[i][1]] - st_lon)**2.0 ))

return listsIndexes, dis

这里,longitude和latitude是二维数组,其中包含保存数据的矩形网格的地理信息。如果您的数据是一维的(例如lat=0-90N,lon=0-360E),您可以使用以下方法创建二维阵列:

^{pr2}$

要使用函数,这些数据必须是正的(0-360),或者您必须编辑函数。要调用该方法,请提供站点的地理位置(例如st_lon=30.0,st_lat=55.2),然后调用:gridIndexes, dis = getStationIndices(longitude,latitude,st_lon,st_lat,numberOfPoints)

这里,numberOfPoints是围绕(st_lon,st_lat)的网格单元数。下一步,从您标识的网格单元格中提取数据。在for i in xrange(numberOfPoints):

latindex=int(gridIndexes[i][0])

lonindex=int(gridIndexes[i][1])

result = TEMP[time,latindex,lonindex]

在这里,我假设您的数据存储在维度(time,latitude,longitude)的数组中。您可以进一步使用dis对站点数据进行加权以进行加权插值。你可以在here中查找我如何使用它的更多信息。希望这有帮助。在

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值