Skip to content

Commit

Permalink
Add examples to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron committed Oct 7, 2024
1 parent 7f59af9 commit 5247af0
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 23 deletions.
Binary file added assets/air-traffic-control.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ais-movingpandas.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions docs/api/layers/trips-layer.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# TripsLayer

<img src="../../../assets/air-traffic-control.gif" height="300px">

> Screenshot from Air Traffic Control example.
::: lonboard.experimental.TripsLayer
options:
filters:
Expand Down
241 changes: 218 additions & 23 deletions examples/ship-data.ipynb → examples/ais-movingpandas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "4fd4d098",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/kyle/github/developmentseed/lonboard/.venv/lib/python3.11/site-packages/movingpandas/__init__.py:37: UserWarning: Missing optional dependencies. To use the trajectory smoother classes please install Stone Soup (see https://stonesoup.readthedocs.io/en/latest/#installation).\n",
" warnings.warn(e.msg, UserWarning)\n"
]
}
],
"source": [
"from datetime import timedelta\n",
"\n",
Expand All @@ -70,7 +79,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "3ce4a739",
"metadata": {},
"outputs": [],
Expand All @@ -89,10 +98,122 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "1fbad7ab",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Timestamp</th>\n",
" <th>MMSI</th>\n",
" <th>NavStatus</th>\n",
" <th>SOG</th>\n",
" <th>COG</th>\n",
" <th>Name</th>\n",
" <th>ShipType</th>\n",
" <th>geometry</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>05/07/2017 00:00:03</td>\n",
" <td>219632000</td>\n",
" <td>Under way using engine</td>\n",
" <td>0.0</td>\n",
" <td>270.4</td>\n",
" <td>None</td>\n",
" <td>Undefined</td>\n",
" <td>POINT (11.85958 57.68817)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>05/07/2017 00:00:05</td>\n",
" <td>265650970</td>\n",
" <td>Under way using engine</td>\n",
" <td>0.0</td>\n",
" <td>0.5</td>\n",
" <td>None</td>\n",
" <td>Undefined</td>\n",
" <td>POINT (11.84175 57.66150)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>05/07/2017 00:00:06</td>\n",
" <td>265503900</td>\n",
" <td>Under way using engine</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>None</td>\n",
" <td>Undefined</td>\n",
" <td>POINT (11.90650 57.69077)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>05/07/2017 00:00:14</td>\n",
" <td>219632000</td>\n",
" <td>Under way using engine</td>\n",
" <td>0.0</td>\n",
" <td>188.4</td>\n",
" <td>None</td>\n",
" <td>Undefined</td>\n",
" <td>POINT (11.85958 57.68817)</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>05/07/2017 00:00:19</td>\n",
" <td>265519650</td>\n",
" <td>Under way using engine</td>\n",
" <td>0.0</td>\n",
" <td>357.2</td>\n",
" <td>None</td>\n",
" <td>Undefined</td>\n",
" <td>POINT (11.87192 57.68233)</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Timestamp MMSI NavStatus SOG COG Name \\\n",
"0 05/07/2017 00:00:03 219632000 Under way using engine 0.0 270.4 None \n",
"1 05/07/2017 00:00:05 265650970 Under way using engine 0.0 0.5 None \n",
"2 05/07/2017 00:00:06 265503900 Under way using engine 0.0 0.0 None \n",
"3 05/07/2017 00:00:14 219632000 Under way using engine 0.0 188.4 None \n",
"4 05/07/2017 00:00:19 265519650 Under way using engine 0.0 357.2 None \n",
"\n",
" ShipType geometry \n",
"0 Undefined POINT (11.85958 57.68817) \n",
"1 Undefined POINT (11.84175 57.66150) \n",
"2 Undefined POINT (11.90650 57.69077) \n",
"3 Undefined POINT (11.85958 57.68817) \n",
"4 Undefined POINT (11.87192 57.68233) "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gdf.head()"
]
Expand All @@ -107,10 +228,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "d51af454",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "da0c4abcb0264fc59a3b06a11767ff82",
"version_major": 2,
"version_minor": 1
},
"text/plain": [
"Map(basemap_style=<CartoBasemap.DarkMatter: 'https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json'…"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"viz(gdf)"
]
Expand All @@ -125,10 +262,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "71f3ce4a",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Original size: 84702 rows\n",
"Reduced to 33593 rows after removing 0 speed records\n"
]
}
],
"source": [
"print(f\"Original size: {len(gdf)} rows\")\n",
"gdf = gdf[gdf[\"SOG\"] > 0]\n",
Expand All @@ -153,10 +299,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "3fd34558",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Finished creating 77 trajectories\n"
]
}
],
"source": [
"gdf[\"t\"] = pd.to_datetime(gdf[\"Timestamp\"], format=\"%d/%m/%Y %H:%M:%S\")\n",
"traj_collection = mpd.TrajectoryCollection(gdf, \"MMSI\", t=\"t\", min_length=100)\n",
Expand All @@ -165,7 +319,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "e161ebd6",
"metadata": {},
"outputs": [],
Expand All @@ -185,7 +339,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "ffa475cf",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -220,7 +374,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"id": "0c33f584",
"metadata": {},
"outputs": [],
Expand All @@ -243,7 +397,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "57598b6c",
"metadata": {},
"outputs": [],
Expand All @@ -261,10 +415,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"id": "838bfbe5",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/kyle/github/developmentseed/lonboard/lonboard/experimental/traits.py:146: UserWarning: Reducing precision of input timestamp data to 's' to fit into available GPU precision.\n",
" warnings.warn(\n"
]
}
],
"source": [
"trips_layer = TripsLayer.from_movingpandas(\n",
" traj_collection, get_color=get_color, width_min_pixels=5, trail_length = 200\n",
Expand All @@ -273,10 +436,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"id": "853030f8",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "67c54a1d0c154d28b08913c2890a90f2",
"version_major": 2,
"version_minor": 1
},
"text/plain": [
"Map(custom_attribution='', layers=(TripsLayer(get_color=arro3.core.ChunkedArray<FixedSizeList(Field { name: \"\"…"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m = Map(trips_layer, _height=600)\n",
"m"
Expand All @@ -292,10 +471,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"id": "33d21613-1d45-4467-ada8-1bbbcf632d88",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "46a31714d33d4c3797ed99007f8e3823",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(Play(value=-16777216, interval=20, max=-16690894, min=-16777216, repeat=True, step=30), Output(…"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"trips_layer.animate(step=timedelta(seconds=30), fps=50)"
]
Expand All @@ -314,7 +509,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"id": "42f9829f",
"metadata": {},
"outputs": [],
Expand All @@ -334,7 +529,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"id": "a32fe305-2fe7-41ae-8ea7-43128b88a0fe",
"metadata": {},
"outputs": [],
Expand Down
3 changes: 3 additions & 0 deletions examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Speedtest data ![](../assets/scatterplot-layer-network-speeds.jpg)](../examples/internet-speeds) using [`ScatterplotLayer`](../api/layers/scatterplot-layer)
- [North America roads ![](../assets/path-layer-roads.jpg)](../examples/north-america-roads) using [`PathLayer`](../api/layers/path-layer)
- [Overture Maps buildings ![](../assets/overture.jpg)](../examples/overture-maps) using [`PolygonLayer`](../api/layers/polygon-layer)
- [Air Traffic Control animation ![](../assets/air-traffic-control.gif)](../examples/air-traffic-control) using [`TripsLayer`](../api/layers/trips-layer)
- [Global boundaries ![](../assets/boundaries.png)](../examples/global-boundaries) using [`PolygonLayer`](../api/layers/polygon-layer)
- [U.S. County-to-County Migration ![](../assets/arc-layer-migration-example.gif)](../examples/migration) using [`ArcLayer`](../api/layers/arc-layer) and [`BrushingExtension`](../api/layer-extensions/brushing-extension)
- [Scatterplot with GPU data filtering ![](../assets/data-filter-extension.gif)](../examples/data-filter-extension) using [`ScatterplotLayer`](../api/layers/scatterplot-layer) and [`DataFilterExtension`](../api/layer-extensions/data-filter-extension)
Expand All @@ -22,6 +23,8 @@
- [DuckDB Spatial ![](../assets/duckdb-heatmap.jpg)](../examples/duckdb) using [`HeatmapLayer`](../api/layers/heatmap-layer)
- [Color picker integration ![](../assets/color-picker.jpg)](../examples/integrations/color-picker) using [`SolidPolygonLayer`](../api/layers/solid-polygon-layer)
- [JupyterLab Sidecar integration ![](../assets/jupyter-sidecar.jpg)](../examples/integrations/sidecar/) using [`ScatterplotLayer`](../api/layers/scatterplot-layer) and [`JupyterLab Sidecar`](https://github.com/jupyter-widgets/jupyterlab-sidecar)
- [MovingPandas ![](../assets/ais-movingpandas.gif)](../examples/ais-movingpandas) using [`TripsLayer`](../api/layers/trips-layer)


</div>

Expand Down
Loading

0 comments on commit 5247af0

Please sign in to comment.