Speed profiles of freeways in California (I5-S and I210-E)
收藏资源简介:
Speed profiles of freeways in California (I5-S and I210-E). Original data is retrieved from PeMS. Each YEAR_FREEWAY.csv file contains Timestamp and Speed data. freeway_meta.csv file contains meta information for each detector: freeway number, direction, detector ID, absolute milepost, and x y coordinates. <pre><code class="language-markdown"># Freeway speed data description ### Data loading example (single freeway: I5-S 2012) ```python %%time import pandas as pd # Date time parser mydateparser = lambda x: pd.datetime.strptime(x, "%m/%d/%Y %H:%M:%S") # Freeway data loading (This part should be changed to a proper URL in zenodo.org) data = pd.read_csv("dataset/2012_I5S.csv", parse_dates=["Timestamp"], date_parser=mydateparser).pivot(index="Timestamp",columns='Station_ID', values='Speed') # Meta data loading meta = pd.read_csv("dataset/freeway_meta.csv").set_index(['Fwy','Dir']) ``` CPU times: user 50.5 s, sys: 911 ms, total: 51.4 s Wall time: 50.9 s ### Speed data and meta data ```python data.head() ``` <div> <style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style> <table border="1" class="dataframe"> <thead> <tr style="text-align: right;"> <th>Station_ID</th> <th>1</th> <th>2</th> <th>3</th> <th>4</th> <th>5</th> <th>6</th> <th>7</th> <th>8</th> <th>9</th> <th>10</th> <th>...</th> <th>80</th> <th>81</th> <th>82</th> <th>83</th> <th>84</th> <th>85</th> <th>86</th> <th>87</th> <th>88</th> <th>89</th> </tr> <tr> <th>Timestamp</th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> </tr> </thead> <tbody> <tr> <td>2012-01-01 06:00:00</td> <td>70.0</td> <td>69.8</td> <td>70.1</td> <td>69.6</td> <td>69.9</td> <td>70.8</td> <td>70.1</td> <td>69.3</td> <td>69.2</td> <td>68.2</td> <td>...</td> <td>72.1</td> <td>67.6</td> <td>71.0</td> <td>66.8</td> <td>65.9</td> <td>58.2</td> <td>67.1</td> <td>63.8</td> <td>67.1</td> <td>71.6</td> </tr> <tr> <td>2012-01-01 06:05:00</td> <td>69.2</td> <td>69.8</td> <td>69.8</td> <td>69.4</td> <td>69.5</td> <td>69.5</td> <td>68.3</td> <td>67.5</td> <td>67.4</td> <td>67.2</td> <td>...</td> <td>71.5</td> <td>66.1</td> <td>69.5</td> <td>67.4</td> <td>68.3</td> <td>59.0</td> <td>66.9</td> <td>60.8</td> <td>66.6</td> <td>65.7</td> </tr> <tr> <td>2012-01-01 06:10:00</td> <td>69.2</td> <td>69.0</td> <td>68.6</td> <td>68.7</td> <td>68.6</td> <td>68.9</td> <td>61.7</td> <td>68.3</td> <td>67.4</td> <td>67.7</td> <td>...</td> <td>71.1</td> <td>65.2</td> <td>71.2</td> <td>66.5</td> <td>65.4</td> <td>59.6</td> <td>66.3</td> <td>58.4</td> <td>68.2</td> <td>65.6</td> </tr> <tr> <td>2012-01-01 06:15:00</td> <td>69.9</td> <td>69.6</td> <td>69.7</td> <td>69.2</td> <td>69.0</td> <td>69.1</td> <td>65.3</td> <td>67.6</td> <td>67.1</td> <td>66.8</td> <td>...</td> <td>69.9</td> <td>67.1</td> <td>69.3</td> <td>66.9</td> <td>68.2</td> <td>60.6</td> <td>66.0</td> <td>55.5</td> <td>67.1</td> <td>69.7</td> </tr> <tr> <td>2012-01-01 06:20:00</td> <td>68.7</td> <td>68.4</td> <td>68.2</td> <td>67.9</td> <td>68.3</td> <td>69.3</td> <td>67.0</td> <td>68.4</td> <td>68.2</td> <td>68.2</td> <td>...</td> <td>70.9</td> <td>67.2</td> <td>69.9</td> <td>65.6</td> <td>66.7</td> <td>62.8</td> <td>66.2</td> <td>62.6</td> <td>67.2</td> <td>67.5</td> </tr> </tbody> </table> <p>5 rows × 89 columns</p> </div> ```python meta.head() ``` <div> <style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style> <table border="1" class="dataframe"> <thead> <tr style="text-align: right;"> <th></th> <th></th> <th>ID</th> <th>Abs_mp</th> <th>Latitude</th> <th>Longitude</th> </tr> <tr> <th>Fwy</th> <th>Dir</th> <th></th> <th></th> <th></th> <th></th> </tr> </thead> <tbody> <tr> <td rowspan="5" valign="top">5</td> <td>S</td> <td>1</td> <td>0.058</td> <td>32.542731</td> <td>-117.030501</td> </tr> <tr> <td>S</td> <td>2</td> <td>0.146</td> <td>32.543587</td> <td>-117.031769</td> </tr> <tr> <td>S</td> <td>3</td> <td>1.291</td> <td>32.552409</td> <td>-117.048120</td> </tr> <tr> <td>S</td> <td>4</td> <td>2.222</td> <td>32.558422</td> <td>-117.062360</td> </tr> <tr> <td>S</td> <td>5</td> <td>2.559</td> <td>32.561106</td> <td>-117.067228</td> </tr> </tbody> </table> </div> ### Choose a day ```python # Sampling (2012-01-13) myday = "2012-01-13" # Filter the data by the day myday_speed_data = data.loc[myday] ``` ### A speed profile ```python from matplotlib import pyplot as plt import matplotlib.dates as mdates # Axis value setting mp = meta[meta.ID.isin(data.columns)].Abs_mp hour = myday_speed_data.index # Draw the day fig, ax = plt.subplots() heatmap = ax.pcolormesh(hour,mp,myday_speed_data.T, cmap=plt.cm.RdYlGn, vmin=0, vmax=80, alpha=1) plt.colorbar(heatmap, ax=ax) # Appearance setting ax.xaxis.set_major_formatter(mdates.DateFormatter("%H")) plt.title(pd.Timestamp(myday).strftime("%Y-%m-%d [%a]")) plt.xlabel("hour") plt.ylabel("milepost") plt.show() ```  </code></pre>



