Skip to content

Commit 230f55a

Browse files
authored
Fix import issues and restore backwards compatibility (#25)
1 parent 609bf7b commit 230f55a

File tree

9 files changed

+181
-164
lines changed

9 files changed

+181
-164
lines changed

examples/example_curve.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66

77
# First party modules
8-
from pyspline import pySpline
8+
from pyspline import Curve
99

1010
# Get some Helix-like data
1111

@@ -15,29 +15,29 @@
1515
y = np.sin(theta)
1616
z = np.linspace(0, 1, n)
1717
print("Helix Data")
18-
curve = pySpline.Curve(x=x, y=y, z=z, k=4, Nctl=16, niter=100)
18+
curve = Curve(x=x, y=y, z=z, k=4, Nctl=16, niter=100)
1919
curve.writeTecplot("helix.dat")
2020

2121
# Load naca0012 data
2222
print("Naca 0012 data")
2323
x, y = np.loadtxt("naca0012", unpack=True)
24-
curve = pySpline.Curve(x=x, y=y, k=4, Nctl=11, niter=500)
24+
curve = Curve(x=x, y=y, k=4, Nctl=11, niter=500)
2525
curve.writeTecplot("naca_data.dat")
2626

2727
# Projection Tests
2828
print("Projection Tests")
2929
x = [0, 2, 3, 5]
3030
y = [-2, 5, 3, 0]
3131
z = [0, 0, 0, 0]
32-
curve1 = pySpline.Curve(x=x, y=y, z=z, k=4)
32+
curve1 = Curve(x=x, y=y, z=z, k=4)
3333

3434
curve1.writeTecplot("curve1.dat")
3535

3636
x = [-2, 5, 2, 1]
3737
y = [5, 1, 4, 2]
3838
z = [3, 0, 1, 4]
3939

40-
curve2 = pySpline.Curve(x=x, y=y, z=z, k=4)
40+
curve2 = Curve(x=x, y=y, z=z, k=4)
4141
curve2.writeTecplot("curve2.dat")
4242

4343
# Get the minimum distance distance between a point and each curve

examples/example_surf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import numpy as np
55

66
# First party modules
7-
from pyspline import pySpline
7+
from pyspline import Curve, Surface
88

99
# Create a generic surface
1010
nu = 20
@@ -13,15 +13,15 @@
1313
v = np.linspace(0, 4, nv)
1414
[V, U] = np.meshgrid(v, u)
1515
Z = np.cos(U) * np.sin(V)
16-
surf = pySpline.Surface(x=U, y=V, z=Z, ku=4, kv=4, Nctlu=5, Nctlv=5)
16+
surf = Surface(x=U, y=V, z=Z, ku=4, kv=4, Nctlu=5, Nctlv=5)
1717
surf.writeTecplot("surface.dat")
1818

1919
n = 100
2020
theta = np.linspace(0.0000, 2 * np.pi, n)
2121
x = np.cos(theta) - 1
2222
y = np.sin(theta) + 1
2323
z = np.linspace(0, 1, n) + 2
24-
curve = pySpline.Curve(x=x, y=y, z=z, k=4, Nctl=16, niter=100)
24+
curve = Curve(x=x, y=y, z=z, k=4, Nctl=16, niter=100)
2525
curve.writeTecplot("helix.dat")
2626

2727
u, v, s, D = surf.projectCurve(curve, Niter=100, eps1=1e-10, eps2=1e-10, u=1, v=1, s=1)

examples/example_volume.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77

88
# First party modules
9-
from pyspline import pySpline
9+
from pyspline import Volume
1010

1111
X = np.zeros((2, 2, 2, 3))
1212
X[0, 0, 0, :] = [0, 0, 0]
@@ -19,7 +19,7 @@
1919
X[1, 1, 1, :] = [1.2, 1.0, 2]
2020
X[0, 1, 1, :] = [-0.2, 1.3, 2.1]
2121

22-
vol = pySpline.Volume(X=X, ku=2, kv=2, kw=2, Nctlu=2, Nctlv=2, Nctlw=2)
22+
vol = Volume(X=X, ku=2, kv=2, kw=2, Nctlu=2, Nctlv=2, Nctlw=2)
2323
vol.writeTecplot("vol.dat", orig=True)
2424

2525
# Generate random data

pyspline/pyCurve.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ class Curve(object):
7676
>>> y = [0, 0.25, 1.0]
7777
>>> s = [0., 0.5, 1.0]
7878
>>> # Spatial interpolated seg
79-
>>> line_seg = pySpline.Curve(x=x, y=y, k=2)
79+
>>> line_seg = Curve(x=x, y=y, k=2)
8080
>>> # With explicit parameter values
81-
>>> line_seg = pySpline.Curve(x=x, y=y, k=2, s=s)
81+
>>> line_seg = Curve(x=x, y=y, k=2, s=s)
8282
>>> #LMS parabolic curve
83-
>>> parabola = pySpline.Curve(x=x, y=y, k=3)
83+
>>> parabola = Curve(x=x, y=y, k=3)
8484
>>> #LMS parabolic curve with parameter values
85-
>>> parabola = pySpline.Curve(x=x, y=y, k=3, s=s)
85+
>>> parabola = Curve(x=x, y=y, k=3, s=s)
8686
"""
8787

8888
def __init__(self, **kwargs):

pyspline/pySpline.py

Lines changed: 14 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -6,142 +6,19 @@
66
:class:`Volume`
77
"""
88

9-
# External modules
10-
import numpy as np
11-
129
# Local modules
1310
from . import libspline # noqa: F401
14-
from .pyCurve import Curve
15-
from .pySurface import Surface
16-
from .pyVolume import Volume
17-
from .utils import Error
18-
19-
# ----------------------------------------------------------------------
20-
# Misc Helper Functions
21-
# ----------------------------------------------------------------------
22-
23-
24-
def trilinearVolume(*args):
25-
"""This is a short-cut function to create a trilinear b-spline
26-
volume. It can be created with ``x`` **OR** with ``xmin`` and
27-
``xmax``.
28-
29-
Parameters
30-
----------
31-
x : array of size (2, 2, 2, 3)
32-
Coordinates of the corners of the box.
33-
34-
xmin : array of size (3)
35-
The extreme lower corner of the box
36-
xmax : array of size (3)
37-
The extreme upper corner of the box. In this case, by
38-
construction, the box will be coordinate axis aligned.
39-
"""
40-
tu = [0, 0, 1, 1]
41-
tv = [0, 0, 1, 1]
42-
tw = [0, 0, 1, 1]
43-
ku = 2
44-
kv = 2
45-
kw = 2
46-
47-
if len(args) == 1:
48-
return Volume(coef=args[0], tu=tu, tv=tv, tw=tw, ku=ku, kv=kv, kw=kw)
49-
elif len(args) == 2:
50-
xmin = np.array(args[0]).astype("d")
51-
xmax = np.array(args[1]).astype("d")
52-
53-
xLow = xmin[0]
54-
xHigh = xmax[0]
55-
yLow = xmin[1]
56-
yHigh = xmax[1]
57-
zLow = xmin[2]
58-
zHigh = xmax[2]
59-
60-
coef = np.zeros((2, 2, 2, 3))
61-
coef[0, 0, 0, :] = [xLow, yLow, zLow]
62-
coef[1, 0, 0, :] = [xHigh, yLow, zLow]
63-
coef[0, 1, 0, :] = [xLow, yHigh, zLow]
64-
coef[1, 1, 0, :] = [xHigh, yHigh, zLow]
65-
coef[0, 0, 1, :] = [xLow, yLow, zHigh]
66-
coef[1, 0, 1, :] = [xHigh, yLow, zHigh]
67-
coef[0, 1, 1, :] = [xLow, yHigh, zHigh]
68-
coef[1, 1, 1, :] = [xHigh, yHigh, zHigh]
69-
70-
return Volume(coef=coef, tu=tu, tv=tv, tw=tw, ku=ku, kv=kv, kw=kw)
71-
else:
72-
raise Error("An unknown number of arguments was passed to trilinear Volume")
73-
74-
75-
def bilinearSurface(*args):
76-
"""This is short-cut function to create a bilinear surface.
77-
78-
Args can contain:
79-
80-
1. ``x`` array of size(4, 3). The four corners of the array
81-
arranged in the coordinate direction orientation::
82-
83-
2 3
84-
+----------+
85-
| |
86-
| |
87-
| |
88-
+----------+
89-
0 1
90-
91-
2. ``p1``, ``p2``, ``p3``, ``p4``. Individual corner points in CCW Ordering::
92-
93-
3 2
94-
+----------+
95-
| |
96-
| |
97-
| |
98-
+----------+
99-
0 1
100-
"""
101-
if len(args) == 1:
102-
# One argument passed in ... assume its X
103-
if len(args[0]) != 4:
104-
raise Error("A single argument passed to bilinear surface must contain 4 points and be of size (4, 3)")
105-
coef = np.zeros((2, 2, 3))
106-
coef[0, 0] = args[0][0]
107-
coef[1, 0] = args[0][1]
108-
coef[0, 1] = args[0][2]
109-
coef[1, 1] = args[0][3]
110-
return Surface(coef=coef, tu=[0, 0, 1, 1], tv=[0, 0, 1, 1], ku=2, kv=2)
111-
else:
112-
# Assume 4 arguments
113-
coef = np.zeros([2, 2, 3])
114-
coef[0, 0] = args[0]
115-
coef[1, 0] = args[1]
116-
coef[0, 1] = args[3]
117-
coef[1, 1] = args[2]
118-
return Surface(coef=coef, tu=[0, 0, 1, 1], tv=[0, 0, 1, 1], ku=2, kv=2)
119-
120-
121-
def line(*args, **kwargs):
122-
"""This is a short cut function to create a line as a pySpline Curve object.
123-
124-
Args can contain: (pick one)
125-
126-
1. ``X`` array of size(2, ndim). The two end points
127-
2. ``x1``, ``x2`` The two end points (each of size ndim)
128-
3. ``x```, dir=direction. A point and a displacement vector
129-
4. ``x1``, dir=direction, length=length. As 3. but with a specific length
130-
"""
131-
132-
if len(args) == 2:
133-
# Its a two-point type
134-
return Curve(coef=[args[0], args[1]], k=2, t=[0, 0, 1, 1])
135-
elif len(args) == 1:
136-
if len(args[0]) == 2: # its X
137-
return Curve(coef=args[0], k=2, t=[0, 0, 1, 1])
138-
elif "dir" in kwargs:
139-
# We have point and direction
140-
if "length" in kwargs:
141-
x2 = args[0] + kwargs["dir"] / np.linalg.norm(kwargs["dir"]) * kwargs["length"]
142-
else:
143-
x2 = args[0] + kwargs["dir"]
144-
145-
return Curve(coef=[args[0], x2], k=2, t=[0, 0, 1, 1])
146-
else:
147-
Error("Error: dir must be specified if only 1 argument is given")
11+
from .pyCurve import Curve # noqa: F401
12+
from .pySurface import Surface # noqa: F401
13+
from .pyVolume import Volume # noqa: F401
14+
from .utils import ( # noqa: F401
15+
bilinearSurface,
16+
checkInput,
17+
closeTecplot,
18+
line,
19+
openTecplot,
20+
trilinearVolume,
21+
writeTecplot1D,
22+
writeTecplot2D,
23+
writeTecplot3D,
24+
)

0 commit comments

Comments
 (0)