简体   繁体   English

Python求和地理半径内的lat / lon点和网格的总和

[英]Python sum lat/lon points within geographic radius and sum to grid

Basically, my experimental program is trying to find the number of points that fall within a (eg, 50km) radius of a valid point at a given time. 基本上,我的实验程序试图找到在给定时间落在有效点的半径(例如,50km)内的点的数量。 My data is structured (but I can restructure if need-be) in three separate arrays such: 我的数据是在三个独立的数组中构建的(但我可以根据需要进行重组),例如:

1_LAT,1_LON,1_TIM 1_LAT,1_LON,1_TIM

Where 1_LAT,1_LON,1_TIM all contain roughly ~250 values corresponding to Latitude, Longitude (decimal degrees), and time respectively. 其中1_LAT,1_LON,1_TIM都包含分别对应于纬度,经度(十进制度)和时间的约250个值。

I have 20 sets of these arrays (ie, 1_LAT,1_LON,1_TIM...20_LAT,20_LON,20_TIM). 我有20组这些数组(即1_LAT,1_LON,1_TIM ... 20_LAT,20_LON,20_TIM)。

Here is what I would like to accomplish: 这是我想要完成的:

1) Figure out the number of lat/lon sets that fall within a particular radius of each set. 1)计算出落在每组特定半径内的纬度/经度集的数量。 For example, how many points fall within a 50km radius of 1_LAT,1_LON at the valid time of 1_TIM from the other 19 sets of points. 例如,有多少点落在1_LAT半径的50km范围内,在1_TIM的有效时间内从其他19组点落入1_LON。 I would then like to iterate through each valid time to figure out the number of points in the valid radius at each specific point and valid time. 然后,我想迭代每个有效时间,以确定每个特定点和有效时间的有效半径中的点数。

I have attached a picture below to help visually describe. 我附上了一张图片,以帮助直观地描述。 sampleimage

The black squares represent all the points in the LAT_1/LON_1 arrays. 黑色方块表示LAT_1 / LON_1阵列中的所有点。 The blue squares represent all the points in the LAT_n/LAT_n arrays. 蓝色方块表示LAT_n / LAT_n阵列中的所有点。

I would like to count the number of points in each radius at each valid time for each set of lat/lon arrays. 我想计算每组lat / lon数组在每个有效时间内每个半径的点数。 The final display would be a summed raster or meshgrid of the denisty (ie, number of counts / 20) for each grid spot on a geographic basemap image. 最终显示将是地理底图图像上的每个网格点的明暗(即,计数数量/ 20)的总和栅格或网格网格。

I have a feeling that a KDEtree may be the best way to accomplish this, but I have little/no experience with such. 我有一种感觉,KDEtree可能是实现这一目标的最佳方式,但我很少/没有经验。 Any ideas or suggestions would be greatly appreciated. 任何想法或建议将不胜感激。

You would do something like the following... First, group your (x, y) coordinates for each group in a single points_x array: 您可以执行以下操作...首先,将每个组的(x, y)坐标分组到一个points_x数组中:

points_1 = np.column_stack((LAT_1, LON_1))
...
points_n = np.column_stack((LAT_n, LON_n))

It may be a good idea to store them in a list of arrays: 将它们存储在数组列表中可能是个好主意:

points = [point_1, points_2, ..., points_n]

Now, make a kdTree out of each set of points: 现在,从每组点中创建一个kdTree:

import scipy.spatial as spsp
kdtrees = [spsp.cKdTree(p) for p in point]

And you are ready to go. 你准备好了。 If you now run the following code: 如果您现在运行以下代码:

r = whatever_your_threshold_value_is
points_within_r = np.zeros((len(kdtrees), len(kdtrees)), dtype=np.int)
for j in xrange(len(kdtrees)):
    for k in xrange(j+1, len(kdtrees)):
        points_within_r[j, k] = kdtrees[j].count_neighbors(kdtrees[k], r, 2)
points_within_r = points_within_r + points_within_r.T

You should now find that points_within_r[j, k] holds how many points in points_j are within radius r of a point in points_k . 您现在应该发现points_within_r[j, k]拥有多点如何points_j的半径范围内r中的一个点的points_k

Keep in mind that distances here are the euclidean distance of the coordinates, disregarding the fact that what they measure are spherical angles. 请记住,这里的距离是坐标的欧氏距离,而忽略了它们测量的是球面角度的事实。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM