Menu

[r3311]: / trunk / htdocs / screenshots / mri_with_eeg.py  Maximize  Restore  History

Download this file

97 lines (74 with data), 2.6 kB

 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
#!/usr/bin/env python
"""
This now uses the imshow command instead of pcolor which *is much
faster*
"""
from __future__ import division
from pylab import *
from matplotlib.lines import Line2D
from matplotlib.transforms import get_bbox_transform, Point, Value, Bbox,\
unit_bbox
# I use if 1 to break up the different regions of code visually
if 1: # load the data
# data are 256x256 16 bit integers
dfile = 'data/s1045.ima'
im = fromstring(file(dfile, 'rb').read(), UInt16).astype(Float)
im.shape = 256, 256
if 1: # plot the MRI in pcolor
subplot(221)
imshow(im)
axis('off')
if 1: # plot the histogram of MRI intensity
subplot(222)
im = ravel(im)
im = take(im, nonzero(im)) # ignore the background
im = im/(2.0**15) # normalize
hist(im, 100)
xticks([])
yticks([])
xlabel('intensity')
ylabel('MRI density')
if 1: # plot the EEG
# load the data
numSamples, numRows = 800,4
data = fromstring(file('data/eeg.dat', 'rb').read(), Float)
data.shape = numSamples, numRows
t = arange(numSamples)/float(numSamples)*10.0
ticklocs = []
ax = subplot(212)
boxin = Bbox(
Point(ax.viewLim.ll().x(), Value(-20)),
Point(ax.viewLim.ur().x(), Value(20)))
height = ax.bbox.ur().y() - ax.bbox.ll().y()
boxout = Bbox(
Point(ax.bbox.ll().x(), Value(-1)*height),
Point(ax.bbox.ur().x(), Value(1) * height))
transOffset = get_bbox_transform(
unit_bbox(),
Bbox( Point( Value(0), ax.bbox.ll().y()),
Point( Value(1), ax.bbox.ur().y())
))
for i in range(numRows):
# effectively a copy of transData
trans = get_bbox_transform(boxin, boxout)
offset = (i+1)/(numRows+1)
trans.set_offset( (0, offset), transOffset)
thisLine = Line2D(
t, data[:,i]-data[0,i],
)
thisLine.set_transform(trans)
ax.add_line(thisLine)
ticklocs.append(offset)
xlim(0,10)
xticks(arange(10))
yticks(ticklocs, ['PG3', 'PG5', 'PG7', 'PG9'])
# set the yticks to use axes coords on the y axis
ax.set_yticks(ticklocs)
for tick in ax.yaxis.get_major_ticks():
tick.label1.set_transform(ax.transAxes)
tick.label2.set_transform(ax.transAxes)
tick.tick1line.set_transform(ax.transAxes)
tick.tick2line.set_transform(ax.transAxes)
tick.gridline.set_transform(ax.transAxes)
xlabel('time (s)')
show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.