python - osmnx 如何在 HPC 集群中使用?
问题描述
osmnx 如何在 HPC 集群中使用?
我想在 Ubuntu Server 的 HPC 类型的集群中运行一个 python 这个脚本来加快它的执行时间
(目前在没有集群的服务器上完成该过程大约需要 4 分钟)
附上Python代码:
import sys
import networkx as nx
import osmnx as ox
import geopandas as gpd
import math
from shapely.geometry import Point
import json
ox.config(use_cache=False)
origlatTmp = float(sys.argv[1])
origlngTmp = float(sys.argv[2])
destlatTmp = float(sys.argv[3])
destlngTmp = float(sys.argv[4])
def fromAtoBpoints(origlat, origlng, destlat, destlng):
G = ox.load_graphml('/var/www/html/jalisco.graphml')
#This .graphml file was generated with:
#import osmnx as ox
#ox.config(use_cache=True, log_console=True)
#G = ox.graph_from_place('Jalisco,Mexico', network_type = 'drive', simplify=False)
#G = ox.add_edge_speeds(G)
#G = ox.add_edge_travel_times(G)
#ox.save_graphml(G, '/var/www/html/jalisco.graphml')
#print("Done!")
#Jalisco is a state of Mexico and the territorial extension of Jalisco is 78,588 km²
lats = []
lngs = []
lats.insert(0, origlat)
lats.insert(1, destlat)
lngs.insert(0, origlng)
lngs.insert(1, destlng)
points_list = [Point((lng, lat)) for lat, lng in zip(lats, lngs)]
points = gpd.GeoSeries(points_list, crs='epsg:4326')
points_proj = points.to_crs(G.graph['crs'])
nearest_nodes = [ox.distance.nearest_nodes(G, pt.x, pt.y) for pt in points_proj]
route = nx.shortest_path (G, nearest_nodes[0], nearest_nodes[1], weight='length')
time = nx.shortest_path_length(G, nearest_nodes[0], nearest_nodes[1], weight='travel_time')
#print("Tiempo:",time/60,"min")
distance = nx.shortest_path_length(G, nearest_nodes[0], nearest_nodes[1], weight='length')
#print("Distancia:",distance/1000,"km")
resultArray = []
resultArray2 = []
for a in route:
resultArray.append("{lat:"+ str(G.nodes[a]['y'])+",lng:"+ str(G.nodes[a]['x'])+"}")
return (distance/1000),"@@@",resultArray
print(fromAtoBpoints(origlatTmp,origlngTmp,destlatTmp,destlngTmp))
这段代码执行时间长(我上面提到的4分钟),但是我们想到的是它可以离线工作,并且提出的解决响应时间的解决方案是使用HPC集群
解决方案
推荐阅读
- reactjs - 使用具有可选属性的联合类型作为 React 道具类型时如何获得正确的类型推断
- python - 如何在我的 Windows 命令提示符下设置 python 3.9?它显示一个错误 python not found
- macros - 有没有办法将函数转换为 Julia 中的表达式?
- php - PHP 注意:未定义的偏移量:0-3000
- javascript - 如何删除由多个子元素组成的主父元素?
- reactjs - 如何在js文件中单击按钮设置功能
- android - 反应本机地图Android标注不根据内容拉伸
- c# - 如何在http客户端注册通用接口?
- firebase - flutter/firebase - 方法 XX 在 null 上被调用
- json - 使用 PostgreSQL 查询哈希的嵌套哈希