From 82adb4ac11b9c465a71755d13615853afdece917 Mon Sep 17 00:00:00 2001 From: Kaustav Deka <116963260+deka27@users.noreply.github.com> Date: Thu, 29 Aug 2024 19:59:16 +0530 Subject: [PATCH] RF: Doctest warnings --- dipy/core/geometry.py | 12 +++++++----- dipy/core/graph.py | 8 ++++---- dipy/core/sphere_stats.py | 4 ++-- dipy/data/__init__.py | 6 +++--- dipy/io/dpy.py | 4 ++-- dipy/reconst/gqi.py | 2 +- dipy/stats/qc.py | 2 +- dipy/tracking/metrics.py | 12 ++++++------ dipy/tracking/utils.py | 2 +- dipy/utils/deprecator.py | 10 +++++----- 10 files changed, 32 insertions(+), 30 deletions(-) diff --git a/dipy/core/geometry.py b/dipy/core/geometry.py index bdb569b2c2..cca323cf8e 100644 --- a/dipy/core/geometry.py +++ b/dipy/core/geometry.py @@ -610,17 +610,17 @@ def euler_matrix(ai, aj, ak, *, axes="sxyz"): Examples -------- >>> import numpy - >>> R = euler_matrix(1, 2, 3, 'syxz') + >>> R = euler_matrix(1, 2, 3, axes='syxz') >>> numpy.allclose(numpy.sum(R[0]), -1.34786452) True - >>> R = euler_matrix(1, 2, 3, (0, 1, 0, 1)) + >>> R = euler_matrix(1, 2, 3, axes=(0, 1, 0, 1)) >>> numpy.allclose(numpy.sum(R[0]), -0.383436184) True >>> ai, aj, ak = (4.0*math.pi) * (numpy.random.random(3) - 0.5) >>> for axes in _AXES2TUPLE.keys(): - ... _ = euler_matrix(ai, aj, ak, axes) + ... _ = euler_matrix(ai, aj, ak, axes=axes) >>> for axes in _TUPLE2AXES.keys(): - ... _ = euler_matrix(ai, aj, ak, axes) + ... _ = euler_matrix(ai, aj, ak, axes=axes) """ try: @@ -706,7 +706,9 @@ def compose_matrix( >>> angles = (np.random.random(3) - 0.5) * (2*math.pi) >>> trans = np.random.random(3) - 0.5 >>> persp = np.random.random(4) - 0.5 - >>> M0 = gm.compose_matrix(scale, shear, angles, trans, persp) + >>> M0 = gm.compose_matrix( + ... scale=scale, shear=shear, angles=angles, translate=trans, perspective=persp + ... ) """ M = np.identity(4) diff --git a/dipy/core/graph.py b/dipy/core/graph.py index 12eb35a3c8..78e9a75170 100644 --- a/dipy/core/graph.py +++ b/dipy/core/graph.py @@ -20,10 +20,10 @@ def __init__(self): -------- >>> from dipy.core.graph import Graph >>> g=Graph() - >>> g.add_node('a',5) - >>> g.add_node('b',6) - >>> g.add_node('c',10) - >>> g.add_node('d',11) + >>> g.add_node('a', attr=5) + >>> g.add_node('b', attr=6) + >>> g.add_node('c', attr=10) + >>> g.add_node('d', attr=11) >>> g.add_edge('a','b') >>> g.add_edge('b','c') >>> g.add_edge('c','d') diff --git a/dipy/core/sphere_stats.py b/dipy/core/sphere_stats.py index 0216612327..6f7400aeff 100644 --- a/dipy/core/sphere_stats.py +++ b/dipy/core/sphere_stats.py @@ -39,10 +39,10 @@ def random_uniform_on_sphere(*, n=1, coords="xyz"): Examples -------- >>> from dipy.core.sphere_stats import random_uniform_on_sphere - >>> X = random_uniform_on_sphere(4, 'radians') + >>> X = random_uniform_on_sphere(n=4, coords='radians') >>> X.shape == (4, 2) True - >>> X = random_uniform_on_sphere(4, 'xyz') + >>> X = random_uniform_on_sphere(n=4, coords='xyz') >>> X.shape == (4, 3) True """ diff --git a/dipy/data/__init__.py b/dipy/data/__init__.py index d4400bf16f..3924594ab7 100644 --- a/dipy/data/__init__.py +++ b/dipy/data/__init__.py @@ -171,7 +171,7 @@ def get_sim_voxels(*, name="fib1"): Examples -------- >>> from dipy.data import get_sim_voxels - >>> sv=get_sim_voxels('fib1') + >>> sv=get_sim_voxels(name='fib1') >>> sv['data'].shape == (100, 102) True >>> sv['fibres'] @@ -182,7 +182,7 @@ def get_sim_voxels(*, name="fib1"): True >>> sv['snr'] '60' - >>> sv2=get_sim_voxels('fib2') + >>> sv2=get_sim_voxels(name='fib2') >>> sv2['fibres'] '2' >>> sv2['snr'] @@ -217,7 +217,7 @@ def get_skeleton(*, name="C1"): Examples -------- >>> from dipy.data import get_skeleton - >>> C=get_skeleton('C1') + >>> C=get_skeleton(name='C1') >>> len(C.keys()) 117 >>> for c in C: break diff --git a/dipy/io/dpy.py b/dipy/io/dpy.py index b11f809f1f..44da773865 100644 --- a/dipy/io/dpy.py +++ b/dipy/io/dpy.py @@ -41,7 +41,7 @@ def __init__(self, fname, *, mode="r", compression=0): >>> def dpy_example(): ... fd,fname = mkstemp() ... fname += '.dpy'#add correct extension - ... dpw = Dpy(fname,'w') + ... dpw = Dpy(fname, mode='w') ... A=np.ones((5,3)) ... B=2*A.copy() ... C=3*A.copy() @@ -49,7 +49,7 @@ def __init__(self, fname, *, mode="r", compression=0): ... dpw.write_track(B) ... dpw.write_track(C) ... dpw.close() - ... dpr = Dpy(fname,'r') + ... dpr = Dpy(fname, mode='r') ... dpr.read_track() ... dpr.read_track() ... dpr.read_tracksi([0, 1, 2, 0, 0, 2]) diff --git a/dipy/reconst/gqi.py b/dipy/reconst/gqi.py index abff336aa0..b3fbe26f3e 100644 --- a/dipy/reconst/gqi.py +++ b/dipy/reconst/gqi.py @@ -53,7 +53,7 @@ def __init__(self, gtab, method="gqi2", sampling_length=1.2, normalize_peaks=Fal >>> from dipy.data import dsi_voxels >>> data, gtab = dsi_voxels() >>> from dipy.core.subdivide_octahedron import create_unit_sphere - >>> sphere = create_unit_sphere(5) + >>> sphere = create_unit_sphere(recursion_level=5) >>> from dipy.reconst.gqi import GeneralizedQSamplingModel >>> gq = GeneralizedQSamplingModel(gtab, 'gqi2', 1.1) >>> voxel_signal = data[0, 0, 0] diff --git a/dipy/stats/qc.py b/dipy/stats/qc.py index 41746f022a..3ab04f9cf4 100644 --- a/dipy/stats/qc.py +++ b/dipy/stats/qc.py @@ -30,7 +30,7 @@ def find_qspace_neighbors(gtab): >>> import numpy as np >>> gtab = gradient_table( ... np.array([0, 1000, 1000, 2000]), - ... np.array([ + ... bvecs=np.array([ ... [1, 0, 0], ... [1, 0, 0], ... [0.99, 0.0001, 0.0001], diff --git a/dipy/tracking/metrics.py b/dipy/tracking/metrics.py index f8013b37cf..b952a416c8 100644 --- a/dipy/tracking/metrics.py +++ b/dipy/tracking/metrics.py @@ -302,15 +302,15 @@ def frenet_serret(xyz): dxyz = np.gradient(xyz)[0] ddxyz = np.gradient(dxyz)[0] # Tangent - T = np.divide(dxyz, magn(dxyz, 3)) + T = np.divide(dxyz, magn(dxyz, n=3)) # Derivative of Tangent dT = np.gradient(T)[0] # Normal - N = np.divide(dT, magn(dT, 3)) + N = np.divide(dT, magn(dT, n=3)) # Binormal B = np.cross(T, N) # Curvature - k = magn(np.cross(dxyz, ddxyz), 1) / (magn(dxyz, 1) ** 3) + k = magn(np.cross(dxyz, ddxyz), n=1) / (magn(dxyz, n=1) ** 3) # Torsion # (In matlab was t=dot(-B,N,2)) t = np.sum(-B * N, axis=1) @@ -358,7 +358,7 @@ def mean_curvature(xyz): ddxyz = np.gradient(dxyz)[0] # Curvature - k = magn(np.cross(dxyz, ddxyz), 1) / (magn(dxyz, 1) ** 3) + k = magn(np.cross(dxyz, ddxyz), n=1) / (magn(dxyz, n=1) ** 3) return np.mean(k) @@ -452,7 +452,7 @@ def longest_track_bundle(bundle, *, sort=False): >>> longest_track_bundle(bundle) array([[0, 0, 0], [4, 4, 4]]) - >>> longest_track_bundle(bundle, True) #doctest: +ELLIPSIS + >>> longest_track_bundle(bundle, sort=True) #doctest: +ELLIPSIS array([0, 1]...) """ @@ -665,7 +665,7 @@ def spline(xyz, *, s=3, k=2, nest=-1): >>> y+= np.random.normal(scale=0.1, size=y.shape) >>> z+= np.random.normal(scale=0.1, size=z.shape) >>> xyz=np.vstack((x,y,z)).T - >>> xyzn=spline(xyz,3,2,-1) + >>> xyzn=spline(xyz,s=3,k=2,nest=-1) >>> len(xyzn) > len(xyz) True diff --git a/dipy/tracking/utils.py b/dipy/tracking/utils.py index 041e18dfeb..ff263f140d 100644 --- a/dipy/tracking/utils.py +++ b/dipy/tracking/utils.py @@ -380,7 +380,7 @@ def seeds_from_mask(mask, affine, *, density=(1, 1, 1)): -------- >>> mask = np.zeros((3,3,3), 'bool') >>> mask[0,0,0] = 1 - >>> seeds_from_mask(mask, np.eye(4), [1,1,1]) + >>> seeds_from_mask(mask, np.eye(4), density=[1,1,1]) array([[ 0., 0., 0.]]) """ diff --git a/dipy/utils/deprecator.py b/dipy/utils/deprecator.py index 021ccedd20..efaedbee1b 100644 --- a/dipy/utils/deprecator.py +++ b/dipy/utils/deprecator.py @@ -105,9 +105,9 @@ def cmp_pkg_version(version_str, *, pkg_version_str=__version__): Examples -------- - >>> cmp_pkg_version('1.2.1', '1.2.0') + >>> cmp_pkg_version('1.2.1', pkg_version_str='1.2.0') 1 - >>> cmp_pkg_version('1.2.0dev', '1.2.0') + >>> cmp_pkg_version('1.2.0dev', pkg_version_str='1.2.0') -1 """ @@ -277,7 +277,7 @@ def deprecated_params( The deprecation warnings are not shown in the following examples. To deprecate a positional or keyword argument:: >>> from dipy.utils.deprecator import deprecated_params - >>> @deprecated_params('sig', 'sigma', '0.3') + >>> @deprecated_params('sig', new_name='sigma', since='0.3') ... def test(sigma): ... return sigma >>> test(2) @@ -290,8 +290,8 @@ def deprecated_params( It is also possible to replace multiple arguments. The ``old_name``, ``new_name`` and ``since`` have to be `tuple` or `list` and contain the same number of entries:: - >>> @deprecated_params(['a', 'b'], ['alpha', 'beta'], - ... ['0.2', 0.4]) + >>> @deprecated_params(['a', 'b'], new_name=['alpha', 'beta'], + ... since=['0.2', 0.4]) ... def test(alpha, beta): ... return alpha, beta >>> test(a=2, b=3) # doctest: +SKIP