From b5ffe91c743eb7c951028fa1cce308af4ffef7c6 Mon Sep 17 00:00:00 2001 From: Scott Talbert Date: Thu, 30 Dec 2021 14:17:23 -0500 Subject: [PATCH] wx.lib.floatcanvas: replace deprecated use of numpy float --- wx/lib/floatcanvas/FCObjects.py | 86 ++++++++++++++-------------- wx/lib/floatcanvas/FloatCanvas.py | 40 ++++++------- wx/lib/floatcanvas/Utilities/BBox.py | 16 +++--- 3 files changed, 71 insertions(+), 71 deletions(-) diff --git a/wx/lib/floatcanvas/FCObjects.py b/wx/lib/floatcanvas/FCObjects.py index c11eef10..624b03e0 100644 --- a/wx/lib/floatcanvas/FCObjects.py +++ b/wx/lib/floatcanvas/FCObjects.py @@ -566,7 +566,7 @@ class XYObjectMixin: array of shape (2, ) """ - Delta = N.asarray(Delta, N.float) + Delta = N.asarray(Delta, float) self.XY += Delta self.BoundingBox += Delta @@ -579,7 +579,7 @@ class XYObjectMixin: self.BoundingBox = BBox.asBBox((self.XY, self.XY)) def SetPoint(self, xy): - xy = N.array(xy, N.float) + xy = N.array(xy, float) xy.shape = (2,) self.XY = xy @@ -603,7 +603,7 @@ class PointsObjectMixin: array of shape (2, ) """ - Delta = N.asarray(Delta, N.float) + Delta = N.asarray(Delta, float) Delta.shape = (2,) self.Points += Delta self.BoundingBox += Delta @@ -637,10 +637,10 @@ class PointsObjectMixin: """ if copy: - self.Points = N.array(Points, N.float) + self.Points = N.array(Points, float) self.Points.shape = (-1, 2) # Make sure it is a NX2 array, even if there is only one point else: - self.Points = N.asarray(Points, N.float) + self.Points = N.asarray(Points, float) self.CalcBoundingBox() @@ -677,7 +677,7 @@ class Polygon(PointsObjectMixin, LineAndFillMixin, DrawObject): """ DrawObject.__init__(self, InForeground) - self.Points = N.array(Points ,N.float) # this DOES need to make a copy + self.Points = N.array(Points ,float) # this DOES need to make a copy self.CalcBoundingBox() self.LineColor = LineColor @@ -728,7 +728,7 @@ class Line(PointsObjectMixin, LineOnlyMixin, DrawObject): DrawObject.__init__(self, InForeground) - self.Points = N.array(Points,N.float) + self.Points = N.array(Points,float) self.CalcBoundingBox() self.LineColor = LineColor @@ -805,7 +805,7 @@ class Arrow(XYObjectMixin, LineOnlyMixin, DrawObject): DrawObject.__init__(self, InForeground) - self.XY = N.array(XY, N.float) + self.XY = N.array(XY, float) self.XY.shape = (2,) # Make sure it is a length 2 vector self.Length = Length self.Direction = float(Direction) @@ -865,10 +865,10 @@ class Arrow(XYObjectMixin, LineOnlyMixin, DrawObject): ## theta = (self.Direction-90.0) * N.pi / 180 ## ArrowPoints = N.array( ( (0, L, L - S*N.cos(phi),L, L - S*N.cos(phi) ), ## (0, 0, S*N.sin(phi), 0, -S*N.sin(phi) ) ), -## N.float ) +## float ) ## RotationMatrix = N.array( ( ( N.cos(theta), -N.sin(theta) ), ## ( N.sin(theta), N.cos(theta) ) ), -## N.float +## float ## ) ## ArrowPoints = N.matrixmultiply(RotationMatrix, ArrowPoints) ## self.ArrowPoints = N.transpose(ArrowPoints) @@ -884,7 +884,7 @@ class Arrow(XYObjectMixin, LineOnlyMixin, DrawObject): (N.cos(theta - phi), -N.sin(theta - phi) ), (0,0), (N.cos(theta + phi), -N.sin(theta + phi) ), - ), N.float ) + ), float ) AP *= S shift = (-L*N.cos(theta), L*N.sin(theta) ) AP[1:,:] += shift @@ -934,7 +934,7 @@ class ArrowLine(PointsObjectMixin, LineOnlyMixin, DrawObject): DrawObject.__init__(self, InForeground) - self.Points = N.asarray(Points,N.float) + self.Points = N.asarray(Points,float) self.Points.shape = (-1,2) # Make sure it is a NX2 array, even if there is only one point self.ArrowHeadSize = ArrowHeadSize self.ArrowHeadAngle = float(ArrowHeadAngle) @@ -956,7 +956,7 @@ class ArrowLine(PointsObjectMixin, LineOnlyMixin, DrawObject): phi = self.ArrowHeadAngle * N.pi / 360 Points = self.Points n = Points.shape[0] - self.ArrowPoints = N.zeros((n-1, 3, 2), N.float) + self.ArrowPoints = N.zeros((n-1, 3, 2), float) for i in range(n-1): dx, dy = self.Points[i] - self.Points[i+1] theta = N.arctan2(dy, dx) @@ -965,7 +965,7 @@ class ArrowLine(PointsObjectMixin, LineOnlyMixin, DrawObject): (0,0), (N.cos(theta + phi), -N.sin(theta + phi)) ), - N.float ) + float ) self.ArrowPoints[i,:,:] = AP self.ArrowPoints *= S @@ -1016,7 +1016,7 @@ class PointSet(PointsObjectMixin, ColorOnlyMixin, DrawObject): """ DrawObject.__init__(self, InForeground) - self.Points = N.array(Points,N.float) + self.Points = N.array(Points,float) self.Points.shape = (-1,2) # Make sure it is a NX2 array, even if there is only one point self.CalcBoundingBox() self.Diameter = Diameter @@ -1117,7 +1117,7 @@ class Point(XYObjectMixin, ColorOnlyMixin, DrawObject): DrawObject.__init__(self, InForeground) - self.XY = N.array(XY, N.float) + self.XY = N.array(XY, float) self.XY.shape = (2,) # Make sure it is a length 2 vector self.CalcBoundingBox() self.SetColor(Color) @@ -1174,7 +1174,7 @@ class SquarePoint(XYObjectMixin, ColorOnlyMixin, DrawObject): """ DrawObject.__init__(self, InForeground) - self.XY = N.array(Point, N.float) + self.XY = N.array(Point, float) self.XY.shape = (2,) # Make sure it is a length 2 vector self.CalcBoundingBox() self.SetColor(Color) @@ -1262,16 +1262,16 @@ class RectEllipse(XYObjectMixin, LineAndFillMixin, DrawObject): :param `WH`: a tuple with the Width and Height for the object """ - self.XY = N.array( XY, N.float) + self.XY = N.array( XY, float) self.XY.shape = (2,) - self.WH = N.array( WH, N.float) + self.WH = N.array( WH, float) self.WH.shape = (2,) self.CalcBoundingBox() def CalcBoundingBox(self): """Calculate the bounding box.""" # you need this in case Width or Height are negative - corners = N.array((self.XY, (self.XY + self.WH) ), N.float) + corners = N.array((self.XY, (self.XY + self.WH) ), float) self.BoundingBox = BBox.fromPoints(corners) if self._Canvas: self._Canvas.BoundingBoxDirty = True @@ -1329,8 +1329,8 @@ class Circle(XYObjectMixin, LineAndFillMixin, DrawObject): """ DrawObject.__init__(self, InForeground) - self.XY = N.array(XY, N.float) - self.WH = N.array((Diameter/2, Diameter/2), N.float) # just to keep it compatible with others + self.XY = N.array(XY, float) + self.WH = N.array((Diameter/2, Diameter/2), float) # just to keep it compatible with others self.CalcBoundingBox() self.LineColor = LineColor @@ -1355,7 +1355,7 @@ class Circle(XYObjectMixin, LineAndFillMixin, DrawObject): :param integer `Diameter`: the diameter for the object """ - self.WH = N.array((Diameter/2, Diameter/2), N.float) # just to keep it compatible with others + self.WH = N.array((Diameter/2, Diameter/2), float) # just to keep it compatible with others def CalcBoundingBox(self): """Calculate the bounding box of the object.""" @@ -1633,7 +1633,7 @@ class ScaledText(TextObjectMixin, DrawObject): DrawObject.__init__(self,InForeground) self.String = String - self.XY = N.array( XY, N.float) + self.XY = N.array( XY, float) self.XY.shape = (2,) self.Size = Size self.Color = Color @@ -1810,7 +1810,7 @@ class ScaledTextBox(TextObjectMixin, DrawObject): """ DrawObject.__init__(self,InForeground) - self.XY = N.array(Point, N.float) + self.XY = N.array(Point, float) self.Size = Size self.Color = Color self.BackgroundColor = BackgroundColor @@ -1926,7 +1926,7 @@ class ScaledTextBox(TextObjectMixin, DrawObject): SpaceWidth = dc.GetTextExtent(" ")[0] LineHeight = TextHeight * self.LineSpacing - LineWidths = N.zeros((len(self.Strings),), N.float) + LineWidths = N.zeros((len(self.Strings),), float) y = 0 Words = [] AllLinePoints = [] @@ -1934,7 +1934,7 @@ class ScaledTextBox(TextObjectMixin, DrawObject): for i, s in enumerate(self.Strings): LineWidths[i] = 0 LineWords = s.split(" ") - LinePoints = N.zeros((len(LineWords),2), N.float) + LinePoints = N.zeros((len(LineWords),2), float) for j, word in enumerate(LineWords): if j > 0: LineWidths[i] += SpaceWidth @@ -1951,7 +1951,7 @@ class ScaledTextBox(TextObjectMixin, DrawObject): BoxWidth = TextWidth * ScaleFactor + 2*self.PadSize else: # use the defined Width BoxWidth = self.Width - Points = N.zeros((0,2), N.float) + Points = N.zeros((0,2), float) for i, LinePoints in enumerate(AllLinePoints): ## Scale to World Coords. @@ -2225,7 +2225,7 @@ class ScaledBitmap2(TextObjectMixin, DrawObject, ): elif type(Bitmap) == wx.Image: self.Image = Bitmap - self.XY = N.array(XY, N.float) + self.XY = N.array(XY, float) self.Height = Height (self.bmpWidth, self.bmpHeight) = float(self.Image.GetWidth()), float(self.Image.GetHeight()) self.bmpWH = N.array((self.bmpWidth, self.bmpHeight), N.int32) @@ -2233,7 +2233,7 @@ class ScaledBitmap2(TextObjectMixin, DrawObject, ): if Width is None: self.BmpScale = float(self.bmpHeight) / Height self.Width = self.bmpWidth / self.BmpScale - self.WH = N.array((self.Width, Height), N.float) + self.WH = N.array((self.Width, Height), float) ##fixme: should this have a y = -1 to shift to y-up? self.BmpScale = self.bmpWH / self.WH @@ -2388,7 +2388,7 @@ class DotGrid: """ def __init__(self, Spacing, Size = 2, Color = "Black", Cross=False, CrossThickness = 1): - self.Spacing = N.array(Spacing, N.float) + self.Spacing = N.array(Spacing, float) self.Spacing.shape = (2,) self.Size = Size self.Color = Color @@ -2406,7 +2406,7 @@ class DotGrid: ##fixme: this could use vstack or something with numpy x = N.arange(minx, maxx+Spacing[0], Spacing[0]) # making sure to get the last point y = N.arange(miny, maxy+Spacing[1], Spacing[1]) # an extra is OK - Points = N.zeros((len(y), len(x), 2), N.float) + Points = N.zeros((len(y), len(x), 2), float) x.shape = (1,-1) y.shape = (-1,1) Points[:,:,0] += x @@ -2501,12 +2501,12 @@ class Arc(XYObjectMixin, LineAndFillMixin, DrawObject): XY = [minX,minY] WH = [maxX-minX,maxY-minY] - self.XY = N.asarray( XY, N.float).reshape((2,)) - self.WH = N.asarray( WH, N.float).reshape((2,)) + self.XY = N.asarray( XY, float).reshape((2,)) + self.WH = N.asarray( WH, float).reshape((2,)) - self.StartXY = N.asarray(StartXY, N.float).reshape((2,)) - self.CenterXY = N.asarray(CenterXY, N.float).reshape((2,)) - self.EndXY = N.asarray(EndXY, N.float).reshape((2,)) + self.StartXY = N.asarray(StartXY, float).reshape((2,)) + self.CenterXY = N.asarray(CenterXY, float).reshape((2,)) + self.EndXY = N.asarray(EndXY, float).reshape((2,)) #self.BoundingBox = array((self.XY, (self.XY + self.WH)), Float) self.CalcBoundingBox() @@ -2532,7 +2532,7 @@ class Arc(XYObjectMixin, LineAndFillMixin, DrawObject): """ - Delta = N.asarray(Delta, N.float) + Delta = N.asarray(Delta, float) self.XY += Delta self.StartXY += Delta self.CenterXY += Delta @@ -2555,7 +2555,7 @@ class Arc(XYObjectMixin, LineAndFillMixin, DrawObject): def CalcBoundingBox(self): """Calculate the bounding box.""" self.BoundingBox = BBox.asBBox( N.array((self.XY, (self.XY + self.WH) ), - N.float) ) + float) ) if self._Canvas: self._Canvas.BoundingBoxDirty = True @@ -2604,9 +2604,9 @@ class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject): """ DrawObject.__init__(self, InForeground) - self.XY = N.asarray(XY, N.float).reshape( (2,) ) + self.XY = N.asarray(XY, float).reshape( (2,) ) self.Diameter = Diameter - self.Values = N.asarray(Values, dtype=N.float).reshape((-1,1)) + self.Values = N.asarray(Values, dtype=float).reshape((-1,1)) if FillColors is None: FillColors = self.DefaultColorList[:len(Values)] if FillStyles is None: @@ -2647,7 +2647,7 @@ class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject): :param `Values`: sequence of values you want to use for the chart """ - Values = N.asarray(Values, dtype=N.float).reshape((-1,1)) + Values = N.asarray(Values, dtype=float).reshape((-1,1)) self.Values = Values self.CalculatePoints() @@ -2684,7 +2684,7 @@ class PieChart(XYObjectMixin, LineOnlyMixin, DrawObject): Diameter = ScaleWorldToPixel( (self.Diameter,self.Diameter) )[0] else: Diameter = self.Diameter - WH = N.array((Diameter,Diameter), dtype = N.float) + WH = N.array((Diameter,Diameter), dtype = float) Corner = CenterXY - (WH / 2) dc.SetPen(self.Pen) for i, brush in enumerate(self.Brushes): diff --git a/wx/lib/floatcanvas/FloatCanvas.py b/wx/lib/floatcanvas/FloatCanvas.py index 66fe87ae..5d3abc44 100644 --- a/wx/lib/floatcanvas/FloatCanvas.py +++ b/wx/lib/floatcanvas/FloatCanvas.py @@ -210,12 +210,12 @@ class FloatCanvas(wx.Panel): self.BoundingBoxDirty = False self.MinScale = None self.MaxScale = None - self.ViewPortCenter= N.array( (0,0), N.float) + self.ViewPortCenter= N.array( (0,0), float) self.SetProjectionFun(None) - self.MapProjectionVector = N.array( (1,1), N.float) # No Projection to start! - self.TransformVector = N.array( (1,-1), N.float) # default Transformation + self.MapProjectionVector = N.array( (1,1), float) # No Projection to start! + self.TransformVector = N.array( (1,-1), float) # default Transformation self.Scale = 1 self.ObjectUnderMouse = None @@ -239,7 +239,7 @@ class FloatCanvas(wx.Panel): elif callable(ProjectionFun): self.ProjectionFun = ProjectionFun elif ProjectionFun is None: - self.ProjectionFun = lambda x=None: N.array( (1,1), N.float) + self.ProjectionFun = lambda x=None: N.array( (1,1), float) else: raise FloatCanvasError('Projectionfun must be either:' ' "FlatEarth", None, or a callable object ' @@ -262,7 +262,7 @@ class FloatCanvas(wx.Panel): MinLatitude = -75 Lat = min(CenterPoint[1],MaxLatitude) Lat = max(Lat,MinLatitude) - return N.array((N.cos(N.pi*Lat/180),1),N.float) + return N.array((N.cos(N.pi*Lat/180),1),float) def SetMode(self, Mode): """ @@ -703,9 +703,9 @@ class FloatCanvas(wx.Panel): ============== ====================================================== """ - shift = N.asarray(shift,N.float) + shift = N.asarray(shift,float) if CoordType.lower() == 'panel':# convert from panel coordinates - shift = shift * N.array((-1,1),N.float) *self.PanelSize/self.TransformVector + shift = shift * N.array((-1,1),float) *self.PanelSize/self.TransformVector elif CoordType.lower() == 'pixel': # convert from pixel coordinates shift = shift/self.TransformVector elif CoordType.lower() == 'world': # No conversion @@ -715,7 +715,7 @@ class FloatCanvas(wx.Panel): self.ViewPortCenter = self.ViewPortCenter + shift self.MapProjectionVector = self.ProjectionFun(self.ViewPortCenter) - self.TransformVector = N.array((self.Scale,-self.Scale),N.float) * self.MapProjectionVector + self.TransformVector = N.array((self.Scale,-self.Scale),float) * self.MapProjectionVector self._BackgroundDirty = True if ReDraw: self.Draw() @@ -745,7 +745,7 @@ class FloatCanvas(wx.Panel): if centerCoords.lower() == "pixel": oldpoint = self.PixelToWorld( center ) elif centerCoords.lower() == 'world': - oldpoint = N.array(center, N.float) + oldpoint = N.array(center, float) else: raise FloatCanvasError('centerCoords must be either "World" or "Pixel"') @@ -756,7 +756,7 @@ class FloatCanvas(wx.Panel): if centerCoords.lower() == "pixel": newpoint = self.PixelToWorld( center ) else: - newpoint = N.array(center, N.float) + newpoint = N.array(center, float) delta = (newpoint - oldpoint) self.MoveImage(-delta, 'World') else: @@ -779,7 +779,7 @@ class FloatCanvas(wx.Panel): BoundingBox = self.BoundingBox if (BoundingBox is not None) and (not BoundingBox.IsNull()): self.ViewPortCenter = N.array(((BoundingBox[0,0]+BoundingBox[1,0])/2, - (BoundingBox[0,1]+BoundingBox[1,1])/2 ),N.float_) + (BoundingBox[0,1]+BoundingBox[1,1])/2 ),float_) self.MapProjectionVector = self.ProjectionFun(self.ViewPortCenter) # Compute the new Scale BoundingBox = BoundingBox*self.MapProjectionVector # this does need to make a copy! @@ -799,7 +799,7 @@ class FloatCanvas(wx.Panel): self._BackgroundDirty = True else: # Reset the shifting and scaling to defaults when there is no BB - self.ViewPortCenter= N.array( (0,0), N.float) + self.ViewPortCenter= N.array( (0,0), float) self.Scale= 1 self.SetToNewScale(DrawFlag=DrawFlag) @@ -816,7 +816,7 @@ class FloatCanvas(wx.Panel): if self.MaxScale is not None: Scale = min(Scale, self.MaxScale) self.MapProjectionVector = self.ProjectionFun(self.ViewPortCenter) - self.TransformVector = N.array((Scale,-Scale),N.float) * self.MapProjectionVector + self.TransformVector = N.array((Scale,-Scale),float) * self.MapProjectionVector self.Scale = Scale self._BackgroundDirty = True if DrawFlag: @@ -889,9 +889,9 @@ class FloatCanvas(wx.Panel): SetToNull=True if SetToNull: self.BoundingBox = BBox.NullBBox() - self.ViewPortCenter= N.array( (0,0), N.float) - self.TransformVector = N.array( (1,-1), N.float) - self.MapProjectionVector = N.array( (1,1), N.float) + self.ViewPortCenter= N.array( (0,0), float) + self.TransformVector = N.array( (1,-1), float) + self.MapProjectionVector = N.array( (1,1), float) self.Scale = 1 self.BoundingBoxDirty = False @@ -903,7 +903,7 @@ class FloatCanvas(wx.Panel): or a NX2 Numpy array of x,y coordinates. """ - return (((N.asarray(Points, N.float) - + return (((N.asarray(Points, float) - (self.PanelSize/2))/self.TransformVector) + self.ViewPortCenter) @@ -915,7 +915,7 @@ class FloatCanvas(wx.Panel): a 2-tuple, or sequence of 2-tuples. """ #Note: this can be called by users code for various reasons, so N.asarray is needed. - return (((N.asarray(Coordinates,N.float) - + return (((N.asarray(Coordinates,float) - self.ViewPortCenter)*self.TransformVector)+ (self.HalfPanelSize)).astype('i') @@ -927,7 +927,7 @@ class FloatCanvas(wx.Panel): Lengths should be a NX2 array of (x,y) coordinates, or a 2-tuple, or sequence of 2-tuples. """ - return ( (N.asarray(Lengths, N.float)*self.TransformVector) ).astype('i') + return ( (N.asarray(Lengths, float)*self.TransformVector) ).astype('i') def ScalePixelToWorld(self,Lengths): """ @@ -937,7 +937,7 @@ class FloatCanvas(wx.Panel): Lengths should be a NX2 array of (x,y) coordinates, or a 2-tuple, or sequence of 2-tuples. """ - return (N.asarray(Lengths,N.float) / self.TransformVector) + return (N.asarray(Lengths,float) / self.TransformVector) def AddObject(self, obj): """ diff --git a/wx/lib/floatcanvas/Utilities/BBox.py b/wx/lib/floatcanvas/Utilities/BBox.py index a20f94ce..9d848f7c 100755 --- a/wx/lib/floatcanvas/Utilities/BBox.py +++ b/wx/lib/floatcanvas/Utilities/BBox.py @@ -61,7 +61,7 @@ class BBox(N.ndarray): fromPoints """ - arr = N.array(data, N.float) + arr = N.array(data, float) arr.shape = (2,2) if arr[0,0] > arr[1,0] or arr[0,1] > arr[1,1]: # note: zero sized BB OK. @@ -174,7 +174,7 @@ class BBox(N.ndarray): #~ # returns the bounding box of a bunch of bounding boxes #~ upperleft = N.minimum.reduce(bboxarray[:,0]) #~ lowerright = N.maximum.reduce(bboxarray[:,1]) - #~ return N.array((upperleft, lowerright), N.float) + #~ return N.array((upperleft, lowerright), float) #~ _getboundingbox = staticmethod(_getboundingbox) @@ -212,7 +212,7 @@ def asBBox(data): if isinstance(data, BBox): return data - arr = N.asarray(data, N.float) + arr = N.asarray(data, float) return N.ndarray.__new__(BBox, shape=arr.shape, dtype=arr.dtype, buffer=arr) def fromPoints(Points): @@ -225,7 +225,7 @@ def fromPoints(Points): If a single point is passed in, a zero-size Bounding Box is returned. """ - Points = N.asarray(Points, N.float).reshape(-1,2) + Points = N.asarray(Points, float).reshape(-1,2) arr = N.vstack( (Points.min(0), Points.max(0)) ) return N.ndarray.__new__(BBox, shape=arr.shape, dtype=arr.dtype, buffer=arr) @@ -241,9 +241,9 @@ def fromBBArray(BBarray): #upperleft = N.minimum.reduce(BBarray[:,0]) #lowerright = N.maximum.reduce(BBarray[:,1]) - # BBarray = N.asarray(BBarray, N.float).reshape(-1,2) + # BBarray = N.asarray(BBarray, float).reshape(-1,2) # arr = N.vstack( (BBarray.min(0), BBarray.max(0)) ) - BBarray = N.asarray(BBarray, N.float).reshape(-1,2,2) + BBarray = N.asarray(BBarray, float).reshape(-1,2,2) arr = N.vstack( (BBarray[:,0,:].min(0), BBarray[:,1,:].max(0)) ) return asBBox(arr) #return asBBox( (upperleft, lowerright) ) * 2 @@ -260,7 +260,7 @@ def NullBBox(): """ - arr = N.array(((N.nan, N.nan),(N.nan, N.nan)), N.float) + arr = N.array(((N.nan, N.nan),(N.nan, N.nan)), float) return N.ndarray.__new__(BBox, shape=arr.shape, dtype=arr.dtype, buffer=arr) def InfBBox(): @@ -269,7 +269,7 @@ def InfBBox(): """ - arr = N.array(((-N.inf, -N.inf),(N.inf, N.inf)), N.float) + arr = N.array(((-N.inf, -N.inf),(N.inf, N.inf)), float) return N.ndarray.__new__(BBox, shape=arr.shape, dtype=arr.dtype, buffer=arr) class RectBBox(BBox):