Giter Club home page Giter Club logo

movingpandas-examples's Introduction

MovingPandas

pypi Conda Version Conda Downloads Conda Recipe Conda Platforms Project Status: Active – The project has reached a stable, usable state and is being actively developed. Tests docs status codecov DOI pyOpenSci Code style: black StandWithUkraine

Mastodon Follow

SWUbanner

MovingPandas implements a Trajectory class and corresponding methods based on GeoPandas.

Visit movingpandas.org for details!

You can run MovingPandas examples on MyBinder - no installation required: Binder (These examples use the latest MovingPandas release version.)

To try the cutting-edge dev version, use this MyBinder link.

Documentation

We recommend starting your MovingPandas journey with the tutorial notebooks on the official homepage

The official API documentation is hosted on ReadTheDocs

Examples

Trajectory plots View Jupyter Notebook

Create interactive trajectory plots, including multiple linked plots with ease

movingpandas_animated

For all types of tracking data, e.g. video-based trajectories

Bicycle tracks from object tracking in videos

Including plots in custom projections View Jupyter Notebook

MovingPandas Iceberg trajectory in custom SouthPolarStereo projection

Stop detection View Jupyter Notebook

Detect stops in trajectories, extract them as points or segments, and use them to split trajectories

movingpandas_stop_detection

Trajectory generalization View Jupyter Notebook

Generalize trajectories using spatial, temporal, and spatiotemporal methods

movingpandas_generalize

Trajectory cleaning & smoothing View Jupyter Notebook

Clean and sooth trajectories by removing outliers and applying Kalman filters

movingpandas smooth

Trajectory aggregation View Jupyter Notebook

Aggregate trajectories to explore larger patterns

movingpandas_ais

Installation

MovingPandas for Python >= 3.7 and all its dependencies are available from conda-forge and can be installed using

conda install -c conda-forge movingpandas

or faster using

mamba install -c conda-forge movingpandas

Note that it is NOT recommended to install MovingPandas from PyPI! If you are using Windows or Mac, many GeoPandas / MovingPandas dependencies may not install correctly with pip (for details see the corresponding notes in the GeoPandas documentation). On Ubuntu, pip install may fail, e.g. on cartopy with "Proj 4.9.0 must be installed".

Development installation

Use the following steps to run the notebooks using the current development version:

Using conda / mamba

conda env create -f environment.yml

Develop mode

To install MovingPandas in "develop" or "editable" mode you may use:

python setup.py develop

Contributing to MovingPandas GitHub contributors

All contributions, bug reports, bug fixes, documentation improvements, enhancements and ideas are welcome.

A detailed overview on how to contribute can be found in the contributing guide on GitHub.

Related Python packages

For a more comprehensive list, including non-Python solutions, check https://github.com/anitagraser/movement-analysis-tools

scikit-mobility is a similar package which also deals with movement data. It implements TrajectoryDataFrames and FlowDataFrames on top of Pandas instead of GeoPandas. There is little overlap in the covered use cases and implemented functionality (comparing MovingPandas tutorials and scikit-mobility tutorials). MovingPandas focuses on spatio-temporal data exploration with corresponding functions for data manipulation and analysis. scikit-mobility on the other hand focuses on computing human mobility metrics, generating synthetic trajectories and assessing privacy risks. Plotting is based on Folium.

Traja extends the capabilitis of Pandas DataFrames specific for animal trajectory analysis in 2D. Plots (static) are based on seaborn.

PyMove provides functionality similar to MovingPandas. It implements PandasMoveDataFrames and DaskMoveDataFrame on top of Pandas and Dask DataFrames. Plotting is based on Folium.

Tracktable is a related Python package with its core data structures and algorithms implemented in C++, i.e. it is not based on Pandas. Plotting is based on Cartopy (for still images) and Folium (for interactive rendering).

Citation information

Please cite [0] when using MovingPandas in your research and reference the appropriate release version. All releases of MovingPandas are listed on Zenodo where you will find citation information, including DOIs.

Publications

About MovingPandas

[0] Graser, A. (2019). MovingPandas: Efficient Structures for Movement Data in Python. GI_Forum ‒ Journal of Geographic Information Science 2019, 1-2019, 54-68. doi:10.1553/giscience2019_01_s54.

@article{graser_movingpandas_2019,
	title = {{MovingPandas}: {Efficient} {Structures} for {Movement} {Data} in {Python}},
	volume = {7},
	number = {1},
	issn = {2308-1708, 2308-1708},
	shorttitle = {{MovingPandas}},
	url = {https://hw.oeaw.ac.at?arp=0x003aba2b},
	doi = {10.1553/giscience2019_01_s54},
	language = {en},
	urldate = {2023-04-19},
	journal = {GI\_Forum ‒ Journal of Geographic Information Science},
	author = {Graser, Anita},
	year = {2019},
	pages = {54--68},
}

[1] Graser, A. & Dragaschnig, M. (2020). Exploring movement data in notebook environments. Presented at MoVIS 2020, IEEE VIS 2020.

[2] Graser, A. (2021). Exploratory Movement Data Analysis. GeoPython 2021. – 🎬 video

Scientific publications using MovingPandas

Full Google Scholar list

Platforms using MovingPandas

Teaching materials referencing MovingPandas

Workshop videos

WorkshopVideo ogh2023

movingpandas-examples's People

Contributors

anitagraser avatar raybellwaves avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

movingpandas-examples's Issues

Error using plot (in tutorial example)

Following the tutoriañ 1-getting-started.ipynb, I encounter the following error at cell [23] : toy_traj.plot(column="speed")

IndexError Traceback (most recent call last)
Input In [23], in <cell line: 1>()
----> 1 toy_traj.plot(column="speed")

File ~/proyectos/examples/movingpandas/movingpandas/trajectory.py:215, in Trajectory.plot(self, *args, **kwargs)
194 def plot(self, *args, **kwargs):
195 """
196 Generate a plot using GeoPandas default plotting (Matplotlib).
197
(...)
213 >>> trajectory.plot(column='speed', legend=True, figsize=(9,5))
214 """
--> 215 return _TrajectoryPlotter(self, *args, **kwargs).plot()

File ~/proyectos/examples/movingpandas/movingpandas/trajectory_plotter.py:106, in _TrajectoryPlotter.plot(self)
104 if not self.ax:
105 self.ax = plt.figure(figsize=self.figsize).add_subplot(1, 1, 1)
--> 106 ax = self._plot_trajectory(self.data)
107 self.kwargs[
108 "legend"
109 ] = False # has to be removed after the first iteration, otherwise we get multiple legends! # noqa E501
110 self.kwargs.pop(
111 "column", None
112 ) # has to be popped, otherwise there's an error in the following plot call

File ~/proyectos/examples/movingpandas/movingpandas/trajectory_plotter.py:64, in _TrajectoryPlotter._plot_trajectory(self, traj)
62 self.kwargs.pop("vmin", None)
63 self.kwargs.pop("vmax", None)
---> 64 return temp_df.plot(
65 ax=self.ax,
66 vmin=self.min_value,
67 vmax=self.max_value,
68 *self.args,
69 **self.kwargs
70 )

File ~/anaconda3/lib/python3.8/site-packages/geopandas/geodataframe.py:899, in GeoDataFrame.plot(self, *args, **kwargs)
889 def plot(self, *args, **kwargs):
890 """Generate a plot of the geometries in the GeoDataFrame.
891
892 If the column parameter is given, colors plot according to values
(...)
897 from there.
898 """
--> 899 return plot_dataframe(self, *args, **kwargs)

File ~/anaconda3/lib/python3.8/site-packages/geopandas/plotting.py:730, in plot_dataframe(df, column, cmap, color, ax, cax, categorical, legend, scheme, k, vmin, vmax, markersize, figsize, legend_kwds, categories, classification_kwds, missing_kwds, aspect, **style_kwds)
728 subset = values[line_idx & np.invert(nan_idx)]
729 if not lines.empty:
--> 730 _plot_linestring_collection(
731 ax, lines, subset, vmin=mn, vmax=mx, cmap=cmap, **style_kwds
732 )
734 # plot all Points in the same collection
735 points = expl_series[point_idx & np.invert(nan_idx)]

File ~/anaconda3/lib/python3.8/site-packages/geopandas/plotting.py:203, in _plot_linestring_collection(ax, geoms, values, color, cmap, vmin, vmax, **kwargs)
199 kwargs["color"] = color
201 _expand_kwargs(kwargs, multiindex)
--> 203 segments = [np.array(linestring)[:, :2] for linestring in geoms]
204 collection = LineCollection(segments, **kwargs)
206 if values is not None:

File ~/anaconda3/lib/python3.8/site-packages/geopandas/plotting.py:203, in (.0)
199 kwargs["color"] = color
201 _expand_kwargs(kwargs, multiindex)
--> 203 segments = [np.array(linestring)[:, :2] for linestring in geoms]
204 collection = LineCollection(segments, **kwargs)
206 if values is not None:

IndexError: too many indices for array


Installation seems ok:
2022-12-15 01_30_47-1-getting-started - Jupyter Notebook

2-computing-speed.ipynb error :

my_traj.hvplot(c='speed', clim=(0,20), line_width=7.0, tiles='OSM', cmap='Viridis', colorbar=True, width=500, height=300)

--> 326 return self._array_interface_base()
327
328 @Property

TypeError: 'dict' object is not callable

:Overlay
.Tiles.I :Tiles [x,y]
.Path.I :Path [Longitude,Latitude] (speed)

ValueError: Latitude must be in the [-90; 90] range.

I tried to run the code below

gdf = gpd.read_file('geolife_small.gpkg')
gdf
tc = mpd.TrajectoryCollection(gdf, 'trajectory_id', t='t')

my_traj = tc.trajectories[0]
my_traj
detector = mpd.TrajectoryStopDetector(my_traj)
stop_time_ranges = detector.get_stop_time_ranges(min_duration=timedelta(seconds=60), max_diameter=100)

Essentially following the tutorial on stop detection with single trajectory.
But I got ValueError: Latitude must be in the [-90; 90] range.

This is not an issue when the longitude value is less than 90.

Examples viewable in pre-executed notebook

I'm looking to use movingpandas on a project and to get a feel for the functionality looking at the examples really helps, however I don't really want to run all the examples, just have a scan/search through them and the output for what I'm after. To help with this, it would be useful to have an executed version of the examples saved somewhere, either the notebooks themselves, or them in markdown/html.

Trajectory does not get clipped correctly by a polygon

if the points in the trajectory are identical and they are all inside the polygon, clip() does NOT return any trajectory segment.
if the points in the trajectory are slightly different and they are all inside the polygon, clip() does return the trajectory segment correctly.

code

working

not working

Holoviews error

After creating a blank conda environment for movingpandas and installing I tried to run the ship data example but unfortunately Holoviews throws an error about not finding Lattitude or Longitude in the data

DataError: Supplied data does not contain specified dimensions, the following dimensions were not found: ['Longitude', 'Latitude']

Probably an API change or something? The data is obviously there in the points(geometry).

I added the columns

test = [a.coords.xy for a in df['geometry']]
df['Longitude'] = [a[0][0] for a in test]
df['Latitude'] = [a[1][0] for a in test]
del test

but then I just get a new error regarding recursion depth

~/miniconda3/envs/movement/lib/python3.9/site-packages/geoviews/element/geo.py in clone(self, data, shared_data, new_type, *args, **overrides)
100 if 'crs' not in overrides and (not new_type or isinstance(new_type, _Element)):
101 overrides['crs'] = self.crs
--> 102 return super(_Element, self).clone(data, shared_data, new_type,
103 *args, **overrides)
104

RecursionError: maximum recursion depth exceeded while calling a Python object

Error running `1-bird-migration` notebook on mybinder

First, I really appreciate the great project and examples you have put together.

When I tried running the 1-bird-migration notebook on mybinder, the following error occurs in cell 20:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-20-52e63e9e0a94> in <module>
----> 1 arrivals = [traj for traj in my_traj.clip(area_of_interest)]
      2 print("Found {} arrivals".format(len(arrivals)))
      3 
      4 for traj in arrivals:
      5     print("Individual '{}' arrived at {}".format(traj.df['individual-local-identifier'].iloc[0], traj.get_start_time()))

/srv/conda/envs/notebook/lib/python3.7/site-packages/movingpandas/trajectory.py in clip(self, polygon, pointbased)
    643             Clipped trajectory segments
    644         """
--> 645         return clip(self, polygon, pointbased)
    646 
    647     def intersection(self, feature, pointbased=False):

/srv/conda/envs/notebook/lib/python3.7/site-packages/movingpandas/overlay.py in clip(traj, polygon, pointbased)
    169         ranges = _determine_time_ranges_pointbased(traj, polygon)
    170     else:
--> 171         ranges = _determine_time_ranges_linebased(traj, polygon)
    172     return _get_segments_for_ranges(traj, ranges)
    173 

/srv/conda/envs/notebook/lib/python3.7/site-packages/movingpandas/overlay.py in _determine_time_ranges_linebased(traj, polygon)
    155     possible_matches = _get_potentially_intersecting_lines(traj, polygon)
    156     possible_matches['spatial_intersection'] = possible_matches.intersection(polygon)
--> 157     possible_matches['spatiotemporal_intersection'] = possible_matches.apply(_get_spatiotemporal_ref, axis=1)
    158     ranges = possible_matches['spatiotemporal_intersection']
    159     return _dissolve_ranges(ranges)

/srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/core/frame.py in apply(self, func, axis, raw, result_type, args, **kwds)
   7763             kwds=kwds,
   7764         )
-> 7765         return op.get_result()
   7766 
   7767     def applymap(self, func, na_action: Optional[str] = None) -> DataFrame:

/srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/core/apply.py in get_result(self)
    183             return self.apply_raw()
    184 
--> 185         return self.apply_standard()
    186 
    187     def apply_empty_result(self):

/srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/core/apply.py in apply_standard(self)
    274 
    275     def apply_standard(self):
--> 276         results, res_index = self.apply_series_generator()
    277 
    278         # wrap results

/srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/core/apply.py in apply_series_generator(self)
    288             for i, v in enumerate(series_gen):
    289                 # ignore SettingWithCopy here in case the user mutates
--> 290                 results[i] = self.f(v)
    291                 if isinstance(results[i], ABCSeries):
    292                     # If we have a view on v, we need to make a copy because

/srv/conda/envs/notebook/lib/python3.7/site-packages/movingpandas/overlay.py in _get_spatiotemporal_ref(row)
     14     """
     15     if type(row['spatial_intersection']) == LineString:
---> 16         pt0 = Point(row['spatial_intersection'].coords[0])
     17         ptn = Point(row['spatial_intersection'].coords[-1])
     18         t = row['prev_t']

IndexError: list index out of range

Missing ship-data

When trying to run ship-data example, the following data is not available :

FileNotFoundError: [Errno 2] No such file or directory: 'E:/Geodata/MarineCadastre/AIS_2021_03_28.zip'

import datashader fails with SystemError: initialization of _internal failed without raising an exception

In datashader.ipynb:

---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
Cell In[2], line 12
     10 from geopandas import read_file
     11 from holoviews.element import tiles
---> 12 from holoviews.operation.datashader import datashade, spread
     13 from holoviews import opts
     14 from shapely.geometry import Polygon

File ~/anaconda3/envs/seasy/lib/python3.9/site-packages/holoviews/operation/datashader.py:10
      8 import pandas as pd
      9 import xarray as xr
---> 10 import datashader as ds
     11 import datashader.reductions as rd
     12 import datashader.transfer_functions as tf

File ~/anaconda3/envs/seasy/lib/python3.9/site-packages/datashader/__init__.py:8
      5 import param
      6 __version__ = str(param.version.Version(fpath=__file__, archive_commit="$Format:%h$",reponame="datashader"))
----> 8 from .core import Canvas                                 # noqa (API import)
      9 from .reductions import *                                # noqa (API import)
     10 from .glyphs import Point                                # noqa (API import)

File ~/anaconda3/envs/seasy/lib/python3.9/site-packages/datashader/core.py:13
     10 from xarray import DataArray, Dataset
     11 from collections import OrderedDict
---> 13 from .utils import Dispatcher, ngjit, calc_res, calc_bbox, orient_array, \
     14     dshape_from_xarray_dataset
     15 from .utils import get_indices, dshape_from_pandas, dshape_from_dask
     16 from .utils import Expr # noqa (API import)

File ~/anaconda3/envs/seasy/lib/python3.9/site-packages/datashader/utils.py:8
      4 import re
      6 from inspect import getmro
----> 8 import numba as nb
      9 import numpy as np
     10 import pandas as pd

File ~/anaconda3/envs/seasy/lib/python3.9/site-packages/numba/__init__.py:43
     39 from numba.core.decorators import (cfunc, generated_jit, jit, njit, stencil,
     40                                    jit_module)
     42 # Re-export vectorize decorators and the thread layer querying function
---> 43 from numba.np.ufunc import (vectorize, guvectorize, threading_layer,
     44                             get_num_threads, set_num_threads)
     46 # Re-export Numpy helpers
     47 from numba.np.numpy_support import carray, farray, from_dtype

File ~/anaconda3/envs/seasy/lib/python3.9/site-packages/numba/np/ufunc/__init__.py:3
      1 # -*- coding: utf-8 -*-
----> 3 from numba.np.ufunc.decorators import Vectorize, GUVectorize, vectorize, guvectorize
      4 from numba.np.ufunc._internal import PyUFunc_None, PyUFunc_Zero, PyUFunc_One
      5 from numba.np.ufunc import _internal, array_exprs

File ~/anaconda3/envs/seasy/lib/python3.9/site-packages/numba/np/ufunc/decorators.py:3
      1 import inspect
----> 3 from numba.np.ufunc import _internal
      4 from numba.np.ufunc.parallel import ParallelUFuncBuilder, ParallelGUFuncBuilder
      6 from numba.core.registry import TargetRegistry

SystemError: initialization of _internal failed without raising an exception

With the following environment:

MovingPandas 0.15.rc1

SYSTEM INFO
-----------
python     : 3.9.16 | packaged by conda-forge | (main, Feb  1 2023, 21:39:03)  [GCC 11.3.0]
executable : /srv/conda/envs/notebook/bin/python
machine    : Linux-5.10.147+-x86_64-with-glibc2.27

GEOS, GDAL, PROJ INFO
---------------------
GEOS       : None
GEOS lib   : None
GDAL       : 3.6.2
GDAL data dir: /srv/conda/envs/notebook/share/gdal
PROJ       : 9.1.0
PROJ data dir: /srv/conda/envs/notebook/share/proj

PYTHON DEPENDENCIES
-------------------
geopandas  : 0.12.2
pandas     : 1.5.3
fiona      : 1.9.1
numpy      : 1.24.2
shapely    : 2.0.1
rtree      : 1.0.1
pyproj     : 3.4.1
matplotlib : 3.6.3
mapclassify: None
geopy      : 2.3.0
holoviews  : 1.15.4
hvplot     : 0.8.2
geoviews   : 1.9.6
stonesoup  : 0.1b11

ImportError: cannot import name 'Markup' from 'jinja2'

ImportError: cannot import name 'Markup' from 'jinja2'

Hi! I am using python 3.8.8 and installed the movingpandas using conda, but got the error when i am trying the osm-traces example. This error occurs when importing movingpandas.

Please help, thanks!

Plot not showing in jupyter

when i run this code:my_traj.hvplot(width=500, height=300, line_width=7.0, tiles='OSM'),jupyter cannot display output

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.