Skip to content

Commit ef55a98

Browse files
authored
Add movingpandas post (#42)
* Add movingpandas post * Fixed image handling Github didn't pick up on the lower case file extensions. Therefore I had to change the file name.
1 parent edaedc9 commit ef55a98

File tree

7 files changed

+121
-0
lines changed

7 files changed

+121
-0
lines changed

_data/authors.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,17 @@ Niels Bantilan:
2626
- label: "Twitter"
2727
icon: "fab fa-fw fa-twitter-square"
2828
url: "https://twitter.com/cosmicbboy"
29+
Anita Graser:
30+
name : "Anita Graser"
31+
bio : "Data Scientist, Spatial Data Analyst, AIT Vienna"
32+
avatar : "/images/people/anita-graser.png"
33+
links:
34+
- label: "Email"
35+
icon: "fas fa-fw fa-envelope-square"
36+
url: "mailto:[email protected]"
37+
- label: "Website"
38+
icon: "fas fa-fw fa-link"
39+
url: "http://anitagraser.com"
40+
- label: "Twitter"
41+
icon: "fab fa-fw fa-twitter-square"
42+
url: "https://twitter.com/underdarkGIS"
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
layout: single
3+
title: "MovingPandas: Data Structures and Methods for Movement Data Analysis"
4+
excerpt: "MovingPandas is an easy to use toolkit for exploring movement data that has recently passed the PyOpenSci review."
5+
author: "Anita Graser"
6+
permalink: /blog/movingpandas-movement-data-analysis
7+
header:
8+
overlay_image: images/pandas.jpg
9+
overlay_filter: 0.6
10+
caption: "Photo credit: [**Ann Batdorf, Smithsonian's National Zoo**](https://www.flickr.com/photos/nationalzoo/5371290900/in/photostream/)"
11+
categories:
12+
- blog-post
13+
- pandas
14+
- spatial
15+
---
16+
17+
Movement data is everywhere: from tracking apps that record human or vehicle movement to ecologists monitoring wildlife behaviour. Movement data analysis is challenging since movement data combines time series and spatial data analyses questions. Existing spatial analysis libraries, such as GeoPandas, are great at handling spatial data but they don't support moving objects.
18+
19+
MovingPandas aims to fill the gap of missing tools for exploring movement data. It provides data structures and methods for dealing with data of moving objects. MovingPandas has been accepted by pyOpenSci as part of its ecosystem in March 2020.
20+
21+
## A Toolkit for Movement Data Analysis
22+
23+
The MovingPandas repository contains multiple tutorials in the form of Jupyter notebooks that illustrate diverse analysis capabilities using different datasets, including: tracking data of ships, migration of birds, and tracks from a horse's GPS collar.
24+
25+
MovingPandas Trajectory objects are created from GeoPandas GeoDataFrames. A minimal example would be:
26+
27+
```python
28+
import pandas as pd
29+
import geopandas as gpd
30+
import movingpandas as mpd
31+
from shapely.geometry import Point
32+
from datetime import datetime
33+
from pyproj import CRS
34+
35+
df = pd.DataFrame([
36+
{'geometry':Point(0,0), 't':datetime(2018,1,1,12,0,0)},
37+
{'geometry':Point(6,0), 't':datetime(2018,1,1,12,6,0)},
38+
{'geometry':Point(6,6), 't':datetime(2018,1,1,12,10,0)},
39+
{'geometry':Point(9,9), 't':datetime(2018,1,1,12,15,0)}
40+
]).set_index('t')
41+
gdf = gpd.GeoDataFrame(df, crs=CRS(31256))
42+
traj = mpd.Trajectory(gdf, 1)
43+
```
44+
45+
MovingPandas provides static plots using Matplotlib and interactive plots using hvplot:
46+
47+
```python
48+
traj.plot()
49+
```
50+
51+
![The trajectory is plotted as a blue line on a white background with latitude and longitude values labeled on the axes.]({{ site.url }}/images/movingpandas/mp_fig1.png)
52+
53+
Matplotlib and hvplot parameters are passed along to the underlying libraries to enable extensive customization of plots:
54+
55+
```python
56+
traj.hvplot(geo=True, tiles='OSM', line_width=5, frame_width=300, frame_height=300)
57+
```
58+
59+
![The trajectory is plotted as a wide blue line on an OpenStreetMap background with latitude and longitude values labeled on the axes.]({{ site.url }}/images/movingpandas/mp_fig2.png)
60+
61+
### Exploring Movement Characteristics
62+
63+
MovingPandas makes it straightforward to compute movement characteristics, such as trajectory length and duration, as well as movement speed and direction.
64+
65+
For example, we can explore the daily travelled distance as recorded by a GPS tracker:
66+
67+
```python
68+
df = read_file('tracker.gpkg')
69+
df = df.set_index('t')
70+
tc = mpd.TrajectoryCollection(df, 'CollarID')
71+
72+
daily = tc.split_by_date(mode='day')
73+
daily_lengths = [traj.get_length() for traj in daily.trajectories]
74+
daily_t = [traj.get_start_time() for traj in daily.trajectories]
75+
daily_lengths = pd.DataFrame(daily_lengths, index=daily_t, columns=['length'])
76+
daily_lengths.hvplot(title='Daily trajectory length')
77+
```
78+
79+
![The evolution of the length of the daily trajectories is plotted over the whole obseration period.]({{ site.url }}/images/movingpandas/mp_fig3.png)
80+
81+
In this case, the movement data, which comes from a GPS collar of a horse, reveals that the animal tends to travel farther during summer days than during shorter winter days.
82+
83+
Other functions deal with trajectory generalization, splitting trajectories into subtrajectories, clipping trajectories to an area of interest, and extracting trajectory start and end times and locations.
84+
85+
### Standing on the Shoulders of Giants
86+
87+
By leveraging existing functionality within the Python data analysis ecosystem, such as, for example:
88+
time series handling by Pandas,
89+
spatial data analysis by GeoPandas, and
90+
interactive plotting by HoloViews,
91+
MovingPandas can focus on its core functionality dealing with challenges that are specific to movement data.
92+
93+
For example, the close integration with HoloViews makes it possible to create
94+
[interactive dashboards](http://holoviews.org/user_guide/Dashboards.html) to explore the effect of different trajectory generalization methods:
95+
96+
![The animated map and speed histogram show that speeds increase when the generalization tolerance value is increased.]({{ site.url }}/images/movingpandas/mp_fig4.gif)
97+
98+
## Test Your Movement Data Anylsis Skills Today!
99+
100+
You can [try MovingPandas in a MyBinder notebook - no installation required](https://mybinder.org/v2/gh/anitagraser/movingpandas/binder-tag?filepath=tutorials/0_getting_started.ipynb).
101+
102+
## What's next?
103+
104+
MovingPandas is under active development and there are some exciting features coming up.
105+
If you’d like to contribute to this project, you’re welcome to head on over to the [Github repo](https://github.com/anitagraser/movingpandas)!
106+
107+

images/movingpandas/mp_fig1.png

10.7 KB
Loading

images/movingpandas/mp_fig2.png

211 KB
Loading

images/movingpandas/mp_fig3.png

31.2 KB
Loading

images/movingpandas/mp_fig4.gif

1.55 MB
Loading

images/people/anita-graser.png

34.2 KB
Loading

0 commit comments

Comments
 (0)