style: Normalise numpy imports with import numpy as np

The convention when importing numpy is to use `import numpy as np`

Fixes: unconventional-import-alias (ICN001)
Ruff rule: https://docs.astral.sh/ruff/rules/unconventional-import-alias/
This commit is contained in:
Edouard Choinière
2025-02-08 16:48:57 +00:00
parent 45f9e89f5d
commit 95cafd1a3f
26 changed files with 233 additions and 233 deletions

View File

@@ -9,7 +9,7 @@ BNA is a simple text format for storing polygons in lat-long coordinates.
import os, sys
import sets
import numpy as N
import numpy as np
#### import local version:
#sys.path.append("..")
@@ -75,7 +75,7 @@ class BNAData:
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)
@@ -208,7 +208,7 @@ class DrawFrame(wx.Frame):
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]

View File

@@ -9,7 +9,7 @@ from wx.lib.floatcanvas import NavCanvas, FloatCanvas
#sys.path.append("../")
#from floatcanvas import NavCanvas, FloatCanvas
import numpy as N
import numpy as np
from numpy import random as random
NumChannels = 200
@@ -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):
"""
@@ -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):
@@ -75,7 +75,7 @@ class DrawFrame(wx.Frame):
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):

View File

@@ -20,7 +20,7 @@ import wx
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):

View File

@@ -19,7 +19,7 @@ from wx.lib.floatcanvas import NavCanvas, FloatCanvas
NumHexagons = 1000
import numpy as N
import numpy as np
from numpy.random import uniform
import random
@@ -56,8 +56,8 @@ class DrawFrame(wx.Frame):
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),

View File

@@ -26,7 +26,7 @@ elif ver == 'local':
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:
@@ -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]),
@@ -119,7 +119,7 @@ class ConnectorLine(FC.LineOnlyMixin, FC.DrawObject,):
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)
@@ -139,7 +139,7 @@ class TriangleShape1(FC.Polygon, MovingObjectMixin):
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)
@@ -155,12 +155,12 @@ class TriangleShape1(FC.Polygon, MovingObjectMixin):
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
@@ -189,10 +189,10 @@ class DrawFrame(wx.Frame):
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),

View File

@@ -7,7 +7,7 @@ efficient moving line on it.
"""
import wx
import numpy as N
import numpy as np
## import the installed version
from wx.lib.floatcanvas import NavCanvas, FloatCanvas
@@ -114,19 +114,19 @@ class DrawFrame(wx.Frame):
# 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')
@@ -145,7 +145,7 @@ class DrawFrame(wx.Frame):
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)
@@ -155,11 +155,11 @@ class DrawFrame(wx.Frame):
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()

View File

@@ -21,7 +21,7 @@ elif ver == 'local':
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
@@ -45,7 +45,7 @@ class TriangleShape1(FC.Polygon, ShapeMixin):
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)
@@ -59,12 +59,12 @@ class TriangleShape1(FC.Polygon, ShapeMixin):
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
@@ -101,10 +101,10 @@ class DrawFrame(wx.Frame):
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),

View File

@@ -14,7 +14,7 @@ from wx.lib.floatcanvas.FCObjects import PieChart
#from floatcanvas.SpecialObjects import PieChart
import numpy as N
import numpy as np
class DrawFrame(wx.Frame):
@@ -39,22 +39,22 @@ class DrawFrame(wx.Frame):
Values = (10,10,10)
Colors = ('Red', 'Blue', 'Green')
Pie1 = PieChart(N.array((0, 0)), 10, Values, Colors, Scaled=False)
Pie1 = PieChart(np.array((0, 0)), 10, Values, Colors, Scaled=False)
Canvas.AddObject(Pie1)
Values = (10, 5, 5)
Pie2 = PieChart(N.array((40, 0)), 10, Values, Colors)
Pie2 = PieChart(np.array((40, 0)), 10, Values, Colors)
Canvas.AddObject(Pie2)
# test default colors
Values = (10, 15, 12, 24, 6, 10, 13, 11, 9, 13, 15, 12)
Pie3 = PieChart(N.array((20, 20)), 10, Values, LineColor="Black")
Pie3 = PieChart(np.array((20, 20)), 10, Values, LineColor="Black")
Canvas.AddObject(Pie3)
# missng slice!
Values = (10, 15, 12, 24)
Colors = ('Red', 'Blue', 'Green', None)
Pie4 = PieChart(N.array((0, -15)), 10, Values, Colors, LineColor="Black")
Pie4 = PieChart(np.array((0, -15)), 10, Values, Colors, LineColor="Black")
Canvas.AddObject(Pie4)
@@ -62,7 +62,7 @@ class DrawFrame(wx.Frame):
Values = (10, 12, 14)
Styles = ("Solid", "CrossDiagHatch","CrossHatch")
Colors = ('Red', 'Blue', 'Green')
Pie4 = PieChart(N.array((20, -20)), 10, Values, Colors, Styles)
Pie4 = PieChart(np.array((20, -20)), 10, Values, Colors, Styles)
Canvas.AddObject(Pie2)
Pie1.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.Pie1Hit)

View File

@@ -5,7 +5,7 @@ PolyEditor: a simple app for editing polygons
Used as a demo for FloatCanvas
"""
import numpy as N
import numpy as np
import random
import numpy.random as RandomArray
@@ -112,7 +112,7 @@ class DrawFrame(wx.Frame):
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.float64)
self.SelectedPointNeighbors = np.zeros((3,2), np.float64)
#fixme: This feels very inelegant!
if Index == 0:
self.SelectedPointNeighbors[0] = self.SelectedPoly.Points[-1]

View File

@@ -25,7 +25,7 @@ elif ver == 'local':
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:
## fixme: These really belong in floatcanvas package -- but I kind of want to clean it up some first
@@ -45,7 +45,7 @@ class MovingObjectMixin:
"""
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]),
@@ -100,8 +100,8 @@ class NodeObject(FC.Group, MovingObjectMixin, ConnectorObjectMixin):
TextColor = "Black",
InForeground = False,
IsVisible = True):
XY = N.asarray(XY, N.float).reshape(2,)
WH = N.asarray(WH, N.float).reshape(2,)
XY = np.asarray(XY, np.float).reshape(2,)
WH = np.asarray(WH, np.float).reshape(2,)
Label = FC.ScaledText(Label,
XY,
Size = WH[1] / 2.0,
@@ -171,7 +171,7 @@ class ConnectorLine(FC.LineOnlyMixin, FC.DrawObject,):
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)
@@ -191,7 +191,7 @@ class TriangleShape1(FC.Polygon, MovingObjectMixin):
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)
@@ -207,12 +207,12 @@ class TriangleShape1(FC.Polygon, MovingObjectMixin):
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

View File

@@ -22,7 +22,7 @@ from wx.lib.floatcanvas import NavCanvas, FloatCanvas
#from floatcanvas import NavCanvas, FloatCanvas
import numpy as N
import numpy as np
def YScaleFun(center):
"""
@@ -30,7 +30,7 @@ def YScaleFun(center):
"""
# center gets ignored in this case
return N.array((5e7, 1), N.float)
return np.array((5e7, 1), np.float)
class DrawFrame(wx.Frame):
@@ -54,8 +54,8 @@ class DrawFrame(wx.Frame):
self.Canvas = Canvas
Point = N.array((50e-6, 0))
Size = N.array(( (2000e-6 - 5e-6), 50000))
Point = np.array((50e-6, 0))
Size = np.array(( (2000e-6 - 5e-6), 50000))
Box = Canvas.AddRectangle(Point,
Size,
FillColor = "blue"

View File

@@ -15,7 +15,7 @@ from wx.lib.floatcanvas import NavCanvas, FloatCanvas
#sys.path.append("..")
#from floatcanvas import NavCanvas, FloatCanvas
import numpy as N
import numpy as np
class DrawFrame(wx.Frame):
@@ -188,7 +188,7 @@ class DrawFrame(wx.Frame):
Family = wx.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,
@@ -202,7 +202,7 @@ class DrawFrame(wx.Frame):
)
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"]:
@@ -221,7 +221,7 @@ class DrawFrame(wx.Frame):
)
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,
@@ -237,7 +237,7 @@ class DrawFrame(wx.Frame):
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,
@@ -252,7 +252,7 @@ class DrawFrame(wx.Frame):
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,

View File

@@ -22,7 +22,7 @@ from wx.lib.floatcanvas import NavCanvas, FloatCanvas, Resources
#from floatcanvas import NavCanvas, FloatCanvas, Resources
import numpy as N
import numpy as np
LongString = (
"""This is a long string. It is a bunch of text. I am using it to test how the nifty wrapping text box works when you want to re-size.
@@ -62,7 +62,7 @@ class DrawFrame(wx.Frame):
self.Canvas.Bind(FloatCanvas.EVT_LEFT_UP, self.OnLeftUp )
self.Canvas.Bind(FloatCanvas.EVT_LEFT_DOWN, self.OnLeftDown)
Point = N.array((0,0), N.float)
Point = np.array((0,0), np.float)

View File

@@ -25,7 +25,7 @@ elif ver == 'local':
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:
## fixme: These really belong in floatcanvas package -- but I kind of want to clean it up some first
@@ -45,7 +45,7 @@ class MovingObjectMixin:
"""
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]),
@@ -100,8 +100,8 @@ class NodeObject(FC.Group, MovingObjectMixin, ConnectorObjectMixin):
TextColor = "Black",
InForeground = False,
IsVisible = True):
XY = N.asarray(XY, N.float).reshape(2,)
WH = N.asarray(WH, N.float).reshape(2,)
XY = np.asarray(XY, np.float).reshape(2,)
WH = np.asarray(WH, np.float).reshape(2,)
Label = FC.ScaledText(Label,
XY,
Size = WH[1] / 2.0,
@@ -163,7 +163,7 @@ class ConnectorLine(FC.LineOnlyMixin, FC.DrawObject,):
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)
@@ -183,7 +183,7 @@ class TriangleShape1(FC.Polygon, MovingObjectMixin):
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)
@@ -199,12 +199,12 @@ class TriangleShape1(FC.Polygon, MovingObjectMixin):
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

View File

@@ -6,7 +6,7 @@ A small test app that uses FloatCanvas to draw a vector plot.
"""
import wx
import numpy as N
import numpy as np
import random
## import the installed version
@@ -95,19 +95,19 @@ class DrawFrame(wx.Frame):
# 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')
@@ -122,10 +122,10 @@ class DrawFrame(wx.Frame):
#Canvas.Draw()
def Plot(self, event = None):
x = N.arange(0, 2*N.pi, 0.1)
x = np.arange(0, 2*np.pi, 0.1)
x.shape = (-1,1)
y = N.sin(x)
data = N.concatenate((x, y),1)
y = np.sin(x)
data = np.concatenate((x, y),1)
Canvas = self.Canvas
self.Canvas.ClearAll()

View File

@@ -23,10 +23,10 @@ from wx.lib.floatcanvas import NavCanvas, FloatCanvas
#from floatcanvas import NavCanvas, FloatCanvas
import numpy as N
import numpy as np
def YDownProjection(CenterPoint):
return N.array((1,-1))
return np.array((1,-1))
class DrawFrame(wx.Frame):

View File

@@ -20,9 +20,9 @@ TEST_GC = False
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:
USE_NUMPY = False