Skip to content

Commit

Permalink
cleaning up code included extra spaces and commented sections
Browse files Browse the repository at this point in the history
  • Loading branch information
caitwolf committed Jan 31, 2024
1 parent 492cbe5 commit 585c81c
Showing 1 changed file with 12 additions and 34 deletions.
46 changes: 12 additions & 34 deletions src/sas/qtgui/Calculators/DataOperationUtilityPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from PySide6 import QtGui
from PySide6 import QtWidgets
import numpy as np
from typing import Optional

from sas.qtgui.Plotting.PlotterData import Data1D
from sas.qtgui.Plotting.Plotter import PlotterWidget
Expand All @@ -27,6 +26,7 @@
TRIMMED_COLOR = '#FFFFFF' # white
TRIMMED_ALPHA = 0.3 # semi-transparent points trimmed for operation


class DataOperationUtilityPanel(QtWidgets.QDialog, Ui_DataOperationUtility):
def __init__(self, parent=None):
super(DataOperationUtilityPanel, self).__init__()
Expand Down Expand Up @@ -132,13 +132,11 @@ def onClose(self):
self.cbData2.addItems(['No Data Available'])
self.close()


def onCompute(self):
""" perform calculation - don't send to data explorer"""
# set operator to be applied
operator = self.cbOperator.currentText()
# calculate and send data to DataExplorer
output = None
if self.data1 is None or self.data2 is None:
logging.warning("Please set both Data1 and Data2 to complete operation.")
try:
Expand Down Expand Up @@ -184,8 +182,7 @@ def onPrepareOutputData(self):
self.output,
name=name)

new_datalist_item = {name + str(time.time()):
self.output}
new_datalist_item = {name + str(time.time()): self.output}
self.communicator. \
updateModelFromDataOperationPanelSignal.emit(new_item, new_datalist_item)

Expand Down Expand Up @@ -230,7 +227,7 @@ def onSelectData1(self):
self.newPlot(self.graphData1, self.layoutData1)
self.data1 = None
self.data1OK = False
self.cmdCompute.setEnabled(False) # self.onCheckChosenData())
self.cmdCompute.setEnabled(False) # self.onCheckChosenData())
return

else:
Expand Down Expand Up @@ -288,7 +285,6 @@ def onSelectData2(self):
else:
self.cautionStatement.setText("")


def onInputCoefficient(self):
""" Check input of number when a coefficient is required
for operation """
Expand Down Expand Up @@ -332,12 +328,12 @@ def onCheckChosenData(self):

elif self.data1.__class__.__name__ == 'Data2D' \
and (len(self.data2.qx_data) != len(self.data1.qx_data) \
or len(self.data2.qy_data) != len(self.data1.qy_data)
or not all(i == j for i, j in
zip(self.data1.qx_data, self.data2.qx_data))
or not all(i == j for i, j in
zip(self.data1.qy_data, self.data2.qy_data))
):
or len(self.data2.qy_data) != len(self.data1.qy_data)
or not all(i == j for i, j in
zip(self.data1.qx_data, self.data2.qx_data))
or not all(i == j for i, j in
zip(self.data1.qy_data, self.data2.qy_data))
):
self.cbData1.setStyleSheet(BG_RED)
self.cbData2.setStyleSheet(BG_RED)
logging.error('Cannot compute 2D data of different lengths')
Expand Down Expand Up @@ -443,28 +439,10 @@ def operationData1D(self, operation_data, reference_data=None):
new_operation_data.dy = np.zeros(2)
new_operation_data.dx = np.zeros(2)
else:
try:
new_operation_data = Data1D(x=operation_data.x, y=operation_data.y, dy=operation_data.dy, dx=None)
new_operation_data.copy_from_datainfo(data1d=operation_data)
except:
new_operation_data = None

new_operation_data = Data1D(x=operation_data.x, y=operation_data.y, dy=operation_data.dy, dx=None)
new_operation_data.copy_from_datainfo(data1d=operation_data)
return new_operation_data

# for d_op, c_op in zip(data_op, color_op):
# if isinstance(d_op, Data1D):
# op_data = Data1D(x=d_op._operation.x, y=d_op._operation.y, dy=d_op._operation.dy, dx=None)
# op_data.copy_from_datainfo(data1d=d_op._operation)
# plotter.plot(data=op_data, hide_error=True, marker='.', color=c_op)
# else:
# op_data = Data1D(2)
# op_data.copy_from_datainfo(data1d=data)
# op_data.x = np.array([data.x.min(), data.x.max()])
# op_data.y = np.array([d_op, d_op])
# op_data.dy = np.zeros(2)
# op_data.dx = np.zeros(2)
# plotter.plot(data=op_data, hide_error=True, marker='-', color=c_op)

def updatePlot(self, graph, layout, data, color=None, operation_data=False):
""" plot data in graph after clearing its layout """

Expand Down Expand Up @@ -542,7 +520,7 @@ def updatePlot(self, graph, layout, data, color=None, operation_data=False):
hide_error=True, marker='o', color=DATA2_COLOR,
markerfacecolor=None, markeredgecolor=None)
plotter.plot(data=data, hide_error=True, marker='o', color=color, markerfacecolor=markerfacecolor,
markeredgecolor=markeredgecolor)
markeredgecolor=markeredgecolor)
else:
plotter.plot(data=data, hide_error=True, marker='o', color=color, markerfacecolor=markerfacecolor,
markeredgecolor=markeredgecolor, alpha=alpha)
Expand Down

0 comments on commit 585c81c

Please sign in to comment.