Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PyMca5/PyMcaCore/PyMcaMatplotlibSave.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def __postImage(self, ylim, filename):
import sys
if len(sys.argv) < 2:
a=numpy.arange(1200.)
a.shape = 20, 60
a = a.reshape(20, 60)
PyMcaMatplotlibSaveImage(a, "filename.png", colormap="rainbow")
print("Image filename.png saved")
else:
Expand Down
2 changes: 1 addition & 1 deletion src/PyMca5/PyMcaCore/SpecFileDataSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def getDataObject(self,key,selection=None):
output.data[i,:] = mcaData
#I have all the MCA data ready for image plot
if selectiontype == 'STACK':
output.data.shape = 1, npoints, -1
output.data = output.data.reshape(1, npoints, -1)
shape = output.data.shape
for i in range(len(shape)):
key = 'Dim_%d' % (i+1,)
Expand Down
14 changes: 7 additions & 7 deletions src/PyMca5/PyMcaCore/StackBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def stackUpdated(self, positioners=None):
numpy.add(self._stackImageData[i:i+step,:],
numpy.sum(tmpData, 2),
self._stackImageData[i:i+step,:])
tmpData.shape = step*shape[1], shape[2]
tmpData = tmpData.reshape(step*shape[1], shape[2])
Copy link
Collaborator

@woutdenolf woutdenolf Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I did not know that elements of the shape parameter can be passed in as separate arguments.

https://numpy.org/devdocs/reference/generated/numpy.ndarray.reshape.html

FYI The free numpy.reshape function only accepts a tuple.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but you did it in the suggestion for issue #1162

New pattern using ndarray.reshape
arr = numpy.zeros((1,3,4));arr = arr.reshape(-1, 6);print(arr.shape)
(2, 6)

and to be concistent between
arr.reshape(X, Y) + arr.reshape(*tuple)
or
arr.reshape((X, Y)) + arr.reshape(tuple)
I chose 1st option

Copy link
Collaborator

@woutdenolf woutdenolf Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. I just didn't know before. I've only used the free numpy.reshape until I looked at the easiest way to refactor setting shape.

tmpMax = numpy.nanmax(tmpData, axis=0)
numpy.add(mcaData0, numpy.sum(tmpData, 0), mcaData0)
mcaMax =numpy.max([mcaMax, tmpMax], axis=0)
Expand All @@ -317,7 +317,7 @@ def stackUpdated(self, positioners=None):
step = 1
for i in range(shape[0]):
tmpData = self._stack.data[i:i+step,:,:]
tmpData.shape = tmpData.shape[1:]
tmpData = tmpData.reshape(tmpData.shape[1:])
numpy.add(self._stackImageData,
tmpData,
self._stackImageData)
Expand Down Expand Up @@ -748,7 +748,7 @@ def calculateMcaDataObject(self, normalize=False, mask=None, mcamax=False):
row_dict[r].append(c)
for r in row_list:
tmpMcaData = self._stack.data[r:r + 1, row_dict[r], :]
tmpMcaData.shape = -1, mcaData.shape[0]
tmpMcaData = tmpMcaData.reshape(-1, mcaData.shape[0])
mcaData += numpy.sum(tmpMcaData, axis=0, dtype=numpy.float64)
if mcamax:
mcaMax = numpy.max([mcaMax, numpy.max(tmpMcaData, axis=0)], axis=0)
Expand Down Expand Up @@ -793,7 +793,7 @@ def calculateMcaDataObject(self, normalize=False, mask=None, mcamax=False):
row_dict[r].append(c)
for r in row_list:
tmpMcaData = self._stack.data[r:r + 1, row_dict[r], :]
tmpMcaData.shape = -1, mcaData.shape[0]
tmpMcaData = tmpMcaData.reshape(-1, mcaData.shape[0])
mcaData += tmpMcaData.sum(axis=0, dtype=numpy.float64)
if mcamax:
mcaMax = numpy.max([mcaMax, numpy.max(tmpMcaData, axis=0)], axis=0)
Expand Down Expand Up @@ -832,7 +832,7 @@ def calculateMcaDataObject(self, normalize=False, mask=None, mcamax=False):
if "McaLiveTime" in self._stack.info:
selectedPixels = actualSelectionMask > 0
liveTime = self._stack.info["McaLiveTime"][:]
liveTime.shape = actualSelectionMask.shape
liveTime = liveTime.reshape(actualSelectionMask.shape)
liveTime = liveTime[selectedPixels].sum()
if normalize:
liveTime = liveTime / float(npixels)
Expand Down Expand Up @@ -940,7 +940,7 @@ def calculateROIImages(self, index1, index2, imiddle=None, energy=None):
minImage = numpy.zeros(leftImage.shape, numpy.int32)
for i in range(i1, i2):
tmpData = self._stack.data[i]
tmpData.shape = leftImage.shape
tmpData = tmpData.reshape(leftImage.shape)
if i == i1:
minImageData = tmpData * 1.0
maxImageData = tmpData * 1.0
Expand Down Expand Up @@ -974,7 +974,7 @@ def calculateROIImages(self, index1, index2, imiddle=None, energy=None):
istep = 1
for i in range(i1, i2):
tmpData = self._stack.data[i:i + istep]
tmpData.shape = roiImage.shape
tmpData = tmpData.reshape(roiImage.shape)
if i == i1:
minImageData = tmpData * 1.0
maxImageData = tmpData * 1.0
Expand Down
2 changes: 1 addition & 1 deletion src/PyMca5/PyMcaGraph/Colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def applyColormap(data, colormap='gray', norm='linear', bounds=None):

if __name__ == "__main__":
data = np.arange(1024 * 1024.)
data.shape = 1024, -1
data = data.reshape(1024, -1)

for colormap in COLORMAPS:
pixmap, _ = applyColormap(data, colormap)
Expand Down
2 changes: 1 addition & 1 deletion src/PyMca5/PyMcaGraph/backends/GLSupport/GLPlotCurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ def prepare(self, isXLog, isYLog):

if self.fill is not None:
xData = self.xData[:]
xData.shape = xData.size, 1
xData = xData.reshape(xData.size, 1)
zero = np.array((1e-32,), dtype=self.yData.dtype)

# Add one point before data: (x0, 0.)
Expand Down
2 changes: 1 addition & 1 deletion src/PyMca5/PyMcaGraph/backends/GLSupport/PlotEvents.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def prepareDrawingSignal(event, type_, points, parameters=None):
eventDict['event'] = event
eventDict['type'] = type_
points = np.array(points, dtype=np.float32)
points.shape = -1, 2
points = points.reshape(-1, 2)
eventDict['points'] = points
eventDict['xdata'] = points[:, 0]
eventDict['ydata'] = points[:, 1]
Expand Down
2 changes: 1 addition & 1 deletion src/PyMca5/PyMcaGraph/backends/GLUTOpenGLBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def glutMouseMoved(self, xPixel, yPixel):
w = Plot(None, backend=GLUTOpenGLBackend)
size = 4096
data = np.arange(float(size)*size, dtype=np.dtype(np.float32))
data.shape = size, size
data = data.reshape(size, size)

colormap = {'name': 'gray', 'normalization': 'linear',
'autoscale': True, 'vmin': 0.0, 'vmax': 1.0,
Expand Down
8 changes: 4 additions & 4 deletions src/PyMca5/PyMcaGraph/backends/MatplotlibBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ def _emitDrawingSignal(self, event="drawingFinished"):
#print(dir(self._drawingPatch))
a = self._drawingPatch.get_xy()
ddict['points'] = numpy.array(a)
ddict['points'].shape = -1, 2
ddict['points'] = ddict['points'].reshape(-1, 2)
ddict['xdata'] = ddict['points'][:, 0]
ddict['ydata'] = ddict['points'][:, 1]
#print(numpyvstack(a))
Expand Down Expand Up @@ -1751,8 +1751,8 @@ def addItem(self, x, y, legend, info=None, replace=False, replot=True, **kw):
if fill:
item.set_hatch('.')
elif shape in ['polygon']:
xView.shape = 1, -1
yView.shape = 1, -1
xView = xView.reshape(1, -1)
yView = yView.reshape(1, -1)
item = Polygon(numpyvstack((xView, yView)).T,
closed=True,
fill=False,
Expand Down Expand Up @@ -2858,7 +2858,7 @@ def main(parent=None):
w.replot()
#w.invertYAxis(True)
data = numpy.arange(1000.*1000)
data.shape = 10000,100
data = data.reshape(10000, 100)
#plot.replot()
#w.invertYAxis(True)
#w.replot()
Expand Down
2 changes: 1 addition & 1 deletion src/PyMca5/PyMcaGraph/backends/OSMesaGLBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def getWidgetHandle(self):

size = 1024
data = np.arange(float(size)*size, dtype=np.uint16)
data.shape = size, size
data = data.reshape(size, size)

colormap = {'name': 'gray', 'normalization': 'linear',
'autoscale': True, 'vmin': 0.0, 'vmax': 1.0,
Expand Down
2 changes: 1 addition & 1 deletion src/PyMca5/PyMcaGraph/backends/OpenGLBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def resizeGL(self, width, height):

size = 4096
data = np.arange(float(size)*size, dtype=np.dtype(np.float32))
data.shape = size, size
data = data.reshape(size, size)

colormap = {'name': 'gray', 'normalization': 'linear',
'autoscale': True, 'vmin': 0.0, 'vmax': 1.0,
Expand Down
2 changes: 1 addition & 1 deletion src/PyMca5/PyMcaGraph/ctools/_ctools/cython/Colormap.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def dataToRGBAColormap(data,
c_nanColorPtr,
&c_pixmap[0, 0])

pixmap.shape = data.shape + (4,)
pixmap = pixmap.reshape(data.shape + (4,))
return pixmap, (c_start, c_end)

def fastLog10(double value):
Expand Down
14 changes: 7 additions & 7 deletions src/PyMca5/PyMcaGraph/ctools/_ctools/test/testColormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def buildControlPixmap(data, colormap, start=None, end=None,
dtype=np.uint32)

pixmap = np.take(colormap, indices, axis=0)
pixmap.shape = data.shape + (4,)
pixmap = pixmap.reshape(data.shape + (4,))
return np.ascontiguousarray(pixmap)

@staticmethod
Expand Down Expand Up @@ -158,7 +158,7 @@ def buildSPSLUTRedPixmap(data, start=None, end=None, isLog10=False):
(start, end),
(0, 255),
1)
pixmap.shape = data.shape[0], data.shape[1], 4
pixmap = pixmap.reshape(data.shape[0], data.shape[1], 4)

return pixmap

Expand Down Expand Up @@ -188,8 +188,8 @@ def _testColormap(self, data, colormap, start, end, control=None,
# Only works with red colormap and even size
# as it needs 2D data
if len(data.shape) == 1:
data.shape = data.size // 2, -1
pixmap.shape = data.shape + (4,)
data = data.reshape(data.size // 2, -1)
pixmap = pixmap.reshape(data.shape + (4,))
control = self.buildSPSLUTRedPixmap(data, start, end, isLog10)
controlType = 'SPS LUT'

Expand Down Expand Up @@ -243,7 +243,7 @@ def testNoData(self):
for isLog10 in (False, True):
data = np.array((), dtype=dtype)
result = np.array((), dtype=np.uint8)
result.shape = 0, 4
result = result.reshape(0, 4)
duration = self._testColormap(data, self.COLORMAPS['red 256'],
None, None, result, isLog10)
self._log('No data', 'red 256', dtype, len(data), (None, None),
Expand Down Expand Up @@ -359,7 +359,7 @@ def test2DData(self):
# Increasing values
data = np.arange(size * size, dtype=dtype)
data = np.nan_to_num(data)
data.shape = size, size
data = data.reshape(size, size)
duration = self._testColormap(data, colormap,
start, end)

Expand Down Expand Up @@ -493,7 +493,7 @@ def test2DDataAllPositive(self):
# Increasing values
data = np.arange(size * size, dtype=dtype) + 1
data = np.nan_to_num(data)
data.shape = size, size
data = data.reshape(size, size)
duration = self._testColormap(data, colormap,
start, end,
isLog10=True)
Expand Down
2 changes: 1 addition & 1 deletion src/PyMca5/PyMcaGui/io/QEdfFileWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ def getPixmapFromData(self, data, colormap):
(colormap[2],colormap[3]),
(0,255), 1)

pixmap.shape = [data.shape[0], data.shape[1], 4]
pixmap = pixmap.reshape(data.shape[0], data.shape[1], 4)
if not goodData:
pixmap[finiteData < 1] = 255
return pixmap
Expand Down
2 changes: 1 addition & 1 deletion src/PyMca5/PyMcaGui/math/FFTAlignmentWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def __init__(self, parent=None):

def setDummyStack(self):
dummyStack = numpy.arange(2 * 128 *256)
dummyStack.shape = 2, 128, 256
dummyStack = dummyStack.reshape(2, 128, 256)
self.setStack(dummyStack, index=0)

def getParameters(self):
Expand Down
4 changes: 2 additions & 2 deletions src/PyMca5/PyMcaGui/math/NNMADialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ def _calculateSlot(self):
images, eigenvalues, eigenvectors = threadResult
except Exception:
if isinstance(data, numpy.ndarray):
self._data.shape = old_shape
self._data = self._data.reshape(*old_shape)
msg = qt.QMessageBox(self)
msg.setIcon(qt.QMessageBox.Critical)
msg.setText("%s" % sys.exc_info()[1])
msg.exec()
return
if isinstance(self._data, numpy.ndarray):
self._data.shape = old_shape
self._data = self._data.reshape(*old_shape)
_logger.debug("NNMA Elapsed = %s", time.time() - t0)
self.nnmaWindow.setPCAData(images,
eigenvalues,
Expand Down
14 changes: 7 additions & 7 deletions src/PyMca5/PyMcaGui/math/NNMAWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,15 @@ def updatePlot(self):
binning = int(self.binningCombo.currentText())
x = self._x * 1.0
y = self._y * 1.0
x.shape = 1, -1
y.shape = 1, -1
x = x.reshape(1, -1)
y = y.reshape(1, -1)
r, c = x.shape
x.shape = r, int(c / binning), binning
y.shape = r, int(c / binning), binning
x = x.reshape(r, int(c / binning), binning)
y = y.reshape(r, int(c / binning), binning)
x = x.sum(axis=-1, dtype=numpy.float32) / binning
y = y.sum(axis=-1, dtype=numpy.float32)
x.shape = -1
y.shape = -1
x = numpy.ravel(x)
y = numpy.ravel(y)
self._binnedX = x
self._binnedY = y
if self.graph:
Expand Down Expand Up @@ -411,7 +411,7 @@ def test():
app.lastWindowClosed.connect(app.quit)
container = NNMAWindow()
data = numpy.arange(20000)
data.shape = 2, 100, 100
data = data.reshape(2, 100, 100)
data[1, 0:100, 0:50] = 100
container.setPCAData(
data,
Expand Down
4 changes: 2 additions & 2 deletions src/PyMca5/PyMcaGui/math/PCADialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ def _calculateSlot(self):
images, eigenvalues, eigenvectors = threadResult
except Exception:
if isinstance(data, numpy.ndarray):
self._data.shape = old_shape
self._data = self._data.reshape(*old_shape)
msg = qt.QMessageBox(self)
msg.setIcon(qt.QMessageBox.Critical)
msg.setText("%s" % sys.exc_info()[1])
msg.exec()
return
if isinstance(self._data, numpy.ndarray):
self._data.shape = old_shape
self._data = self._data.reshape(old_shape)
_logger.debug("PCA Elapsed = %s", time.time() - t0)
methodlabel = pcaParameters.get('methodlabel', "")
imagenames = None
Expand Down
14 changes: 7 additions & 7 deletions src/PyMca5/PyMcaGui/math/PCAWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,15 @@ def updatePlot(self):
binning = int(self.binningCombo.currentText())
x = self._x * 1.0
y = self._y * 1.0
x.shape = 1, -1
y.shape = 1, -1
x = x.reshape(1, -1)
y = y.reshape(1, -1)
r, c = x.shape
x.shape = r, int(c / binning), binning
y.shape = r, int(c / binning), binning
x = x.reshape(r, int(c / binning), binning)
y = y.reshape(r, int(c / binning), binning)
x = x.sum(axis=-1, dtype=numpy.float32) / binning
y = y.sum(axis=-1, dtype=numpy.float32)
x.shape = -1
y.shape = -1
x = numpy.ravel(x)
y = numpy.ravel(y)
self._binnedX = x
self._binnedY = y
self.graph.addCurve(x, y, legend=self._legend, replace=True)
Expand Down Expand Up @@ -712,7 +712,7 @@ def test():
app.lastWindowClosed.connect(app.quit)
container = PCAWindow()
data = numpy.arange(20000)
data.shape = 2, 100, 100
data = data.reshape(2, 100, 100)
data[1, 0:100, 0:50] = 100
container.setPCAData(
data,
Expand Down
2 changes: 1 addition & 1 deletion src/PyMca5/PyMcaGui/math/SIFTAlignmentWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def __init__(self, parent=None):

def setDummyStack(self):
dummyStack = numpy.arange(2 * 128 *256)
dummyStack.shape = 2, 128, 256
dummyStack = dummyStack.reshape(2, 128, 256)
self.setStack(dummyStack, index=0)

def getParameters(self):
Expand Down
Loading