Skip to content

Commit f6915b3

Browse files
committed
Reflect recent improvements
1 parent 13edfc3 commit f6915b3

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

2-analysis-examples/ever-given.ipynb

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"source": [
5959
"df = pd.read_csv('../data/boat-positions.csv')\n",
6060
"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",
6261
"df"
6362
]
6463
},
@@ -88,7 +87,7 @@
8887
"metadata": {},
8988
"outputs": [],
9089
"source": [
91-
"tc = mpd.TrajectoryCollection(gdf, 'ID')"
90+
"tc = mpd.TrajectoryCollection(gdf, 'ID', t='t')"
9291
]
9392
},
9493
{
@@ -98,7 +97,7 @@
9897
"outputs": [],
9998
"source": [
10099
"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)"
102101
]
103102
},
104103
{
@@ -107,7 +106,9 @@
107106
"metadata": {},
108107
"outputs": [],
109108
"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"
111112
]
112113
},
113114
{
@@ -116,10 +117,8 @@
116117
"metadata": {},
117118
"outputs": [],
118119
"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"
123122
]
124123
},
125124
{
@@ -135,7 +134,7 @@
135134
"metadata": {},
136135
"outputs": [],
137136
"source": [
138-
"stop_pts[stop_pts['ID']==EVERID]"
137+
"stop_pts[stop_pts['traj_id']==EVERID]"
139138
]
140139
},
141140
{
@@ -144,13 +143,17 @@
144143
"metadata": {},
145144
"outputs": [],
146145
"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"
154157
]
155158
},
156159
{
@@ -166,7 +169,7 @@
166169
"metadata": {},
167170
"outputs": [],
168171
"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",
170173
" .sort_values('duration_s', ascending=False)\\\n",
171174
" .head(12)\\\n",
172175
" .style.background_gradient(cmap='Reds')"
@@ -196,7 +199,7 @@
196199
"name": "python",
197200
"nbconvert_exporter": "python",
198201
"pygments_lexer": "ipython3",
199-
"version": "3.10.10"
202+
"version": "3.10.12"
200203
},
201204
"vscode": {
202205
"interpreter": {

0 commit comments

Comments
 (0)