Skip to main content

Build visibility graphs from time series data.

Project description

pypi pyversions wheel license

Example plot of a visibility graph


The Python ts2vg package provides high-performance algorithm implementations to build visibility graphs from time series data.

The visibility graphs and some of their properties (e.g. degree distributions) are computed quickly and efficiently even for time series with millions of observations.

The visibility graphs are provided according to the mathematical definitions presented in:

  • Lucas Lacasa et al., “From time series to complex networks: The visibility graph”, 2008.

  • Lucas Lacasa et al., “Horizontal visibility graphs: exact results for random time series”, 2009.

An efficient divide-and-conquer algorithm is used to compute the graphs, as described in:

  • Xin Lan et al., “Fast transformation from time series to visibility graphs”, 2015.

Installation

The latest released ts2vg version is available at the Python Package Index (PyPI) and can be easily installed by running:

pip install ts2vg

For other advanced uses, to build ts2vg from source Cython is required.

Supported graph types

Root graph types

  • Natural Visibility Graphs (NVG) (ts2vg.NaturalVG)

  • Horizontal Visibility Graphs (HVG) (ts2vg.HorizontalVG)

Available variations

  • Weighted Visibility Graphs (via the weighted parameter)

  • Directed Visibility Graphs (via the directed parameter)

  • Parametric Visibility Graphs (via the min_weight and max_weight parameters)

  • Limited Penetrable Visibility Graphs (LPVG) (via the penetrable_limit parameter)

Note that multiple graph variations can be combined and used simultaneously.

Basic usage

Visibility graph

To build a visibility graph:

from ts2vg import NaturalVG

ts = [1.0, 0.5, 0.3, 0.7, 1.0, 0.5, 0.3, 0.8]

g = NaturalVG()
g.build(ts)

edges = g.edges

The time series passed (ts) can be any one-dimensional iterable, such as a list or a numpy 1D array.

By default, the input observations are assumed to be equally spaced in time. Alternatively, a second 1D iterable (xs) can be provided for unevenly spaced time series.

Horizontal visibility graph

Horizontal visibility graphs can be obtained in a very similar way:

from ts2vg import HorizontalVG

ts = [1.0, 0.5, 0.3, 0.7, 1.0, 0.5, 0.3, 0.8]

g = HorizontalVG()
g.build(ts)

edges = g.edges

Degree distribution

If we are only interested in the degree distribution of the visibility graph we can pass only_degrees=True to the build method. This will be more efficient in time and memory than computing the whole graph.

g = NaturalVG()
g.build(ts, only_degrees=True)

ks, ps = g.degree_distribution

Directed visibility graph

Directed graphs can be obtained by using the directed parameter. See the reference documentation for the different available options.

g = NaturalVG(directed='left_to_right')
g.build(ts)

Weighted visibility graph

Weighted graphs can be obtained by using the weighted parameter. See the reference documentation for the different available options.

g = NaturalVG(weighted='distance')
g.build(ts)

For more information and options see: Examples and API Reference.

Interoperability with other libraries

The graphs obtained can be easily converted to graph objects from other common Python graph libraries such as igraph, NetworkX and SNAP for further analysis.

The following methods are provided:

  • as_igraph()

  • as_networkx()

  • as_snap()

For example:

g = NaturalVG()
g.build(ts)

nx_g = g.as_networkx()

Command line interface

ts2vg can also be used as a command line program directly from the console:

ts2vg ./timeseries.txt -o out.edg

For more help and a list of options run:

ts2vg --help

Contributing

ts2vg can be found on GitHub. Pull requests and issue reports are welcome.

License

ts2vg is licensed under the terms of the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ts2vg-1.2.0.tar.gz (637.8 kB view hashes)

Uploaded Source

Built Distributions

ts2vg-1.2.0-pp37-pypy37_pp73-win_amd64.whl (302.6 kB view hashes)

Uploaded PyPy Windows x86-64

ts2vg-1.2.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (384.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

ts2vg-1.2.0-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (395.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ts2vg-1.2.0-cp311-cp311-win_amd64.whl (329.9 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

ts2vg-1.2.0-cp311-cp311-win32.whl (284.7 kB view hashes)

Uploaded CPython 3.11 Windows x86

ts2vg-1.2.0-cp311-cp311-musllinux_1_1_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

ts2vg-1.2.0-cp311-cp311-musllinux_1_1_i686.whl (2.0 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

ts2vg-1.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ts2vg-1.2.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ts2vg-1.2.0-cp311-cp311-macosx_10_9_x86_64.whl (394.0 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ts2vg-1.2.0-cp310-cp310-win_amd64.whl (334.2 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

ts2vg-1.2.0-cp310-cp310-win32.whl (288.1 kB view hashes)

Uploaded CPython 3.10 Windows x86

ts2vg-1.2.0-cp310-cp310-musllinux_1_1_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

ts2vg-1.2.0-cp310-cp310-musllinux_1_1_i686.whl (2.0 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

ts2vg-1.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ts2vg-1.2.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ts2vg-1.2.0-cp39-cp39-win_amd64.whl (340.3 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

ts2vg-1.2.0-cp39-cp39-win32.whl (293.1 kB view hashes)

Uploaded CPython 3.9 Windows x86

ts2vg-1.2.0-cp39-cp39-musllinux_1_1_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

ts2vg-1.2.0-cp39-cp39-musllinux_1_1_i686.whl (2.1 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

ts2vg-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ts2vg-1.2.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ts2vg-1.2.0-cp39-cp39-macosx_10_9_x86_64.whl (403.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

ts2vg-1.2.0-cp38-cp38-win_amd64.whl (339.8 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

ts2vg-1.2.0-cp38-cp38-win32.whl (292.8 kB view hashes)

Uploaded CPython 3.8 Windows x86

ts2vg-1.2.0-cp38-cp38-musllinux_1_1_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

ts2vg-1.2.0-cp38-cp38-musllinux_1_1_i686.whl (2.1 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ i686

ts2vg-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

ts2vg-1.2.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ts2vg-1.2.0-cp38-cp38-macosx_10_9_x86_64.whl (392.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

ts2vg-1.2.0-cp37-cp37m-win_amd64.whl (334.2 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

ts2vg-1.2.0-cp37-cp37m-win32.whl (286.5 kB view hashes)

Uploaded CPython 3.7m Windows x86

ts2vg-1.2.0-cp37-cp37m-musllinux_1_1_x86_64.whl (2.0 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

ts2vg-1.2.0-cp37-cp37m-musllinux_1_1_i686.whl (1.9 MB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ i686

ts2vg-1.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

ts2vg-1.2.0-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.9 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ts2vg-1.2.0-cp37-cp37m-macosx_10_9_x86_64.whl (395.0 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

ts2vg-1.2.0-cp36-cp36m-win_amd64.whl (385.5 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

ts2vg-1.2.0-cp36-cp36m-win32.whl (316.1 kB view hashes)

Uploaded CPython 3.6m Windows x86

ts2vg-1.2.0-cp36-cp36m-musllinux_1_1_x86_64.whl (2.0 MB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ x86-64

ts2vg-1.2.0-cp36-cp36m-musllinux_1_1_i686.whl (1.9 MB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ i686

ts2vg-1.2.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

ts2vg-1.2.0-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.9 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ts2vg-1.2.0-cp36-cp36m-macosx_10_9_x86_64.whl (392.2 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page