Skip to content

Commit

Permalink
Use asarray
Browse files Browse the repository at this point in the history
  • Loading branch information
vasole committed May 7, 2024
1 parent 259a6bf commit 118f495
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions PyMca5/PyMcaIO/JcampReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)"]:
Expand Down
4 changes: 2 additions & 2 deletions PyMca5/PyMcaMath/ImageListStats.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions PyMca5/PyMcaMath/SimpleMath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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])
Expand Down
8 changes: 4 additions & 4 deletions PyMca5/PyMcaMath/fitting/Gefit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions PyMca5/PyMcaMath/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions PyMca5/PyMcaMath/mva/KMeansModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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):
Expand All @@ -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,
Expand Down

0 comments on commit 118f495

Please sign in to comment.