From 4a947faaaf8ba165d311784cf3a43d24f59d57ab Mon Sep 17 00:00:00 2001 From: David Romascano Date: Wed, 19 Dec 2018 13:47:53 +0100 Subject: [PATCH 1/3] Define shells as unique combinations of G, Delta, delta and TE --- amico/scheme.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/amico/scheme.py b/amico/scheme.py index b898baa..31a3b68 100644 --- a/amico/scheme.py +++ b/amico/scheme.py @@ -95,30 +95,27 @@ def load_from_table( self, data, b0_thr = 0 ) : # store information about each shell in a dictionary self.shells = [] - - tmp = np.ascontiguousarray( self.raw[:,3:] ) - schemeUnique, schemeUniqueInd = np.unique( tmp.view([('', tmp.dtype)]*tmp.shape[1]), return_index=True ) - schemeUnique = schemeUnique.view(tmp.dtype).reshape((schemeUnique.shape[0], tmp.shape[1])) - schemeUnique = [tmp[index] for index in sorted(schemeUniqueInd)] - bUnique = [self.b[index] for index in sorted(schemeUniqueInd)] - for i in xrange(len(schemeUnique)) : - if bUnique[i] <= b0_thr : - continue + + tmp1,tmp2 = np.unique(self.raw[:,3:],axis=0,return_index=True) # Find unique b-values or combinations of G, Delta, delta and TE (and the 1st index of each of those shells) + tmp1 = tmp1[self.b[tmp2] > 0,:] # Remove b0 + tmp2 = tmp2[self.b[tmp2] > 0] # Remove b0 + # For each shell, find its indexes, grad, b-value and shell parameters + for tmp3 in np.argsort(tmp2): + shell_features = tmp1[tmp3,:] shell = {} - shell['b'] = bUnique[i] - if self.version == 0 : + shell['idx'] = np.where((self.raw[:,3:] == shell_features).all(axis=1)) + shell['grad'] = self.raw[shell['idx'],:3] + shell['b'] = np.unique(self.b[shell['idx']])[0] + if self.version == 0: shell['G'] = None shell['Delta'] = None shell['delta'] = None shell['TE'] = None else : - shell['G'] = schemeUnique[i][0] - shell['Delta'] = schemeUnique[i][1] - shell['delta'] = schemeUnique[i][2] - shell['TE'] = schemeUnique[i][3] - - shell['idx'] = np.where((tmp == schemeUnique[i]).all(axis=1))[0] - shell['grad'] = self.raw[shell['idx'],0:3] + shell['G'] = shell_features[0] + shell['Delta'] = shell_features[1] + shell['delta'] = shell_features[2] + shell['TE'] = shell_features[3] self.shells.append( shell ) From b0e8e3260f54adc9240c7d0d673c86ccd1e97ddf Mon Sep 17 00:00:00 2001 From: David Romascano Date: Wed, 19 Dec 2018 14:12:07 +0100 Subject: [PATCH 2/3] Bug: extract idx from list returned by np.where --- amico/scheme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amico/scheme.py b/amico/scheme.py index 31a3b68..9fa9587 100644 --- a/amico/scheme.py +++ b/amico/scheme.py @@ -103,7 +103,7 @@ def load_from_table( self, data, b0_thr = 0 ) : for tmp3 in np.argsort(tmp2): shell_features = tmp1[tmp3,:] shell = {} - shell['idx'] = np.where((self.raw[:,3:] == shell_features).all(axis=1)) + shell['idx'] = np.where((self.raw[:,3:] == shell_features).all(axis=1))[0] shell['grad'] = self.raw[shell['idx'],:3] shell['b'] = np.unique(self.b[shell['idx']])[0] if self.version == 0: From b8ce4178cb7606cf762668539bde2c3efb583f3d Mon Sep 17 00:00:00 2001 From: David Romascano Date: Thu, 25 Mar 2021 15:06:40 +0100 Subject: [PATCH 3/3] Added latin1 encoding --- amico/lut.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amico/lut.py b/amico/lut.py index d8aae5f..81beb68 100644 --- a/amico/lut.py +++ b/amico/lut.py @@ -70,7 +70,7 @@ def load_precomputed_rotation_matrices( lmax = 12 ) : filename = pjoin( dipy_home, 'AMICO_aux_matrices_lmax=%d.pickle'%lmax ) if not isfile( filename ) : raise RuntimeError( 'Auxiliary matrices not found; call "lut.precompute_rotation_matrices()" first.' ) - return pickle.load( open(filename,'rb') ) + return pickle.load( open(filename,'rb'),encoding='latin1' ) def aux_structures_generate( scheme, lmax = 12 ) :