Skip to content

Commit

Permalink
Pylint warnings. Refs #11585
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiSavici committed Apr 16, 2015
1 parent 9c3f0a5 commit e1086dd
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 59 deletions.
Expand Up @@ -30,10 +30,10 @@ def PyInit(self):

def PyExec(self):
workspace = self.getProperty("InputWorkspace").value

# Background offset in number of pixels
bck_width = self.getProperty("BackgroundWidth").value

# Signal region
[peak_from_pixel, peak_to_pixel] = self.getProperty("SignalRange").value

Expand All @@ -60,12 +60,14 @@ def PyExec(self):
avg_bck = 0
avg_bck_err = 0
for i in range(bck_from_pixel, peak_from_pixel):
if data_e[i] == 0: data_e[i] = 1.0
if data_e[i] == 0:
data_e[i] = 1.0
avg_bck += data_y[i] / data_e[i] / data_e[i]
avg_bck_err += 1.0 / data_e[i] / data_e[i]

for i in range(peak_to_pixel+1, bck_to_pixel+1):
if data_e[i] == 0: data_e[i] = 1
if data_e[i] == 0:
data_e[i] = 1
avg_bck += data_y[i] / data_e[i] / data_e[i]
avg_bck_err += 1.0 / data_e[i] / data_e[i]

Expand All @@ -78,7 +80,8 @@ def PyExec(self):
specular_counts_err = 0
for i in range(peak_from_pixel, peak_to_pixel+1):
specular_counts += data_y[i] - avg_bck
if data_e[i] == 0: data_e[i] = 1.0
if data_e[i] == 0:
data_e[i] = 1.0
specular_counts_err += data_e[i] * data_e[i] + avg_bck_err * avg_bck_err
specular_counts_err = math.sqrt(specular_counts_err)

Expand All @@ -87,7 +90,7 @@ def PyExec(self):
# Specular ratio
r = specular_counts / total_counts
r_err = r * math.sqrt(specular_counts_err * specular_counts_err / specular_counts / specular_counts) + 1.0/total_counts

self.setProperty("ScalingFactor", [r, r_err])

logger.information("Total counts: %s" % total_counts)
Expand Down
Expand Up @@ -2,7 +2,6 @@
from mantid.kernel import *
from mantid.api import *
from mantid.simpleapi import *
import numpy as np
import __builtin__


Expand Down Expand Up @@ -77,7 +76,6 @@ def _merge_runs(self, to_merge):
return merge_alg.getProperty('OutputWorkspace').value

def _single_run(self, input_workspace, emode, psi, gl, gs, alatt=None, angdeg=None, u=None, v=None,):
import numpy as np
ub_params = map(any, [alatt, angdeg, u, v])
goniometer_params = [psi, gl, gs]
if any(ub_params) and not all(ub_params):
Expand All @@ -86,17 +84,18 @@ def _single_run(self, input_workspace, emode, psi, gl, gs, alatt=None, angdeg=N
if input_workspace.sample().hasOrientedLattice():
logger.warning("Sample already has a UB. This will not be overwritten by %s. Use ClearUB and re-run."%self.name())
else:
self._set_ub(workspace=input_workspace, a=alatt[0], b=alatt[1], c=alatt[2], alpha=angdeg[0], beta=angdeg[1], gamma=angdeg[2], u=u, v=v)
self._set_ub(workspace=input_workspace, a=alatt[0], b=alatt[1], c=alatt[2],
alpha=angdeg[0], beta=angdeg[1], gamma=angdeg[2], u=u, v=v)

if any(goniometer_params):
self._add_sample_log(workspace=input_workspace, log_name='gl', log_number=gl)
self._add_sample_log(workspace=input_workspace, log_name='gs', log_number=gs)
self._add_sample_log(workspace=input_workspace, log_name='psi', log_number=psi)
self._set_goniometer(workspace=input_workspace)

output_run = self._convert_to_md(workspace=input_workspace, analysis_mode=emode)
return output_run


def category(self):
return 'MDAlgorithms'
Expand Down Expand Up @@ -127,48 +126,47 @@ def PyInit(self):
self.declareProperty(IMDWorkspaceProperty('OutputWorkspace', '', direction=Direction.Output ), doc='Output MDWorkspace')

def _validate_inputs(self):

emode = self.getProperty('Emode').value
alatt = self.getProperty('Alatt').value
angdeg = self.getProperty('Angdeg').value
u = self.getProperty('u').value
v = self.getProperty('v').value
psi = self.getProperty('Psi').value
gl = self.getProperty('Gl').value
gs = self.getProperty('Gs').value
gs = self.getProperty('Gs').value

input_workspaces = self.getProperty("InputWorkspaces").value

ws_entries = len(input_workspaces)

if ws_entries < 1:
raise ValueError("Need one or more input workspace")

if len(u) != 3:
raise ValueError("u must have 3 components")

if len(v) != 3:
raise ValueError("v must have 3 components")

if len(alatt) != 3:
raise ValueError("lattice parameters must have 3 components")

if len(angdeg) != 3:
raise ValueError("Angle must have 3 components")

if not emode in self._possible_emodes():
raise ValueError("Unknown emode %s Allowed values are %s" % (emode, self._possible_emodes()))

if len(psi) > 0 and len(psi) != ws_entries:
raise ValueError("If Psi is given a entry should be provided for every input workspace")

if len(gl) > 0 and len(gl) != ws_entries:
raise ValueError("If Gl is given a entry should be provided for every input workspace")

if len(gs) > 0 and len(gs) != ws_entries:
raise ValueError("If Gs is given a entry should be provided for every input workspace")


def PyExec(self):

logger.warning('You are running algorithm %s that is the beta stage of development' % (self.name()))
Expand Down Expand Up @@ -204,12 +202,12 @@ def PyExec(self):

run_data = zip(input_workspaces, psi, gl, gs)
for run_entry in run_data:
ws_name, psi_entry, gl_entry, gs_entry = run_entry
ws = AnalysisDataService.retrieve(ws_name)
run_md = self._single_run(input_workspace=ws, emode=emode, alatt=alatt, angdeg=angdeg, u=u, v=v, psi=psi_entry, gl=gl_entry, gs=gs_entry)
to_merge_name = ws_name + "_md"
AnalysisDataService.addOrReplace(to_merge_name, run_md)
to_merge_names.append(to_merge_name)
ws_name, psi_entry, gl_entry, gs_entry = run_entry
ws = AnalysisDataService.retrieve(ws_name)
run_md = self._single_run(input_workspace=ws, emode=emode, alatt=alatt, angdeg=angdeg, u=u, v=v, psi=psi_entry, gl=gl_entry, gs=gs_entry)
to_merge_name = ws_name + "_md"
AnalysisDataService.addOrReplace(to_merge_name, run_md)
to_merge_names.append(to_merge_name)

if len(to_merge_names) > 1:
output_workspace = self._merge_runs(to_merge_names)
Expand All @@ -221,12 +219,5 @@ def PyExec(self):
DeleteWorkspace(ws)

self.setProperty("OutputWorkspace", output_workspace)








AlgorithmFactory.subscribe(CreateMD)
Expand Up @@ -195,7 +195,7 @@ def read_legacy(self, filename):
except ValueError:
# if start and end time are not given, let them empty
pass


def parse_header(h):
"""
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/scripts/DGSPlanner/InstrumentSetupWidget.py
Expand Up @@ -5,7 +5,7 @@
import numpy
import matplotlib
matplotlib.use('Qt4Agg')
matplotlib.rcParams['backend.qt4']='PyQt4'
matplotlib.rcParams['backend.qt4']='PyQt4'
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from mpl_toolkits.mplot3d import Axes3D
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/scripts/FilterEvents/Ui_MainWindow.py
@@ -1,4 +1,4 @@
#pylint: disable=invalid-name,attribute-defined-outside-init
#pylint: disable=invalid-name,attribute-defined-outside-init,too-many-locals, too-many-statements,too-many-instance-attributes
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'MainWindow.ui'
Expand Down
20 changes: 6 additions & 14 deletions Code/Mantid/scripts/FilterEvents/eventFilterGUI.py
@@ -1,4 +1,4 @@
#pylint: disable=invalid-name
#pylint: disable=invalid-name, too-many-lines, too-many-instance-attributes
import numpy

from FilterEvents.Ui_MainWindow import Ui_MainWindow #import line for the UI python class
Expand Down Expand Up @@ -292,8 +292,6 @@ def on_mouseDownEvent(self, event):
def computeMock(self):
""" Compute vecx and vecy as mocking
"""
import random, math

x0 = 0.
xf = 1.
dx = 0.1
Expand Down Expand Up @@ -672,10 +670,10 @@ def load_File(self):
filename = str(self.ui.lineEdit.text())

# Find out it is relative path or absolute path
if os.path.abspath(filename) == filename:
isabspath = True
else:
isabspath = False
#if os.path.abspath(filename) == filename:
# isabspath = True
#else:
# isabspath = False

dataws = self._loadFile(str(filename))
if dataws is None:
Expand Down Expand Up @@ -1018,12 +1016,6 @@ def filterByTime(self):

title = str(self.ui.lineEdit_title.text())

""" Debug
for k in kwargs.keys():
print k, kwargs[k], type(kwargs[k])
print "Input workspace = ", str(self._dataWS)
END DB """

splitws, infows = api.GenerateEventsFilter(\
InputWorkspace = self._dataWS,\
UnitOfTime = "Seconds",\
Expand Down Expand Up @@ -1171,7 +1163,7 @@ def _searchTableWorkspaces(self):
tablewsnames = []
for wsname in wsnames:
wksp = AnalysisDataService.retrieve(wsname)
if isinstance(wksp, mantid.api._api.ITableWorkspace):
if isinstance(wksp, mantid.api.ITableWorkspace):
tablewsnames.append(wsname)
# ENDFOR

Expand Down
@@ -1,4 +1,4 @@
#pylint: disable=invalid-name
#pylint: disable=invalid-name,line-too-long,attribute-defined-outside-init
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'diffraction_info.ui'
Expand Down
@@ -1,4 +1,4 @@
#pylint: disable=invalid-name
#pylint: disable=invalid-name,line-too-long,too-many-lines,too-many-instance-attributes,too-many-locals,too-many-statements,attribute-defined-outside-init
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'data_refl_simple.ui'
Expand Down
@@ -1,4 +1,4 @@
#pylint: disable=invalid-name
#pylint: disable=invalid-name,line-too-long,too-many-lines,too-many-instance-attributes,too-many-locals,too-many-statements,attribute-defined-outside-init
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'refm_reduction.ui'
Expand Down
@@ -1,4 +1,4 @@
#pylint: disable=invalid-name
#pylint: disable=invalid-name,line-too-long,too-many-instance-attributes,too-many-statements,attribute-defined-outside-init
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'ui/sans/eqsans_instrument.ui'
Expand Down
@@ -1,4 +1,4 @@
#pylint: disable=invalid-name
#pylint: disable=invalid-name,line-too-long,too-many-instance-attributes,too-many-statements,attribute-defined-outside-init
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'ui/sans/hfir_instrument.ui'
Expand Down

0 comments on commit e1086dd

Please sign in to comment.