-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
153 lines (137 loc) · 6.12 KB
/
main.py
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
__author__ = 'psilentp'
from numpy import array
from heka_io import HekaIO,gbi
from read_heka import *
from chaco.example_support import COLOR_PALETTE
from enable.example_support import DemoFrame, demo_main
# Enthought library imports
from enable.api import Window, Component, ComponentEditor
from traits.api import HasTraits, Instance
from enthought.traits.ui.api import Item, Group, View
# Chaco imports
from chaco.api import create_line_plot, add_default_axes,\
add_default_grids, OverlayPlotContainer, PlotLabel,\
create_scatter_plot, Legend
from chaco.tools.api import PanTool, ZoomTool, LegendTool,\
TraitsTool, DragZoom
from read_heka import *
#===============================================================================
# # Create the Chaco plot.
#===============================================================================
def _create_plot_component():
container = OverlayPlotContainer(padding = 50, fill_padding = True,
bgcolor = "lightgray", use_backbuffer=True)
fprefix = './test_data/CEN184/'
filename1 = fprefix + 'THL_2012-03-21_18-40-42_000.dat'
filename2 = fprefix + 'THL_2012-03-21_18-44-42_000.dat'
fprefix = './test_data/CEN111/'
filename3 = fprefix + 'THL_2011-07-09_15-02-54_000.dat'
ioreader = HekaIO(filename3)
#read a block
blo = ioreader.read_block(group = 2)
#protocol stuff
f = open(filename1)
head = BundleHeader(f)
head.load(f)
bi = head.oBundleItems[2]
pgf = PGFFile(f,bi)
value_mapper = None
index_mapper = None
plots = {}
firstplot = True
for seg in blo.segments:
#prococol building
for a_sig in seg.analogsignals:
x = array(a_sig.times)
y = array(a_sig)
ch = int(a_sig.annotations['trSourceChannel'])
plot = create_line_plot((x,y), width=0.5,color=tuple(COLOR_PALETTE[ch]))
plot.index.sort_order = "ascending"
plot.bgcolor = "white"
plot.border_visible = True
#code for protocols
print "###########################"
st_rec = pgf.tree['children'][a_sig.annotations['pgf_index']]['contents']
se_rec = pgf.tree['children'][a_sig.annotations['pgf_index']]['children'][0]['children'][1]['contents']
for key in ['stMark','stDataStartSegment','stDataStartTime']:
print key+ ' ' +str(st_rec.__dict__[key])
for key in ['seVoltageIncMode','seDuration','seDurationIncMode','seVoltage',]:
print key+' '+str(se_rec.__dict__[key])
for key in ['pgf_index','trTraceCount','trAdcChannel','trSourceChannel','swStimCount']:
print "%s:%s"%(key,a_sig.annotations[key])
#se_index = int(seg.annotations['seSeriesCount']) -1
#sw_index = int(a_sig.annotations['swSweepCount']) -1
#st_index = int(a_sig.annotations['swStimCount']) -1
#print pgf.tree['children'][se_index]['children'][st_index]['children'][1]['contents'].seVoltage
if not firstplot:
plot.value_mapper = value_mapper
value_mapper.range.add(plot.value)
plot.index_mapper = index_mapper
index_mapper.range.add(plot.index)
else:
value_mapper = plot.value_mapper
index_mapper = plot.index_mapper
add_default_grids(plot)
add_default_axes(plot)
plot.index_range.tight_bounds = False
plot.index_range.refresh()
plot.value_range.tight_bounds = False
plot.value_range.refresh()
plot.tools.append(PanTool(plot))
# The ZoomTool tool is stateful and allows drawing a zoom
# box to select a zoom region.
zoom = ZoomTool(plot, tool_mode="box", always_on=False)
plot.overlays.append(zoom)
# The DragZoom tool just zooms in and out as the user drags
# the mouse vertically.
dragzoom = DragZoom(plot, drag_button="right")
plot.tools.append(dragzoom)
# Add a legend in the upper right corner, and make it relocatable
legend = Legend(component=plot, padding=10, align="ur")
legend.tools.append(LegendTool(legend, drag_button="right"))
#print a_sig.annotations
plot.overlays.append(legend)
firstplot = False
container.add(plot)
plots["sweep %s"%a_sig.annotations['trLabel'][:4]] = plot
# Set the list of plots on the legend
legend.plots = plots
# Add the title at the top
container.overlays.append(PlotLabel(blo.annotations['grLabel'],
component=container,
font = "swiss 16",
overlay_position="top"))
# Add the traits inspector tool to the container
container.tools.append(TraitsTool(container))
return container
#===============================================================================
# Attributes to use for the plot view.
size=(800,700)
title="Simple Line Plot"
#===============================================================================
# # Demo class that is used by the demo.py application.
#===============================================================================
class Demo(HasTraits):
plot = Instance(Component)
traits_view = View(
Group(
Item('plot', editor=ComponentEditor(size=size),
show_label=False),
orientation = "vertical"),
resizable=True, title=title,
width=size[0], height=size[1]
)
def _plot_default(self):
return _create_plot_component()
demo = Demo()
#===============================================================================
# Stand-alone frame to display the plot.
#===============================================================================
class PlotFrame(DemoFrame):
def _create_window(self):
# Return a window containing our plots
return Window(self, -1, component=_create_plot_component())
if __name__ == "__main__":
demo_main(PlotFrame, size=size, title=title)
#gbi()
# EOF