1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
.. _tutorial:
=========
Tutorial
=========
In this tutorial, we will demonstrate the basic use of nitime in initializing,
manipulating and analyzing a simple time-series object. For more advanced usage
see the examples section (:ref:`examples`)
In order to get started, import :mod:`nitime.timeseries`:
.. code-block:: python
In [1]: import nitime.timeseries as ts
Then, you can initialize a simple time-series object, by providing data and
some information about the sampling-rate or sampling-interval:
.. code-block:: python
In [2]: t1 = ts.TimeSeries([[1,2,3],[3,6,8]],sampling_rate=0.5)
If you tab-complete, you will see that the object now has several different
attributes:
.. code-block:: python
In [3]: t1.
t1.at t1.metadata t1.time
t1.data t1.sampling_interval t1.time_unit
t1.duration t1.sampling_rate
t1.from_time_and_data t1.t0
Note that the sampling_interval is the inverse of the sampling_rate:
.. code-block:: python
In [4]: t1.sampling_interval
Out[4]: 2.0 s
In addition, the sampling rate is now represented with the units in Hz:
.. code-block:: python
In [5]: t1.sampling_rate
Out[5]: 0.5 Hz
Also - once this object is available to you, you have access to the underlying
representation of time:
.. code-block:: python
In [6]: t1.time
Out[6]: UniformTime([ 0., 2., 4.], time_unit='s')
Now import the analysis library:
.. code-block:: python
In [7]: import nitime.analysis as nta
and initialize an analyzer for correlation analysis:
.. code-block:: python
In [8]: c = nta.CorrelationAnalyzer(t1)
The simplest use of this analyzer (and also the default output) is to compute
the correlation coefficient matrix of the data in the different rows of the
time-series:
.. code-block:: python
In [9]: c.corrcoef
Out[9]:
array([[ 1. , 0.99339927],
[ 0.99339927, 1. ]])
but it can also be used in order to generate the cross-correlation function
between the channels, which is also a time-series object:
.. code-block:: python
In [63]: x = c.xcorr
In [64]: x.time
Out[64]: UniformTime([-6., -4., -2., 0., 2.], time_unit='s')
In [65]: x.data
Out[65]:
array([[[ 3., 8., 14., 8., 3.],
[ 8., 22., 39., 24., 9.]],
[[ 8., 22., 39., 24., 9.],
[ 24., 66., 109., 66., 24.]]])
|