Commit da882a9b authored by payno's avatar payno Committed by Henri Payno
Browse files

[fix][storing processing] add an overwrite option to insure update of the nx process is valid

parent 9e901b20
......@@ -222,7 +222,7 @@ class AutobkOW(_ProcessForOrangeMixIn, OWWidget):
self.process(self._latest_xas_obj)
def _update_settings(self):
self._pymcaSettings = self._window._parametersWindow.getParameters()
self._larchSettings = self._window._parametersWindow.getParameters()
def process(self, xas_obj):
if xas_obj is None:
......@@ -239,7 +239,7 @@ class AutobkOW(_ProcessForOrangeMixIn, OWWidget):
process_obj = QLarch_autobk()
process_obj._advancement.sigProgress.connect(self._setProgressValue)
process_obj.setProperties({
'_pymcaSettings': self._window._parametersWindow.getParameters()})
'_larchSettings': self._window._parametersWindow.getParameters()})
# update the processing thread
thread = self.getProcessingThread()
......
......@@ -64,24 +64,6 @@ def _get_title(dgroup, title=None):
return repr(dgroup)
def _plot_chik(spectrum):
# TODO: plot un resultat qui n'est pas stocké quand même !!! ???
if not hasattr(spectrum, 'kweight') or spectrum.kweight is None:
kweight = 0
xft = getattr(spectrum, 'xftf_details', None)
if xft is not None:
kweight = xft.call_args.get('kweight', 0)
if not hasattr(spectrum, 'k'):
_logger.error('k not computed, unable to display it')
return
if not hasattr(spectrum, 'chi'):
_logger.error('chi not computed, unable to display it')
return
chi = spectrum.chi * spectrum.k ** kweight
return _CurveOperation(x=spectrum.k, y=chi, legend='chi k')
def _plot_chir_mag(spectrum):
if not hasattr(spectrum, 'r'):
_logger.error('r not computed, unable to display it')
......@@ -143,7 +125,7 @@ class MbackWindow(qt.QMainWindow):
self.xasObjViewer._mapView.keySelectionDocker)
# plot settings
for ope in (_plot_chik, _plot_chir_mag, _plot_chir_re, _plot_chir_imag):
for ope in (_plot_chir_mag, _plot_chir_re, _plot_chir_imag):
self.xasObjViewer._spectrumViews[0].addCurveOperation(ope)
self.setWindowFlags(qt.Qt.Widget)
......@@ -209,7 +191,6 @@ class MXFTFOW(_ProcessForOrangeMixIn, OWWidget):
self._larchSettings = self._window._parametersWindow.getParameters()
def process(self, xas_obj):
print('*** in process')
if xas_obj is None:
return
......@@ -231,7 +212,6 @@ class MXFTFOW(_ProcessForOrangeMixIn, OWWidget):
self._callback_finish = functools.partial(self._endProcess, xas_obj)
thread.finished.connect(self._callback_finish)
# start processing
print('launch the thread')
thread.start(priority=qt.QThread.LowPriority)
......@@ -248,7 +228,6 @@ class QLarch_xftf(xas.core.process.larch.xftf.Larch_xftf):
self.pool = qt.QThreadPool()
self.pool.setMaxThreadCount(5)
for spectrum in xas_obj.spectra:
print('call one')
runnable = ProcessRunnable(fct=xas.core.process.larch.xftf.process_spectr_xftf,
spectrum=spectrum,
configuration=xas_obj.configuration,
......
......@@ -170,7 +170,7 @@ class ExafsOW(_ProcessForOrangeMixIn, OWWidget):
process_function = xas.core.process.pymca.exafs.PyMca_exafs
_pymcaSettings = Setting(dict())
_larchSettings = Setting(dict())
"""Store the configuration of the PyMca XASClass"""
def __init__(self):
......@@ -184,8 +184,8 @@ class ExafsOW(_ProcessForOrangeMixIn, OWWidget):
self._window.xasObjViewer._spectrumViews[0]._plot.getYAxis().setLabel("Normalized Units")
# manage settings
if self._pymcaSettings != dict():
self._window._pymcaWindow.setParameters(self._pymcaSettings)
if self._larchSettings != dict():
self._window._pymcaWindow.setParameters(self._larchSettings)
# signal / slot connection
_sig = self._window._pymcaWindow.sigPostEdgeParametersSignal
......@@ -197,7 +197,7 @@ class ExafsOW(_ProcessForOrangeMixIn, OWWidget):
self.process(self._latest_xas_obj)
def _update_settings(self):
self._pymcaSettings = self._window._pymcaWindow.getParameters()
self._larchSettings = self._window._pymcaWindow.getParameters()
def process(self, xas_obj):
if xas_obj is None:
......@@ -213,7 +213,7 @@ class ExafsOW(_ProcessForOrangeMixIn, OWWidget):
# setup the exafs process
process_obj = QPyMca_exafs()
process_obj._advancement.sigProgress.connect(self._setProgressValue)
process_obj.setProperties({'_pymcaSettings': self._window._pymcaWindow.getParameters()})
process_obj.setProperties({'_larchSettings': self._window._pymcaWindow.getParameters()})
# update the processing thread
thread = self.getProcessingThread()
......
......@@ -97,8 +97,8 @@ class Larch_autobk(Process):
Process.__init__(self, name='autobk')
def setProperties(self, properties):
if '_pymcaSettings' in properties:
self._settings = properties['_pymcaSettings']
if '_larchSettings' in properties:
self._settings = properties['_larchSettings']
def process(self, xas_obj):
_xas_obj = self.getXasObject(xas_obj=xas_obj)
......
......@@ -102,8 +102,8 @@ class Larch_mback_norm(Process):
Process.__init__(self, name='mback_norm')
def setProperties(self, properties):
if '_pymcaSettings' in properties:
self._settings = properties['_pymcaSettings']
if '_larchSettings' in properties:
self._settings = properties['_larchSettings']
def process(self, xas_obj):
_xas_obj = self.getXasObject(xas_obj=xas_obj)
......
......@@ -57,12 +57,14 @@ def process_spectr_pre_edge(spectrum, configuration, overwrite=True, callback=No
_logger.error('Energy and or Mu is/are not specified, unable to '
'compute pre edge')
return None, None
_conf = configuration
if 'pre_edge' in _conf:
_conf = _conf['pre_edge']
opts = {}
for opt_name in ('z', 'edge', 'e0', 'pre1', 'pre2', 'norm1', 'norm2',
'order', 'leexiang', 'tables', 'fit_erfc'):
if opt_name in configuration:
opts[opt_name] = configuration[opt_name]
if opt_name in _conf:
opts[opt_name] = _conf[opt_name]
if _DEBUG is True:
assert isinstance(spectrum, Group)
......
......@@ -57,12 +57,14 @@ def process_spectr_xftf(spectrum, configuration, overwrite=True, callback=None,
_logger.error('k and/or chi is/are not specified, unable to compute '
'xftf. Maybe you need to run autobk process before ?')
return None, None
_conf = configuration
if 'xftf' in _conf:
_conf = _conf['xftf']
opts = {}
for opt_name in ('kmin', 'kmax', 'kweight', 'dk', 'dk2', 'with_phase',
'window', 'rmax_out', 'nfft', 'kstep'):
if opt_name in configuration:
opts[opt_name] = configuration[opt_name]
if opt_name in _conf:
opts[opt_name] = _conf[opt_name]
if _DEBUG is True:
assert isinstance(spectrum, Group)
......@@ -95,13 +97,15 @@ class Larch_xftf(Process):
Process.__init__(self, name='xftf')
def setProperties(self, properties):
if '_pymcaSettings' in properties:
self._settings = properties['_pymcaSettings']
if '_larchSettings' in properties:
self._settings = properties['_larchSettings']
def process(self, xas_obj):
_xas_obj = self.getXasObject(xas_obj=xas_obj)
if self._settings:
_xas_obj.configuration['xftf'] = self._settings
elif 'xftf' not in _xas_obj.configuration:
_xas_obj.configuration['xftf'] = {}
self._advancement.reset(max_=_xas_obj.n_spectrum)
self._advancement.startProcess()
......
......@@ -369,7 +369,7 @@ class XASObject(object):
"""
xas.io.write_xas_proc(self.linked_h5_file, entry=self.__entry_name,
processing_order=self.get_next_processing_index(),
process=process, data=data)
process=process, data=data, overwrite=True)
def get_process_flow(self):
"""
......
......@@ -131,7 +131,8 @@ def read_xas(spectra_url, channel_url, config_url=None):
# TODO: process, sample, energy and data can be embed in a 'result' / output object
def write_xas_proc(h5_file, entry, process, data, processing_order, data_path='/'):
def write_xas_proc(h5_file, entry, process, data, processing_order,
data_path='/', overwrite=True):
"""
Write a xas :class:`.Process` into .h5
......@@ -150,6 +151,11 @@ def write_xas_proc(h5_file, entry, process, data, processing_order, data_path='/
nx_process = nx_entry.require_group(process_name)
nx_process.attrs['NX_class'] = "NXprocess"
if overwrite:
for key in ('program', 'version', 'date', 'processing_order',
'class_instance'):
if key in nx_process:
del nx_process[key]
nx_process['program'] = process.program_name()
nx_process['version'] = process.program_version()
nx_process['date'] = datetime.now().replace(microsecond=0).isoformat()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment