From 118f495314cfa65db8dac0d7cdd146db63bff425 Mon Sep 17 00:00:00 2001 From: "V. Armando Sole" Date: Tue, 7 May 2024 14:14:23 +0200 Subject: [PATCH] Use asarray --- PyMca5/PyMcaIO/JcampReader.py | 4 ++-- PyMca5/PyMcaMath/ImageListStats.py | 4 ++-- PyMca5/PyMcaMath/SimpleMath.py | 8 ++++---- PyMca5/PyMcaMath/fitting/Gefit.py | 8 ++++---- PyMca5/PyMcaMath/linalg.py | 8 ++++---- PyMca5/PyMcaMath/mva/KMeansModule.py | 8 ++++---- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/PyMca5/PyMcaIO/JcampReader.py b/PyMca5/PyMcaIO/JcampReader.py index 888003738..169999781 100644 --- a/PyMca5/PyMcaIO/JcampReader.py +++ b/PyMca5/PyMcaIO/JcampReader.py @@ -2,7 +2,7 @@ # # The PyMca X-Ray Fluorescence Toolkit # -# Copyright (c) 2004-2023 European Synchrotron Radiation Facility +# Copyright (c) 2004-2024 European Synchrotron Radiation Facility # # This file is part of the PyMca X-ray Fluorescence Toolkit developed at # the ESRF. @@ -231,7 +231,7 @@ def parseData(self, dataLines): yValues = values[1::2] xFactor = float(self.info.get("XFACTOR", 1.0)) yFactor = float(self.info.get("YFACTOR", 1.0)) - return x * xFactor, numpy.array(yValues, copy=False) * yFactor + return x * xFactor, numpy.asarray(yValues) * yFactor def parseDataOld(self, dataLines): if self.info['XYDATA'].upper().strip() not in ["(X++(Y..Y))", "(XY..XY)"]: diff --git a/PyMca5/PyMcaMath/ImageListStats.py b/PyMca5/PyMcaMath/ImageListStats.py index a564ae8cf..4535efa31 100644 --- a/PyMca5/PyMcaMath/ImageListStats.py +++ b/PyMca5/PyMcaMath/ImageListStats.py @@ -1,5 +1,5 @@ # /*########################################################################## -# Copyright (C) 2023 European Synchrotron Radiation Facility +# Copyright (C) 2023-2024 European Synchrotron Radiation Facility # # This file is part of the PyMca X-ray Fluorescence Toolkit developed at # the ESRF. @@ -53,7 +53,7 @@ def arrayListMeanRatioAndMedianRatio(imageList, mask=None): goodIndex = numpy.isfinite(image0) & numpy.isfinite(image1) image0 = image0[goodIndex] image1 = image1[goodIndex] - mean_ratio = image0 / numpy.array(image1, copy=False, dtype=numpy.float64) + mean_ratio = image0 / numpy.asarray(image1, dtype=numpy.float64) goodIndex = numpy.isfinite(mean_ratio) mean_ratio = mean_ratio[goodIndex] median_ratio = numpy.median(mean_ratio) diff --git a/PyMca5/PyMcaMath/SimpleMath.py b/PyMca5/PyMcaMath/SimpleMath.py index e538f49f8..e663fc7c5 100644 --- a/PyMca5/PyMcaMath/SimpleMath.py +++ b/PyMca5/PyMcaMath/SimpleMath.py @@ -2,7 +2,7 @@ # # The PyMca X-Ray Fluorescence Toolkit # -# Copyright (c) 2004-2022 European Synchrotron Radiation Facility +# Copyright (c) 2004-2024 European Synchrotron Radiation Facility # # This file is part of the PyMca X-ray Fluorescence Toolkit developed at # the ESRF. @@ -44,8 +44,8 @@ class SimpleMath(object): "SG smoothed 5 point"] def derivate(self,xdata,ydata, xlimits=None, option=None): - x=numpy.array(xdata, copy=False, dtype=numpy.float64) - y=numpy.array(ydata, copy=False, dtype=numpy.float64) + x=numpy.asarray(xdata, dtype=numpy.float64) + y=numpy.asarray(ydata, dtype=numpy.float64) if xlimits is not None: i1=numpy.nonzero((xdata>=xlimits[0])&\ (xdata<=xlimits[1]))[0] @@ -211,7 +211,7 @@ def smooth(self, *var, **kw): else: ydata=self.y f=[0.25,0.5,0.25] - result=numpy.array(ydata, copy=False, dtype=numpy.float64) + result=numpy.asarray(ydata, dtype=numpy.float64) if len(result) > 1: result[1:-1]=numpy.convolve(result,f,mode=0) result[0]=0.5*(result[0]+result[1]) diff --git a/PyMca5/PyMcaMath/fitting/Gefit.py b/PyMca5/PyMcaMath/fitting/Gefit.py index c45a7e359..caa01de4d 100644 --- a/PyMca5/PyMcaMath/fitting/Gefit.py +++ b/PyMca5/PyMcaMath/fitting/Gefit.py @@ -2,7 +2,7 @@ # # The PyMca X-Ray Fluorescence Toolkit # -# Copyright (c) 2004-2016 European Synchrotron Radiation Facility +# Copyright (c) 2004-2024 European Synchrotron Radiation Facility # # This file is part of the PyMca X-ray Fluorescence Toolkit developed at # the ESRF by the Software group. @@ -107,7 +107,7 @@ def LeastSquaresFit(model, parameters0, data=None, maxiter = 100,constrains=None """ if constrains is None: constrains = [] - parameters = numpy.array(parameters0, dtype=numpy.float64, copy=False) + parameters = numpy.asarray(parameters0, dtype=numpy.float64) if linear is None:linear=0 if deltachi is None: deltachi = 0.01 @@ -212,7 +212,7 @@ def LinearLeastSquaresFit(model0,parameters0,data0,maxiter, raise ValueError("Linear fit cannot handle quoted constraint") # make a local copy of the function for an easy speed up ... model = model0 - parameters = numpy.array(parameters0, dtype=numpy.float64, copy=False) + parameters = numpy.asarray(parameters0, dtype=numpy.float64) if data0 is not None: selfx = numpy.array([x[0] for x in data0]) selfy = numpy.array([x[1] for x in data0]) @@ -326,7 +326,7 @@ def RestreinedLeastSquaresFit(model0,parameters0,data0,maxiter, raise ValueError("Unknown constraint %s" % constrains[0][i]) # make a local copy of the function for an easy speed up ... model = model0 - parameters = numpy.array(parameters0, dtype=numpy.float64, copy=False) + parameters = numpy.asarray(parameters0, dtype=numpy.float64) if ONED: data = numpy.array(data0) x = data[1:2,0] diff --git a/PyMca5/PyMcaMath/linalg.py b/PyMca5/PyMcaMath/linalg.py index 8006de5a7..d7a887649 100644 --- a/PyMca5/PyMcaMath/linalg.py +++ b/PyMca5/PyMcaMath/linalg.py @@ -2,7 +2,7 @@ # # The PyMca X-Ray Fluorescence Toolkit # -# Copyright (c) 2004-2023 European Synchrotron Radiation Facility +# Copyright (c) 2004-2024 European Synchrotron Radiation Facility # # This file is part of the PyMca X-ray Fluorescence Toolkit developed at # the ESRF. @@ -229,8 +229,8 @@ def lstsq(a, b, rcond=None, sigma_b=None, weight=False, >>> plt.show() """ - a = numpy.array(a, dtype=numpy.float64, copy=False) - b = numpy.array(b, dtype=numpy.float64, copy=False) + a = numpy.asarray(a, dtype=numpy.float64) + b = numpy.asarray(b, dtype=numpy.float64) a_shape = a.shape b_shape = b.shape original = b_shape @@ -250,7 +250,7 @@ def lstsq(a, b, rcond=None, sigma_b=None, weight=False, if weight: if sigma_b is not None: # experimental uncertainties provided these are the ones to use (if any) - w = numpy.abs(numpy.array(sigma_b, dtype=numpy.float64, copy=False)) + w = numpy.abs(numpy.asarray(sigma_b, dtype=numpy.float64)) w = w + numpy.equal(w, 0) if w.size == b_shape[0]: # same uncertainty for every spectrum diff --git a/PyMca5/PyMcaMath/mva/KMeansModule.py b/PyMca5/PyMcaMath/mva/KMeansModule.py index 79dbf9ad8..db4a870bc 100644 --- a/PyMca5/PyMcaMath/mva/KMeansModule.py +++ b/PyMca5/PyMcaMath/mva/KMeansModule.py @@ -2,7 +2,7 @@ # # The PyMca X-Ray Fluorescence Toolkit # -# Copyright (c) 2020-2023 European Synchrotron Radiation Facility +# Copyright (c) 2020-2024 European Synchrotron Radiation Facility # # This file is part of the PyMca X-ray Fluorescence Toolkit developed at # the ESRF. @@ -64,7 +64,7 @@ def _labelCythonKMeans(x, k): labels, means, iterations, converged = _kmeans.kmeans(x, k) return { - "labels": numpy.array(labels, dtype=numpy.int32, copy=False), + "labels": numpy.asarray(labels, dtype=numpy.int32), "means": means, "iterations": iterations, "converged": converged, @@ -79,7 +79,7 @@ def _labelMdp(x, k): classifier.train(x[i : i + 1]) # classifier.train(x) labels = classifier.label(x) - return {"labels": numpy.array(labels, dtype=numpy.int32, copy=False)} + return {"labels": numpy.asarray(labels, dtype=numpy.int32)} def _labelScikitLearn(x, k): @@ -91,7 +91,7 @@ def _labelScikitLearn(x, k): # labels = km.predict(x) converged = len(km.cluster_centers_) == len(labels) return { - "labels": numpy.array(labels, dtype=numpy.int32, copy=False), + "labels": numpy.asarray(labels, dtype=numpy.int32), "means": km.cluster_centers_, "iterations": km.n_iter_, "converged": converged,