From 8910849006e8a2d03883a648e51bdfb098554612 Mon Sep 17 00:00:00 2001 From: Wojciech Potrzebowski Date: Sat, 30 Sep 2023 22:23:13 +0200 Subject: [PATCH] Merge pull request #2653 from SasView/new_numpy_behaviour Fixes for the new numpy syntax --- src/sas/qtgui/Calculators/SlitSizeCalculator.py | 2 +- src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py | 3 ++- src/sas/sascalc/fit/AbstractFitEngine.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sas/qtgui/Calculators/SlitSizeCalculator.py b/src/sas/qtgui/Calculators/SlitSizeCalculator.py index 26783b1daf..65b3a3da4f 100644 --- a/src/sas/qtgui/Calculators/SlitSizeCalculator.py +++ b/src/sas/qtgui/Calculators/SlitSizeCalculator.py @@ -116,7 +116,7 @@ def calculateSlitSize(self, data=None): try: xdata = data.x ydata = data.y - if xdata == [] or xdata is None or ydata == [] or ydata is None: + if xdata.size == 0 or xdata is None or ydata.size == 0 or ydata is None: msg = "The current data is empty please check x and y" logging.error(msg) return diff --git a/src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py b/src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py index 48330b8090..2d1cbc79e5 100644 --- a/src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py +++ b/src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py @@ -435,7 +435,8 @@ def calculateChi2(reference_data, current_data, weight): if index is None: index = numpy.ones(len(current_data.y), dtype=bool) - if current_data.dy is None or current_data.dy == []: + # if current_data.dy is None or not len(current_data.dy): + if current_data.dy is None or current_data.dy.size == 0: dy = numpy.ones(len(current_data.y)) else: dy = weight diff --git a/src/sas/sascalc/fit/AbstractFitEngine.py b/src/sas/sascalc/fit/AbstractFitEngine.py index e374f5a7af..83494e8cef 100644 --- a/src/sas/sascalc/fit/AbstractFitEngine.py +++ b/src/sas/sascalc/fit/AbstractFitEngine.py @@ -161,7 +161,7 @@ class DataLoader.data_info.Data1D # Check error bar; if no error bar found, set it constant(=1) # TODO: Should provide an option for users to set it like percent, # constant, or dy data - if dy is None or dy == [] or dy.all() == 0: + if dy is None or dy.size == 0 or np.all(dy == 0): self.dy = np.ones(len(y)) else: self.dy = np.asarray(dy).copy() @@ -299,7 +299,7 @@ def set_data(self, sas_data2d, qmin=None, qmax=None): if qmax is None: self.qmax = math.sqrt(x_max * x_max + y_max * y_max) ## new error image for fitting purpose - if self.err_data is None or self.err_data == []: + if self.err_data is None or self.err_data.size == 0: self.res_err_data = np.ones(len(self.data)) else: self.res_err_data = copy.deepcopy(self.err_data)