From 3475cf1f5f5c26f766b9faab29e30d9525ac48aa Mon Sep 17 00:00:00 2001 From: Michael Anderson Date: Mon, 22 Jan 2018 11:58:22 -0800 Subject: [PATCH 1/3] fixed docstring --- brainiak/searchlight/searchlight.py | 60 ++++++++++++++++------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/brainiak/searchlight/searchlight.py b/brainiak/searchlight/searchlight.py index 968a33e99..ffccc9249 100644 --- a/brainiak/searchlight/searchlight.py +++ b/brainiak/searchlight/searchlight.py @@ -26,20 +26,20 @@ "Searchlight", ] +"""Shape -class Shape: - """Shape +Searchlight shape which is contained in a cube sized +(2*rad+1,2*rad+1,2*rad+1) - Searchlight shape which is contained in a cube sized - (2*rad+1,2*rad+1,2*rad+1) +Attributes +---------- - Attributes - ---------- +mask_ : a 3D boolean numpy array of size (2*rad+1,2*rad+1,2*rad+1) + which is set to True within the boundaries of the desired shape +""" - mask_ : a 3D boolean numpy array of size (2*rad+1,2*rad+1,2*rad+1) - which is set to True within the boundaries of the desired shape - """ +class Shape: def __init__(self, rad): """Constructor @@ -53,11 +53,13 @@ def __init__(self, rad): self.rad = rad -class Cube(Shape): - """Cube +"""Cube - Searchlight shape which is a cube of size (2*rad+1,2*rad+1,2*rad+1) - """ +Searchlight shape which is a cube of size (2*rad+1,2*rad+1,2*rad+1) +""" + + +class Cube(Shape): def __init__(self, rad): """Constructor @@ -73,14 +75,16 @@ def __init__(self, rad): self.mask_ = np.ones((2*rad+1, 2*rad+1, 2*rad+1), dtype=np.bool) -class Diamond(Shape): - """Diamond +"""Diamond - Searchlight shape which is a diamond - inscribed in a cube of size (2*rad+1,2*rad+1,2*rad+1). - Any location in the cube which has a Manhattan distance of less than rad - from the center point is set to True. - """ +Searchlight shape which is a diamond +inscribed in a cube of size (2*rad+1,2*rad+1,2*rad+1). +Any location in the cube which has a Manhattan distance of less than rad +from the center point is set to True. +""" + + +class Diamond(Shape): def __init__(self, rad): """Constructor @@ -101,15 +105,17 @@ def __init__(self, rad): self.mask_[r1, r2, r3] = True -class Searchlight: - """Distributed Searchlight +"""Distributed Searchlight - Run a user-defined function over each voxel in a multi-subject - dataset. +Run a user-defined function over each voxel in a multi-subject +dataset. - Optionally, users can define a block function which runs over - larger portions of the volume called blocks. - """ +Optionally, users can define a block function which runs over +larger portions of the volume called blocks. +""" + + +class Searchlight: def __init__(self, sl_rad=1, max_blk_edge=10, shape=Cube, min_active_voxels_proportion=0): """Constructor From b443b07469ff64167c9343d007bf37985cdf7aa2 Mon Sep 17 00:00:00 2001 From: Michael Anderson Date: Mon, 29 Jan 2018 10:59:23 -0800 Subject: [PATCH 2/3] Fixed docstring --- brainiak/searchlight/searchlight.py | 130 +++++++++++++--------------- 1 file changed, 58 insertions(+), 72 deletions(-) diff --git a/brainiak/searchlight/searchlight.py b/brainiak/searchlight/searchlight.py index ffccc9249..756b6b848 100644 --- a/brainiak/searchlight/searchlight.py +++ b/brainiak/searchlight/searchlight.py @@ -26,75 +26,65 @@ "Searchlight", ] -"""Shape -Searchlight shape which is contained in a cube sized -(2*rad+1,2*rad+1,2*rad+1) +class Shape: + """Shape -Attributes ----------- + Searchlight shape which is contained in a cube sized + (2*rad+1,2*rad+1,2*rad+1) -mask_ : a 3D boolean numpy array of size (2*rad+1,2*rad+1,2*rad+1) - which is set to True within the boundaries of the desired shape -""" + Attributes + ---------- + mask_ : a 3D boolean numpy array of size (2*rad+1,2*rad+1,2*rad+1) + which is set to True within the boundaries of the desired shape -class Shape: - def __init__(self, rad): - """Constructor + Parameters + ---------- - Parameters - ---------- + rad: radius, in voxels, of the sphere inscribed in the + searchlight cube, not counting the center voxel - rad: radius, in voxels, of the sphere inscribed in the - searchlight cube, not counting the center voxel + """ - """ + def __init__(self, rad): self.rad = rad -"""Cube - -Searchlight shape which is a cube of size (2*rad+1,2*rad+1,2*rad+1) -""" - - class Cube(Shape): - def __init__(self, rad): - """Constructor + """Cube - Parameters - ---------- + Searchlight shape which is a cube of size (2*rad+1,2*rad+1,2*rad+1) - rad: radius, in voxels, of the sphere inscribed in the - searchlight cube, not counting the center voxel + Parameters + ---------- - """ + rad: radius, in voxels, of the sphere inscribed in the + searchlight cube, not counting the center voxel + + """ + def __init__(self, rad): super().__init__(rad) self.rad = rad self.mask_ = np.ones((2*rad+1, 2*rad+1, 2*rad+1), dtype=np.bool) -"""Diamond - -Searchlight shape which is a diamond -inscribed in a cube of size (2*rad+1,2*rad+1,2*rad+1). -Any location in the cube which has a Manhattan distance of less than rad -from the center point is set to True. -""" - - class Diamond(Shape): - def __init__(self, rad): - """Constructor + """Diamond - Parameters - ---------- + Searchlight shape which is a diamond + inscribed in a cube of size (2*rad+1,2*rad+1,2*rad+1). + Any location in the cube which has a Manhattan distance of less than rad + from the center point is set to True. - rad: radius, in voxels, of the sphere inscribed in the - searchlight cube, not counting the center voxel + Parameters + ---------- - """ + rad: radius, in voxels, of the sphere inscribed in the + searchlight cube, not counting the center voxel + + """ + def __init__(self, rad): super().__init__(rad) self.mask_ = np.zeros((2*rad+1, 2*rad+1, 2*rad+1), dtype=np.bool) for r1 in range(2*self.rad+1): @@ -105,40 +95,36 @@ def __init__(self, rad): self.mask_[r1, r2, r3] = True -"""Distributed Searchlight - -Run a user-defined function over each voxel in a multi-subject -dataset. - -Optionally, users can define a block function which runs over -larger portions of the volume called blocks. -""" +class Searchlight: + """Distributed Searchlight + Run a user-defined function over each voxel in a multi-subject + dataset. -class Searchlight: - def __init__(self, sl_rad=1, max_blk_edge=10, shape=Cube, - min_active_voxels_proportion=0): - """Constructor + Optionally, users can define a block function which runs over + larger portions of the volume called blocks. - Parameters - ---------- + Parameters + ---------- - sl_rad: radius, in voxels, of the sphere inscribed in the - searchlight cube, not counting the center voxel + sl_rad: radius, in voxels, of the sphere inscribed in the + searchlight cube, not counting the center voxel - max_blk_edge: max edge length, in voxels, of the 3D block + max_blk_edge: max edge length, in voxels, of the 3D block - shape: brainiak.searchlight.searchlight.Shape indicating the - shape in voxels of the searchlight region + shape: brainiak.searchlight.searchlight.Shape indicating the + shape in voxels of the searchlight region - min_active_voxels_proportion: float - If a searchlight region does not have more than this minimum - proportion of active voxels in the mask, it is not processed by the - searchlight function. The mask used for the test is the - intersection of the global (brain) mask and the `Shape` mask. The - seed (central) voxel of the searchlight region is taken into - consideration. - """ + min_active_voxels_proportion: float + If a searchlight region does not have more than this minimum + proportion of active voxels in the mask, it is not processed by the + searchlight function. The mask used for the test is the + intersection of the global (brain) mask and the `Shape` mask. The + seed (central) voxel of the searchlight region is taken into + consideration. + """ + def __init__(self, sl_rad=1, max_blk_edge=10, shape=Cube, + min_active_voxels_proportion=0): self.sl_rad = sl_rad self.max_blk_edge = max_blk_edge self.min_active_voxels_proportion = min_active_voxels_proportion From fef499e313e78652411099ab906a68b806cb5fd1 Mon Sep 17 00:00:00 2001 From: Michael Anderson Date: Mon, 29 Jan 2018 11:08:41 -0800 Subject: [PATCH 3/3] Added shape classes --- brainiak/searchlight/searchlight.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brainiak/searchlight/searchlight.py b/brainiak/searchlight/searchlight.py index 756b6b848..651c9c988 100644 --- a/brainiak/searchlight/searchlight.py +++ b/brainiak/searchlight/searchlight.py @@ -23,7 +23,7 @@ """ __all__ = [ - "Searchlight", + "Searchlight", "Shape", "Cube", "Diamond" ]