Here is a three story for loop , The running speed needs to be optimized
for i in range(len(points_xy)): weight_t=1 x_pos = int((points_xy[i][0] - x_min2) / abs(x_res2)) y_pos = int((y_max2 - points_xy[i][1]) / abs(x_res2)) # First search the square area centered on the point , Then search the circle inside y_len_min = (y_pos - radius_pixel_width - 1) if (y_pos - radius_pixel_width - 1) > 0 else 0 y_len_max = (y_pos + radius_pixel_width + 1) if (y_pos + radius_pixel_width + 1) < row else row x_len_min = (x_pos - radius_pixel_width - 1) if (x_pos - radius_pixel_width - 1) > 0 else 0 x_len_max = (x_pos + radius_pixel_width + 1) if (x_pos + radius_pixel_width + 1) < col else col for y in range(y_len_min, y_len_max): for x in range(x_len_min, x_len_max): distance = float(((x - x_pos) ** 2 + (y - y_pos) ** 2) ** 0.5) dis=distance*30 if (distance < radius_pixel_width and distance > 0): value = raster_data[y_pos][x_pos] D_value=((radius_pixel_width - distance + 1)/(radius_pixel_width**2))*weight_t if (result_data[y][x] != -999.0): result_data[y][x] += D_value else: result_data[y][x] = D_value elif(distance==0 and result_data[y][x] != -999.0): result_data[y][x]+=(1*weight_t) elif(distance==0 and result_data[y][x] == -999.0): result_data[y][x] = 1*weight_t
Add at the beginning jit, But the result told me that point_xy yes list It doesn't seem to work , I have put the jit Put it in for Internal loop , The result is that the program keeps running . Ask how to optimize
for i in range(len(points_xy)): x_pos = int((points_xy[i][0] - x_min) / abs(x_res)) y_pos = int((y_max - points_xy[i][1]) / abs(x_res)) # First search the square area centered on the point , Then search the circle inside y_len_min = (y_pos - radius_pixel_width - 1) if (y_pos - radius_pixel_width - 1) > 0 else 0 y_len_max = (y_pos + radius_pixel_width + 1) if (y_pos + radius_pixel_width + 1) < rows else rows x_len_min = (x_pos - radius_pixel_width - 1) if (x_pos - radius_pixel_width - 1) > 0 else 0 x_len_max = (x_pos + radius_pixel_width + 1) if (x_pos + radius_pixel_width + 1) < cols else cols @jit def keral_map(y_len_min, y_len_max, x_len_min, x_len_max, x_pos, y_pos, radius_pixel_width, result_data): weight_t = 1 for y in range(y_len_min, y_len_max): for x in range(x_len_min, x_len_max): distance = float(((x - x_pos) ** 2 + (y - y_pos) ** 2) ** 0.5) # Judge within the radius if (distance < radius_pixel_width and distance > 0): D_value = ((radius_pixel_width - distance + 1) / (radius_pixel_width ** 2)) * weight_t if (result_data[y][x] != -999.0): result_data[y][x] += D_value else: result_data[y][x] = D_value elif (distance == 0 and result_data[y][x] != -999.0): result_data[y][x] += (1 * weight_t) elif (distance == 0 and result_data[y][x] == -999.0): result_data[y][x] = 1 * weight_t return result_data keral_map(y_len_min, y_len_max, x_len_min, x_len_max, x_pos, y_pos, radius_pixel_width, result_data)
The current speed is probably 25 About seconds (6 10000 points ), I wonder if I could hurry up