ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/vu_module.py
(Generate patch)
# Line 1 | Line 1
1   """
2 < vu: Viewer module for SPRI data in a ba class.
3 < This uses the old Tk GUI toolkit.
4 < Christopher Lausted, Institute for Systems Biology,
5 < OSPRAI developers
6 < Last modified on 100416 (yymmdd)
7 <
8 < Example:
9 < #import vu_module as vu
10 < #io_module as io
11 < #ba1 = io.readsprit("spritdata.txt")
12 < #vu.dotgraph(ba1, "Title")
13 < #vu.linegraph(ba1, "Title")
14 < #vu.dualgraph(ba1, ba2, "Title")
15 < #vu.scatterplot(ba1, t1, t2, t3, t4, title)
2 > vu_module
3 > ---------
4 >
5 > This is the viewer module for SPR data in a ba_class.
6 > Traces can be displayed as dotted lines, continuous lines, or combinations.
7 > Typically, up to six traces are displayed at a time.
8 > Features include zooming, measurements, and save-to-PNG.
9 > Graphics utilize the old Tk GUI toolkit.
10 >
11 > .. moduleauthor:: Christopher Lausted,
12 >                  Institute for Systems Biology,
13 >                  OSPRAI developers.
14 > Examples::
15 >
16 >  >>> import vu_module as vu
17 >  >>> import io_module as io
18 >  >>> ba1 = io.readsprit("spritdata.txt")
19 >  >>> vu.dotgraph(ba1, "Title")
20 >  >>> vu.linegraph(ba1, "Title")
21 >  >>> vu.dualgraph(ba1, ba2, "Title")
22 >  >>> vu.scatterplot(ba1, t1, t2, t3, t4, title)
23   """
24 < __version__ = "100416"
24 > __version__ = "110202"
25  
26  
27   ## Import libraries
# Line 30 | Line 37
37  
38  
39   def linegraph(baLine, title=""):
40 <    """Graph data of baLine using lines."""
40 >    """
41 >    Display signal vs time using continuous lines.
42 >    
43 >    :param baLine: Object containing the data.
44 >    :type baLine: ba_class
45 >    :param title: Title to place above the graph.
46 >    :type title: str
47 >    :returns: nothing
48 >    """
49      global root, fig, ax, canvas  ## Tk/mpl globals.
50 <    global ba0, ba1, ba2   ## Ref to ba for roilist, dotgraph, linegraph
50 >    global ba0, ba1, ba2   ## Ref to ba for __roiList, dotgraph, linegraph
51      global gTitle          ## Title for graph.
52      ba0, ba1, ba2 = baLine, 0, baLine
53      gTitle = title
54 <    createSensorgramTkWindow()
55 <    show()
54 >    __createSensorgramTkWindow()
55 >    __show()
56      root.mainloop()
57      return
58 <    ## End of linegraph().
58 >    """
59 >    How does linegraph() work?  It sets some global values, then calls __show().
60 >    """
61      
62   def dotgraph(baDot, title=""):
63 <    """Graph data of baDot using dots."""
63 >    """
64 >    Display signal vs time using dotted lines.
65 >    
66 >    :param baDot: Object containing the data.
67 >    :type baDot: ba_class
68 >    :param title: Title to place above the graph.
69 >    :type title: str
70 >    :returns: nothing
71 >    """
72      global root, fig, ax, canvas  ## Tk/mpl globals..
73 <    global ba0, ba1, ba2   ## Ref to ba for roilist, dotgraph, linegraph
73 >    global ba0, ba1, ba2   ## Ref to ba for __roiList, dotgraph, linegraph
74      global gTitle          ## Title for graph.
75      ba0, ba1, ba2 = baDot, baDot, 0
76      gTitle = title
77 <    createSensorgramTkWindow()
78 <    show()
77 >    __createSensorgramTkWindow()
78 >    __show()
79      root.mainloop()
80      return
81      ## End of dotgraph().
82 +    """
83 +    How does dotgraph() work?  It sets some global values, then calls __show().
84 +    """
85      
86   def dualgraph(baDot, baLine, title=""):
87 <    """Graph data using dots and lines."""
87 >    """
88 >    Display signal vs time using dotted AND continuous lines.
89 >    
90 >    :param baDot: Object containing the dotted-line data.
91 >    :type baDot: ba_class
92 >    :param baLine: Object containing the continuous-line data.
93 >    :type baLine: ba_class
94 >    :param title: Title to place above the graph.
95 >    :type title: str
96 >    :returns: nothing
97 >    """
98      global root, fig, ax, canvas  ## Tk/mpl globals.
99 <    global ba0, ba1, ba2   ## Ref to ba for roilist, dotgraph, linegraph
99 >    global ba0, ba1, ba2   ## Ref to ba for __roiList, dotgraph, linegraph
100      global gTitle          ## Title for graph.
101      ba0, ba1, ba2 = baDot, baDot, baLine
102      gTitle = title
103 <    createSensorgramTkWindow()
104 <    show()
103 >    __createSensorgramTkWindow()
104 >    __show()
105      root.mainloop()
106      return
107 <    ## End of dualgraph().
107 >    """
108 >    How does dualgraph() work?  It sets some global values, then calls __show().
109 >    """
110  
111 < def show():
112 <    """Graph data of ba using Tk window."""
111 > def __show():
112 >    """
113 >    Graph data of ba using Tk window.
114 >    """
115      global root, fig, ax, canvas
116      global ba1, ba2
117      global gTitle
# Line 86 | Line 128
128      if (ba1 != 0):
129          ## Dotted traces.
130          marker = ['r,', 'g,', 'b,', 'c,', 'm,', 'y,'] + ['k,'] * 100
131 <        for i,j in enumerate(roiList()):
131 >        for i,j in enumerate(__roiList()):
132              txt = str(j) + ':' + ba1.roi[j].name
133              t = ba1.roi[j].time
134              y = ba1.roi[j].value
# Line 94 | Line 136
136      if (ba2 != 0):
137          ## Line traces.
138          marker = ['r', 'g', 'b', 'c', 'm', 'y'] + ['k'] * 100
139 <        for i,j in enumerate(roiList()):
139 >        for i,j in enumerate(__roiList()):
140              txt = str(j) + ':' + ba2.roi[j].name
141              t = ba2.roi[j].time
142              y = ba2.roi[j].value
# Line 109 | Line 151
151      
152      canvas.draw()
153      return
154 <    ## End of show().
154 >    """
155 >    End of __show().
156 >    """
157      
158 < def btnNext():  
159 <    ## Show next six traces on the graph.
158 > def __btnNext():  
159 >    """
160 >    Show next six traces on the graph.
161 >    """
162      global ba0
163 <    lo = max(roiList()) + 1
163 >    lo = max(__roiList()) + 1
164      if (lo == len(ba0.roi)): return
165      lo = max(lo,0)
166      hi = lo + 6
167      hi = min(hi, len(ba0.roi))
168      ba0.set_plot_list(range(lo, hi))
169 <    show()
169 >    __show()
170      return
171      
172 < def btnPrev():
173 <    ## Show the previous six traces on the graph.
172 > def __btnPrev():
173 >    """
174 >    Show the previous six traces on the graph.
175 >    """
176      global ba0
177 <    lo = min(roiList()) - 6
177 >    lo = min(__roiList()) - 6
178      lo = max(lo,0)
179      hi = lo + 6
180      hi = min(hi, len(ba0.roi))
181      ba0.set_plot_list(range(lo, hi))
182 <    show()
182 >    __show()
183      return
184  
185 < def btnTraces():
186 <    ## Ask for list of traces to show on graph.
185 > def __btnTraces():
186 >    """
187 >    Ask for list of traces to show on graph.
188 >    """
189      global ba0
190      txt = "Which ROIs would you like to see? (e.g. 19,20,21)"
191      txt = dialog.askstring(title="Input",prompt=txt)
192      txt = txt + ","  ## Be sure eval() produces a list.
193      ba0.set_plot_list(eval(txt))
194 <    show()
194 >    __show()
195      return
196  
197  
198 < def roiList():
199 <    ## List of first six plottable ROIs.
198 > def __roiList():
199 >    """
200 >    List of first six plottable ROIs.
201 >    """
202      global ba0
203      #x = [i for i in range(len(ba.roi)) if ba0.roi[i].plottable]
204      x = [i.index for i in ba0.roi if i.plottable]
205      return x[:6]
206  
207  
208 < def createSensorgramTkWindow():
208 > def __createSensorgramTkWindow():
209      """
210      Create a Tk window for the Matplotlib graph.
211 <    This window has three buttons which will allow the user to
211 >    This window has three buttons which will allow the user to browse through many traces.
212      """
213      global root, fig, ax, canvas
214      root = Tk.Tk()
# Line 168 | Line 220
220      #ax.set_position([0.1, 0.1, 0.6, 0.8])  # Fraction of frame [left,bot,w,h]
221      ## Define tk.DrawingArea
222      canvas = FigureCanvasTkAgg(fig, master=root)
223 <    #canvas.show()
223 >    #canvas.__show()
224      canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
225      ## Add a pylab-style toolbar.
226      toolbar = NavigationToolbar2TkAgg( canvas, root )
227      toolbar.update()
228      canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
229      ## Add buttons.
230 <    button1 = Tk.Button(master=root, text='Next6', command=btnNext)
230 >    button1 = Tk.Button(master=root, text='Next6', command=__btnNext)
231      button1.pack(side=Tk.RIGHT)
232 <    button2 = Tk.Button(master=root, text='Choose..', command=btnTraces)
232 >    button2 = Tk.Button(master=root, text='Choose..', command=__btnTraces)
233      button2.pack(side=Tk.RIGHT)
234 <    button3 = Tk.Button(master=root, text='Prev6', command=btnPrev)
234 >    button3 = Tk.Button(master=root, text='Prev6', command=__btnPrev)
235      button3.pack(side=Tk.RIGHT)
236      return
237 <    ## End of createSensorgramTkWindow().
238 <    
237 >    """
238 >    End of __createSensorgramTkWindow().
239 >    """
240      
241   ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##
242  
# Line 192 | Line 245
245      """
246      Plot binding changes between (t4-t3) versus (t2-t1).
247      Also print the results to the standard output.
248 +    
249 +    :param ba0: Object containing the data.
250 +    :type ba0: ba_class
251 +    :param t1: Timepoint before binding, first axis.
252 +    :type t1: float
253 +    :param t2: Timepoint after binding, first axis.
254 +    :type t2: float
255 +    :param t3: Timepoint before binding, second axis.
256 +    :type t3: float
257 +    :param t4: Timepoint after binding, second axis.
258 +    :type t4: float
259 +    :param title: Title to place above the graph.
260 +    :type title: str
261 +    :returns: nothing
262      """
196     ## Create a Tk window for the ccatterplot graph.
197     ## Variables root, fig, ax, canvas are local here, not global.
263      root = Tk.Tk()
264      root.wm_title("TK matplotlib Osprai Sensorgram")
265      ## Prepare a matplotlib Figure/Axes.
# Line 233 | Line 298
298      canvas.draw()
299      root.mainloop()
300      return
301 <    ## End of scatterplot()
301 >    """
302 >    How does scatterplot() work?
303 >    First create a Tk window for the scatterplot graph.
304 >    Variables root, fig, ax, canvas are local here, not global.
305 >    Use list comprehensions to get list of average signal 30 sec around t1, t2, t3, t4.
306 >    Plot signal change between t1-t2 against t3-t4. Also print to std output.
307 >    """
308  
309  
310   ## Print a message to the users so they see this module is loaded.
311   print "Loaded vu_module.py version ", __version__
312  
242 ################################# End of module #################################
313 + ################################# End of module #################################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines