ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/vu_module.py
(Generate patch)
# Line 22 | Line 22
22    >>> vu.dualgraph(ba1, ba2, "Title")
23    >>> vu.scatterplot(ba1, t1, t2, t3, t4, title)
24   """
25 < __version__ = "110215"
25 > __version__ = "120425"
26  
27  
28   ## Import libraries
29   import ba_class as ba               ## Our Biosensor Array class.
30   import numpy as np
31   from datetime import date
32 + from copy import deepcopy
33   import Tkinter as Tk
34   import tkSimpleDialog as dialog
35   import matplotlib as mpl
# Line 48 | Line 49
49      :returns: nothing
50      """
51      global root, fig, ax, canvas  ## Tk/mpl globals.
52 <    global ba0, ba1, ba2   ## Ref to ba for __roiList, dotgraph, linegraph
52 >    global ba0, ba1, ba2   ## Ref to ba for _roiList, dotgraph, linegraph
53      global gTitle          ## Title for graph.
54      ba0, ba1, ba2 = baLine, 0, baLine
55      gTitle = title
56 <    __createSensorgramTkWindow()
57 <    __show()
56 >    _createSensorgramTkWindow()
57 >    _show()
58      root.mainloop()
59      return
60      """
61 <    How does linegraph() work?  It sets some global values, then calls __show().
61 >    How does linegraph() work?  It sets some global values, then calls _show().
62      """
63      
64   def dotgraph(baDot, title=""):
# Line 71 | Line 72
72      :returns: nothing
73      """
74      global root, fig, ax, canvas  ## Tk/mpl globals..
75 <    global ba0, ba1, ba2   ## Ref to ba for __roiList, dotgraph, linegraph
75 >    global ba0, ba1, ba2   ## Ref to ba for _roiList, dotgraph, linegraph
76      global gTitle          ## Title for graph.
77      ba0, ba1, ba2 = baDot, baDot, 0
78      gTitle = title
79 <    __createSensorgramTkWindow()
80 <    __show()
79 >    _createSensorgramTkWindow()
80 >    _show()
81      root.mainloop()
82      return
83      ## End of dotgraph().
84      """
85 <    How does dotgraph() work?  It sets some global values, then calls __show().
85 >    How does dotgraph() work?  It sets some global values, then calls _show().
86      """
87      
88   def dualgraph(baDot, baLine, title=""):
89      """
90      Display signal vs time using dotted AND continuous lines.
91 +    To graph measured and fitted data together, specify the same
92 +    object for baDot and baLine.
93      
94      :param baDot: Object containing the dotted-line data.
95      :type baDot: BiosensorArray
# Line 97 | Line 100
100      :returns: nothing
101      """
102      global root, fig, ax, canvas  ## Tk/mpl globals.
103 <    global ba0, ba1, ba2   ## Ref to ba for __roiList, dotgraph, linegraph
103 >    global ba0, ba1, ba2   ## Ref to ba for _roiList, dotgraph, linegraph
104      global gTitle          ## Title for graph.
105      ba0, ba1, ba2 = baDot, baDot, baLine
106      gTitle = title
107 <    __createSensorgramTkWindow()
108 <    __show()
107 >    _createSensorgramTkWindow()
108 >    _show()
109      root.mainloop()
110      return
111      """
112 <    How does dualgraph() work?  It sets some global values, then calls __show().
112 >    How does dualgraph() work?  It sets some global values, then calls _show().
113      """
114  
115 < def __show():
115 > def _show():
116      """
117 <    Graph data of ba using Tk window.
117 >    Graph data of BiosensorArray objects using Tk window.
118 >    BiosensorArrays graphed are the globals ba1 and ba2.
119 >    If ba1 and ba2 are the same object, replace ba2 with modeled data.
120      """
121      global root, fig, ax, canvas
122      global ba1, ba2
123      global gTitle
124      
125 +    ## Apply the model with a new ba object, if necessary.
126 +    if (ba1 is ba2):
127 +        ba2 = deepcopy(ba1)
128 +        for i,roi in enumerate(ba1.roi):
129 +            if (roi.model is None):
130 +                ## Use zeros (flatline) if not model is specified.
131 +                ba2.roi[i].value = 0 * roi.value
132 +            else:
133 +                ## Plug params into the specified model.
134 +                ba2.roi[i].value = roi.model(roi.time, roi.value, roi.params)
135 +    
136      ## Prepare graph labels.
137      ax.clear()
138      if (gTitle==""): gTitle='SPR Data plotted %s' % date.today().isoformat()
# Line 129 | Line 145
145      if (ba1 != 0):
146          ## Dotted traces.
147          marker = ['r,', 'g,', 'b,', 'c,', 'm,', 'y,'] + ['k,'] * 100
148 <        for i,j in enumerate(__roiList()):
148 >        for i,j in enumerate(_roiList()):
149              txt = str(j) + ':' + ba1.roi[j].name
150              t = ba1.roi[j].time
151              y = ba1.roi[j].value
# Line 137 | Line 153
153      if (ba2 != 0):
154          ## Line traces.
155          marker = ['r', 'g', 'b', 'c', 'm', 'y'] + ['k'] * 100
156 <        for i,j in enumerate(__roiList()):
156 >        for i,j in enumerate(_roiList()):
157              txt = str(j) + ':' + ba2.roi[j].name
158              t = ba2.roi[j].time
159              y = ba2.roi[j].value
# Line 153 | Line 169
169      canvas.draw()
170      return
171      """
172 <    End of __show().
172 >    End of _show().
173      """
174      
175 < def __btnNext():  
175 > def _btnNext():  
176      """
177      Show next six traces on the graph.
178      """
179      global ba0
180 <    lo = max(__roiList()) + 1
180 >    lo = max(_roiList()) + 1
181      if (lo == len(ba0.roi)): return
182      lo = max(lo,0)
183      hi = lo + 6
184      hi = min(hi, len(ba0.roi))
185      ba0.set_plot_list(range(lo, hi))
186 <    __show()
186 >    _show()
187      return
188      
189 < def __btnPrev():
189 > def _btnPrev():
190      """
191      Show the previous six traces on the graph.
192      """
193      global ba0
194 <    lo = min(__roiList()) - 6
194 >    lo = min(_roiList()) - 6
195      lo = max(lo,0)
196      hi = lo + 6
197      hi = min(hi, len(ba0.roi))
198      ba0.set_plot_list(range(lo, hi))
199 <    __show()
199 >    _show()
200      return
201  
202 < def __btnTraces():
202 > def _btnTraces():
203      """
204      Ask for list of traces to show on graph.
205      """
# Line 192 | Line 208
208      txt = dialog.askstring(title="Input",prompt=txt)
209      txt = txt + ","  ## Be sure eval() produces a list.
210      ba0.set_plot_list(eval(txt))
211 <    __show()
211 >    _show()
212      return
213  
214  
215 < def __roiList():
215 > def _roiList():
216      """
217      List of first six plottable ROIs.
218      """
# Line 206 | Line 222
222      return x[:6]
223  
224  
225 < def __createSensorgramTkWindow():
225 > def _createSensorgramTkWindow():
226      """
227      Create a Tk window for the Matplotlib graph.
228      This window has three buttons which will allow the user to browse through many traces.
# Line 221 | Line 237
237      #ax.set_position([0.1, 0.1, 0.6, 0.8])  # Fraction of frame [left,bot,w,h]
238      ## Define tk.DrawingArea
239      canvas = FigureCanvasTkAgg(fig, master=root)
240 <    #canvas.__show()
240 >    #canvas._show()
241      canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
242      ## Add a pylab-style toolbar.
243      toolbar = NavigationToolbar2TkAgg( canvas, root )
244      toolbar.update()
245      canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
246      ## Add buttons.
247 <    button1 = Tk.Button(master=root, text='Next6', command=__btnNext)
247 >    button1 = Tk.Button(master=root, text='Next6', command=_btnNext)
248      button1.pack(side=Tk.RIGHT)
249 <    button2 = Tk.Button(master=root, text='Choose..', command=__btnTraces)
249 >    button2 = Tk.Button(master=root, text='Choose..', command=_btnTraces)
250      button2.pack(side=Tk.RIGHT)
251 <    button3 = Tk.Button(master=root, text='Prev6', command=__btnPrev)
251 >    button3 = Tk.Button(master=root, text='Prev6', command=_btnPrev)
252      button3.pack(side=Tk.RIGHT)
253      return
254      """
255 <    End of __createSensorgramTkWindow().
255 >    End of _createSensorgramTkWindow().
256      """
257      
258   ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines