Skip to content

Commit db58840

Browse files
authored
Merge pull request #1165 from silx-kit/numpy_shape
Use reshape/ravel to set numpy shape
2 parents 0931c62 + 65b091f commit db58840

File tree

103 files changed

+424
-425
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+424
-425
lines changed

src/PyMca5/PyMcaCore/PyMcaMatplotlibSave.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ def __postImage(self, ylim, filename):
658658
import sys
659659
if len(sys.argv) < 2:
660660
a=numpy.arange(1200.)
661-
a.shape = 20, 60
661+
a = a.reshape(20, 60)
662662
PyMcaMatplotlibSaveImage(a, "filename.png", colormap="rainbow")
663663
print("Image filename.png saved")
664664
else:

src/PyMca5/PyMcaCore/SpecFileDataSource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def getDataObject(self,key,selection=None):
543543
output.data[i,:] = mcaData
544544
#I have all the MCA data ready for image plot
545545
if selectiontype == 'STACK':
546-
output.data.shape = 1, npoints, -1
546+
output.data = output.data.reshape(1, npoints, -1)
547547
shape = output.data.shape
548548
for i in range(len(shape)):
549549
key = 'Dim_%d' % (i+1,)

src/PyMca5/PyMcaCore/StackBase.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def stackUpdated(self, positioners=None):
302302
numpy.add(self._stackImageData[i:i+step,:],
303303
numpy.sum(tmpData, 2),
304304
self._stackImageData[i:i+step,:])
305-
tmpData.shape = step*shape[1], shape[2]
305+
tmpData = tmpData.reshape(step*shape[1], shape[2])
306306
tmpMax = numpy.nanmax(tmpData, axis=0)
307307
numpy.add(mcaData0, numpy.sum(tmpData, 0), mcaData0)
308308
mcaMax =numpy.max([mcaMax, tmpMax], axis=0)
@@ -317,7 +317,7 @@ def stackUpdated(self, positioners=None):
317317
step = 1
318318
for i in range(shape[0]):
319319
tmpData = self._stack.data[i:i+step,:,:]
320-
tmpData.shape = tmpData.shape[1:]
320+
tmpData = tmpData.reshape(tmpData.shape[1:])
321321
numpy.add(self._stackImageData,
322322
tmpData,
323323
self._stackImageData)
@@ -748,7 +748,7 @@ def calculateMcaDataObject(self, normalize=False, mask=None, mcamax=False):
748748
row_dict[r].append(c)
749749
for r in row_list:
750750
tmpMcaData = self._stack.data[r:r + 1, row_dict[r], :]
751-
tmpMcaData.shape = -1, mcaData.shape[0]
751+
tmpMcaData = tmpMcaData.reshape(-1, mcaData.shape[0])
752752
mcaData += numpy.sum(tmpMcaData, axis=0, dtype=numpy.float64)
753753
if mcamax:
754754
mcaMax = numpy.max([mcaMax, numpy.max(tmpMcaData, axis=0)], axis=0)
@@ -793,7 +793,7 @@ def calculateMcaDataObject(self, normalize=False, mask=None, mcamax=False):
793793
row_dict[r].append(c)
794794
for r in row_list:
795795
tmpMcaData = self._stack.data[r:r + 1, row_dict[r], :]
796-
tmpMcaData.shape = -1, mcaData.shape[0]
796+
tmpMcaData = tmpMcaData.reshape(-1, mcaData.shape[0])
797797
mcaData += tmpMcaData.sum(axis=0, dtype=numpy.float64)
798798
if mcamax:
799799
mcaMax = numpy.max([mcaMax, numpy.max(tmpMcaData, axis=0)], axis=0)
@@ -832,7 +832,7 @@ def calculateMcaDataObject(self, normalize=False, mask=None, mcamax=False):
832832
if "McaLiveTime" in self._stack.info:
833833
selectedPixels = actualSelectionMask > 0
834834
liveTime = self._stack.info["McaLiveTime"][:]
835-
liveTime.shape = actualSelectionMask.shape
835+
liveTime = liveTime.reshape(actualSelectionMask.shape)
836836
liveTime = liveTime[selectedPixels].sum()
837837
if normalize:
838838
liveTime = liveTime / float(npixels)
@@ -940,7 +940,7 @@ def calculateROIImages(self, index1, index2, imiddle=None, energy=None):
940940
minImage = numpy.zeros(leftImage.shape, numpy.int32)
941941
for i in range(i1, i2):
942942
tmpData = self._stack.data[i]
943-
tmpData.shape = leftImage.shape
943+
tmpData = tmpData.reshape(leftImage.shape)
944944
if i == i1:
945945
minImageData = tmpData * 1.0
946946
maxImageData = tmpData * 1.0
@@ -974,7 +974,7 @@ def calculateROIImages(self, index1, index2, imiddle=None, energy=None):
974974
istep = 1
975975
for i in range(i1, i2):
976976
tmpData = self._stack.data[i:i + istep]
977-
tmpData.shape = roiImage.shape
977+
tmpData = tmpData.reshape(roiImage.shape)
978978
if i == i1:
979979
minImageData = tmpData * 1.0
980980
maxImageData = tmpData * 1.0

src/PyMca5/PyMcaGraph/Colormap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def applyColormap(data, colormap='gray', norm='linear', bounds=None):
130130

131131
if __name__ == "__main__":
132132
data = np.arange(1024 * 1024.)
133-
data.shape = 1024, -1
133+
data = data.reshape(1024, -1)
134134

135135
for colormap in COLORMAPS:
136136
pixmap, _ = applyColormap(data, colormap)

src/PyMca5/PyMcaGraph/backends/GLSupport/GLPlotCurve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ def prepare(self, isXLog, isYLog):
11631163

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

11691169
# Add one point before data: (x0, 0.)

src/PyMca5/PyMcaGraph/backends/GLSupport/PlotEvents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def prepareDrawingSignal(event, type_, points, parameters=None):
5050
eventDict['event'] = event
5151
eventDict['type'] = type_
5252
points = np.array(points, dtype=np.float32)
53-
points.shape = -1, 2
53+
points = points.reshape(-1, 2)
5454
eventDict['points'] = points
5555
eventDict['xdata'] = points[:, 0]
5656
eventDict['ydata'] = points[:, 1]

src/PyMca5/PyMcaGraph/backends/GLUTOpenGLBackend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def glutMouseMoved(self, xPixel, yPixel):
113113
w = Plot(None, backend=GLUTOpenGLBackend)
114114
size = 4096
115115
data = np.arange(float(size)*size, dtype=np.dtype(np.float32))
116-
data.shape = size, size
116+
data = data.reshape(size, size)
117117

118118
colormap = {'name': 'gray', 'normalization': 'linear',
119119
'autoscale': True, 'vmin': 0.0, 'vmax': 1.0,

src/PyMca5/PyMcaGraph/backends/MatplotlibBackend.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ def _emitDrawingSignal(self, event="drawingFinished"):
12171217
#print(dir(self._drawingPatch))
12181218
a = self._drawingPatch.get_xy()
12191219
ddict['points'] = numpy.array(a)
1220-
ddict['points'].shape = -1, 2
1220+
ddict['points'] = ddict['points'].reshape(-1, 2)
12211221
ddict['xdata'] = ddict['points'][:, 0]
12221222
ddict['ydata'] = ddict['points'][:, 1]
12231223
#print(numpyvstack(a))
@@ -1751,8 +1751,8 @@ def addItem(self, x, y, legend, info=None, replace=False, replot=True, **kw):
17511751
if fill:
17521752
item.set_hatch('.')
17531753
elif shape in ['polygon']:
1754-
xView.shape = 1, -1
1755-
yView.shape = 1, -1
1754+
xView = xView.reshape(1, -1)
1755+
yView = yView.reshape(1, -1)
17561756
item = Polygon(numpyvstack((xView, yView)).T,
17571757
closed=True,
17581758
fill=False,
@@ -2858,7 +2858,7 @@ def main(parent=None):
28582858
w.replot()
28592859
#w.invertYAxis(True)
28602860
data = numpy.arange(1000.*1000)
2861-
data.shape = 10000,100
2861+
data = data.reshape(10000, 100)
28622862
#plot.replot()
28632863
#w.invertYAxis(True)
28642864
#w.replot()

src/PyMca5/PyMcaGraph/backends/OSMesaGLBackend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def getWidgetHandle(self):
251251

252252
size = 1024
253253
data = np.arange(float(size)*size, dtype=np.uint16)
254-
data.shape = size, size
254+
data = data.reshape(size, size)
255255

256256
colormap = {'name': 'gray', 'normalization': 'linear',
257257
'autoscale': True, 'vmin': 0.0, 'vmax': 1.0,

src/PyMca5/PyMcaGraph/backends/OpenGLBackend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def resizeGL(self, width, height):
152152

153153
size = 4096
154154
data = np.arange(float(size)*size, dtype=np.dtype(np.float32))
155-
data.shape = size, size
155+
data = data.reshape(size, size)
156156

157157
colormap = {'name': 'gray', 'normalization': 'linear',
158158
'autoscale': True, 'vmin': 0.0, 'vmax': 1.0,

0 commit comments

Comments
 (0)