|
58 | 58 | "source": [ |
59 | 59 | "df = pd.read_csv('../data/boat-positions.csv')\n", |
60 | 60 | "df['t'] = pd.to_datetime(df['ais_pos_timestamp'], format='%d/%m/%Y %H:%M')\n", |
61 | | - "df = df.set_index('t').tz_localize(None)\n", |
62 | 61 | "df" |
63 | 62 | ] |
64 | 63 | }, |
|
88 | 87 | "metadata": {}, |
89 | 88 | "outputs": [], |
90 | 89 | "source": [ |
91 | | - "tc = mpd.TrajectoryCollection(gdf, 'ID')" |
| 90 | + "tc = mpd.TrajectoryCollection(gdf, 'ID', t='t')" |
92 | 91 | ] |
93 | 92 | }, |
94 | 93 | { |
|
98 | 97 | "outputs": [], |
99 | 98 | "source": [ |
100 | 99 | "evergiven = tc.get_trajectory(EVERID)\n", |
101 | | - "evergiven.hvplot(line_width=7, frame_width=FSIZE, frame_height=FSIZE)" |
| 100 | + "evergiven.hvplot(line_width=3, frame_width=FSIZE, frame_height=FSIZE)" |
102 | 101 | ] |
103 | 102 | }, |
104 | 103 | { |
|
107 | 106 | "metadata": {}, |
108 | 107 | "outputs": [], |
109 | 108 | "source": [ |
110 | | - "stop_pts = mpd.TrajectoryStopDetector(tc).get_stop_points(min_duration=timedelta(hours=3), max_diameter=1000)" |
| 109 | + "stop_detector = mpd.TrajectoryStopDetector(tc)\n", |
| 110 | + "stop_pts = stop_detector.get_stop_points(min_duration=timedelta(hours=3), max_diameter=1000)\n", |
| 111 | + "stop_pts" |
111 | 112 | ] |
112 | 113 | }, |
113 | 114 | { |
|
116 | 117 | "metadata": {}, |
117 | 118 | "outputs": [], |
118 | 119 | "source": [ |
119 | | - "stop_pts['ID'] = stop_pts.index\n", |
120 | | - "stop_pts['ID'] = stop_pts['ID'].apply(lambda row: int(row.split('_')[0]))\n", |
121 | | - "stop_pts['duration_h'] = (stop_pts['end_time']-stop_pts['start_time']).dt.total_seconds() / 3600\n", |
122 | | - "stop_pts.style" |
| 120 | + "stop_pts['duration_h'] = stop_pts['duration_s'] / 3600\n", |
| 121 | + "stop_pts" |
123 | 122 | ] |
124 | 123 | }, |
125 | 124 | { |
|
135 | 134 | "metadata": {}, |
136 | 135 | "outputs": [], |
137 | 136 | "source": [ |
138 | | - "stop_pts[stop_pts['ID']==EVERID]" |
| 137 | + "stop_pts[stop_pts['traj_id']==EVERID]" |
139 | 138 | ] |
140 | 139 | }, |
141 | 140 | { |
|
144 | 143 | "metadata": {}, |
145 | 144 | "outputs": [], |
146 | 145 | "source": [ |
147 | | - "plot = evergiven.hvplot(line_width=5, color='red', frame_width=FSIZE, frame_height=FSIZE, alpha=0.5).opts(active_tools=['pan','wheelzoom'])\n", |
148 | | - "plot = plot * stop_pts.hvplot(geo=True, hover_cols=['start_time'], size=20) \n", |
149 | | - "plot = plot * stop_pts[stop_pts['ID']==EVERID].hvplot(geo=True, hover_cols=['start_time'], size=dim('duration_h')/2, color='red', \n", |
150 | | - " title='Trajectory & stop location of Ever Given and stops of other vessels')\n", |
151 | | - "plot2 = pd.DataFrame(stop_pts).hvplot.scatter(title='Stop start & duration (in hours)', x='start_time', y='duration_h', frame_width=FSIZE, frame_height=FSIZE) \n", |
152 | | - "plot2 = plot2 * pd.DataFrame(stop_pts[stop_pts['ID']==EVERID]).hvplot.scatter(x='start_time', y='duration_h', color='red', size=200)\n", |
153 | | - "link_selections(plot + plot2)" |
| 146 | + "map_plot = ( \n", |
| 147 | + " stop_pts.hvplot(geo=True, hover_cols=['start_time'], size=20, tiles='OSM') * \n", |
| 148 | + " evergiven.hvplot(line_width=5, color='red', frame_width=FSIZE, frame_height=FSIZE, alpha=0.5, tiles=None).opts(active_tools=['pan','wheelzoom']) *\n", |
| 149 | + " stop_pts[stop_pts['traj_id']==EVERID].hvplot(geo=True, hover_cols=['start_time'], size=dim('duration_h')/2, color='red', \n", |
| 150 | + " title='Trajectory & stop location of Ever Given and stops of other vessels')\n", |
| 151 | + ")\n", |
| 152 | + "scatter_plot = ( \n", |
| 153 | + " stop_pts.hvplot.scatter(title='Stop start & duration (in hours)', x='start_time', y='duration_h', frame_width=FSIZE, frame_height=FSIZE, alpha=0.7) * \n", |
| 154 | + " stop_pts[stop_pts['traj_id']==EVERID].hvplot.scatter(x='start_time', y='duration_h', color='red', size=200) \n", |
| 155 | + ")\n", |
| 156 | + "map_plot + scatter_plot" |
154 | 157 | ] |
155 | 158 | }, |
156 | 159 | { |
|
166 | 169 | "metadata": {}, |
167 | 170 | "outputs": [], |
168 | 171 | "source": [ |
169 | | - "stop_pts[stop_pts.start_time > datetime(2021,3,23,5,47,0)]\\\n", |
| 172 | + "stop_pts[stop_pts.start_time > datetime(2021,3,23,5,39,0)]\\\n", |
170 | 173 | " .sort_values('duration_s', ascending=False)\\\n", |
171 | 174 | " .head(12)\\\n", |
172 | 175 | " .style.background_gradient(cmap='Reds')" |
|
196 | 199 | "name": "python", |
197 | 200 | "nbconvert_exporter": "python", |
198 | 201 | "pygments_lexer": "ipython3", |
199 | | - "version": "3.10.10" |
| 202 | + "version": "3.10.12" |
200 | 203 | }, |
201 | 204 | "vscode": { |
202 | 205 | "interpreter": { |
|
0 commit comments