Skip to content

Commit

Permalink
Merge pull request dipy#3342 from deka27/doctest-warnings
Browse files Browse the repository at this point in the history
RF: Doctest warnings
  • Loading branch information
skoudoro authored Aug 29, 2024
2 parents f169492 + 82adb4a commit 5acfcc9
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 30 deletions.
12 changes: 7 additions & 5 deletions dipy/core/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions dipy/core/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions dipy/core/sphere_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
6 changes: 3 additions & 3 deletions dipy/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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']
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dipy/io/dpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ 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()
... dpw.write_track(A)
... 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])
Expand Down
2 changes: 1 addition & 1 deletion dipy/reconst/gqi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion dipy/stats/qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
12 changes: 6 additions & 6 deletions dipy/tracking/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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]...)
"""
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dipy/tracking/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.]])
"""
Expand Down
10 changes: 5 additions & 5 deletions dipy/utils/deprecator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 5acfcc9

Please sign in to comment.