Commit 5ab1f07b authored by Thomas Vincent's avatar Thomas Vincent

Remove useless code + move class and function definiton to module level

parent 3a918941
......@@ -44,6 +44,7 @@ img_base = '/path/to/img/dir/'
# the beam energy (note that this value can be changed later when calling the
# img_2_qpeak function)
# Set to None to read it from scan headers
beam_energy = 8000.
# merge_scan_data will take all scans from the spec file that have a matching
......
......@@ -38,6 +38,28 @@ _PHI_LOWER = u'\u03C6'
_ETA_LOWER = u'\u03B7'
class _DblValidator(Qt.QDoubleValidator):
"""QDoubleValidator accepting empty text"""
def validate(self, text, pos):
if len(text) == 0:
return Qt.QValidator.Acceptable, text, pos
return super(_DblValidator, self).validate(text, pos)
def _dblLineEditWidget(width, read_only):
"""Returns a LineEdit of given width
:param int width: Widget's width in pixels
:param bool read_only: Set read only or read/write widget
:rtype: StyledLineEdit
"""
wid = StyledLineEdit(nChar=width,
readOnly=read_only)
wid.setValidator(_DblValidator())
return wid
class AcqParamsWidget(Qt.QWidget):
def __init__(self,
......@@ -47,33 +69,14 @@ class AcqParamsWidget(Qt.QWidget):
layout = Qt.QGridLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
self.__read_only = read_only
self.__beam_energy = None
self.__dir_beam_h = None
self.__dir_beam_v = None
self.__chpdeg_h = None
self.__chpdeg_v = None
class DblValidator(Qt.QDoubleValidator):
def validate(self, text, pos):
if len(text) == 0:
return Qt.QValidator.Acceptable, text, pos
return super(DblValidator, self).validate(text, pos)
def dblLineEditWidget(width):
wid = StyledLineEdit(nChar=width,
readOnly=read_only)
wid.setValidator(DblValidator())
return wid
# ===========
# beam energy
# ===========
row = 0
h_layout = Qt.QHBoxLayout()
self.__beam_nrg_edit = dblLineEditWidget(8)
self.__beam_nrg_edit = _dblLineEditWidget(8, read_only)
h_layout.addWidget(self.__beam_nrg_edit)
h_layout.addWidget(Qt.QLabel('<b>eV</b>'))
......@@ -96,10 +99,10 @@ class AcqParamsWidget(Qt.QWidget):
h_layout = Qt.QHBoxLayout()
layout.addLayout(h_layout, row, 1,
alignment=Qt.Qt.AlignLeft | Qt.Qt.AlignTop)
self.__dir_beam_v_edit = dblLineEditWidget(6)
self.__dir_beam_v_edit = _dblLineEditWidget(6, read_only)
h_layout.addWidget(Qt.QLabel('v='))
h_layout.addWidget(self.__dir_beam_v_edit)
self.__dir_beam_h_edit = dblLineEditWidget(6)
self.__dir_beam_h_edit = _dblLineEditWidget(6, read_only)
h_layout.addWidget(Qt.QLabel(' h='))
h_layout.addWidget(self.__dir_beam_h_edit)
h_layout.addWidget(Qt.QLabel('<b>px</b>'))
......@@ -121,10 +124,10 @@ class AcqParamsWidget(Qt.QWidget):
h_layout = Qt.QHBoxLayout()
layout.addLayout(h_layout, row, 1,
alignment=Qt.Qt.AlignLeft | Qt.Qt.AlignTop)
self.__chpdeg_v_edit = dblLineEditWidget(6)
self.__chpdeg_v_edit = _dblLineEditWidget(6, read_only)
h_layout.addWidget(Qt.QLabel('v='))
h_layout.addWidget(self.__chpdeg_v_edit)
self.__chpdeg_h_edit = dblLineEditWidget(6)
self.__chpdeg_h_edit = _dblLineEditWidget(6, read_only)
h_layout.addWidget(Qt.QLabel(' h='))
h_layout.addWidget(self.__chpdeg_h_edit)
h_layout.addWidget(Qt.QLabel('<b>px</b>'))
......@@ -151,6 +154,11 @@ class AcqParamsWidget(Qt.QWidget):
self.__chpdeg_h_edit.clear()
self.__chpdeg_v_edit.clear()
@property
def beamEnergyEditor(self):
"""Beam energy editor widget (QLineEdit)"""
return self.__beam_nrg_edit
@property
def beam_energy(self):
text = self.__beam_nrg_edit.text()
......@@ -161,7 +169,6 @@ class AcqParamsWidget(Qt.QWidget):
@beam_energy.setter
def beam_energy(self, beam_energy):
self.__beam_nrg_edit.setText(str(beam_energy))
self.__beam_energy = beam_energy
@property
def direct_beam_h(self):
......@@ -173,7 +180,6 @@ class AcqParamsWidget(Qt.QWidget):
@direct_beam_h.setter
def direct_beam_h(self, direct_beam_h):
self.__dir_beam_h_edit.setText(str(direct_beam_h))
self.__dir_beam_h = direct_beam_h
@property
def direct_beam_v(self):
......@@ -185,7 +191,6 @@ class AcqParamsWidget(Qt.QWidget):
@direct_beam_v.setter
def direct_beam_v(self, direct_beam_v):
self.__dir_beam_v_edit.setText(str(direct_beam_v))
self.__dir_beam_v = direct_beam_v
@property
def chperdeg_h(self):
......@@ -197,7 +202,6 @@ class AcqParamsWidget(Qt.QWidget):
@chperdeg_h.setter
def chperdeg_h(self, chperdeg_h):
self.__chpdeg_h_edit.setText(str(chperdeg_h))
self.__chpdeg_h = chperdeg_h
@property
def chperdeg_v(self):
......@@ -209,4 +213,3 @@ class AcqParamsWidget(Qt.QWidget):
@chperdeg_v.setter
def chperdeg_v(self, chperdeg_v):
self.__chpdeg_v_edit.setText(str(chperdeg_v))
self.__chpdeg_v = chperdeg_v
......@@ -116,7 +116,6 @@ class KmapMerger(object):
self.__output_dir = output_dir
self.__params = {'prefix': None,
'beam_energy': None,
'center_channel': None,
'chan_per_deg': None}
......@@ -148,6 +147,14 @@ class KmapMerger(object):
self.__thread = None
self.beam_energy = None
"""Beam energy in eV to set for all scans.
If None (the default) the energy is read from SPEC for each scan.
Union[float,None]
"""
self.prefix = None
self.__set_status(self.READY)
......@@ -267,13 +274,22 @@ class KmapMerger(object):
results = {}
self.__proc_indices = {}
for proc_idx, (scan_id, infos) in enumerate(scans.items()):
# Get beam energy
if self.beam_energy is not None: # Use forced beam energy
beam_energy = self.beam_energy
else: # Read beam energy from each scan header
nrj_kev = self.get_calibration(scan_id).get('mononrj', None)
if nrj_kev is None:
raise RuntimeError("Cannot read beam energy")
beam_energy = nrj_kev * 1000. # From keV to eV
args = (scan_id,
proc_idx,
self.__spec_h5,
self.__output_dir,
infos['output'],
infos['image'],
self.beam_energy,
beam_energy,
self.chan_per_deg,
self.center_chan,
self.compression,
......@@ -466,8 +482,6 @@ class KmapMerger(object):
def check_parameters(self):
errors = []
if self.beam_energy is None:
errors.append('invalid "Beam energy"')
if self.output_dir is None:
errors.append('invalid "Output directory"')
if self.center_chan is None:
......@@ -476,12 +490,6 @@ class KmapMerger(object):
errors.append('invalid "Channel per degree"')
return errors
beam_energy = property(lambda self: self.__params['beam_energy'])
@beam_energy.setter
def beam_energy(self, beam_energy):
self.__params['beam_energy'] = float(beam_energy)
chan_per_deg = property(lambda self: self.__params['chan_per_deg'])
@chan_per_deg.setter
......
Markdown is supported
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