Giter Site home page Giter Site logo

movingpandas / movingpandas-examples Goto Github PK

View Code? Open in Web Editor NEW
166.0 4.0 32.0 30.58 MB

Example notebooks illustrating MovingPandas use cases

Home Page: http://movingpandas.org

License: BSD 3-Clause "New" or "Revised" License

Jupyter Notebook 99.86% Shell 0.07% Dockerfile 0.07%
movingpandas pandas python geopandas

movingpandas-examples's Introduction

Welcome to the MovingPandas examples repository!

This repository contains Jupyter notebooks demonstrating MovingPandas features.

👉 Jump right in with Example 1: Getting Started

You can run the these notebooks on MyBinder - no installation required: Binder

Alternatively, if you prefer VS Code, you can run Github Codespaces: Open in GitHub Codespaces

The main MovingPandas repo is https://github.com/movingpandas/movingpandas

Visit movingpandas.org for details!

Installation

If you want to run these examples on your local machine, use the environment definition file (environment.yml) provided in this repository.

  1. Install Conda and mamba
  2. Clone the movingpandas-examples repository
  3. Navigate to the cloned directory
  4. Run mamba env create -f environment.yml

Post installation

  1. Activate the mpd-ex environment
  2. Launch Jupyter notebooks and navigate to the movingpandas-examples directory
  3. Now you can run the notebooks, experiment with the code and adjust it to your own data

Generating html exports using nbautoexport

First, you will need to install nbautoexport. Then register nbautoexport to run automatically while using Jupyter Notebook or Jupyter Lab:

  1. conda install nbautoexport --channel conda-forge
  2. nbautoexport install

Finally restart the Jupyter server.

movingpandas-examples's People

Contributors

anitagraser avatar raybellwaves avatar raybellwaves-dtn 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

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

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

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!

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.

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

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.

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

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.