Skip to content

Commit

Permalink
Merge branch 'feature/refactor' into feature/docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaime Arias committed Oct 12, 2017
2 parents c30325a + 6a5e22c commit f8de737
Show file tree
Hide file tree
Showing 21 changed files with 1,634 additions and 1,231 deletions.
77 changes: 46 additions & 31 deletions python/pyhrf/graph.py
Expand Up @@ -466,30 +466,38 @@ def __call__(self, node, parent):


def split_mask_into_cc_iter(mask, min_size=0, kerMask=None):
""" Return an iterator over all connected components (CC) within input mask.
CC which are smaller than min_size are discarded. 'kerMask' defines the connexity,
eg kerMask3D_6n for 6-neighbours in 3D.
Example:
vol = np.array( [[1,1,0,1,1],
[1,1,0,1,1],
[0,0,0,0,0],
[1,0,1,1,0],
[0,0,1,1,0]], dtype=int )
for cc in split_mask_into_cc_iter(vol):
print cc
""" Return an iterator over all connected components (CC) within input mask. CC which are smaller than `min_size`
are discarded. `kerMask` defines the connectivity, e.g., kerMask3D_6n for 6-neighbours in 3D.
Examples
--------
.. code::
vol = np.array( [[1,1,0,1,1],
[1,1,0,1,1],
[0,0,0,0,0],
[1,0,1,1,0],
[0,0,1,1,0]], dtype=int )
for cc in split_mask_into_cc_iter(vol):
print cc
Should output:
np.array( [[1,1,0,0,0],
[1,1,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0]]
np.array( [[0,0,0,1,1],
[0,0,0,1,1],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0]]
...
.. code::
np.array( [[1,1,0,0,0],
[1,1,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0]]
np.array( [[0,0,0,1,1],
[0,0,0,1,1],
[0,0,0,0,0],
[0,0,0,0,0],
[0,0,0,0,0]]
"""
assert isinstance(min_size, int)
flat_mask = mask[np.where(mask)]
Expand Down Expand Up @@ -543,15 +551,22 @@ def sub_graph(graph, nodes):
return subg, nodeMap


def parcels_to_graphs(parcellation, kerMask, toKeep=None,
toDiscard=None):
"""
Compute graphs for each parcel in parcels. A graph is simply defined as
a list of neihbour indexes.
'parcellation' is a n-ary numpy array.
'kerMask' defines the connectivity
Return :
- a dictionnary mapping a roi ID to its graph
def parcels_to_graphs(parcellation, kerMask, toKeep=None, toDiscard=None):
"""Compute graphs for each parcel in parcels. A graph is simply defined as a list of neighbour indexes.
Parameters
----------
parcellation:
is a n-ary numpy array.
kerMask:
defines the connectivity
toKeep
toDiscard
Returns
-------
a dictionary mapping a roi ID to its graph
"""
# determine the set of parcels to work on:
parcelIds = np.unique(parcellation) # everything
Expand Down
23 changes: 12 additions & 11 deletions python/pyhrf/grid.py
Expand Up @@ -613,17 +613,18 @@ def next(self):


class User(object):
'''
User(name, passwd, keytype)
Define user launching task and identification process.
name : username.
passwd : user passwd or if None, try to get ~/.ssh/id_dsa dsa key
for key connection.
keytype : 'rsa' or 'dsa'.
'''
def __init__(self, name = None, passwd = None, keytype = None):
"""Define user launching task and identification process.
Parameters
----------
name
username.
passwd
user passwd or if None, try to get `~/.ssh/id_dsa` dsa key for key connection.
keytype
`rsa` or `dsa`.
"""
def __init__(self, name=None, passwd=None, keytype=None):
if name is None:
name = os.getenv('USER')
self.name = name
Expand Down

0 comments on commit f8de737

Please sign in to comment.