Skip to content

Commit

Permalink
fixes for mode selection panel
Browse files Browse the repository at this point in the history
  • Loading branch information
newville committed Jun 24, 2024
1 parent c18c452 commit a7295c4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 39 deletions.
63 changes: 34 additions & 29 deletions larch/wxxas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,37 +86,42 @@ def make_array_choice(opts):

AnalysisTab = namedtuple('AnalysisTab', ('constructor', 'enabled', 'key', 'desc'))

LARIX_PANELS = {'XAS Normalization':
AnalysisTab('larch.wxxas.xasnorm_panel.XASNormPanel', True, 'xasnorm',
'Normalization and Pre-edge subtraction for XANES and EXAFS'),
'Pre-edge Peaks':
AnalysisTab('larch.wxxas.prepeak_panel.PrePeakPanel', True, 'prepeaks',
'Curve Fitting for XANES Pre-edge Peaks'),
'XAS PCA':
AnalysisTab('larch.wxxas.pca_panel.PCAPanel', True, 'pca',
'Principal Component Analysis for XANES and EXAFS'),
'XAS Linear Combo':
AnalysisTab('larch.wxxas.lincombo_panel.LinearComboPanel', True, 'lincombo',
'Linear Combination Analysis for XANES and EXAFS'),
'XAS Regression':
AnalysisTab('larch.wxxas.regress_panel.RegressionPanel', True, 'regression',
'Linear Regression and Feature Selection for XANES and EXAFS'),
'EXAFS':
AnalysisTab('larch.wxxas.exafs_panel.EXAFSPanel', True, 'exafs',
'EXAFS Background Subtraction and Fourier Transforms'),
'FEFF Fitting':
AnalysisTab('larch.wxxas.feffit_panel.FeffitPanel', True, 'feffit',
'EXAFS Path Fitting with FEFF calculations'),
}
LARIX_PANELS = {
'Column Data':
AnalysisTab('larch.wxxas.rawdata_panel.DataPanel', True, 'rawdata',
'Read and Manipulate Data from Column Data files'),
'XAS Normalization':
AnalysisTab('larch.wxxas.xasnorm_panel.XASNormPanel', True, 'xasnorm',
'Normalization and Pre-edge subtraction for XANES and EXAFS'),
'Pre-edge Peaks':
AnalysisTab('larch.wxxas.prepeak_panel.PrePeakPanel', True, 'prepeaks',
'Curve Fitting for XANES Pre-edge Peaks'),
'XAS PCA':
AnalysisTab('larch.wxxas.pca_panel.PCAPanel', True, 'pca',
'Principal Component Analysis for XANES and EXAFS'),
'XAS Linear Combo':
AnalysisTab('larch.wxxas.lincombo_panel.LinearComboPanel', True, 'lincombo',
'Linear Combination Analysis for XANES and EXAFS'),
'XAS Regression':
AnalysisTab('larch.wxxas.regress_panel.RegressionPanel', True, 'regression',
'Linear Regression and Feature Selection for XANES and EXAFS'),
'EXAFS':
AnalysisTab('larch.wxxas.exafs_panel.EXAFSPanel', True, 'exafs',
'EXAFS Background Subtraction and Fourier Transforms'),
'FEFF Fitting':
AnalysisTab('larch.wxxas.feffit_panel.FeffitPanel', True, 'feffit',
'EXAFS Path Fitting with FEFF calculations'),
}

all_keys = [atab.key for atab in LARIX_PANELS.values()]
LARIX_MODES = {'XANES and EXAFS': ('xasnorm', 'prepeaks', 'pca', 'lincombo', 'exafs', 'feffit'),
'EXAFS only': ('xasnorm', 'exafs', 'feffit'),
'XANES only': ('xasnorm', 'prepeaks', 'pca', 'lincombo'),
# 'XRF Mapping and Analysis': ('maproi', 'mapareas', 'maptomo', 'mapxrf'),
# 'XRD 1D': ('xrd1d',),
# 'General Visualization and Fitting': ('rawdata', 'lmfit'),
'All': all_keys}
LARIX_MODES = {'All': all_keys,
'General Data Visualization and Fitting': ('rawdata', 'lmfit'),
'XANES and EXAFS': ('xasnorm', 'prepeaks', 'pca', 'lincombo', 'exafs', 'feffit'),
'EXAFS only': ('xasnorm', 'exafs', 'feffit'),
'XANES only': ('xasnorm', 'prepeaks', 'pca', 'lincombo'),
'XRF Mapping and Analysis': ('maproi', 'mapareas', 'maptomo', 'mapxrf'),
'XRD 1D': ('xrd1d',),
}

class CVar:
"""configuration variable"""
Expand Down
35 changes: 25 additions & 10 deletions larch/wxxas/xasgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def __init__(self, parent, controller, **kws):
self.controller = controller
self.parent = parent
wx.Frame.__init__(self, None, -1, 'Larix Configuration: Analysis Panels',
style=FRAMESTYLE, size=(700, 725))
style=FRAMESTYLE, size=(650, 500))
self.wids = {}

style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL
Expand All @@ -256,6 +256,8 @@ def __init__(self, parent, controller, **kws):
size=(500, 25),
font=Font(FONTSIZE+1), style=LEFT,
colour=COLORS['nb_text'])
modetitle = SimpleText(panel, 'Analysis Mode: ')
panetitle = SimpleText(panel, 'Select Individual Analysis Panels: ')

self.wids = wids = {}
MODES = list(LARIX_MODES.keys())
Expand All @@ -265,7 +267,15 @@ def __init__(self, parent, controller, **kws):

page_map = self.parent.get_panels()
irow = 0
sizer.Add(title, (irow, 0), (1, 4), labstyle|wx.ALL, 3)
sizer.Add(title, (irow, 0), (1, 2), labstyle|wx.ALL, 3)
irow = 1
sizer.Add(modetitle, (irow, 0), (1, 1), labstyle|wx.ALL, 3)
sizer.Add(wids['modechoice'], (irow, 1), (1, 1), labstyle|wx.ALL, 3)
irow += 1
sizer.Add(HLine(panel, (325, 3)), (irow, 0), (1, 2), labstyle|wx.ALL, 3)
irow += 1
sizer.Add(panetitle, (irow, 0), (1, 2), labstyle|wx.ALL, 3)

self.selections = {}
strlen = 30
for pagename in page_map:
Expand All @@ -282,15 +292,14 @@ def __init__(self, parent, controller, **kws):
sizer.Add(desc, (irow, 1), (1, 1), labstyle, 5)

irow += 1
sizer.Add(wx.StaticLine(panel, size=(200, -1), style=wx.LI_HORIZONTAL),
(irow, 0), (1, 5), wx.ALIGN_CENTER|wx.GROW|wx.ALL, 5)
sizer.Add(HLine(panel, (325, 3)), (irow, 0), (1, 2), labstyle|wx.ALL, 3)

btn_ok = Button(panel, 'Apply', size=(70, -1), action=self.OnOK)
btn_cancel = Button(panel, 'Done', size=(70, -1), action=self.OnCancel)

irow += 1
sizer.Add(btn_ok, (irow, 0), (1, 1), labstyle|wx.ALL, 5)
sizer.Add(btn_cancel, (irow, 1), (1, 1), labstyle|wx.ALL, 5)
sizer.Add(btn_ok, (irow, 0), (1, 1), labstyle|wx.ALL, 3)
sizer.Add(btn_cancel, (irow, 1), (1, 1), labstyle|wx.ALL, 3)

pack(panel, sizer)
panel.SetupScrolling()
Expand Down Expand Up @@ -320,6 +329,7 @@ def OnOK(self, event=None):
for name, cb in self.selections.items():
if cb.IsChecked():
self.parent.add_analysis_panel(name)
self.parent.nb.SetSelection(0)

def OnCancel(self, event=None):
self.Destroy()
Expand Down Expand Up @@ -503,10 +513,15 @@ def add_analysis_panel(self, name):
cons = atab.constructor.split('.')
clsname = cons.pop()
module = '.'.join(cons)
cls = getattr(import_module(module), clsname)
nbpanel = cls(parent=self, controller=self.controller)
# self.controller.panels[name] = nbpanel
self.nb.AddPage(nbpanel, name, True)
try:
cls = getattr(import_module(module), clsname)
except (ImportError, KeyError):
cls = None
print(f"cannot find analysis panel {atab}")
if cls is not None:
nbpanel = cls(parent=self, controller=self.controller)
# self.controller.panels[name] = nbpanel
self.nb.AddPage(nbpanel, name, True)

def process_normalization(self, dgroup, force=True, use_form=True):
self.get_nbpage('xasnorm')[1].process(dgroup, force=force, use_form=use_form)
Expand Down

0 comments on commit a7295c4

Please sign in to comment.