Giter VIP home page Giter VIP logo

pytisean's Introduction

pytisean

Python wrapper for calling functions supplied in the TISEAN package 1 for nonlinear time series analysis (http://www.mpipks-dresden.mpg.de/~tisean/).

[1]: R. Hegger, H. Kantz, and T. Schreiber, Practical implementation of nonlinear time series methods: The TISEAN package, CHAOS 9, 413 (1999). Preprint available: html, other.

Prerequisites

  • TISEAN must be installed and in your path - the code is not included here
  • This software has so far only been tested on OS X but should be easy to port to Linux/Windows. Suggestions are welcome!

How to use

To use this package first import pytisean, numpy and matplotlib:

from pytisean import tiseano, tiseanio
import matplotlib.pyplot as plt
import numpy as np

pytisean supplies two functions:

  1. tiseano for TISEAN functions that do not need an input file,
  2. tiseanio for functions that do need an input file.

Both return a result and the message that TISEAN prints to stdout or stderr.

For single output Tisean commands, stdout is an array. In case of Tisean commands generating multiple output, the stdout will be a dictionary with content grouped by their extensions as keywords, e.g. stdout from d2 is a dictionary with 3 keys, {"c2","d2","h2"}, standing for autocorrelation, correlation dimension, and entropy respectively.

NOTE Currently for multiple output tisean command, PyTisean only expects d2. If you have other multiple output commands need to be used with PyTisean, please inform us.

Examples:

# Generate 5000 iterates of the henon map
henon, msg = tiseano('henon', '-l5000')

# Plot and prettyfi
fig1, ax1 = plt.subplots(1, 1)
ax1.scatter(henon[:, 0], henon[:, 1], color='k', s=0.1)
ax1.set_title('The Henon map')
ax1.set_xlabel(r'$x$', fontsize=16)
ax1.set_ylabel(r'$y$', fontsize=16)
plt.show()

The Henon Map

# Generate some data
N = 1000
t = np.linspace(0, N/10*np.pi, N)
x = np.sin(t) + 0.2*np.random.randn(N)
#  ... and compute the autocorrelation
acf, msg = tiseanio('corr', '-D', 50, data=x)

# Plot and prettyfi
bluish = '#2976bb' # https://xkcd.com/color/rgb/
fig2, ax2 = plt.subplots(2, 1)

ax2[0].set_title(r'Data and autodorrelation')
ax2[0].plot(t, x, color=bluish)
ax2[0].set_xlim(t[0], t[-1])
ax2[0].set_xlabel(r'$t$', fontsize=16)
ax2[0].set_ylabel(r'$x$', fontsize=16)

ax2[1].plot(acf[:, 0], acf[:, 1], color=bluish)
ax2[1].set_xlabel(r'Lag $k$', fontsize=16)
ax2[1].set_ylabel(r'ACF $\rho_x(k)$', fontsize=16)

plt.show()

Data and autocorrelation

# generate Lorenz
stdout, msg = tiseano("lorenz", "-l", "2000")

# Multiple output command example (d2)
d2_out, msg = tiseanio("d2", '-N', '0','-c', "1", data=stdout)

# plot output c2
plt.scatter(d2_out["c2"][:,0], d2_out["c2"][:,1],s=0.1)
plt.yscale('log')
plt.ylim([1e-7,1])
plt.xscale('log')
plt.xlabel("length scale")
plt.ylabel("correlation sum")
plt.show()
# plot output d2
plt.scatter(d2_out["d2"][:,0], d2_out["d2"][:,1],s=0.1)
#plt.yscale('log')
plt.xscale('log')
plt.xlabel("length scale")
plt.ylabel("correlation dimension")
plt.show()
# plot output h2
plt.scatter(d2_out["h2"][:,0], d2_out["h2"][:,1],s=0.1)
#plt.yscale('log')
plt.xscale('log')
plt.xlabel("length scale")
plt.ylabel("correlation entropy")
plt.show()

Correlation Sum Correlation Dimension Correlation Entropy

TODO

  • Make sure output parser support all tisean commands
  • Add support for Windows

pytisean's People

Contributors

bogeholm avatar ron89 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

Watchers

 avatar  avatar  avatar

pytisean's Issues

Syntax error invalid in Python 2.7.12

In [2]: import pytisean
  File "pytisean/pytisean.py", line 98
    def tiseanio(command, *args, data=None, silent=False, legacy=True):
                                    ^
SyntaxError: invalid syntax

I installed my TISEAN on /home/shawnpan/bin , I also add this into my LD PATH, but the syntax error is really weird.

syntax error with tiseanio

I've downloaded pytisean to both windows and Linux versions of python. For some reason I'm getting a syntax error with the tiseanio function. I can't figure out why. (I developed my own python tisean wrapper two years ago which works fine and is an abbreviated version of yours. I can't see any programming error on your part.)

Proposal for multiple output handling

Hi bogeholm, nice wrapper~ It feels good to use tisean within python.

I am thinking of making it support multiple output commands. Here is a simple proposal: changing the output from

    [np.ndarray, msg]

into

    [dictionary={keyword:np.ndarray}, msg]

For single file output, keyword is simply out. For multiple files output, keyword would be the filetype. Since tisean wouldn't warn you about the command using multiple output. This handling need to be done command by command, so I intend to separate an output_parser() from function tiseanio and tiseano.

Now for legacy support, if needed (legacy=true by default for output_parser()), we can still retain command of single output to output [np.ndarray, msg] so that current user wouldn't be upset.

Your thoughts?

tiseanio is not catching seg faults from the child

This generates a segfault when the generated command is run in TISEAN, but it registers as a file output error when run in Python:
stps, _ = tiseanio("stp", '-d1', '-t400', '-%0.5', data=np.zeros(1000))
One hint is that subp.returncode always returns 0, even for the above command. I put some time into trying to solve this, but couldn't. I think it comes down to learning how to catch SIGSEGV or SIGCHLD as thrown by the shell.

Incorrect error message/error checking

Failure to feed TISEAN required arguments leads to impaired file creation (rather than any warning about arguments)

Example:

dat = np.random.uniform(0,1,100)
stps, _ = tiseanio("stp", '-d1', '-m2', '-t400', '-%0.5', data=dat)
stps, _ = tiseanio("stp", '-d1', '-t400', '-%0.5', data=dat)

./stp requires -d and -m, and so the second call should fail, but earlier and not this way:

FileNotFoundError: [Errno 2] No such file or directory: '/private/tmp/pytisean_temp_2018-05-07-13-28-21_16qrs5t3/outFile'

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.