Skip to content

Commit

Permalink
ENH: Rework visualization module (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
bifbof authored Aug 17, 2023
1 parent 9f1b15a commit 11c36f3
Show file tree
Hide file tree
Showing 31 changed files with 808 additions and 1,050 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pfs, tpls = pfs.as_positionfixes.generate_triplegs(sp, method='between_staypoint
**[3.]** Visualization.
```python
# plot the generated tripleg result
tpls.as_triplegs.plot(positionfixes=pfs, staypoints=sp, staypoints_radius=10)
ti.plot(positionfixes=pfs, staypoints=sp, triplegs=tpls, radius_sp=10)
```

**[4.]** Analysis.
Expand Down
34 changes: 3 additions & 31 deletions docs/modules/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,19 @@ Visualization
The visualization module provides a variety of functions to visualize initial,
intermediate and final datasets within trackintel.

Positionfixes
plot
=============

.. autofunction:: trackintel.visualization.positionfixes.plot_positionfixes

.. image:: /_static/example_positionfixes.png
:scale: 25 %
:align: center

Staypoints
==========

.. autofunction:: trackintel.visualization.staypoints.plot_staypoints

.. image:: /_static/example_staypoints.png
:scale: 25 %
:align: center

Triplegs
========

.. autofunction:: trackintel.visualization.triplegs.plot_triplegs

.. image:: /_static/example_triplegs.png
:scale: 25 %
:align: center

Locations
=========

.. autofunction:: trackintel.visualization.locations.plot_locations
.. autofunction:: trackintel.visualization.plot

.. image:: /_static/example_locations.png
:scale: 25 %
:align: center


Modal split
===========

.. autofunction:: trackintel.visualization.modal_split.plot_modal_split
.. autofunction:: trackintel.visualization.plot_modal_split

.. image:: /_static/example_modal_split_geolife.png
:scale: 18 %
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ connection string with your proper username and password.

We now can for example plot the positionfixes::

pfs.as_positionfixes.plot('positionfixes.png')
ti.plot(positionfixes=pfs, filename="positionfixes.png")

Of course, we can start our analysis, for example by detecting staypoints (aggregated positionfixes
where the user stayed for a certain amount of time)::

_, locs = pfs.as_positionfixes.generate_staypoints(method='sliding')
sp.as_staypoints.plot(out_filename='staypoints.png', radius=10, positionfixes=pfs, plot_osm=True)
_, sp = pfs.as_positionfixes.generate_staypoints(method='sliding')
ti.plot(filename="staypoints.png", radius_sp=10, staypoints=sp, positionfixes=pfs, plot_osm=True)

This will additionally plot the original positionfixes, as well as the underlying
street network from OSM. We can for example continue by extracting and plotting locations
(locations that "contain" multiple staypoints, i.e., are visited often by a user)::

_, locs = sp.as_staypoints.generate_locations(method='dbscan', epsilon=100, num_samples=1)
locs.as_locations.plot(out_filename='locations.png', radius=125, positionfixes=pfs,
staypoints=sp, staypoints_radius=100, plot_osm=True)
ti.plot(filename="locations.png", locations=locs, radius_locs=125, positionfixes=pfs,
staypoints=sp, radius_sp=100, plot_osm=True)
This will extract locations and plot them to a file called ``locations.png``, additionally
plotting the original positionfixes and staypoints, as well as the street network.
Expand Down
52 changes: 25 additions & 27 deletions examples/Trackintel case study.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/import_export_postgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

# Geolife trajectory from PostGIS.
# pfs = ti.io.read_positionfixes_postgis('positionfixes', conn_string)
pfs.as_positionfixes.plot()
ti.plot(positionfixes=pfs)
49 changes: 33 additions & 16 deletions examples/preprocess_trajectories.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,66 @@

# GPS trajectory.
pfs = ti.read_positionfixes_csv("examples/data/geolife_trajectory.csv", sep=";", crs="EPSG:4326", index_col=None)
pfs.as_positionfixes.plot(out_filename="examples/out/gps_trajectory_positionfixes.png", plot_osm=True)
ti.plot(filename="examples/out/gps_trajectory_positionfixes.png", positionfixes=pfs, plot_osm=True)

_, sp = pfs.as_positionfixes.generate_staypoints(method="sliding", dist_threshold=100, time_threshold=5)
sp.as_staypoints.plot(
out_filename="examples/out/gps_trajectory_staypoints.png", radius=100, positionfixes=pfs, plot_osm=True
ti.plot(
filename="examples/out/gps_trajectory_staypoints.png",
staypoints=sp,
radius_sp=100,
positionfixes=pfs,
plot_osm=True,
)

_, locs = sp.as_staypoints.generate_locations(method="dbscan", epsilon=100, num_samples=3)
locs.as_locations.plot(
out_filename="examples/out/gps_trajectory_locations.png",
radius=120,
ti.plot(
filename="examples/out/gps_trajectory_locations.png",
locations=locs,
radius_locs=120,
positionfixes=pfs,
staypoints=sp,
staypoints_radius=100,
radius_sp=100,
plot_osm=True,
)

_, tpls = pfs.as_positionfixes.generate_triplegs(staypoints=sp)
tpls.as_triplegs.plot(
out_filename="examples/out/gpsies_trajectory_triplegs.png", staypoints=sp, staypoints_radius=100, plot_osm=True
ti.plot(
filename="examples/out/gpsies_trajectory_triplegs.png", triplegs=tpls, staypoints=sp, radius_sp=100, plot_osm=True
)

# Geolife trajectory.
pfs = ti.read_positionfixes_csv("examples/data/geolife_trajectory.csv", sep=";", crs="EPSG:4326", index_col=None)
pfs.as_positionfixes.plot(out_filename="examples/out/geolife_trajectory_positionfixes.png", plot_osm=False)
ti.plot(filename="examples/out/geolife_trajectory_positionfixes.png", positionfixes=pfs)

_, sp = pfs.as_positionfixes.generate_staypoints(method="sliding", dist_threshold=100, time_threshold=10)
sp.as_staypoints.plot(
out_filename="examples/out/geolife_trajectory_staypoints.png", radius=100, positionfixes=pfs, plot_osm=True
ti.plot(
filename="examples/out/geolife_trajectory_staypoints.png",
staypoints=sp,
radius_sp=100,
positionfixes=pfs,
plot_osm=True,
)

# Google trajectory.
pfs = ti.read_positionfixes_csv("examples/data/google_trajectory.csv", sep=";", crs="EPSG:4326", index_col=None)
_, sp = pfs.as_positionfixes.generate_staypoints(method="sliding", dist_threshold=75, time_threshold=10)
sp.as_staypoints.plot(
out_filename="examples/out/google_trajectory_staypoints.png", radius=75, positionfixes=pfs, plot_osm=True
ti.plot(
filename="examples/out/google_trajectory_staypoints.png",
staypoints=sp,
radius_sp=75,
positionfixes=pfs,
plot_osm=True,
)

# Posmo trajectory.
pfs = ti.read_positionfixes_csv(
"examples/data/posmo_trajectory.csv", sep=";", crs="EPSG:4326", index_col=None, tz="UTC"
)
_, sp = pfs.as_positionfixes.generate_staypoints(method="sliding", dist_threshold=50, time_threshold=1)
sp.as_staypoints.plot(
out_filename="examples/out/posmo_trajectory_staypoints.png", radius=50, positionfixes=pfs, plot_osm=False
ti.plot(
filename="examples/out/posmo_trajectory_staypoints.png",
staypoints=sp,
radius_sp=50,
positionfixes=pfs,
plot_osm=False,
)
Loading

0 comments on commit 11c36f3

Please sign in to comment.