Skip to content

Commit 9402b2a

Browse files
committed
remove dependencies on scipy
1 parent afed0b1 commit 9402b2a

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

spatialmath/base/graphics.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from itertools import product
33
import warnings
44
import numpy as np
5-
import scipy as sp
65
from matplotlib import colors
76

87
from spatialmath import base as smbase
@@ -574,6 +573,8 @@ def ellipse(E, centre=(0, 0), scale=1, confidence=None, resolution=40, inverted=
574573
so to avoid inverting ``E`` twice to compute the ellipse, we flag that
575574
the inverse is provided using ``inverted``.
576575
"""
576+
from scipy.linalg import sqrtm
577+
577578
if E.shape != (2, 2):
578579
raise ValueError("ellipse is defined by a 2x2 matrix")
579580

@@ -590,7 +591,7 @@ def ellipse(E, centre=(0, 0), scale=1, confidence=None, resolution=40, inverted=
590591
if not inverted:
591592
E = np.linalg.inv(E)
592593

593-
e = s * sp.linalg.sqrtm(E) @ xy + np.array(centre, ndmin=2).T
594+
e = s * sqrtm(E) @ xy + np.array(centre, ndmin=2).T
594595
return e
595596

596597

@@ -766,6 +767,8 @@ def ellipsoid(
766767
767768
:seealso: :func:`plot_ellipsoid`, :func:`~matplotlib.pyplot.plot_surface`, :func:`~matplotlib.pyplot.plot_wireframe`
768769
"""
770+
from scipy.linalg import sqrtm
771+
769772
if E.shape != (3, 3):
770773
raise ValueError("ellipsoid is defined by a 3x3 matrix")
771774

@@ -782,7 +785,7 @@ def ellipsoid(
782785

783786
x, y, z = sphere() # unit sphere
784787
e = (
785-
s * sp.linalg.sqrtm(E) @ np.array([x.flatten(), y.flatten(), z.flatten()])
788+
s * sqrtm(E) @ np.array([x.flatten(), y.flatten(), z.flatten()])
786789
+ np.c_[centre].T
787790
)
788791
return e[0, :].reshape(x.shape), e[1, :].reshape(x.shape), e[2, :].reshape(x.shape)

spatialmath/base/transforms2d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import sys
1818
import math
1919
import numpy as np
20-
import scipy.linalg
2120
import spatialmath.base as smb
2221

2322
_eps = np.finfo(np.float64).eps
@@ -793,7 +792,6 @@ def points2tr2(p1, p2):
793792
# https://github.com/1988kramer/intel_dataset/blob/master/scripts/Align2D.py
794793
# hack below to use points2tr above
795794
# use ClayFlannigan's improved data association
796-
from scipy.spatial import KDTree
797795

798796
# reference or target 2xN
799797
# source 2xN
@@ -821,6 +819,8 @@ def points2tr2(p1, p2):
821819
# min_delta_err: float, minimum change in alignment error
822820
def ICP2d(reference, source, T=None, max_iter=20, min_delta_err=1e-4):
823821

822+
from scipy.spatial import KDTree
823+
824824
mean_sq_error = 1.0e6 # initialize error as large number
825825
delta_err = 1.0e6 # change in error (used in stopping condition)
826826
num_iter = 0 # number of iterations

spatialmath/base/transforms3d.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import sys
1818
import math
1919
import numpy as np
20-
import scipy as sp
2120
from collections.abc import Iterable
2221

2322
from spatialmath import base as smb

0 commit comments

Comments
 (0)