数据名称 | 含义 |
---|---|
DEVICEID | 设备ID |
FTNODE | 起始结点 |
FROMTIME | 统计起始时间 |
TOTIME | 统计结束时间 |
INTERVAL | 统计间隔 |
LANEID | 车道ID |
LANENUM | 车道数 |
COUNT | 统计间隔内车辆计数 |
REGULARCOUNT | 统计间隔内小型车计数 |
LARGECOUNT | 统计间隔内大型车计数 |
FLOW | 断面小时换算流量 |
ARITHMETIC_AVERAGE_SPEED | 车速算术平均值 |
HARMONIC_AVERAGE_SPEED | 车速调和平均值 |
TURN | 车道方向信息,LSR分别表示左直右及其组合,LU和RU分别表示左掉头和右掉头,LC表示上下游车道连接过渡段,表明此断面包含车道变化区域 |
其中, C O U N T = R E G U L A R C O U N T + L A R G E C O U N T COUNT=REGULARCOUNT+LARGECOUNT COUNT=REGULARCOUNT+LARGECOUNT F L O W = C O U N T ⋅ 1 H I N T E R V A L FLOW=COUNT \cdot \frac{1H}{INTERVAL} FLOW=COUNT⋅INTERVAL1H
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdate
import time
ldt_path = 'data/ldt_data/ldt.csv' #路径
ldt_data = pd.read_csv(ldt_path) #读取数据
ldt_data['FROMTIME'] = pd.to_datetime(ldt_data['FROMTIME']) #将字符串转化为时间戳
ldt_data['TOTIME'] = pd.to_datetime(ldt_data['TOTIME'])
ldt_East = ldt_data[ldt_data['DEVICEID']==389].copy() #东
ldt_South = ldt_data[ldt_data['DEVICEID']==388].copy() #南
ldt_West = ldt_data[ldt_data['DEVICEID']==387].copy() #西
ldt_North = ldt_data[ldt_data['DEVICEID']==386].copy() #北
def ldt(ldt_data):
ldt_data['1/HARMONIC_AVERAGE_SPEED'] = 1 / ldt_data['HARMONIC_AVERAGE_SPEED'] # 断面平均车速需要使用调和平均车速
ldt_data_group = ldt_data.groupby(['DEVICEID',pd.Grouper(key='FROMTIME',freq='5min')]) # 5分钟为间隔进行统计
ldt_data_flow = ldt_data_group['COUNT'].sum()
ldt_data_flow = ldt_data_flow * 12
ldt_data_speed = 1 / (ldt_data_group['1/HARMONIC_AVERAGE_SPEED'].mean()) # 5分钟间隔的平均车速
return ldt_data_flow,ldt_data_speed
ldt_East_flow,ldt_East_speed = ldt(ldt_East)
ldt_East_flow = ldt_East_flow / 2 # 东进口下游的车道数为2
ldt_South_flow,ldt_South_speed = ldt(ldt_South)
ldt_South_flow = ldt_South_flow / 3 # 南进口下游的车道数为3
ldt_West_flow,ldt_West_speed = ldt(ldt_West)
ldt_West_flow = ldt_West_flow / 2 # 西进口下游的车道数为2
ldt_North_flow,ldt_North_speed = ldt(ldt_North)
ldt_North_flow = ldt_North_flow / 3 # 北进口下游的车道数为3
# 横坐标
time_list = []
time = pd.datetime(2019,7,9,6,0)
while(time < pd.datetime(2019,7,9,10,0)):
time_strf = time.strftime("%H:%M")
time_list.append(time_strf)
time = time + pd.Timedelta(minutes=5)
#规定x轴刻度
time_xticks = []
time = pd.datetime(2019,7,9,6,0)
while(time < pd.datetime(2019,7,9,10,30)):
time_strf = time.strftime("%H:%M")
time_xticks.append(time_strf)
time = time + pd.Timedelta(minutes=30)
p = plt.figure(figsize=(8,10),dpi=80)
ax1 = p.add_subplot(2,1,1) # 创建一个2行1列的子图,并开始绘制第一幅——流量曲线
plt.title('Traffic Volume Curve')
plt.xlabel('Time')
plt.ylabel('Q: veh/h/lane', rotation=360, horizontalalignment='right', verticalalignment='center')
plt.plot(time_list,ldt_East_flow,'r',
time_list,ldt_South_flow,'b',
time_list,ldt_West_flow,'y',
time_list,ldt_North_flow,'g')
plt.legend(['East','South','West','North'])
plt.xticks(time_xticks)
ax2 = p.add_subplot(2,1,2) # 开始绘制第二幅——车速曲线
plt.title('Speed Curve')
plt.xlabel('Time')
plt.ylabel('V: km/h', rotation=360, horizontalalignment='right', verticalalignment='center')
plt.plot(time_list,ldt_East_speed,'r',
time_list,ldt_South_speed,'b',
time_list,ldt_West_speed,'y',
time_list,ldt_North_speed,'g')
plt.legend(['East','South','West','North'])
plt.xticks(time_xticks)
plt.subplots_adjust(hspace=0.35) # 调整子图之间的间距
plt.show()
水平有限,仅供参考,如有错误请指出