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

Overview

ts2vg: Time series to visibility graphs

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 thanks to the use of NumPy and a custom C backend (via Cython) developed for the visibility algorithms.

The visibility graphs are provided according to the mathematical definitions described 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.

Basic usage

Visibility graph

Building visibility graphs from time series is very simple:

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 can be a list, a tuple, or a numpy 1D array.

Horizontal visibility graph

We can also obtain horizontal visibility graphs 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

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

Weighted visibility graph

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.

You might also like...
The Spectral Diagram (SD) is a new tool for the comparison of time series in the frequency domain
The Spectral Diagram (SD) is a new tool for the comparison of time series in the frequency domain

The Spectral Diagram (SD) is a new tool for the comparison of time series in the frequency domain. The SD provides a novel way to display the coherence function, power, amplitude, phase, and skill score of discrete frequencies of two time series. Each SD summarises these quantities in a single plot for multiple targeted frequencies.

The windML framework provides an easy-to-use access to wind data sources within the Python world, building upon numpy, scipy, sklearn, and matplotlib. Renewable Wind Energy, Forecasting, Prediction

windml Build status : The importance of wind in smart grids with a large number of renewable energy resources is increasing. With the growing infrastr

Kglab - an abstraction layer in Python for building knowledge graphs
Kglab - an abstraction layer in Python for building knowledge graphs

Graph Data Science: an abstraction layer in Python for building knowledge graphs, integrated with popular graph libraries – atop Pandas, RDFlib, pySHACL, RAPIDS, NetworkX, iGraph, PyVis, pslpython, pyarrow, etc.

Extensible, parallel implementations of t-SNE
Extensible, parallel implementations of t-SNE

openTSNE openTSNE is a modular Python implementation of t-Distributed Stochasitc Neighbor Embedding (t-SNE) [1], a popular dimensionality-reduction al

Extensible, parallel implementations of t-SNE
Extensible, parallel implementations of t-SNE

openTSNE openTSNE is a modular Python implementation of t-Distributed Stochasitc Neighbor Embedding (t-SNE) [1], a popular dimensionality-reduction al

Graphical display tools, to help students debug their class implementations in the Carcassonne family of projects

carcassonne_tools Graphical display tools, to help students debug their class implementations in the Carcassonne family of projects NOTE NOTE NOTE The

Draw interactive NetworkX graphs with Altair
Draw interactive NetworkX graphs with Altair

nx_altair Draw NetworkX graphs with Altair nx_altair offers a similar draw API to NetworkX but returns Altair Charts instead. If you'd like to contrib

Draw interactive NetworkX graphs with Altair
Draw interactive NetworkX graphs with Altair

nx_altair Draw NetworkX graphs with Altair nx_altair offers a similar draw API to NetworkX but returns Altair Charts instead. If you'd like to contrib

Generate graphs with NetworkX, natively visualize with D3.js and pywebview
Generate graphs with NetworkX, natively visualize with D3.js and pywebview

webview_d3 This is some PoC code to render graphs created with NetworkX natively using D3.js and pywebview. The main benifit of this approac

Comments
  • help getting started

    help getting started

    I am playing around with ts2vg and I am having a hard time with the plotting using igraph. I try to compute the natural vg for a short time series, but when trying to plot it I get this error:

    Traceback (most recent call last):
      File "\anaconda3\envs\DK_01\lib\site-packages\IPython\core\interactiveshell.py", line 3398, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-1-9a1fdcf342e8>", line 1, in <cell line: 1>
        ig.plot(nx_g, target='graph.pdf')
      File "\anaconda3\envs\DK_01\lib\site-packages\igraph\drawing\__init__.py", line 512, in plot
        result.save()
      File "\anaconda3\envs\DK_01\lib\site-packages\igraph\drawing\__init__.py", line 309, in save
        self._ctx.show_page()
    igraph.drawing.cairo.MemoryError: out of memory
    

    The file created is corrupted.

    Here is my code:

    import numpy as np
    from ts2vg import NaturalVG
    import igraph as ig
    
    import matplotlib.pyplot as plt
    
    # time domain
    t = np.linspace(1, 40)
    dt = np.diff(t)
    
    # build series
    x1 = np.sin(2*np.pi/10*t)
    x2 = np.sin(2*np.pi/15*t)
    
    y = x1 + x2
    
    plt.plot(t, y, '.-')
    plt.show()
    
    # build HVG
    g = NaturalVG()
    g.build(y)
    
    nx_g = g.as_igraph()
    
    # plotting
    ig.plot(nx_g, target='graph.pdf')
    

    I am using ts2vg 1.0.0, igraph 0.9.11, and pycairo 1.21.0

    opened by ACatAC 1
Releases(v1.0.0)
Statistics and Visualization of acceptance rate, main keyword of CVPR 2021 accepted papers for the main Computer Vision conference (CVPR)

Statistics and Visualization of acceptance rate, main keyword of CVPR 2021 accepted papers for the main Computer Vision conference (CVPR)

Hoseong Lee 78 Aug 23, 2022
A simple Monte Carlo simulation using Python and matplotlib library

Monte Carlo python simulation Install linux dependencies sudo apt update sudo apt install build-essential \ software-properties-commo

Samuel Terra 2 Dec 13, 2021
Create Badges with stats of Scratch User, Project and Studio. Use those badges in Github readmes, etc.

Scratch-Stats-Badge Create customized Badges with stats of Scratch User, Studio or Project. Use those badges in Github readmes, etc. Examples Document

Siddhesh Chavan 5 Aug 28, 2022
Displaying plot of death rates from past years in Poland. Data source from these years is in readme

Average-Death-Rate Displaying plot of death rates from past years in Poland The goal collect the data from a CSV file count the ADR (Average Death Rat

Oliwier Szymański 0 Sep 12, 2021
Rockstar - Makes you a Rockstar C++ Programmer in 2 minutes

Rockstar Rockstar is one amazing library, which will make you a Rockstar Programmer in just 2 minutes. In last decade, people learned C++ in 21 days.

4k Jan 05, 2023
Python & Julia port of codes in excellent R books

X4DS This repo is a collection of Python & Julia port of codes in the following excellent R books: An Introduction to Statistical Learning (ISLR) Stat

Gitony 5 Jun 21, 2022
Turn a STAC catalog into a dask-based xarray

StackSTAC Turn a list of STAC items into a 4D xarray DataArray (dims: time, band, y, x), including reprojection to a common grid. The array is a lazy

Gabe Joseph 148 Dec 19, 2022
Visualizing weather changes across the world using third party APIs and Python.

WEATHER FORECASTING ACROSS THE WORLD Overview Python scripts were created to visualize the weather for over 500 cities across the world at varying di

G Johnson 0 Jun 12, 2021
erdantic is a simple tool for drawing entity relationship diagrams (ERDs) for Python data model classes

erdantic is a simple tool for drawing entity relationship diagrams (ERDs) for Python data model classes. Diagrams are rendered using the venerable Graphviz library.

DrivenData 129 Jan 04, 2023
Graphical visualizer for spectralyze by Lauchmelder23

spectralyze visualizer Graphical visualizer for spectralyze by Lauchmelder23 Install Install matplotlib and ffmpeg. Put ffmpeg.exe in same folder as v

Matthew 1 Dec 21, 2021
Visualization of hidden layer activations of small multilayer perceptrons (MLPs)

MLP Hidden Layer Activation Visualization To gain some intuition about the internal representation of simple multi-layer perceptrons (MLPs) I trained

Andreas Köpf 7 Dec 30, 2022
Make sankey, alluvial and sankey bump plots in ggplot

The goal of ggsankey is to make beautiful sankey, alluvial and sankey bump plots in ggplot2

David Sjoberg 156 Jan 03, 2023
Flame Graphs visualize profiled code

Flame Graphs visualize profiled code

Brendan Gregg 14.1k Jan 03, 2023
An open-source tool for visual and modular block programing in python

PyFlow PyFlow is an open-source tool for modular visual programing in python ! Although for now the tool is in Beta and features are coming in bit by

1.1k Jan 06, 2023
Easily convert matplotlib plots from Python into interactive Leaflet web maps.

mplleaflet mplleaflet is a Python library that converts a matplotlib plot into a webpage containing a pannable, zoomable Leaflet map. It can also embe

Jacob Wasserman 502 Dec 28, 2022
Political elections, appointment, analysis and visualization in Python

Political elections, appointment, analysis and visualization in Python poli-sci-kit is a Python package for political science appointment and election

Andrew Tavis McAllister 9 Dec 01, 2022
Scientific Visualization: Python + Matplotlib

An open access book on scientific visualization using python and matplotlib

Nicolas P. Rougier 8.6k Dec 31, 2022
Automatically Visualize any dataset, any size with a single line of code. Created by Ram Seshadri. Collaborators Welcome. Permission Granted upon Request.

AutoViz Automatically Visualize any dataset, any size with a single line of code. AutoViz performs automatic visualization of any dataset with one lin

AutoViz and Auto_ViML 1k Jan 02, 2023
Runtime analysis of code with plotting

Runtime analysis of code with plotting A quick comparison among Python, Cython, and the C languages A Programming Assignment regarding the Programming

Cena Ashoori 2 Dec 24, 2021
Because trello only have payed options to generate a RunUp chart, this solves that!

Trello Runup Chart Generator The basic concept of the project is that Corello is pay-to-use and want to use Trello To-Do/Doing/Done automation with gi

Rômulo Schiavon 1 Dec 21, 2021