Skip to content

Commit 3c0cb5a

Browse files
committed
test: Update 2D periodic spline example
Add reproducable randomness and remove matplotlib dependence. Signed-off-by: Sietze van Buuren <s.van.buuren@gmail.com>
1 parent 1f8bf59 commit 3c0cb5a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

cubinterpp/periodic_spline_2d.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" Periodic spline example in 3D """
22

3+
import random
34
import numpy as np
45
import cubinterpp.cubinterpp_py as cubinterpp # cubinterpp_py is a pybind11 module
56
import mlpyqtgraph as mpg
@@ -8,13 +9,14 @@
89
@mpg.plotter(projection='orthographic')
910
def main():
1011
""" Interpolation of a torus to demonstrate periodic splines in 2D """
11-
nx, ny = 5, 5
12+
nx, ny = 9, 9
1213
tx = np.linspace(0.0, 1.0, nx)
1314
ty = np.linspace(0.0, 1.0, ny)
1415
# generate torus points
1516
r_major = 3.0 # major radius
1617
r_minor = 1.0 # minor radius
1718

19+
random.seed(43)
1820
x = np.zeros((nx, ny))
1921
y = np.zeros((nx, ny))
2022
z = np.zeros((nx, ny))
@@ -24,7 +26,10 @@ def main():
2426
v = 2.0 * np.pi * ty[j]
2527
x[i, j] = (r_major + r_minor * np.cos(v)) * np.cos(u)
2628
y[i, j] = (r_major + r_minor * np.cos(v)) * np.sin(u)
27-
z[i, j] = r_minor * np.sin(v)
29+
if i == nx - 1:
30+
z[i, j] = z[0, j]
31+
else:
32+
z[i, j] = (1.0 + random.randint(-2, +2)/8.0) * r_minor * np.sin(v)
2833

2934
# create periodic splines in 2D
3035
spline_x = cubinterpp.NaturalPeriodicSpline2D(tx, ty, x)
@@ -44,7 +49,7 @@ def main():
4449
z_fine[i, j] = spline_z.eval(txi[i], tyi[j])
4550

4651

47-
mpg.figure(title='Periodic Spline Interpolation of a Torus')
52+
mpg.figure(title='Periodic Spline Interpolation of a distorted Torus')
4853
mpg.surf(x_fine, y_fine, z_fine)
4954
ax = mpg.gca()
5055
ax.azimuth = 225
@@ -55,6 +60,8 @@ def main():
5560
yp = y.flatten()
5661
zp = z.flatten()
5762
mpg.points3(xp, yp, zp, color=(0.8, 0.1, 0.1, 1), size=5)
63+
ax.export('periodic_spline_2d.png')
64+
5865

5966
if __name__ == '__main__':
6067
main()

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ classifiers = [
2020
]
2121
urls = { Homepage = "https://github.com/swvanbuuren/cubinterpp" }
2222
dependencies = [
23-
"matplotlib>=3.10.8",
24-
"mlpyqtgraph==0.11.2",
23+
"mlpyqtgraph==0.12.0",
2524
"scipy==1.17.0",
2625
]
2726

0 commit comments

Comments
 (0)