Commit 1079aeee authored by Federico Montesino Pouzols's avatar Federico Montesino Pouzols
Browse files

Merge pull request #15697 from mantidproject/15169_reduce_pylint_warnings_for_refractometer_files

Reduce Pylint warning in Reflectometer files
parents 38555320 52f01ca4
#pylint: disable=invalid-name
# pylint: disable=invalid-name, too-many-instance-attributes, too-many-arguments
# used to parse files more easily
from __future__ import with_statement
# numpy module
import numpy as np
# for command-line arguments
import sys
# Qt4 bindings for core Qt functionalities (non-GUI)
from PyQt4 import QtCore
# python Qt4 bindings for GUI objects
......@@ -15,17 +8,17 @@ from PyQt4 import QtGui
from mantid.simpleapi import *
#blue
# blue
CSS_PEAK = """QLineEdit {
background-color: #54f3f5;
}"""
#red
# red
CSS_BACK = """QLineEdit{
background-color: #f53535;
}"""
#green
# green
CSS_LOWRES = """QLineEdit{
background-color: #a7f6a1;
}"""
......@@ -44,7 +37,7 @@ class DesignerMainWindow(QtGui.QMainWindow):
_lowresToValue = 6.
drs = []
parent = None
dataType = 'data' #'data' or 'norm'
dataType = 'data' # 'data' or 'norm'
x1=None
x2=None
y1=None
......@@ -82,22 +75,23 @@ class DesignerMainWindow(QtGui.QMainWindow):
self.y2 = mt2.readY(0)[:]
self.dataType = type
_summary = parent._summary
if type == 'data':
self._peakFromValue=float(parent._summary.data_peak_from_pixel.text())
self._peakToValue=float(parent._summary.data_peak_to_pixel.text())
self._backFromValue=float(parent._summary.data_background_from_pixel1.text())
self._backToValue=float(parent._summary.data_background_to_pixel1.text())
self._lowresFromValue=float(parent._summary.x_min_edit.text())
self._lowresToValue=float(parent._summary.x_max_edit.text())
self._peakFromValue = float(_summary.data_peak_from_pixel.text())
self._peakToValue = float(_summary.data_peak_to_pixel.text())
self._backFromValue = float(_summary.data_background_from_pixel1.text())
self._backToValue = float(_summary.data_background_to_pixel1.text())
self._lowresFromValue = float(_summary.x_min_edit.text())
self._lowresToValue = float(_summary.x_max_edit.text())
else:
self._peakFromValue=float(parent._summary.norm_peak_from_pixel.text())
self._peakToValue=float(parent._summary.norm_peak_to_pixel.text())
self._backFromValue=float(parent._summary.norm_background_from_pixel1.text())
self._backToValue=float(parent._summary.norm_background_to_pixel1.text())
self._lowresFromValue=float(parent._summary.norm_x_min_edit.text())
self._lowresToValue=float(parent._summary.norm_x_max_edit.text())
#initialization of the superclass
self._peakFromValue = float(_summary.norm_peak_from_pixel.text())
self._peakToValue = float(_summary.norm_peak_to_pixel.text())
self._backFromValue = float(_summary.norm_background_from_pixel1.text())
self._backToValue = float(_summary.norm_background_to_pixel1.text())
self._lowresFromValue = float(_summary.norm_x_min_edit.text())
self._lowresToValue = float(_summary.norm_x_max_edit.text())
# initialization of the superclass
super(DesignerMainWindow, self).__init__(parent)
self.parent = parent
......@@ -107,19 +101,19 @@ class DesignerMainWindow(QtGui.QMainWindow):
self.create_menu()
self.create_main_frame()
#peak text fields
# peak text fields
QtCore.QObject.connect(self.peakFrom, QtCore.SIGNAL("returnPressed()"), self.update_plot)
QtCore.QObject.connect(self.peakTo, QtCore.SIGNAL("returnPressed()"), self.update_plot)
#back text fields
# back text fields
QtCore.QObject.connect(self.backFrom, QtCore.SIGNAL("returnPressed()"), self.update_plot)
QtCore.QObject.connect(self.backTo, QtCore.SIGNAL("returnPressed()"), self.update_plot)
#lowres text fields
# lowres text fields
QtCore.QObject.connect(self.lowresFrom, QtCore.SIGNAL("returnPressed()"), self.update_plot)
QtCore.QObject.connect(self.lowresTo, QtCore.SIGNAL("returnPressed()"), self.update_plot)
#linear and log axis
# linear and log axis
QtCore.QObject.connect(self.linear, QtCore.SIGNAL("clicked()"), self.update_linear_selection_mode)
QtCore.QObject.connect(self.log, QtCore.SIGNAL("clicked()"), self.update_log_selection_mode)
......@@ -318,11 +312,11 @@ class DesignerMainWindow(QtGui.QMainWindow):
def select_file(self):
""" opens a file select dialog """
# open the dialog and get the selected file
file = QtGui.QFileDialog.getOpenFileName()
file_to_open = QtGui.QFileDialog.getOpenFileName()
# if a file is selected
if file:
if file_to_open:
# update the lineEdit text with the selected filename
self.mpllineEdit.setText(file)
self.mpllineEdit.setText(file_to_open)
def parse_file(self, filename):
""" parse a text file to extract letters frequencies """
......@@ -334,7 +328,7 @@ class DesignerMainWindow(QtGui.QMainWindow):
with open(filename) as f:
for line in f:
for char in line:
#counts only letters
# counts only letters
if ord(char.lower()) in range(97, 122+1):
letters[char.lower()] += 1
......@@ -342,7 +336,7 @@ class DesignerMainWindow(QtGui.QMainWindow):
k = sorted(letters.keys())
v = [letters[ki] for ki in k]
return k,v
return k, v
def update_plot(self):
""" retrieve the value of the peak/back/lowres and save it
......@@ -358,7 +352,6 @@ class DesignerMainWindow(QtGui.QMainWindow):
def tmp_plot_data(self, refresh=False):
""" just for testing, display random data """
if refresh:
for rect in self.drs:
rect._refresh()
......@@ -369,7 +362,7 @@ class DesignerMainWindow(QtGui.QMainWindow):
def __init__(self, rect, type, super, parent):
self.rect = rect
self.xpress = None
self.type = type #peak_from, peak_to, back_from, back_to...
self.type = type # peak_from, peak_to, back_from, back_to...
self.super = super
self.parent = parent
......@@ -384,34 +377,38 @@ class DesignerMainWindow(QtGui.QMainWindow):
def on_press(self, event):
'on button press we will see if the mouse is over us and store some data'
if event.inaxes != self.rect.axes: return
if event.inaxes != self.rect.axes:
return
contains, attrd = self.rect.contains(event)
if not contains: return
contains, _attrd = self.rect.contains(event)
if not contains:
return
self.xpress = event.xdata
def on_motion(self, event):
'on motion we will move the rect if the mouse is over us'
if self.xpress is None: return
if event.inaxes != self.rect.axes: return
"""on motion we will move the rect if the mouse is over us"""
if self.xpress is None:
return
if event.inaxes != self.rect.axes:
return
x0 = event.xdata
_x0_format = '{0:.2f}'.format(x0)
_x0_parent_format = str(int(round(x0)))
_summary = self.parent._summary
if self.super.dataType == 'data':
parent_data_peak_from = self.parent._summary.data_peak_from_pixel
parent_data_peak_to = self.parent._summary.data_peak_to_pixel
parent_back_peak_from = self.parent._summary.data_background_from_pixel1
parent_back_peak_to = self.parent._summary.data_background_to_pixel1
parent_x_min = self.parent._summary.x_min_edit
parent_x_max = self.parent._summary.x_max_edit
parent_data_peak_from = _summary.data_peak_from_pixel
parent_data_peak_to = _summary.data_peak_to_pixel
parent_back_peak_from = _summary.data_background_from_pixel1
parent_back_peak_to = _summary.data_background_to_pixel1
parent_x_min = _summary.x_min_edit
parent_x_max = _summary.x_max_edit
else:
parent_data_peak_from = self.parent._summary.norm_peak_from_pixel
parent_data_peak_to = self.parent._summary.norm_peak_to_pixel
parent_back_peak_from = self.parent._summary.norm_background_from_pixel1
parent_back_peak_to = self.parent._summary.norm_background_to_pixel1
parent_x_min = self.parent._summary.norm_x_min_edit
parent_x_max = self.parent._summary.norm_x_max_edit
parent_data_peak_from = _summary.norm_peak_from_pixel
parent_data_peak_to = _summary.norm_peak_to_pixel
parent_back_peak_from = _summary.norm_background_from_pixel1
parent_back_peak_to = _summary.norm_background_to_pixel1
parent_x_min = _summary.norm_x_min_edit
parent_x_max = _summary.norm_x_max_edit
if self.type == 'peak_from':
self.super.peakFrom.setText(_x0_format)
......@@ -452,7 +449,8 @@ class DesignerMainWindow(QtGui.QMainWindow):
self.rect.figure.canvas.draw()
def on_release(self, event):
'on release we reset the press data'
"""on release we reset the press data"""
_event = event
self.xpress = None
self.rect.figure.canvas.draw()
......@@ -464,7 +462,7 @@ class DesignerMainWindow(QtGui.QMainWindow):
parent = self.parent
#top plot will be for peak and background selection
# top plot will be for peak and background selection
axes = self.fig.add_subplot(211)
x = self.x1
......@@ -473,9 +471,9 @@ class DesignerMainWindow(QtGui.QMainWindow):
bLinear = self.linear.isChecked()
if bLinear:
line, = axes.plot(x,y,color='black')
_line, = axes.plot(x, y, color='black')
else:
line, = axes.semilogy(x,y,color='black')
_line, = axes.semilogy(x, y, color='black')
ymax=max(y)
......@@ -484,7 +482,7 @@ class DesignerMainWindow(QtGui.QMainWindow):
else:
ymin = 1
#peak cursor
# peak cursor
peakx1 = self._peakFromValue
self.peakFrom.setText(str(peakx1))
peakx2 = self._peakToValue
......@@ -509,7 +507,7 @@ class DesignerMainWindow(QtGui.QMainWindow):
dr.connect()
self.drs.append(dr)
#back cursor
# back cursor
backx1 = self._backFromValue
self.backFrom.setText(str(backx1))
backx2 = self._backToValue
......@@ -541,9 +539,9 @@ class DesignerMainWindow(QtGui.QMainWindow):
y = self.y2
if bLinear:
line2, = axes2.plot(x,y,color='black')
_line2, = axes2.plot(x,y,color='black')
else:
line2, = axes2.semilogy(x,y,color='black')
_line2, = axes2.semilogy(x,y,color='black')
ymax=max(y)
if bLinear:
......
#pylint: disable=too-many-lines
#pylint: disable=invalid-name
from PyQt4 import QtGui, uic, QtCore
import reduction_gui.widgets.util as util
# pylint: disable=too-many-lines, invalid-name, too-many-arguments
import math
import os
import time
import sys
from functools import partial
import reduction_gui.widgets.util as util
from PyQt4 import QtGui, QtCore
from reduction_gui.reduction.reflectometer.refl_data_script import DataSets as REFLDataSets
from reduction_gui.reduction.reflectometer.refm_data_script import DataSets as REFMDataSets
from reduction_gui.reduction.reflectometer.refl_data_series import DataSeries
from reduction_gui.settings.application_settings import GeneralSettings
from reduction_gui.widgets.base_widget import BaseWidget
import ui.reflectometer.ui_data_refl_simple
......@@ -19,16 +16,15 @@ try:
import mantidplot
from mantid.simpleapi import *
from reduction.instruments.reflectometer import data_manipulation
IS_IN_MANTIDPLOT = True
except:
pass
except ImportError, e:
logger.error(e.message())
class DataReflWidget(BaseWidget):
"""
Widget that present instrument details to the user
"""
## Widget name
# Widget name
name = "Data"
instrument_name = 'REF_L'
short_name = 'REFL'
......@@ -169,8 +165,8 @@ class DataReflWidget(BaseWidget):
call_back = partial(self._edit_event, ctrl=self._summary.data_run_number_edit)
self.connect(self._summary.data_run_number_edit, QtCore.SIGNAL("textChanged(QString)"), self._run_number_changed)
self._run_number_first_edit = True
#call_back = partial(self._edit_event, ctrl=self._summary.log_scale_chk)
#self.connect(self._summary.log_scale_chk, QtCore.SIGNAL("clicked()"), call_back)
# call_back = partial(self._edit_event, ctrl=self._summary.log_scale_chk)
# self.connect(self._summary.log_scale_chk, QtCore.SIGNAL("clicked()"), call_back)
call_back = partial(self._edit_event, ctrl=self._summary.det_angle_edit)
self.connect(self._summary.det_angle_edit, QtCore.SIGNAL("textChanged(QString)"), call_back)
......@@ -246,8 +242,9 @@ class DataReflWidget(BaseWidget):
self._edit_event(ctrl=self._summary.data_run_number_edit)
def _edit_event(self, text=None, ctrl=None):
_text = text
self._summary.edited_warning_label.show()
util.set_edited(ctrl,True)
util.set_edited(ctrl, True)
def _reset_warnings(self):
self._summary.edited_warning_label.hide()
......@@ -345,14 +342,15 @@ class DataReflWidget(BaseWidget):
def _update_scattering_angle(self):
if not self._summary.angle_radio.isChecked():
dangle = util._check_and_get_float_line_edit(self._summary.det_angle_edit)
dangle0 = util._check_and_get_float_line_edit(self._summary.det_angle_offset_edit)
direct_beam_pix = util._check_and_get_float_line_edit(self._summary.direct_pixel_edit)
ref_pix = util._check_and_get_float_line_edit(self._summary.center_pix_edit)
PIXEL_SIZE = 0.0007 # m
PIXEL_SIZE = 0.0007 # m
delta = (dangle-dangle0)*math.pi/180.0/2.0\
+ ((direct_beam_pix-ref_pix)*PIXEL_SIZE)/ (2.0*self._detector_distance)
+ ((direct_beam_pix-ref_pix)*PIXEL_SIZE) / (2.0*self._detector_distance)
scattering_angle = delta*180.0/math.pi
scattering_angle_str = "%4.3g" % scattering_angle
......@@ -404,7 +402,7 @@ class DataReflWidget(BaseWidget):
self._summary.q_min_label.hide()
self._summary.q_min_unit_label.hide()
#TODO: allow log binning
# to-do: allow log binning
self._summary.log_scale_chk.hide()
def _create_auto_reduce_template(self):
......@@ -418,9 +416,9 @@ class DataReflWidget(BaseWidget):
content += "if (os.environ.has_key(\"MANTIDPATH\")):\n"
content += " del os.environ[\"MANTIDPATH\"]\n"
content += "sys.path.insert(0,'/opt/mantidnightly/bin')\n"
script += "import mantid\n"
script += "from mantid.simpleapi import *\n"
script += "from mantid.kernel import ConfigService\n"
reduce_script += "import mantid\n"
reduce_script += "from mantid.simpleapi import *\n"
reduce_script += "from mantid.kernel import ConfigService\n"
content += "eventFileAbs=sys.argv[1]\n"
content += "outputDir=sys.argv[2]\n\n"
......@@ -435,7 +433,7 @@ class DataReflWidget(BaseWidget):
content += "# Place holder for python script\n"
content += "file_path = os.path.join(outputDir, '%s_'+runNumber+'.py')\n" % self.instrument_name
content += "f=open(file_path,'w')\n"
content += "f.write(\"runNumber=\%s \% runNumber\\n\")\n"
content += r"f.write(\"runNumber=\%s \% runNumber\\n\")\n"
content += "f.write(\"\"\"%s\"\"\")\n" % reduce_script
content += "f.close()\n\n"
......@@ -496,9 +494,9 @@ class DataReflWidget(BaseWidget):
f.write(content)
f.close()
QtGui.QMessageBox.information(self, "Automated reduction script saved",\
"The automated reduction script has been updated")
except:
_report_error()
"The automated reduction script has been updated")
except IOError, fileError:
_report_error("Failed to open file: " + fileError.filename())
else:
_report_error("You do not have permissions to write to %s." % sns_path)
else:
......@@ -517,7 +515,7 @@ class DataReflWidget(BaseWidget):
self._summary.auto_reduce_btn.hide()
def _remove_item(self):
if self._summary.angle_list.count()==0:
if self._summary.angle_list.count() == 0:
return
self._summary.angle_list.setEnabled(False)
self._summary.remove_btn.setEnabled(False)
......@@ -633,7 +631,7 @@ class DataReflWidget(BaseWidget):
self._summary.tof_max_label.setEnabled(is_checked)
self._summary.data_to_tof.setEnabled(is_checked)
self._summary.tof_max_label2.setEnabled(is_checked)
#self._summary.plot_tof_btn.setEnabled(is_checked)
# self._summary.plot_tof_btn.setEnabled(is_checked)
self._edit_event(None, self._summary.tof_range_switch)
def _geometry_correction_clicked(self, is_checked):
......@@ -649,13 +647,13 @@ class DataReflWidget(BaseWidget):
For REFM, this is X
For REFL, this is Y
"""
min, max = self._integrated_plot(True,
self._summary.data_run_number_edit,
self._summary.data_peak_from_pixel,
self._summary.data_peak_to_pixel)
self._summary.data_peak_from_pixel_estimate.setText(str(int(math.ceil(min))))
self._summary.data_peak_to_pixel_estimate.setText(str(int(math.ceil(max))))
self._summary.ref_pix_estimate.setText("%4.1f" % ((max+min)/2.0))
_is_peak = is_peak
minimum, maximum = self._integrated_plot(True, self._summary.data_run_number_edit,\
self._summary.data_peak_from_pixel,\
self._summary.data_peak_to_pixel)
self._summary.data_peak_from_pixel_estimate.setText(str(int(math.ceil(minimum))))
self._summary.data_peak_to_pixel_estimate.setText(str(int(math.ceil( maximum))))
self._summary.ref_pix_estimate.setText("%4.1f" % ((maximum+minimum)/2.0))
util.set_tiny(self._summary.data_peak_from_pixel_estimate)
util.set_tiny(self._summary.data_peak_to_pixel_estimate)
util.set_tiny(self._summary.ref_pix_estimate)
......@@ -678,38 +676,38 @@ class DataReflWidget(BaseWidget):
For REFM, this is Y
For REFL, this is X
"""
min, max = self._integrated_plot(False,
self._summary.data_run_number_edit,
self._summary.x_min_edit,
minimum, maximum = self._integrated_plot(False,\
self._summary.data_run_number_edit,\
self._summary.x_min_edit,\
self._summary.x_max_edit)
self._summary.x_min_estimate.setText(str(int(math.ceil(min))))
self._summary.x_max_estimate.setText(str(int(math.ceil(max))))
self._summary.x_min_estimate.setText(str(int(math.ceil(minimum))))
self._summary.x_max_estimate.setText(str(int(math.ceil(maximum))))
util.set_tiny(self._summary.x_min_estimate)
util.set_tiny(self._summary.x_max_estimate)
def _norm_count_vs_y(self):
min, max = self._integrated_plot(True,
self._summary.norm_run_number_edit,
self._summary.norm_peak_from_pixel,
minimum, maximum = self._integrated_plot(True,\
self._summary.norm_run_number_edit,\
self._summary.norm_peak_from_pixel,\
self._summary.norm_peak_to_pixel)
self._summary.norm_peak_from_pixel_estimate.setText(str(int(math.ceil(min))))
self._summary.norm_peak_to_pixel_estimate.setText(str(int(math.ceil(max))))
self._summary.norm_peak_from_pixel_estimate.setText(str(int(math.ceil(minimum))))
self._summary.norm_peak_to_pixel_estimate.setText(str(int(math.ceil(maximum))))
util.set_tiny(self._summary.norm_peak_from_pixel_estimate)
util.set_tiny(self._summary.norm_peak_to_pixel_estimate)
def _norm_count_vs_y_bck(self):
self._integrated_plot(True,
self._summary.norm_run_number_edit,
self._summary.norm_background_from_pixel1,
self._integrated_plot(True,\
self._summary.norm_run_number_edit,\
self._summary.norm_background_from_pixel1,\
self._summary.norm_background_to_pixel1)
def _norm_count_vs_x(self):
min, max = self._integrated_plot(False,
self._summary.norm_run_number_edit,
self._summary.norm_x_min_edit,
minimum, maximum = self._integrated_plot(False,\
self._summary.norm_run_number_edit,\
self._summary.norm_x_min_edit,\
self._summary.norm_x_max_edit)
self._summary.norm_xmin_estimate.setText(str(int(math.ceil(min))))
self._summary.norm_xmax_estimate.setText(str(int(math.ceil(max))))
self._summary.norm_xmin_estimate.setText(str(int(math.ceil(minimum))))
self._summary.norm_xmax_estimate.setText(str(int(math.ceil(maximum))))
util.set_tiny(self._summary.norm_xmin_estimate)
util.set_tiny(self._summary.norm_xmax_estimate)
......@@ -731,7 +729,7 @@ class DataReflWidget(BaseWidget):
@param max_ctrl: control widget containing the range maximum
"""
if not IS_IN_MANTIDPLOT:
return
return None, None
try:
f = FileFinder.findRuns("%s%s" % (self.instrument_name, str(file_ctrl.text())))[0]
......@@ -749,14 +747,14 @@ class DataReflWidget(BaseWidget):
if self.short_name == "REFM":
is_pixel_y = not is_pixel_y
min, max = data_manipulation.counts_vs_pixel_distribution(f, is_pixel_y=is_pixel_y,
callback=call_back,
range_min=range_min,
range_max=range_max,
high_res=is_high_res,
instrument=self.short_name)
return min, max
except:
minimum, maximum = data_manipulation.counts_vs_pixel_distribution(f, is_pixel_y=is_pixel_y,
callback=call_back,
range_min=range_min,
range_max=range_max,
high_res=is_high_res,
instrument=self.short_name)
return minimum, maximum
except IOError:
pass
def _plot_tof(self):
......@@ -775,7 +773,7 @@ class DataReflWidget(BaseWidget):
data_manipulation.tof_distribution(f, call_back,
range_min=range_min,
range_max=range_max)
except:
except IOError:
pass
def _add_data(self):
......@@ -826,7 +824,7 @@ class DataReflWidget(BaseWidget):
self._sangle_parameter = logs["SANGLE"]
self._detector_distance = logs["DET_DISTANCE"]
except:
except IOError:
# Could not read in the parameters, skip.
msg = "No data set was found for run %s\n\n" % run_entry
msg += "Make sure that your data directory was added to the "
......@@ -837,11 +835,11 @@ class DataReflWidget(BaseWidget):
self._summary.waiting_label.hide()
def _angle_changed(self):
if self._summary.angle_list.count()==0:
if self._summary.angle_list.count() == 0:
return
self._summary.angle_list.setEnabled(False)
self._summary.remove_btn.setEnabled(False)
current_item = self._summary.angle_list.currentItem()
current_item = self._summary.angle_list.currentItem()
if current_item is not None:
state = current_item.data(QtCore.Qt.UserRole)
self.set_editing_state(state)
......@@ -892,31 +890,31 @@ class DataReflWidget(BaseWidget):
def set_editing_state(self, state):
#Peak from/to pixels
# Peak from/to pixels
self._summary.data_peak_from_pixel.setText(str(state.DataPeakPixels[0]))
self._summary.data_peak_to_pixel.setText(str(state.DataPeakPixels[1]))
#data low resolution range
# data low resolution range
self._summary.data_low_res_range_switch.setChecked(state.data_x_range_flag)
self._summary.x_min_edit.setText(str(state.data_x_range[0]))
self._summary.x_max_edit.setText(str(state.data_x_range[1]))
self._data_low_res_clicked(state.data_x_range_flag)
#norm low resolution range
# norm low resolution range
self._summary.norm_low_res_range_switch.setChecked(state.norm_x_range_flag)
self._summary.norm_x_min_edit.setText(str(state.norm_x_range[0]))
self._summary.norm_x_max_edit.setText(str(state.norm_x_range[1]))
self._norm_low_res_clicked(state.data_x_range_flag)