|
|
|
|
Span is a Python-driven toolkit for spectral analysis. Data can be loaded from and saved to ASCII files. Span supports the generation of synthetic data by an autoregressive model. Spectral estimation is based on covariance estimates. Alternatively, parametric estimation with maximum likelihood parameters is available. For visualization and printing, span uses the Python version of Gnuplot.
The span package consists of a Python class, implemented in spanVar.py and a shared object library. The Python class contains a constructor to create span variables. These provide access to the methods for spectral estimation. The methods of this class use Fortran routines, which are compiled into the shared object library.
To build the shared object library you need a C and a FORTRAN compiler. gcc with g77 is fine. Other combinations have not been tested yet.
Span uses the NumPtr package to interface between Numeric arrays and the Fortran library. NumPtr is distributed with span and will be built and installed automatically.
The Python interface to the shared object library has been built with Swig and Swift. However, to install and use span you don't need them. The interfaces are included in the distribution.
Span makes use of the Numeric package and the Gnuplot package. Span works without Gnuplot, but plotting and printing is not available in this case.
Span has been tested on Mac OS X/Darwin with Python 2.2 and Python 2.3 and on Debian Linux with Python 2.2 and Python 2.3.
Download the latest version of span and unpack it
There is no setup.py script yet. Installation needs to be done manually, using a Makefile. To install the span package, go to the ./src directory and type make
> tar xf span-0.7.tar
This should build the shared object library. To install span in the default location and then clean up the ./src directory, type
> make
If you want to install span in your home directory for example, provide the prefix, where the package is to be installed
> make clean
If the installation process was successful, span should be ready to use now. To test the span package, type
which performs testing of the docstrings in the Python files and executes the unit tests in spanUnit.py. Start the Python interpreter, import the span module and type help(span) to get started
A html version of the documentation is included in the ./doc directory. These files contain relative paths, which work as long as the directory structure is unchanged. If you like to put the html documentation somewhere else, you can create a new html version of the docstrings, including absolute paths. After span is installed, run
>>> import span
>>> help(span)
to generate html-files of the installed span package.
To get used to span, there is demo script in the ./lib directory. To run the demo #1, type
To run all the demos, type
Documentation for the span package is included in the Python files. From the interpreter it is accessed via the help() function
or from the command line, using the --help switch
>>> help(span)
Browse the detailed html documentation or read the overview of the span package. The overview is reproduced below.
Span is designed as an easy-to-use toolbox for spectral analysis of one-dimensional time series. The package supports univariate and multivariate time series analysis.
The basic entity of the span package is the span variable. Such a variable is basically a Numeric array which holds the data. Time series, covariance functions, spectral densities, maximum likelihood parameters are all span variables.
Additional data attributes keep track of the methods applied to the span variable. The spectrum, computed from the covariance function of a time series for example, knows that it is a spectrum. It also knows the sampling interval of the time series, the number of lags in the covariance estimate, its degree of freedom and the bandwidth.
Span variables have access to all methods of the class and most methods return span variables. So, it is straightforward to use the result of a previous computation as input to the next one.
To create an initial span variable the constructor of the class accepts a wide variety of input. Span variables containing synthetic or real data can be created from single numbers, tuples, lists, Numeric arrays, span variables and files. Special constructors provide easy means to generate commonly used time series, like white noise, autoregressive processes and data from ASCII files.
To generate a normally distributed series of white noise and save the data to an ASCII file, use
To estimate and plot the power spectral density and its confidence limits of data from an ASCII file, use
>>> y = span.normal(100)
>>> y.dump('foo.asc')
To create an autoregressive process, estimate its maximum likelihood parameters with confidence limits and dump the parameters to an ASCII file, use
>>> cvf = y.ccvf()
>>> psd = cvf.epsd()
>>> [lpsd, upsd] = psd.confidence()
>>> psd.plot(); lpsd.replot(); upsd.replot()
To estimate and visualize the spectral response functions of a bivariate process and save the plot to a postscript file, use
>>> par = y.arm()
>>> [lpar, upar] = par.confidence(y)
>>> par.dump('foo.asc')
>>> cvf = y.ccvf()
>>> [copsd, qupsd] = cvf.cpsd()
>>> [cohsq, phase] = copsd.transfer(qupsd)
>>> [gain, resid] = cohsq.response(copsd)
>>> [lgain, ugain] = gain.confidence(cohsq)
>>> gain.plot(num=3); lgain.replot(num=3); ugain.replot(num=3)
>>> gain.hardcopy('foo.ps')
The algorithms used in span are based on
Gwilym M. Jenkins and Donald G. Watts
Holden-Day, San Francisco, 1968
Numerical Recipes in FORTRAN
W. H. Press, S. A. Teukolsky, W. T. Vetterling, and B. P. Flannery
Cambridge University Press, 1992, 2nd edition
span - Spectral Analysis Toolkit
Copyright (C) 2004, 2005 Christian Dieterich
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA