soup = BeautifulSoup(r.text, 'html.parser') line_names = [ l.text.strip() for l in soup.find_all('dt', class_='basicInfo-item name') ] line_values = [ l.text.strip() for l in soup.find_all('dd', class_='basicInfo-item value') ] dict_info = dict(zip(line_names, line_values)) return dict_info ttt = MeasureT() path = 'E:/Code/需求与辐射模型/transfer/多车站' files = lib_file.list_all_files(path) names = [f.split('\\')[-1].split('.png')[0] for f in files] dict_HSRLocs = lib_file.pickle_load('../需求与辐射模型/dict_HSRLocs.pkl') dict_nameBaiduInfo = {} for i, name in enumerate(list(dict_HSRLocs.keys())): info = grab_BaiduItem(name + '站') dict_nameBaiduInfo[name] = info if i % 10 == 0: ttt.duration(str(i) + ' processed') lib_file.json_save(dict_nameBaiduInfo, '车站信息.json')
import geopandas as gpd import geoplot as gplt import lib_geo import geoplot.crs as gcrs import numpy as np import lib_time import multiprocessing import random import matplotlib.pyplot as plt import lib_time ### 关于时间的相应操作在这个包里 from lib_time import get_deltaT, strT_to_floatT, floatT_to_strT # 1 数据准备 ##### 1.1 车站的位置 dict_HSRLocs = lib_file.pickle_load('E:/Code/需求与辐射模型-欧洲/dict_HSRLocs.pkl') ###### 1.1 列车时刻表,加载有向图 timetable = Timetable() timetable.load_file('E:/Code/Data/EuropeRailway/Europe_Railway_Schedule.csv', mode='ALL', encoding='utf-8') ### ALL 指的是全部车型, 还可以特指HSR,但是欧洲不支持 #list_names = ['London Euston', 'London Paddington', 'London St Pancras', # 'London Kings Cross', 'London Liverpool Street', 'London Blackfriars', # 'London Bridge', 'London Charing Cross', 'London Victoria'] ## dict_pairJS 应该也建成图 ###### 识别一个互补车站群 ##################################### #G = nx.Graph() #for pair in dict_pairJS:
#if info['scheduleDelay'] > 12: # 在车站等待四个小时以上 # continue if (n in dict_accessed) and (info['travelT'] - dict_accessed[n] >= -0.1): ## 就没快几分钟,不用换了 continue if (n not in dict_ChildInfo) or (dict_ChildInfo[n]['travelT'] > info['travelT']): dict_ChildInfo[n] = info return dict_ChildInfo ############################################################################### ###################### Data prepare ################################### ##### 1.1 高铁车站的位置 dict_HSRLocs = lib_file.pickle_load('dict_HSRLocs.pkl') ##### 2.2 高铁时刻表,加载有向图 timetable = Timetable() timetable.load_file( '/run/media/pengfei/OTHERS/Code/Data/ChinaRailway/China_Railway_Schedule_20190701.csv' ) ###### 2.3 去掉时刻表中没有位置的点 G_schedule = timetable.get_TravelT(mode="all") for n in list(G_schedule.nodes()): if n not in dict_HSRLocs: G_schedule.remove_node(n) #### 3.1 加载 车站在三小时car driving 时间内可达的格点的图(graph) f_HSRGrid = '/run/media/pengfei/OTHERS/Code/Data/ChinaRailway/CalculateGridTravelTTeacherGiveME/StationGridAccessibility_Adapt.csv' G_HSRGrid = lib_graph.createG_fromFile( f_HSRGrid,
import lib_transferTWO from xpinyin import Pinyin import time ppinyin = Pinyin() """ 1. 基础数据 车站位置,机场位置 数据类型: 字典 dict """ ##### 1.1 车站的位置 df_railwayLocs = lib_file.read_file2df( OS + 'Code/Data/ChinaRailway/China_Station_Locs_All.csv') dict_HSRLocs = lib_file.get_LocIndex(df_railwayLocs) ##### 1.2 机场的位置 dict_AirportLocs = lib_file.pickle_load( OS + 'Code/空铁联合换乘/data/dict_AirportLocs.pkl') ##### 1.3 位置信息合并 dict_PortLocs = dict(dict_HSRLocs, **dict_AirportLocs) """ 2. 时刻表数据 数据类型: 有向图 DiGraph """ def add_type2G(G, dict_HSRLocs, dict_AirportLocs): ## 为图中的节点添加类型标示, "station" or "airport" for name in G: ## 为图节点添加属性 if name in dict_HSRLocs: # 火车站 G.node[name]['type'] = 'station' elif name in dict_AirportLocs: G.node[name]['type'] = 'airport'
import lib_geo import geoplot.crs as gcrs import numpy as np import lib_time #### 1. 加载第0步已经做好的数据 (HSR:50km, Airport:150km) G_AirGrids = lib_graph.createG_fromFile('graph_GridAir.csv', source='source', target='target', attr='') G_HSRGrids = lib_graph.createG_fromFile('graph_GridHSR.csv', source='source', target='target', attr='') #### 1.1 加载机场、车站位置数据 dict_AirportLocs = lib_file.pickle_load('dict_AirportLocs.pkl') dict_HSRLocs = lib_file.pickle_load('dict_HSRLocs.pkl') #### 2 由时刻表建图,获取联通关系 ## 属性上有车次 ##### 2.1 飞机时刻表建图 air_timetable = FlightTimetable() air_timetable.load_file('E:/Code/Data/ChinaAir/China_Air_Schedule_clean.csv') G_airTimetable = air_timetable.get_graph() ##### 2.2 高铁时刻表 ### 建图,属性上有车次 timetable = Timetable() timetable.load_file( 'E:/Code/Data/ChinaRailway/China_Railway_Schedule_20190701.csv') G_HSRTimetable = timetable.get_graph()
dict_AirportLocs = lib_graph.getLocation_fromFile( OS + 'Code/Data/Sebastian_ScheduleDataChina20191114/airports.csv', ID='ID', lon='lon', lat='lat') dict_PortLocs = copy.deepcopy(dict_HSRLocs) for k in dict_AirportLocs: dict_PortLocs[k] = dict_AirportLocs[k] ## 异站换乘driving time G_PortPort = lib_graph.createG_fromFile( OS + 'Code/Data/Sebastian_ScheduleDataChina20191114/drivingTime.csv', source='source', target='target', attr=['contype', 'distance_km', 'duration_s']) ## 车站到网格的驾车时间 G_PortGrid = lib_file.pickle_load('G_PortGrid.pkl') ############################################### ### 时刻表建图 timetable = TimetableNew() timetable.load_trainFile( OS + 'Code/Data/Sebastian_ScheduleDataChina20191114/trains.txt') timetable.load_flightFile( OS + 'Code/Data/Sebastian_ScheduleDataChina20191114/flights.csv') G_schedule = timetable.get_DiGraph(mode='all') for name in G_schedule: ## 为图节点添加属性 G_schedule.node[name][ 'type'] = 'airport' if name in dict_AirportLocs else 'station' """ 5.城市中心坐标数据 """ ffff = OS + 'Code/Data/ChinaRailway/China_cities_population.csv' df_pops = pd.read_csv(ffff)