Skip to content

Commit 4c12c70

Browse files
committed
fix: import numpy for doctests
1 parent d49849a commit 4c12c70

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

mindboggle/mio/colors.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def distinguishable_colors(ncolors, backgrounds=[[0,0,0],[1,1,1]],
5454
Examples
5555
--------
5656
>>> from mindboggle.mio.colors import distinguishable_colors
57+
>>> import numpy as np
5758
>>> ncolors = 31
5859
>>> backgrounds = [[0,0,0],[1,1,1]]
5960
>>> save_csv = False
@@ -218,6 +219,7 @@ def label_adjacency_matrix(label_file, ignore_values=[-1, 999], add_value=0,
218219
--------
219220
>>> from mindboggle.mio.colors import label_adjacency_matrix
220221
>>> from mindboggle.mio.fetch_data import prep_tests
222+
>>> import numpy as np
221223
>>> urls, fetch_data = prep_tests()
222224
>>> ignore_values = [-1, 0]
223225
>>> add_value = 0
@@ -402,6 +404,7 @@ def group_colors(colormap, colormap_name, description='', adjacency_matrix=[],
402404
--------
403405
>>> # Get colormap:
404406
>>> from mindboggle.mio.colors import distinguishable_colors
407+
>>> import numpy as np
405408
>>> colormap = distinguishable_colors(ncolors=31,
406409
... backgrounds=[[0,0,0],[1,1,1]],
407410
... save_csv=False, plot_colormap=False, verbose=False)
@@ -432,29 +435,29 @@ def group_colors(colormap, colormap_name, description='', adjacency_matrix=[],
432435
>>> colors = group_colors(colormap, colormap_name, description,
433436
... adjacency_matrix, IDs, names, groups,
434437
... save_text_files, plot_colors, plot_graphs, out_dir, verbose)
435-
>>> colors[0]
436-
[0.7586206896551724, 0.20689655172413793, 0.0]
437-
>>> colors[1]
438-
[0.48275862068965514, 0.4482758620689655, 0.48275862068965514]
439-
>>> colors[2]
440-
[0.3448275862068966, 0.3103448275862069, 0.034482758620689655]
441-
>>> colors[-1]
442-
[0.7931034482758621, 0.9655172413793103, 0.7931034482758621]
438+
>>> np.allclose(colors[0], [0.7586206896551724, 0.20689655172413793, 0.0])
439+
True
440+
>>> np.allclose(colors[1], [0.48275862068965514, 0.4482758620689655, 0.48275862068965514])
441+
True
442+
>>> np.allclose(colors[2], [0.3448275862068966, 0.3103448275862069, 0.034482758620689655])
443+
True
444+
>>> np.allclose(colors[-1], [0.7931034482758621, 0.9655172413793103, 0.7931034482758621])
445+
True
443446
444447
No groups / subgraphs:
445448
446449
>>> groups = []
447450
>>> colors = group_colors(colormap, colormap_name, description,
448451
... adjacency_matrix, IDs, names, groups,
449452
... save_text_files, plot_colors, plot_graphs, out_dir, verbose)
450-
>>> colors[0]
451-
[0.5172413793103449, 0.8275862068965517, 1.0]
452-
>>> colors[1]
453-
[0.13793103448275862, 0.0, 0.24137931034482757]
454-
>>> colors[2]
455-
[0.3793103448275862, 0.27586206896551724, 0.48275862068965514]
456-
>>> colors[-1]
457-
[0.6206896551724138, 0.48275862068965514, 0.3448275862068966]
453+
>>> np.allclose(colors[0], [0.5172413793103449, 0.8275862068965517, 1.0])
454+
True
455+
>>> np.allclose(colors[1], [0.13793103448275862, 0.0, 0.24137931034482757])
456+
True
457+
>>> np.allclose(colors[2], [0.3793103448275862, 0.27586206896551724, 0.48275862068965514])
458+
True
459+
>>> np.allclose(colors[-1], [0.6206896551724138, 0.48275862068965514, 0.3448275862068966])
460+
True
458461
459462
"""
460463
import os
@@ -834,6 +837,7 @@ def write_json_colormap(colormap, label_numbers, label_names=[],
834837
--------
835838
>>> from mindboggle.mio.colors import write_xml_colormap
836839
>>> from mindboggle.mio.labels import DKTprotocol
840+
>>> import numpy as np
837841
>>> dkt = DKTprotocol()
838842
>>> colormap = dkt.colormap_normalized
839843
>>> colormap = [[x[2], x[3], x[4]] for x in colormap]
@@ -842,8 +846,8 @@ def write_json_colormap(colormap, label_numbers, label_names=[],
842846
>>> colormap_file = ''
843847
>>> colormap_name = "DKT31colormap"
844848
>>> description = "Colormap for DKT31 human brain cortical labels"
845-
>>> colormap[0]
846-
[0.803921568627451, 0.24313725490196078, 0.3058823529411765]
849+
>>> np.allclose(colormap[0], [0.803921568627451, 0.24313725490196078, 0.3058823529411765])
850+
True
847851
>>> write_json_colormap(colormap, label_numbers, label_names,
848852
... colormap_file, colormap_name, description)
849853
"""
@@ -895,14 +899,15 @@ def write_xml_colormap(colormap, label_numbers, colormap_file='',
895899
--------
896900
>>> from mindboggle.mio.colors import write_xml_colormap
897901
>>> from mindboggle.mio.labels import DKTprotocol
902+
>>> import numpy as np
898903
>>> dkt = DKTprotocol()
899904
>>> colormap = dkt.colormap_normalized
900905
>>> colormap = [[x[2], x[3], x[4]] for x in colormap]
901906
>>> label_numbers = dkt.label_numbers
902907
>>> colormap_file = ''
903908
>>> colormap_name = 'DKT31colormap'
904-
>>> colormap[0]
905-
[0.803921568627451, 0.24313725490196078, 0.3058823529411765]
909+
>>> np.allclose(colormap[0], [0.803921568627451, 0.24313725490196078, 0.3058823529411765])
910+
True
906911
>>> write_xml_colormap(colormap, label_numbers, colormap_file,
907912
... colormap_name)
908913
"""

mindboggle/mio/tables.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ def select_column_from_tables(tables, index=0, write_table=True,
815815
--------
816816
>>> from mindboggle.mio.tables import select_column_from_tables
817817
>>> from mindboggle.mio.fetch_data import prep_tests
818+
>>> import numpy as np
818819
>>> urls, fetch_data = prep_tests()
819820
>>> tables = [fetch_data(urls['thickinthehead_freesurfer_labels_table'], '', '.csv'),
820821
... fetch_data(urls['thickinthehead_freesurfer_labels_table'], '', '.csv')]

0 commit comments

Comments
 (0)