Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RF: rename variables in ROI selection loops #423

Merged
merged 2 commits into from
Feb 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions nipy/labs/spatial_models/mroi.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def __init__(self, domain, label, id=None):
should access ROI through their id to avoid hazardous manipulations.

"""
self._init(domain, label, id)

def _init(self, domain, label, id=None):
# check that label size is consistent with domain
if np.size(label) != domain.size:
raise ValueError('inconsistent labels and domains specification')
Expand Down Expand Up @@ -686,7 +689,7 @@ def select_roi(self, id_list):
"""
# handle the case of an empty selection
if len(id_list) == 0:
self = SubDomains(self.domain, -np.ones(self.label.size))
self._init(self.domain, -np.ones(self.label.size))
return
# convert id to indices
id_list_pos = np.ravel([self.select_id(k) for k in id_list])
Expand All @@ -699,19 +702,19 @@ def select_roi(self, id_list):

# set new features
# (it's ok to do that after labels and id modification since we are
# poping out the former features and use the former id indices)
for fid in list(self.features):
f = self.remove_feature(fid)
sf = [f[id] for id in id_list_pos]
self.set_feature(fid, sf)
# popping out the former features and use the former id indices)
for feature_name in list(self.features):
current_feature = self.remove_feature(feature_name)
sf = [current_feature[id] for id in id_list_pos]
self.set_feature(feature_name, sf)
# set new ROI features
# (it's ok to do that after labels and id modification since we are
# poping out the former features and use the former id indices)
for fid in list(self.roi_features):
if fid != 'id':
f = self.remove_roi_feature(fid)
sf = np.ravel(f[int(id_list_pos)])
self.set_roi_feature(fid, sf)
# popping out the former features and use the former id indices)
for feature_name in list(self.roi_features):
if feature_name != 'id':
current_feature = self.remove_roi_feature(feature_name)
sf = np.ravel(current_feature[int(id_list_pos)])
self.set_roi_feature(feature_name, sf)


def subdomain_from_array(labels, affine=None, nn=0):
Expand Down
9 changes: 7 additions & 2 deletions nipy/labs/spatial_models/tests/test_mroi.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,21 @@ def test_copy_subdomain():


def test_select_roi():
"""
"""
# Test select_roi method
mroi = make_subdomain()
aux = np.random.randn(np.prod(shape))
data = [aux[mroi.label == k] for k in range(8)]
mroi.set_feature('data', data)
mroi.set_roi_feature('data_mean', list(range(8)))
mroi.select_roi([0])
assert(mroi.k == 1)
assert_equal(mroi.roi_features['id'], [0])
assert_equal(mroi.get_roi_feature('data_mean', 0), 0)
mroi.select_roi([])
assert(mroi.k == 0)
assert_equal(list(mroi.roi_features), ['id'])
assert_equal(mroi.roi_features['id'], [])


def test_roi_features():
"""
Expand Down