Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Normalise numpy imports with import numpy as np #2693

Merged
merged 1 commit into from
Feb 9, 2025
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
20 changes: 10 additions & 10 deletions demo/FloatCanvas.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

try:
import numpy as N
import numpy as np
import numpy.random as RandomArray
haveNumpy = True
#print("Using numpy, version:", N.__version__)
Expand Down Expand Up @@ -720,7 +720,7 @@ def TestHitTest(self, event=None):

x += dx
color = "SEA GREEN"
Points = N.array(( (x, y), (x, y+2.*h/3), (x+w, y+h), (x+w, y+h/2.), (x + 2.*w/3, y+h/2.), (x + 2.*w/3,y) ), N.float64)
Points = np.array(( (x, y), (x, y+2.*h/3), (x+w, y+h), (x+w, y+h/2.), (x + 2.*w/3, y+h/2.), (x + 2.*w/3,y) ), np.float64)
R = Canvas.AddPolygon(Points, LineWidth = 2, FillColor = color)
R.Name = color + " Polygon"
R.Bind(FloatCanvas.EVT_FC_RIGHT_DOWN, self.RectGotHitRight)
Expand All @@ -729,7 +729,7 @@ def TestHitTest(self, event=None):

x += dx
color = "Red"
Points = N.array(( (x, y), (x, y+2.*h/3), (x+w, y+h), (x+w, y+h/2.), (x + 2.*w/3, y+h/2.), (x + 2.*w/3,y) ), N.float64)
Points = np.array(( (x, y), (x, y+2.*h/3), (x+w, y+h), (x+w, y+h/2.), (x + 2.*w/3, y+h/2.), (x + 2.*w/3,y) ), np.float64)
R = Canvas.AddPointSet(Points, Diameter = 4, Color = color)
R.Name = "PointSet"
R.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.PointSetGotHit)
Expand Down Expand Up @@ -1139,7 +1139,7 @@ def TestScaledTextBox(self, event= None):
Family = wx.FONTFAMILY_ROMAN,
Alignment = "right"
)
Point = N.array((100, -20), N.float64)
Point = np.array((100, -20), np.float64)
Box = Canvas.AddScaledTextBox("Here is even more auto wrapped text. This time the line spacing is set to 0.8. \n\nThe Padding is set to 0.",
Point,
Size = 3,
Expand All @@ -1153,7 +1153,7 @@ def TestScaledTextBox(self, event= None):
)
Canvas.AddPoint(Point, "Red", 2)

Point = N.array((0, -40), N.float64)
Point = np.array((0, -40), np.float64)
# Point = N.array((0, 0), N.float_)
for Position in ["tl", "bl", "tr", "br"]:
# for Position in ["br"]:
Expand All @@ -1172,7 +1172,7 @@ def TestScaledTextBox(self, event= None):
)
Canvas.AddPoint(Point, "Red", 4)

Point = N.array((-20, 60), N.float64)
Point = np.array((-20, 60), np.float64)
Box = Canvas.AddScaledTextBox("Here is some\ncentered\ntext",
Point,
Size = 4,
Expand All @@ -1188,7 +1188,7 @@ def TestScaledTextBox(self, event= None):
LineSpacing = 0.8
)

Point = N.array((-20, 20), N.float64)
Point = np.array((-20, 20), np.float64)
Box = Canvas.AddScaledTextBox("Here is some\nright aligned\ntext",
Point,
Size = 4,
Expand All @@ -1203,7 +1203,7 @@ def TestScaledTextBox(self, event= None):
LineSpacing = 0.8
)

Point = N.array((100, -60), N.float64)
Point = np.array((100, -60), np.float64)
Box = Canvas.AddScaledTextBox("Here is some auto wrapped text. This time it is centered, rather than right aligned.\n\nThe Padding is set to 2.",
Point,
Size = 3,
Expand Down Expand Up @@ -1728,11 +1728,11 @@ def Read_MapGen(self, filename, stats = 0,AllLines=0):
for line in data:
if line:
if line == "# -b": #New segment beginning
if segment: Shorelines.append(N.array(segment))
if segment: Shorelines.append(np.array(segment))
segment = []
else:
segment.append([float(e) for e in line.split()])
if segment: Shorelines.append(N.array(segment))
if segment: Shorelines.append(np.array(segment))

if stats:
NumSegments = len(Shorelines)
Expand Down
2 changes: 1 addition & 1 deletion demo/PyPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

hadImportError = False
try:
import numpy
import numpy as np
import wx.lib.plot
except ImportError:
hadImportError = True
Expand Down
4 changes: 2 additions & 2 deletions demo/RawBitmapAccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

if USE_NUMPY:
try:
import numpy
import numpy as np
def makeByteArray(shape):
return numpy.empty(shape, numpy.uint8)
return np.empty(shape, np.uint8)
numtype = 'numpy'
except ImportError:
try:
Expand Down
6 changes: 3 additions & 3 deletions samples/floatcanvas/BNAEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os, sys
import sets

import numpy as N
import numpy as np

#### import local version:
#sys.path.append("..")
Expand Down Expand Up @@ -75,7 +75,7 @@ def Load(self, filename):
num_points = int(line)
self.Types.append(Type)
self.Names.append(Name)
polygon = N.zeros((num_points,2),N.float)
polygon = np.zeros((num_points,2),np.float)
for i in range(num_points):
polygon[i,:] = map(float, file_.readline().split(','))
self.PointsData.append(polygon)
Expand Down Expand Up @@ -208,7 +208,7 @@ def OnMove(self, event):
dc.SetPen(wx.Pen('WHITE', 2, wx.SHORT_DASH))
dc.SetLogicalFunction(wx.XOR)
if self.SelectedPointNeighbors is None:
self.SelectedPointNeighbors = N.zeros((3,2), N.float)
self.SelectedPointNeighbors = np.zeros((3,2), np.float)
#fixme: This feels very inelegant!
if Index == 0:
self.SelectedPointNeighbors[0] = self.SelectedPoly.Points[-1]
Expand Down
8 changes: 4 additions & 4 deletions samples/floatcanvas/BarPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#sys.path.append("../")
#from floatcanvas import NavCanvas, FloatCanvas

import numpy as N
import numpy as np
from numpy import random as random

NumChannels = 200
Expand All @@ -27,7 +27,7 @@ def YScaleFun(center):
"""

# center gets ignored in this case
return N.array((1, float(NumChannels)/MaxValue), N.float)
return np.array((1, float(NumChannels)/MaxValue), np.float)

def ScaleWorldToPixel(self, Lengths):
"""
Expand All @@ -41,7 +41,7 @@ def ScaleWorldToPixel(self, Lengths):
Lengths should be a NX2 array of (x,y) coordinates, or
a 2-tuple, or sequence of 2-tuples.
"""
return N.ceil(( (N.asarray(Lengths, N.float)*self.TransformVector) )).astype('i')
return np.ceil(( (np.asarray(Lengths, np.float)*self.TransformVector) )).astype('i')


class DrawFrame(wx.Frame):
Expand Down Expand Up @@ -75,7 +75,7 @@ def __init__(self, *args, **kwargs):
self.BarWidth = 0.75
# add an X axis
Canvas.AddLine(((0,0), (NumChannels, 0 )),)
for x in N.linspace(1, NumChannels, 11):
for x in np.linspace(1, NumChannels, 11):
Canvas.AddText("%i"%x, (x-1+self.BarWidth/2,0), Position="tc")

for i, Value in enumerate(self.Values):
Expand Down
2 changes: 1 addition & 1 deletion samples/floatcanvas/DrawRect.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from wx.lib.floatcanvas import NavCanvas, FloatCanvas, GUIMode
from wx.lib.floatcanvas.Utilities import GUI

import numpy as N
import numpy as np

class DrawFrame(wx.Frame):

Expand Down
6 changes: 3 additions & 3 deletions samples/floatcanvas/Hexagons.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

NumHexagons = 1000

import numpy as N
import numpy as np
from numpy.random import uniform

import random
Expand Down Expand Up @@ -56,8 +56,8 @@ def MakeHexagons(self):
print("Max colors:", len(self.colors))
Canvas = self.Canvas
D = 1.0
h = D *N.sqrt(3)/2
Hex = N.array(((D , 0),
h = D *np.sqrt(3)/2
Hex = np.array(((D , 0),
(D/2 , -h),
(-D/2, -h),
(-D , 0),
Expand Down
18 changes: 9 additions & 9 deletions samples/floatcanvas/MovingElements.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from floatcanvas import FloatCanvas as FC
from floatcanvas.Utilities import BBox

import numpy as N
import numpy as np

## here we create some new mixins:

Expand All @@ -38,7 +38,7 @@ class MovingObjectMixin:

def GetOutlinePoints(self):
BB = self.BoundingBox
OutlinePoints = N.array( ( (BB[0,0], BB[0,1]),
OutlinePoints = np.array( ( (BB[0,0], BB[0,1]),
(BB[0,0], BB[1,1]),
(BB[1,0], BB[1,1]),
(BB[1,0], BB[0,1]),
Expand Down Expand Up @@ -119,7 +119,7 @@ def CalcBoundingBox(self):


def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
Points = N.array( (self.Object1.GetConnectPoint(),
Points = np.array( (self.Object1.GetConnectPoint(),
self.Object2.GetConnectPoint()) )
Points = WorldToPixel(Points)
dc.SetPen(self.Pen)
Expand All @@ -139,7 +139,7 @@ def __init__(self, XY, L):
L is the length of one side of the Triangle
"""

XY = N.asarray(XY)
XY = np.asarray(XY)
XY.shape = (2,)

Points = self.CompPoints(XY, L)
Expand All @@ -155,12 +155,12 @@ def GetOutlinePoints(self):
return self.Points

def CompPoints(self, XY, L):
c = L/ N.sqrt(3)
c = L/ np.sqrt(3)

Points = N.array(((0, c),
Points = np.array(((0, c),
( L/2.0, -c/2.0),
(-L/2.0, -c/2.0)),
N.float64)
np.float64)

Points += XY
return Points
Expand Down Expand Up @@ -189,10 +189,10 @@ def __init__(self, *args, **kwargs):
Canvas.Bind(FC.EVT_MOTION, self.OnMove )
Canvas.Bind(FC.EVT_LEFT_UP, self.OnLeftUp )

Points = N.array(((0,0),
Points = np.array(((0,0),
(1,0),
(0.5, 1)),
N.float)
np.float)

data = (( (0,0), 1),
( (3,3), 2),
Expand Down
16 changes: 8 additions & 8 deletions samples/floatcanvas/MovingPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

import wx
import numpy as N
import numpy as np

## import the installed version
from wx.lib.floatcanvas import NavCanvas, FloatCanvas
Expand Down Expand Up @@ -114,19 +114,19 @@ def DrawAxis(self):
# what the options are.

self.Canvas.AddRectangle((0, -1.1),
(2*N.pi, 2.2),
(2*np.pi, 2.2),
LineColor = "Black",
LineStyle = "Solid",
LineWidth = 1,
FillColor = None,
FillStyle = "Solid",
InForeground = 0)
for tic in N.arange(7):
for tic in np.arange(7):
self.Canvas.AddText("%1.1f"%tic,
(tic,-1.1),
Position = 'tc')

for tic in N.arange(-1, 1.1, 0.5):
for tic in np.arange(-1, 1.1, 0.5):
self.Canvas.AddText("%1.1f"%tic,
(0,tic),
Position = 'cr')
Expand All @@ -145,7 +145,7 @@ def Stop(self,event):

def OnTimer(self,event):
self.count += .1
self.data1[:,1] = N.sin(self.time+self.count) #fake move
self.data1[:,1] = np.sin(self.time+self.count) #fake move

self.line.SetPoints(self.data1)

Expand All @@ -155,11 +155,11 @@ def RunTest(self,event = None):
self.n = 100
self.dT = 0.05

self.time = 2.0*N.pi*N.arange(100)/100.0
self.time = 2.0*np.pi*np.arange(100)/100.0

self.data1 = 1.0*N.ones((100,2))
self.data1 = 1.0*np.ones((100,2))
self.data1[:,0] = self.time
self.data1[:,1] = N.sin(self.time)
self.data1[:,1] = np.sin(self.time)
Canvas = self.Canvas
self.Canvas.ClearAll()
self.DrawAxis()
Expand Down
14 changes: 7 additions & 7 deletions samples/floatcanvas/MovingTriangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from floatcanvas import NavCanvas, Resources
from floatcanvas import FloatCanvas as FC

import numpy as N
import numpy as np

## here we create a new DrawObject:
## code borrowed and adapted from Werner Bruhin
Expand All @@ -45,7 +45,7 @@ def __init__(self, XY, L):
L is the length of one side of the Triangle
"""

XY = N.asarray(XY)
XY = np.asarray(XY)
XY.shape = (2,)

Points = self.CompPoints(XY, L)
Expand All @@ -59,12 +59,12 @@ def __init__(self, XY, L):
ShapeMixin.__init__(self)

def CompPoints(self, XY, L):
c = L/ N.sqrt(3)
c = L/ np.sqrt(3)

Points = N.array(((0, c),
Points = np.array(((0, c),
( L/2.0, -c/2.0),
(-L/2.0, -c/2.0)),
N.float64)
np.float64)

Points += XY
return Points
Expand Down Expand Up @@ -101,10 +101,10 @@ def __init__(self,parent, id,title,position,size):
FillColor = "CYAN",
FillStyle = "Solid")

Points = N.array(((0,0),
Points = np.array(((0,0),
(1,0),
(0.5, 1)),
N.float64)
np.float64)

data = (( (0,0), 1),
( (3,3), 2),
Expand Down
Loading