Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add movingpandas post #42

Merged
merged 2 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions _data/authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ Niels Bantilan:
- label: "Twitter"
icon: "fab fa-fw fa-twitter-square"
url: "https://twitter.com/cosmicbboy"
Anita Graser:
name : "Anita Graser"
bio : "Data Scientist, Spatial Data Analyst, AIT Vienna"
avatar : "/images/people/anita-graser.png"
links:
- label: "Email"
icon: "fas fa-fw fa-envelope-square"
url: "mailto:anitagraser@gmx.at"
- label: "Website"
icon: "fas fa-fw fa-link"
url: "http://anitagraser.com"
- label: "Twitter"
icon: "fab fa-fw fa-twitter-square"
url: "https://twitter.com/underdarkGIS"
107 changes: 107 additions & 0 deletions _posts/2020-04-29-movingpandas-movement-data-analysis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
layout: single
title: "MovingPandas: Data Structures and Methods for Movement Data Analysis"
excerpt: "MovingPandas is an easy to use toolkit for exploring movement data that has recently passed the PyOpenSci review."
author: "Anita Graser"
permalink: /blog/movingpandas-movement-data-analysis
header:
overlay_image: images/pandas.jpg
overlay_filter: 0.6
caption: "Photo credit: [**Ann Batdorf, Smithsonian's National Zoo**](https://www.flickr.com/photos/nationalzoo/5371290900/in/photostream/)"
categories:
- blog-post
- pandas
- spatial
---

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.

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.

## A Toolkit for Movement Data Analysis

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.

MovingPandas Trajectory objects are created from GeoPandas GeoDataFrames. A minimal example would be:

```python
import pandas as pd
import geopandas as gpd
import movingpandas as mpd
from shapely.geometry import Point
from datetime import datetime
from pyproj import CRS

df = pd.DataFrame([
{'geometry':Point(0,0), 't':datetime(2018,1,1,12,0,0)},
{'geometry':Point(6,0), 't':datetime(2018,1,1,12,6,0)},
{'geometry':Point(6,6), 't':datetime(2018,1,1,12,10,0)},
{'geometry':Point(9,9), 't':datetime(2018,1,1,12,15,0)}
]).set_index('t')
gdf = gpd.GeoDataFrame(df, crs=CRS(31256))
traj = mpd.Trajectory(gdf, 1)
```

MovingPandas provides static plots using Matplotlib and interactive plots using hvplot:

```python
traj.plot()
```

<img src="https://raw.githubusercontent.com/pyOpenSci/pyopensci.github.io/master/images/movingpandas/mpd_fig1.PNG">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this image link will need to be adjusted !

let's do the following.

  1. make the image extension .png (lower case)
  2. image url's should look like this: single sentence text description of image here
    they will then render properly!
  3. this is optional but adding alt tags would be good as it allows people with screen readers to "see" your images via words" a simple text description is plenty.


Matplotlib and hvplot parameters are passed along to the underlying libraries to enable extensive customization of plots:

```python
traj.hvplot(geo=True, tiles='OSM', line_width=5, frame_width=300, frame_height=300)
```

<img src="https://raw.githubusercontent.com/pyOpenSci/pyopensci.github.io/master/images/movingpandas/mpd_fig2.PNG">

### Exploring Movement Characteristics

MovingPandas makes it straightforward to compute movement characteristics, such as trajectory length and duration, as well as movement speed and direction.

For example, we can explore the daily travelled distance as recorded by a GPS tracker:

```python
df = read_file('tracker.gpkg')
df = df.set_index('t')
tc = mpd.TrajectoryCollection(df, 'CollarID')

daily = tc.split_by_date(mode='day')
daily_lengths = [traj.get_length() for traj in daily.trajectories]
daily_t = [traj.get_start_time() for traj in daily.trajectories]
daily_lengths = pd.DataFrame(daily_lengths, index=daily_t, columns=['length'])
daily_lengths.hvplot(title='Daily trajectory length')
```

<img src="https://raw.githubusercontent.com/pyOpenSci/pyopensci.github.io/master/images/movingpandas/mpd_fig3.PNG">

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.

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.

### Standing on the Shoulders of Giants

By leveraging existing functionality within the Python data analysis ecosystem, such as, for example:
time series handling by Pandas,
spatial data analysis by GeoPandas, and
interactive plotting by HoloViews,
MovingPandas can focus on its core functionality dealing with challenges that are specific to movement data.

For example, the close integration with HoloViews makes it possible to create
[interactive dashboards](http://holoviews.org/user_guide/Dashboards.html) to explore the effect of different trajectory generalization methods:

<img src="https://raw.githubusercontent.com/pyOpenSci/pyopensci.github.io/master/images/movingpandas/mpd_fig4.GIF">

## Test Your Movement Data Anylsis Skills Today!

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).

## What's next?

MovingPandas is under active development and there are some exciting features coming up.
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)!


Binary file added images/movingpandas/mpd_fig1.PNG
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 images/movingpandas/mpd_fig2.PNG
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 images/movingpandas/mpd_fig3.PNG
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 images/movingpandas/mpd_fig4.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 images/people/anita-graser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.