Skip to content

Commit

Permalink
- additional speed-up (issue #77)
Browse files Browse the repository at this point in the history
- code cleanup


Former-commit-id: 5b1b1ca3257449f76660c82c3e26eda73620b38a [formerly f21f9d65de549758d0531d5aff100dc2ff2b8fce] [formerly d3613bfcb2c718ad5c714297832f1a676afb8efe [formerly 1761f35079ab9f5d519f0993b8abe124730b15b6]] [formerly 54893877121cc440ae361bad69cb10f3f6f88335 [formerly b1c46714fa933e69ee1e6c8278cd08f688b780a6] [formerly 12715ac2aed5678cb92e33eb9dc7d31e60caeb44 [formerly 5fb7042]]]
Former-commit-id: 08e20e3b982a1ef0e38963a3eadb1f8386f010c2 [formerly 6b90030671cf88f037d177d42b4fa5dfa364707e] [formerly 7701c48361f3898b9c8230a964c69146a136e10c [formerly 4bf4c690a0508ba84daf8e0fcf2ceeb26634ee81]]
Former-commit-id: 501c10877bfe829769bf52b97c264639eaef8738 [formerly d7041c14fa943a62b67abb4f1d20ecf0a1e02be2]
Former-commit-id: eef488aea424c1923565c87788d91f9cd197a7ed
  • Loading branch information
Paul Müller committed Apr 3, 2014
1 parent 25d2079 commit bdfec30
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 45 deletions.
64 changes: 35 additions & 29 deletions src/frontend.py
Expand Up @@ -229,7 +229,7 @@ def add_fitting_tab(self, event=None, modelid=None, counter=None):
Newtab = page.FittingPanel(self, counter, modelid, active_parms,
self.tau)
#self.Freeze()
self.notebook.AddPage(Newtab, counter+model, select=True)
self.notebook.AddPage(Newtab, counter+model, select=False)
#self.Thaw()
self.tabcounter = self.tabcounter + 1
# Enable the "Current" Menu
Expand All @@ -243,18 +243,15 @@ def add_fitting_tab(self, event=None, modelid=None, counter=None):
# window is open.
# Find Tool Statistics
# Get open tools
toolkeys = self.ToolsOpen.keys()
for key in toolkeys:
tool = self.ToolsOpen[key]
try:
if tool.MyName=="STATISTICS":
# Call the function properly.
tool.OnPageChanged(Newtab)
except:
pass
#
#######
#
#toolkeys = self.ToolsOpen.keys()
#for key in toolkeys:
# tool = self.ToolsOpen[key]
# try:
# if tool.MyName=="STATISTICS":
# # Call the function properly.
# tool.OnPageChanged(Newtab)
# except:
# pass
return Newtab


Expand Down Expand Up @@ -660,7 +657,7 @@ def OnFNBClosedPage(self,e=None):



def OnFNBPageChanged(self,e=None, Page=None, trigger=None):
def OnFNBPageChanged(self, e=None, Page=None, trigger=None):
""" Called, when
- Page focus switches to another Page
- Page with focus changes significantly:
Expand All @@ -669,6 +666,11 @@ def OnFNBPageChanged(self,e=None, Page=None, trigger=None):
- trigger is a string. For more information read the
doc strings of the `tools` submodule.
"""

if (e is not None and
e.GetEventType()==fnb.EVT_FLATNOTEBOOK_PAGE_CHANGED.typeId
and trigger is None):
trigger = "tab_browse"
# Get the Page
if Page is None:
Page = self.notebook.GetCurrentPage()
Expand Down Expand Up @@ -855,7 +857,13 @@ def OnMyLeftUp(self, event):


def ImportData(self, Page, dataexp, trace, curvetype="",
filename="", curveid="", run=""):
filename="", curveid="", run="", trigger=None):
"""
Import data into the current page.
`trigger` is passed to PlotAll. For more info see the
submodule `tools`.
"""
CurPage = Page
# Import traces. Traces are usually put into a list, even if there
# is only one trace. The reason is, that for cross correlation, we
Expand Down Expand Up @@ -884,7 +892,7 @@ def ImportData(self, Page, dataexp, trace, curvetype="",
# It might be possible, that we want the channels to be
# fixed to some interval. This is the case if the
# checkbox on the "Channel selection" dialog is checked.
self.OnFNBPageChanged()
#self.OnFNBPageChanged()
# Enable Fitting Button
CurPage.Fit_enable_fitting()
# Set new tabtitle value and strip leading or trailing
Expand All @@ -895,11 +903,11 @@ def ImportData(self, Page, dataexp, trace, curvetype="",
title = "{} id{:03d}-{}".format(filename, int(curveid), curvetype)
CurPage.tabtitle.SetValue(title.strip())
# Plot everything
CurPage.PlotAll()
CurPage.PlotAll(trigger=trigger)
# Call this function to allow the "Channel Selection" window that
# might be open to update itself.
# We are aware of the fact, that we just did that
self.OnFNBPageChanged()
#self.OnFNBPageChanged()


def OnLatexCheck(self,e):
Expand Down Expand Up @@ -1146,13 +1154,14 @@ def OnLoadBatch(self, e):
# Fill Page with data
self.ImportData(CurPage, Correlation[i], Trace[i],
curvetype=Type[i], filename=Filename[i],
curveid=str(Curveid[i]), run=str(Run[i]))
curveid=str(Curveid[i]), run=str(Run[i]),
trigger="page_add_batch")
# Let the user abort, if he wants to:
# We want to do this here before an empty page is added
# to the notebok.
if dlg.Update(i+1, "Loading pages...")[0] == False:
dlg.Destroy()
return
break
self.OnFNBPageChanged(trigger="page_add_finalize")
# If the user did not select curves but chose a model, destroy
# the dialog.
dlg.Destroy()
Expand Down Expand Up @@ -1212,9 +1221,8 @@ def OnOpenSession(self,e=None,sessionfile=None):
# the page later.
counter = Infodict["Parameters"][i][0]
modelid = Infodict["Parameters"][i][1]
self.add_fitting_tab(modelid=modelid, counter=counter)
# Get New Page, so we can add our stuff.
Newtab = self.notebook.GetCurrentPage()
Newtab = self.add_fitting_tab(modelid=modelid,
counter=counter)
# Add experimental Data
# Import dataexp:
number = counter.strip().strip(":").strip("#")
Expand Down Expand Up @@ -1278,7 +1286,7 @@ def OnOpenSession(self,e=None,sessionfile=None):
else:
Newtab.tracecc = trace
# Plot everything
Newtab.PlotAll()
Newtab.PlotAll(trigger="page_add_batch")
# Set Session Comment
try:
self.SessionComment = Infodict["Comments"]["Session"]
Expand All @@ -1291,7 +1299,7 @@ def OnOpenSession(self,e=None,sessionfile=None):
if self.notebook.GetPageCount() > 0:
# Enable the "Current" Menu
self.EnableToolCurrent(True)
self.OnFNBPageChanged()
self.OnFNBPageChanged(trigger="page_add_finalize")
else:
# There are no pages in the session.
# Disable some menus and close some dialogs
Expand Down Expand Up @@ -1548,15 +1556,13 @@ def UnpackParameters(self, Parms, Page):
if len(Parms[5]) == 2:
[weighted, weights] = Parms[5]
knots = None
algorithm = "Lev-Mar"
elif len(Parms[5]) == 3:
# We have knots as of v. 0.6.5
[weighted, weights, knots] = Parms[5]
algorithm = "Lev-Mar"
else:
# We have different fitting algorithms as of v. 0.8.3
[weighted, weights, knots, algorithm] = Parms[5]
Page.fit_algorithm = algorithm
Page.fit_algorithm = algorithm
if knots is not None:
# This is done with apply_paramters_reverse:
# text = Page.Fitbox[1].GetValue()
Expand Down
4 changes: 1 addition & 3 deletions src/page.py
Expand Up @@ -173,7 +173,7 @@ def __init__(self, parent, counter, modelid, active_parms, tau):
self.canvascorr = plot.PlotCanvas(self.spcanvas)
self.canvascorr.setLogScale((True, False))
self.canvascorr.SetEnableZoom(True)
self.PlotAll()
self.PlotAll(event="init", trigger="tab_init")
self.canvascorr.SetSize((canvasx, cupsizey))
# Lower Plot for plotting of the residuals
self.canvaserr = plot.PlotCanvas(self.spcanvas)
Expand Down Expand Up @@ -742,8 +742,6 @@ def OnTitleChanged(self, e):
# in the tab? We choose 9: AC1-012 plus 2 whitespaces
text = self.counter + self.tabtitle.GetValue()[-9:]
self.parent.notebook.SetPageText(pid,text)
#import IPython
#IPython.embed()


def OnSetRange(self, e):
Expand Down
13 changes: 8 additions & 5 deletions src/tools/__init__.py
Expand Up @@ -13,11 +13,14 @@
speeds up tools like "Statistics view" when batch fitting.
Recognized triggers:
view : the user is looking at the page right now
fit_batch : the page is batch-fitted right now
fit_finalize : a (batch) fitting process is finished
parm_batch : parameters are changed in a batch process
parm_finalize : finished (batch) changing of a pages parameters
tab_init : initial stuff that is done for a new page
tab_browse : the tab has change and a new page is visible
fit_batch : the page is batch-fitted right now
fit_finalize : a (batch) fitting process is finished
parm_batch : parameters are changed in a batch process
parm_finalize : finished (batch) changing of page parameters
page_add_batch : when many pages are added at the same time
page_add_finalize : finished (batch) adding of pages
Dimensionless representation:
unit of time : 1 ms
Expand Down
19 changes: 15 additions & 4 deletions src/tools/overlaycurves.py
Expand Up @@ -138,6 +138,9 @@ def OnPageChanged(self, page=None, trigger=None):
Forr a list of possible triggers, see the doc string of
`tools`.
"""
if trigger in ["parm_batch", "fit_batch", "page_add_batch",
"tab_init", "tab_browse"]:
return
# When parent changes
# This is a necessary function for PyCorrFit.
# This is stuff that should be done when the active page
Expand All @@ -146,6 +149,7 @@ def OnPageChanged(self, page=None, trigger=None):
self.Selector.SelectBox.SetItems([])
self.Selector.sp.Disable()
else:
self.Selector.sp.Enable()
# Sticky behavior cleaned up in 0.7.8
curvedict, labels = self.GetCurvedict()
self.Selector.curvedict = curvedict
Expand All @@ -155,7 +159,7 @@ def OnPageChanged(self, page=None, trigger=None):
self.Selector.SelectBox.SetItems(self.Selector.curvelabels)
for i in np.arange(len(self.Selector.curvekeys)):
self.Selector.SelectBox.SetSelection(i)
self.Selector.OnUpdatePlot()
self.Selector.OnUpdatePlot(trigger=trigger)


def OnResults(self, keyskeep, keysrem):
Expand Down Expand Up @@ -191,7 +195,7 @@ def OnResults(self, keyskeep, keysrem):
self.OnPageChanged()


def OnSelectionChanged(self, keylist):
def OnSelectionChanged(self, keylist, trigger=None):
if len(keylist) == 0:
return
# integer type list with page number
Expand Down Expand Up @@ -282,6 +286,7 @@ def __init__(self, parent, curvedict, wrapper=None, selkeys=None,
style=style, choices=self.curvelabels)
for i in np.arange(len(self.curvekeys)):
self.SelectBox.SetSelection(i)

# Deselect keys that are not in self.selkeys
if self.selkeys is not None:
for i in np.arange(len(self.curvekeys)):
Expand Down Expand Up @@ -363,15 +368,21 @@ def OnPushResults(self, e=None):
self.wrapper.OnResults(keyskeep, keysrem)


def OnUpdatePlot(self, e=None):
def OnUpdatePlot(self, e=None, trigger=None):
""" What should happen when the selection in *self.SelectBox*
is changed?
This function will alsy try to call the function
*self.parent.OnSelectionChanged* and hand over the list of
currently selected curves. This is an addon for 0.7.8
where we will control the page selection in the average
tool.
If `trigger` is something that occurs during loading of
data, then we will not replot everything.
"""
#if e is not None and e.GetEventType() == 10007:
# return

# Get selected curves
curves = list()
legends = list()
Expand Down Expand Up @@ -401,6 +412,6 @@ def OnUpdatePlot(self, e=None):
for i in self.SelectBox.GetSelections():
keyskeep.append(self.curvekeys[i])
try:
self.wrapper.OnSelectionChanged(keyskeep)
self.wrapper.OnSelectionChanged(keyskeep, trigger=trigger)
except:
pass
18 changes: 14 additions & 4 deletions src/tools/statistics.py
Expand Up @@ -71,7 +71,7 @@ def __init__(self, parent):
# Page - the currently active page of the notebook.
self.Page = self.parent.notebook.GetCurrentPage()
# Pagenumbers
self.PageNumbers = np.arange(self.parent.notebook.GetPageCount())
self.PageNumbers =range(1,1+self.parent.notebook.GetPageCount())
## Splitter window. left side: checkboxes
## right side: plot with parameters
self.sp = wx.SplitterWindow(self, style=wx.SP_3DSASH)
Expand Down Expand Up @@ -540,11 +540,21 @@ def OnPageChanged(self, page, trigger=None):
# This is a necessary function for PyCorrFit.
# This is stuff that should be done when the active page
# of the notebook changes.

# filter unwanted triggers to improve speed
if trigger in ["parm_batch", "fit_batch", "load_batch"]:
if trigger in ["parm_batch", "fit_batch", "page_add_batch"]:
return

elif trigger in ["tab_init"] and page is not None:
# Check if we have to replot for a new model
if self.Page.modelid == page.modelid:
return
if (trigger in ["page_add_finalize"] and
self.WXTextPages.GetValue() == "1"):
# We probably imported data with statistics window open
self.PageNumbers = range(1,
1+self.parent.notebook.GetPageCount())
setstring = misc.parsePagenum2String(self.PageNumbers)
self.WXTextPages.SetValue(setstring)

#
# Prevent this function to be run twice at once:
#
Expand Down

0 comments on commit bdfec30

Please sign in to comment.