In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
First download the dataset and place it in the data/ folder: https://www.avoindata.fi/data/fi/dataset/liikennemaarat-helsingissa
The data is obtained from an automatic meassurement point at: https://www.google.fi/maps/place/60%C2%B009'44.6%22N+24%C2%B053'58.6%22E/@60.1623877,24.8974263,17z/data=!3m1!4b1!4m5!3m4!1s0x0:0x0!8m2!3d60.162385!4d24.899615?hl=en
Legend(in Finnish): ha=henkilöautot pa=pakettiautot ka=kuorma-autot ra=rekka-autot la=linja-autot mp=moottoripyörät rv=raitiovaunut
Laskenta on tehty tunneittain, paitsi ruuhka-aikoina (klo 6.00-9.00 ja 15.00-18.00) jaksotus on 15 minuuttia. Kellonajat ovat alkavia kellonaikoja. Laskentapisteiden poikkileikkaukset lasketaan suunnittain (suunta 1 on keskustaan, linjalla D D1-D13 länteen)
In [2]:
data = pd.read_csv('data/hki_liikennemaarat.csv', encoding='latin-1',delimiter=';')
data.head()
Out[2]:
The columns are: ha=henkilöautot pa=pakettiautot ka=kuorma-autot ra=rekka-autot la=linja-autot mp=moottoripyörät rv=raitiovaunut
Remove data about trams and other measurement points.
In [3]:
laru = data[data.nimi == 'LAUTTASAAREN SILTA']
laru = laru.loc[:,['suunta','aika','vuosi','autot','ha','pa','ka','ra','la','mp']]
Since the time series is at uneven intervals some reductions have to be made.
In [4]:
laru['tunti'] = (laru['aika'] / 100).apply(np.floor)
laru
Out[4]:
Lets define light as: ha=henkilöautot pa=pakettiautot mp=moottoripyörät Heavy as: ka=kuorma-autot ra=rekka-autot Buses as: la=linja-autot
In [5]:
laru['light traffic'] = laru['ha'] + laru['pa'] + laru['mp']
laru['heavy traffic'] = laru['ka'] + laru['ra'] + laru['la']
laru['buses'] = laru['la']
In [6]:
laru.head()
Out[6]:
In [7]:
laru = laru.drop(['autot','ha','pa','ka','ra','la','mp'],axis=1)
laru.head()
Out[7]:
In [8]:
yrl = laru.groupby(['vuosi','suunta','tunti']).sum()
yrl.reset_index(inplace=True)
yrl
Out[8]:
In [9]:
y_2016_tohel = yrl[(yrl.vuosi == 2016) & (yrl.suunta == 1.0) ]
y_2016_tolaru = yrl[(yrl.vuosi == 2016) & (yrl.suunta == 2.0) ]
y_2016_tohel = y_2016_tohel.drop(['aika','suunta','vuosi'],axis = 1)
y_2016_tolaru = y_2016_tolaru.drop(['aika','suunta','vuosi'],axis = 1)
In [10]:
y_2016_tohel.head()
Out[10]:
In [11]:
y_2016_tolaru.head()
Out[11]:
In [12]:
y_2016_tohel['time'] = y_2016_tohel['tunti'].apply(lambda x: pd.to_timedelta(x, unit='h'))
y_2016_tolaru['time'] = y_2016_tolaru['tunti'].apply(lambda x: pd.to_timedelta(x, unit='h'))
y_2016_tolaru = y_2016_tolaru.set_index('time')
y_2016_tohel = y_2016_tohel.set_index('time')
y_2016_tohel
Out[12]:
In [13]:
y_2016_tohel = y_2016_tohel.drop(['tunti'], axis = 1)
y_2016_tolaru = y_2016_tolaru.drop(['tunti'], axis = 1)
y_2016_tolaru
Out[13]:
In [14]:
xinterval = pd.date_range('1/1/2011', periods=24, freq='H').time
In [15]:
plt.figure(figsize=(23,13))
plt.xticks(xinterval,rotation=45)
plt.grid(True)
plt.title('Traffic towards Lauttasaari. Representative sample from 2016, 1 hour sample interval')
plt.plot(xinterval,y_2016_tolaru['light traffic']);
plt.plot(xinterval,y_2016_tolaru['heavy traffic']);
plt.plot(xinterval,y_2016_tolaru['buses']);
plt.legend(['light traffic','heavy traffic','buses']);
plt.xlabel('Time');
plt.ylabel('Vehicles / hour');
In [16]:
plt.figure(figsize=(23,13))
plt.xticks(xinterval,rotation=45)
plt.grid(True)
plt.title('Traffic towards Helsinki. Representative sample from 2016, 1 hour sample interval')
plt.plot(xinterval,y_2016_tohel['light traffic']);
plt.plot(xinterval,y_2016_tohel['heavy traffic']);
plt.plot(xinterval,y_2016_tohel['buses']);
plt.legend(['light traffic','heavy traffic','buses']);
plt.xlabel('Time');
plt.ylabel('Vehicles / hour');
In [17]:
y_2016_tohel.to_csv('data/dist_larubridge_tohel_16.csv')
y_2016_tolaru.to_csv('data/dist_larubridge_tolaru_16.csv')