File: event_amplitude.py

package info (click to toggle)
nipy 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,352 kB
  • sloc: python: 39,115; ansic: 30,931; makefile: 210; sh: 93
file content (34 lines) | stat: -rw-r--r-- 933 bytes parent folder | download
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
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
import numpy as np
import pylab

from nipy.modalities.fmri.hrf import glover
from nipy.modalities.fmri.utils import Symbol, events, lambdify_t

# Symbol for amplitude
a = Symbol('a')

# Some event onsets regularly spaced
onsets = np.linspace(0,50,6)

# Make amplitudes from onset times (greater as function of time)
amplitudes = onsets[:]

# Flip even numbered amplitudes
amplitudes = amplitudes * ([-1, 1] * 3)

# Make event functions
evs = events(onsets, amplitudes=amplitudes, g=a + 0.5 * a**2, f=glover)

# Real valued function for symbolic events
real_evs = lambdify_t(evs)

# Time points at which to sample
t_samples = np.linspace(0,60,601)

pylab.plot(t_samples, real_evs(t_samples), c='r')
for onset, amplitude in zip(onsets, amplitudes):
    pylab.plot([onset, onset],[0, 25 * amplitude], c='b')

pylab.show()