dmri-commit 2.4.0__tar.gz → 2.4.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/PKG-INFO +1 -1
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/commit/core.pyx +128 -140
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/commit/models.pyx +23 -19
- dmri_commit-2.4.1/commit/operator/operator.pyx +227 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/commit/operator/operator_c.c +27 -26
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/commit/solvers.py +2 -2
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/commit/trk2dictionary/trk2dictionary.pyx +18 -15
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/commit/trk2dictionary/trk2dictionary_c.cpp +80 -90
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/dmri_commit.egg-info/PKG-INFO +1 -1
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/pyproject.toml +1 -1
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/setup_operator.py +8 -7
- dmri_commit-2.4.0/commit/operator/operator.pyx +0 -249
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/LICENSE +0 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/MANIFEST.in +0 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/README.md +0 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/commit/__init__.py +0 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/commit/operator/__init__.py +0 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/commit/proximals.pyx +0 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/commit/trk2dictionary/ProgressBar.h +0 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/commit/trk2dictionary/Vector.h +0 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/dmri_commit.egg-info/SOURCES.txt +0 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/dmri_commit.egg-info/dependency_links.txt +0 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/dmri_commit.egg-info/requires.txt +0 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/dmri_commit.egg-info/top_level.txt +0 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/setup.cfg +0 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/setup.py +0 -0
- {dmri_commit-2.4.0 → dmri_commit-2.4.1}/tests/test_demo.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dmri-commit
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.1
|
|
4
4
|
Summary: Convex Optimization Modeling for Microstructure Informed Tractography (COMMIT)
|
|
5
5
|
Author-email: Alessandro Daducci <alessandro.daducci@univr.it>
|
|
6
6
|
Maintainer-email: DICE lab <DICE_lab@strutture.univr.it>
|
|
@@ -238,7 +238,7 @@ cdef class Evaluation :
|
|
|
238
238
|
if self.get_config('doNormalizeSignal') :
|
|
239
239
|
if self.scheme.b0_count > 0:
|
|
240
240
|
ret_subinfo = logger.subinfo('Normalizing to b0:', with_progress=True, indent_char='*', indent_lvl=1)
|
|
241
|
-
with ProgressBar(disable=self.verbose
|
|
241
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo):
|
|
242
242
|
b0 = np.mean( self.niiDWI_img[:,:,:,self.scheme.b0_idx], axis=3 )
|
|
243
243
|
idx = b0 <= b0_min_signal * b0[b0>0].mean()
|
|
244
244
|
b0[ idx ] = 1
|
|
@@ -295,13 +295,12 @@ cdef class Evaluation :
|
|
|
295
295
|
else:
|
|
296
296
|
logger.error( f'Model "{model_name}" not recognized' )
|
|
297
297
|
|
|
298
|
-
# Check if a
|
|
299
|
-
if self.dictionary_info['
|
|
298
|
+
# Check if a mask was provided to restrict ISO compartments (and if the model supports it)
|
|
299
|
+
if self.dictionary_info['iso_mask']:
|
|
300
300
|
if self.model.id == 'ScalarMap':
|
|
301
301
|
self.model.lesion_mask = True
|
|
302
|
-
else:
|
|
303
|
-
|
|
304
|
-
|
|
302
|
+
# else:
|
|
303
|
+
# logger.error('Lesion mask is not compatible with the selected model. Please use "ScalarMap" model.')
|
|
305
304
|
|
|
306
305
|
self.set_config('ATOMS_path', pjoin( self.get_config('study_path'), 'kernels', self.model.id ))
|
|
307
306
|
|
|
@@ -376,7 +375,7 @@ cdef class Evaluation :
|
|
|
376
375
|
logger.info( 'Loading the kernels' )
|
|
377
376
|
log_list = []
|
|
378
377
|
ret_subinfo = logger.subinfo( f'Resampling LUT for subject "{self.get_config("subject")}":', indent_char='*', indent_lvl=1, with_progress=True )
|
|
379
|
-
with ProgressBar(disable=self.verbose
|
|
378
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
|
|
380
379
|
# auxiliary data structures
|
|
381
380
|
idx_OUT, Ylm_OUT = amico.lut.aux_structures_resample( self.scheme, self.get_config('lmax') )
|
|
382
381
|
|
|
@@ -400,7 +399,7 @@ cdef class Evaluation :
|
|
|
400
399
|
if self.get_config('doDemean') :
|
|
401
400
|
log_list = []
|
|
402
401
|
ret_subinfo = logger.subinfo('Demeaning signal', with_progress=True, indent_lvl=2, indent_char='-' )
|
|
403
|
-
with ProgressBar(disable=self.verbose
|
|
402
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
|
|
404
403
|
for j in xrange(self.get_config('ndirs')) :
|
|
405
404
|
for i in xrange(nIC) :
|
|
406
405
|
self.KERNELS['wmr'][i,j,:] -= self.KERNELS['wmr'][i,j,:].mean()
|
|
@@ -413,7 +412,7 @@ cdef class Evaluation :
|
|
|
413
412
|
if self.get_config('doNormalizeKernels') :
|
|
414
413
|
log_list = []
|
|
415
414
|
ret_subinfo = logger.subinfo('Normalizing kernels', with_progress=True, indent_lvl=2, indent_char='-' )
|
|
416
|
-
with ProgressBar(disable=self.verbose
|
|
415
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
|
|
417
416
|
self.KERNELS['wmr_norm'] = np.zeros( nIC )
|
|
418
417
|
for i in xrange(nIC) :
|
|
419
418
|
self.KERNELS['wmr_norm'][i] = np.linalg.norm( self.KERNELS['wmr'][i,0,:] )
|
|
@@ -489,7 +488,7 @@ cdef class Evaluation :
|
|
|
489
488
|
# ------------------------
|
|
490
489
|
log_list = []
|
|
491
490
|
ret_subinfo = logger.subinfo('Segments from the tracts:', indent_char='*', indent_lvl=1, with_progress=True )
|
|
492
|
-
with ProgressBar(disable=self.verbose
|
|
491
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
|
|
493
492
|
self.DICTIONARY['TRK'] = {}
|
|
494
493
|
self.DICTIONARY['TRK']['kept'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_TRK_kept.dict'), dtype=np.uint8 )
|
|
495
494
|
self.DICTIONARY['TRK']['norm'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_TRK_norm.dict'), dtype=np.float32 )
|
|
@@ -498,19 +497,20 @@ cdef class Evaluation :
|
|
|
498
497
|
|
|
499
498
|
|
|
500
499
|
self.DICTIONARY['IC'] = {}
|
|
501
|
-
self.DICTIONARY['IC']['
|
|
502
|
-
self.DICTIONARY['IC']['
|
|
503
|
-
self.DICTIONARY['IC']['
|
|
500
|
+
self.DICTIONARY['IC']['str'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_IC_f.dict'), dtype=np.uint32 )
|
|
501
|
+
self.DICTIONARY['IC']['vox'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_IC_v.dict'), dtype=np.uint32 )
|
|
502
|
+
self.DICTIONARY['IC']['dir'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_IC_o.dict'), dtype=np.uint16 )
|
|
504
503
|
self.DICTIONARY['IC']['len'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_IC_len.dict'), dtype=np.float32 )
|
|
505
|
-
self.DICTIONARY['IC']['n'] = self.DICTIONARY['IC']['
|
|
506
|
-
self.DICTIONARY['IC']['
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
self.DICTIONARY['IC']['
|
|
511
|
-
self.DICTIONARY['IC']['
|
|
512
|
-
self.DICTIONARY['IC']['
|
|
513
|
-
self.DICTIONARY['IC']['
|
|
504
|
+
self.DICTIONARY['IC']['n'] = self.DICTIONARY['IC']['vox'].size
|
|
505
|
+
self.DICTIONARY['IC']['nSTR'] = self.DICTIONARY['TRK']['norm'].size
|
|
506
|
+
self.DICTIONARY['IC']['nVOX'] = self.DICTIONARY['MASK'].sum() # tot voxels of the fit
|
|
507
|
+
|
|
508
|
+
# reorder the segments based on the "vox" field
|
|
509
|
+
idx = np.argsort( self.DICTIONARY['IC']['vox'], kind=self.get_config('sortDictionaryWith') )
|
|
510
|
+
self.DICTIONARY['IC']['vox'] = self.DICTIONARY['IC']['vox'][ idx ]
|
|
511
|
+
self.DICTIONARY['IC']['dir'] = self.DICTIONARY['IC']['dir'][ idx ]
|
|
512
|
+
self.DICTIONARY['IC']['str'] = self.DICTIONARY['IC']['str'][ idx ]
|
|
513
|
+
self.DICTIONARY['IC']['len'] = self.DICTIONARY['IC']['len'][ idx ]
|
|
514
514
|
del idx
|
|
515
515
|
|
|
516
516
|
# divide the length of each segment by the fiber length so that all the columns of the linear operator will have same length
|
|
@@ -518,56 +518,56 @@ cdef class Evaluation :
|
|
|
518
518
|
cdef :
|
|
519
519
|
np.float32_t [:] sl = self.DICTIONARY['IC']['len']
|
|
520
520
|
np.float32_t [:] tl = self.DICTIONARY['TRK']['norm']
|
|
521
|
-
np.uint32_t [:] f = self.DICTIONARY['IC']['
|
|
521
|
+
np.uint32_t [:] f = self.DICTIONARY['IC']['str']
|
|
522
522
|
int s
|
|
523
523
|
if self.get_config('doNormalizeKernels') :
|
|
524
524
|
for s in xrange(self.DICTIONARY['IC']['n']) :
|
|
525
525
|
sl[s] /= tl[ f[s] ]
|
|
526
526
|
|
|
527
|
-
logger.subinfo(f"{self.DICTIONARY['IC']['
|
|
527
|
+
logger.subinfo(f"{self.DICTIONARY['IC']['nSTR']} streamlines", indent_char='-', indent_lvl=2 )
|
|
528
|
+
logger.subinfo(f"{self.DICTIONARY['IC']['n']} contributions (i.e. segments)", indent_char='-', indent_lvl=2 )
|
|
529
|
+
logger.subinfo(f"{self.DICTIONARY['IC']['nVOX']} voxels", indent_char='-', indent_lvl=2 )
|
|
528
530
|
|
|
529
|
-
#
|
|
531
|
+
# contributions from the peaks
|
|
530
532
|
# -----------------------
|
|
531
533
|
log_list = []
|
|
532
|
-
ret_subinfo = logger.subinfo('
|
|
533
|
-
with ProgressBar(disable=self.verbose
|
|
534
|
+
ret_subinfo = logger.subinfo('Contributions from the peaks:', indent_char='*', indent_lvl=1, with_progress=True )
|
|
535
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
|
|
534
536
|
self.DICTIONARY['EC'] = {}
|
|
535
|
-
self.DICTIONARY['EC']['
|
|
536
|
-
self.DICTIONARY['EC']['
|
|
537
|
-
self.DICTIONARY['EC']['
|
|
538
|
-
|
|
539
|
-
# reorder the
|
|
540
|
-
idx = np.argsort( self.DICTIONARY['EC']['
|
|
541
|
-
self.DICTIONARY['EC']['
|
|
542
|
-
self.DICTIONARY['EC']['
|
|
537
|
+
self.DICTIONARY['EC']['vox'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_EC_v.dict'), dtype=np.uint32 )
|
|
538
|
+
self.DICTIONARY['EC']['dir'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_EC_o.dict'), dtype=np.uint16 )
|
|
539
|
+
self.DICTIONARY['EC']['n'] = self.DICTIONARY['EC']['vox'].size
|
|
540
|
+
|
|
541
|
+
# reorder the elements based on the "vox" field
|
|
542
|
+
idx = np.argsort( self.DICTIONARY['EC']['vox'], kind=self.get_config('sortDictionaryWith') )
|
|
543
|
+
self.DICTIONARY['EC']['vox'] = self.DICTIONARY['EC']['vox'][ idx ]
|
|
544
|
+
self.DICTIONARY['EC']['dir'] = self.DICTIONARY['EC']['dir'][ idx ]
|
|
543
545
|
del idx
|
|
544
546
|
|
|
545
|
-
logger.subinfo( f"{self.DICTIONARY['EC']['
|
|
547
|
+
logger.subinfo( f"{self.DICTIONARY['EC']['n']} segments", indent_char='-', indent_lvl=2)
|
|
546
548
|
|
|
547
549
|
# isotropic compartments
|
|
548
550
|
# ----------------------
|
|
549
551
|
log_list = []
|
|
550
552
|
ret_subinfo = logger.subinfo('Isotropic contributions:', indent_char='*', indent_lvl=1, with_progress=True )
|
|
551
|
-
with ProgressBar(disable=self.verbose
|
|
553
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
|
|
552
554
|
self.DICTIONARY['ISO'] = {}
|
|
553
555
|
|
|
554
|
-
self.DICTIONARY['ISO']['
|
|
555
|
-
self.DICTIONARY['ISO']['
|
|
556
|
+
self.DICTIONARY['ISO']['vox'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_ISO_v.dict'), dtype=np.uint32 )
|
|
557
|
+
self.DICTIONARY['ISO']['n'] = self.DICTIONARY['ISO']['vox'].size
|
|
556
558
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
idx = np.argsort( self.DICTIONARY['ISO']['v'], kind=self.get_config('sortDictionaryWith') )
|
|
561
|
-
self.DICTIONARY['ISO']['v'] = self.DICTIONARY['ISO']['v'][ idx ]
|
|
559
|
+
# reorder the segments based on the "vox" field
|
|
560
|
+
idx = np.argsort( self.DICTIONARY['ISO']['vox'], kind=self.get_config('sortDictionaryWith') )
|
|
561
|
+
self.DICTIONARY['ISO']['vox'] = self.DICTIONARY['ISO']['vox'][ idx ]
|
|
562
562
|
del idx
|
|
563
563
|
|
|
564
|
-
logger.subinfo( f"{self.DICTIONARY['ISO']['
|
|
564
|
+
logger.subinfo( f"{self.DICTIONARY['ISO']['n']} voxels", indent_char='-', indent_lvl=2 )
|
|
565
565
|
|
|
566
566
|
# post-processing
|
|
567
567
|
# ---------------
|
|
568
568
|
log_list = []
|
|
569
569
|
ret_subinfo = logger.subinfo('Post-processing', indent_char='*', indent_lvl=1, with_progress=True )
|
|
570
|
-
with ProgressBar(disable=self.verbose
|
|
570
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
|
|
571
571
|
# get the indices to extract the VOI as in MATLAB (in place of DICTIONARY.MASKidx)
|
|
572
572
|
idx = self.DICTIONARY['MASK'].ravel(order='F').nonzero()[0]
|
|
573
573
|
self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'] = np.unravel_index( idx, self.DICTIONARY['MASK'].shape, order='F' )
|
|
@@ -575,9 +575,9 @@ cdef class Evaluation :
|
|
|
575
575
|
lut = np.zeros( self.get_config('dim'), dtype=np.uint32 ).ravel()
|
|
576
576
|
for i in xrange(idx.size) :
|
|
577
577
|
lut[ idx[i] ] = i
|
|
578
|
-
self.DICTIONARY['IC'][ '
|
|
579
|
-
self.DICTIONARY['EC'][ '
|
|
580
|
-
self.DICTIONARY['ISO']['
|
|
578
|
+
self.DICTIONARY['IC'][ 'vox'] = lut[ self.DICTIONARY['IC'][ 'vox'] ]
|
|
579
|
+
self.DICTIONARY['EC'][ 'vox'] = lut[ self.DICTIONARY['EC'][ 'vox'] ]
|
|
580
|
+
self.DICTIONARY['ISO']['vox'] = lut[ self.DICTIONARY['ISO']['vox'] ]
|
|
581
581
|
|
|
582
582
|
logger.info( f'[ {format_time(time.time() - tic)} ]' )
|
|
583
583
|
|
|
@@ -622,14 +622,14 @@ cdef class Evaluation :
|
|
|
622
622
|
# Distribute load for the computation of A*x product
|
|
623
623
|
log_list = []
|
|
624
624
|
ret_subinfo = logger.subinfo('A operator ', indent_char='*', indent_lvl=1, with_progress=True )
|
|
625
|
-
with ProgressBar(disable=self.verbose
|
|
625
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
|
|
626
626
|
if self.DICTIONARY['IC']['n'] > 0 :
|
|
627
627
|
self.THREADS['IC'] = np.zeros( n+1, dtype=np.uint32 )
|
|
628
628
|
if n > 1 :
|
|
629
629
|
N = np.floor( self.DICTIONARY['IC']['n']/n )
|
|
630
630
|
t = 1
|
|
631
631
|
tot = 0
|
|
632
|
-
C = np.bincount( self.DICTIONARY['IC']['
|
|
632
|
+
C = np.bincount( self.DICTIONARY['IC']['vox'] )
|
|
633
633
|
for c in C :
|
|
634
634
|
tot += c
|
|
635
635
|
if tot >= N and t <= n :
|
|
@@ -645,11 +645,11 @@ cdef class Evaluation :
|
|
|
645
645
|
else :
|
|
646
646
|
self.THREADS['IC'] = None
|
|
647
647
|
|
|
648
|
-
if self.DICTIONARY['EC']['
|
|
648
|
+
if self.DICTIONARY['EC']['n'] > 0 :
|
|
649
649
|
self.THREADS['EC'] = np.zeros( n+1, dtype=np.uint32 )
|
|
650
650
|
for i in xrange(n) :
|
|
651
|
-
self.THREADS['EC'][i] = np.searchsorted( self.DICTIONARY['EC']['
|
|
652
|
-
self.THREADS['EC'][n] = self.DICTIONARY['EC']['
|
|
651
|
+
self.THREADS['EC'][i] = np.searchsorted( self.DICTIONARY['EC']['vox'], self.DICTIONARY['IC']['vox'][ self.THREADS['IC'][i] ] )
|
|
652
|
+
self.THREADS['EC'][n] = self.DICTIONARY['EC']['n']
|
|
653
653
|
|
|
654
654
|
# check if some threads are not assigned any segment
|
|
655
655
|
if np.count_nonzero( np.diff( self.THREADS['EC'].astype(np.int32) ) <= 0 ) :
|
|
@@ -658,24 +658,23 @@ cdef class Evaluation :
|
|
|
658
658
|
else :
|
|
659
659
|
self.THREADS['EC'] = None
|
|
660
660
|
|
|
661
|
-
if self.DICTIONARY['
|
|
661
|
+
if self.DICTIONARY['ISO']['n'] > 0 :
|
|
662
662
|
self.THREADS['ISO'] = np.zeros( n+1, dtype=np.uint32 )
|
|
663
663
|
for i in xrange(n) :
|
|
664
|
-
self.THREADS['ISO'][i] = np.searchsorted( self.DICTIONARY['ISO']['
|
|
665
|
-
self.THREADS['ISO'][n] = self.DICTIONARY['ISO']['
|
|
666
|
-
|
|
664
|
+
self.THREADS['ISO'][i] = np.searchsorted( self.DICTIONARY['ISO']['vox'], self.DICTIONARY['IC']['vox'][ self.THREADS['IC'][i] ] )
|
|
665
|
+
self.THREADS['ISO'][n] = self.DICTIONARY['ISO']['n']
|
|
667
666
|
else :
|
|
668
667
|
self.THREADS['ISO'] = None
|
|
669
668
|
|
|
670
669
|
# Distribute load for the computation of At*y product
|
|
671
670
|
log_list = []
|
|
672
671
|
ret_subinfo = logger.subinfo('A\' operator', indent_char='*', indent_lvl=1, with_progress=True )
|
|
673
|
-
with ProgressBar(disable=self.verbose
|
|
672
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
|
|
674
673
|
if self.DICTIONARY['IC']['n'] > 0 :
|
|
675
674
|
self.THREADS['ICt'] = np.full( self.DICTIONARY['IC']['n'], n-1, dtype=np.uint8 )
|
|
676
675
|
if n > 1 :
|
|
677
|
-
idx = np.argsort( self.DICTIONARY['IC']['
|
|
678
|
-
C = np.bincount( self.DICTIONARY['IC']['
|
|
676
|
+
idx = np.argsort( self.DICTIONARY['IC']['str'], kind=self.get_config('sortThreadsWith') )
|
|
677
|
+
C = np.bincount( self.DICTIONARY['IC']['str'] )
|
|
679
678
|
t = tot = i1 = i2 = 0
|
|
680
679
|
N = np.floor(self.DICTIONARY['IC']['n']/n)
|
|
681
680
|
for c in C :
|
|
@@ -693,12 +692,12 @@ cdef class Evaluation :
|
|
|
693
692
|
else :
|
|
694
693
|
self.THREADS['ICt'] = None
|
|
695
694
|
|
|
696
|
-
if self.DICTIONARY['EC']['
|
|
695
|
+
if self.DICTIONARY['EC']['n'] > 0 :
|
|
697
696
|
self.THREADS['ECt'] = np.zeros( n+1, dtype=np.uint32 )
|
|
698
|
-
N = np.floor( self.DICTIONARY['EC']['
|
|
697
|
+
N = np.floor( self.DICTIONARY['EC']['n']/n )
|
|
699
698
|
for i in xrange(1,n) :
|
|
700
699
|
self.THREADS['ECt'][i] = self.THREADS['ECt'][i-1] + N
|
|
701
|
-
self.THREADS['ECt'][n] = self.DICTIONARY['EC']['
|
|
700
|
+
self.THREADS['ECt'][n] = self.DICTIONARY['EC']['n']
|
|
702
701
|
|
|
703
702
|
# check if some threads are not assigned any segment
|
|
704
703
|
if np.count_nonzero( np.diff( self.THREADS['ECt'].astype(np.int32) ) <= 0 ) :
|
|
@@ -707,13 +706,13 @@ cdef class Evaluation :
|
|
|
707
706
|
else :
|
|
708
707
|
self.THREADS['ECt'] = None
|
|
709
708
|
|
|
710
|
-
if self.DICTIONARY['ISO']['
|
|
709
|
+
if self.DICTIONARY['ISO']['n'] > 0 :
|
|
711
710
|
self.THREADS['ISOt'] = np.zeros( n+1, dtype=np.uint32 )
|
|
712
|
-
N = np.floor( self.DICTIONARY['ISO']['
|
|
711
|
+
N = np.floor( self.DICTIONARY['ISO']['n']/n )
|
|
713
712
|
|
|
714
713
|
for i in xrange(1,n) :
|
|
715
714
|
self.THREADS['ISOt'][i] = self.THREADS['ISOt'][i-1] + N
|
|
716
|
-
self.THREADS['ISOt'][n] = self.DICTIONARY['ISO']['
|
|
715
|
+
self.THREADS['ISOt'][n] = self.DICTIONARY['ISO']['n']
|
|
717
716
|
|
|
718
717
|
# check if some threads are not assigned any segment
|
|
719
718
|
if np.count_nonzero( np.diff( self.THREADS['ISOt'].astype(np.int32) ) <= 0 ) :
|
|
@@ -736,22 +735,16 @@ cdef class Evaluation :
|
|
|
736
735
|
if self.THREADS is None :
|
|
737
736
|
logger.error( 'Threads not set; call "set_threads()" first' )
|
|
738
737
|
|
|
739
|
-
if self.DICTIONARY['IC']['
|
|
740
|
-
logger.error( 'No
|
|
741
|
-
if self.DICTIONARY['EC']['
|
|
738
|
+
if self.DICTIONARY['IC']['nSTR'] <= 0 :
|
|
739
|
+
logger.error( 'No streamlines found in the dictionary; check your data' )
|
|
740
|
+
if self.DICTIONARY['EC']['n'] <= 0 and self.KERNELS['wmh'].shape[0] > 0 :
|
|
742
741
|
logger.error( 'The selected model has EC compartments, but no peaks have been provided; check your data' )
|
|
743
742
|
|
|
744
743
|
tic = time.time()
|
|
745
744
|
logger.subinfo('')
|
|
746
745
|
logger.info( 'Building linear operator A' )
|
|
747
|
-
|
|
748
|
-
nF = self.DICTIONARY['IC']['nF'] # number of FIBERS
|
|
749
|
-
n2 = nF * self.KERNELS['wmr'].shape[0]
|
|
750
|
-
|
|
751
|
-
self.DICTIONARY["IC"]["eval"] = np.ones( int(n2), dtype=np.uint32)
|
|
752
|
-
|
|
746
|
+
self.DICTIONARY["IC"]["eval"] = np.ones( int(self.DICTIONARY['IC']['nSTR'] * self.KERNELS['wmr'].shape[0]), dtype=np.uint32)
|
|
753
747
|
self.A = operator.LinearOperator( self.DICTIONARY, self.KERNELS, self.THREADS, True if hasattr(self.model, 'nolut') else False )
|
|
754
|
-
|
|
755
748
|
logger.info( f'[ {format_time(time.time() - tic)} ]' )
|
|
756
749
|
|
|
757
750
|
|
|
@@ -994,11 +987,11 @@ cdef class Evaluation :
|
|
|
994
987
|
regularisation = {}
|
|
995
988
|
|
|
996
989
|
regularisation['startIC'] = 0
|
|
997
|
-
regularisation['sizeIC'] = int( self.DICTIONARY['IC']['
|
|
990
|
+
regularisation['sizeIC'] = int( self.DICTIONARY['IC']['nSTR'] * self.KERNELS['wmr'].shape[0] )
|
|
998
991
|
regularisation['startEC'] = int( regularisation['sizeIC'] )
|
|
999
|
-
regularisation['sizeEC'] = int( self.DICTIONARY['EC']['
|
|
992
|
+
regularisation['sizeEC'] = int( self.DICTIONARY['EC']['n'] * self.KERNELS['wmh'].shape[0] )
|
|
1000
993
|
regularisation['startISO'] = int( regularisation['sizeIC'] + regularisation['sizeEC'] )
|
|
1001
|
-
regularisation['sizeISO'] = int( self.DICTIONARY['
|
|
994
|
+
regularisation['sizeISO'] = int( self.DICTIONARY['ISO']['n'] * self.KERNELS['iso'].shape[0] )
|
|
1002
995
|
|
|
1003
996
|
regularisation['regIC'] = regularisers[0]
|
|
1004
997
|
regularisation['regEC'] = regularisers[1]
|
|
@@ -1121,7 +1114,7 @@ cdef class Evaluation :
|
|
|
1121
1114
|
# check if group_idx contains all the indices of the input streamlines
|
|
1122
1115
|
if regularisation['regIC'] == 'group_lasso' or regularisation['regIC'] == 'sparse_group_lasso':
|
|
1123
1116
|
all_idx_in = np.sort(np.unique(np.concatenate(dictIC_params['group_idx'])))
|
|
1124
|
-
all_idx = np.arange(self.DICTIONARY['IC']['
|
|
1117
|
+
all_idx = np.arange(self.DICTIONARY['IC']['nSTR'], dtype=np.int32)
|
|
1125
1118
|
if np.any(all_idx_in != all_idx):
|
|
1126
1119
|
logger.error('Group indices must contain all the indices of the input streamlines')
|
|
1127
1120
|
|
|
@@ -1145,7 +1138,7 @@ cdef class Evaluation :
|
|
|
1145
1138
|
if (0 in self.DICTIONARY['TRK']['kept']):
|
|
1146
1139
|
dictionary_TRK_kept = self.DICTIONARY['TRK']['kept']
|
|
1147
1140
|
idx_in_kept = np.zeros(dictionary_TRK_kept.size, dtype=np.int32) - 1 # -1 is used to flag indices for removal
|
|
1148
|
-
idx_in_kept[dictionary_TRK_kept==1] = list(range(self.DICTIONARY['IC']['
|
|
1141
|
+
idx_in_kept[dictionary_TRK_kept==1] = list(range(self.DICTIONARY['IC']['nSTR']))
|
|
1149
1142
|
|
|
1150
1143
|
newICgroup_idx = []
|
|
1151
1144
|
newweightsIC_group = []
|
|
@@ -1444,14 +1437,13 @@ cdef class Evaluation :
|
|
|
1444
1437
|
confidence_array_changed = True
|
|
1445
1438
|
|
|
1446
1439
|
if(confidence_array_changed):
|
|
1447
|
-
|
|
1448
|
-
self.confidence_map_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'], : ] = np.reshape( confidence_array, (
|
|
1440
|
+
nVOX = self.DICTIONARY['IC']['nVOX']
|
|
1441
|
+
self.confidence_map_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'], : ] = np.reshape( confidence_array, (nVOX,-1) ).astype(np.float32)
|
|
1449
1442
|
|
|
1450
1443
|
if x0 is not None :
|
|
1451
1444
|
if x0.shape[0] != self.A.shape[1] :
|
|
1452
1445
|
logger.error( 'x0 dimension does not match the number of columns of the dictionary' )
|
|
1453
1446
|
|
|
1454
|
-
|
|
1455
1447
|
self.CONFIG['optimization'] = {}
|
|
1456
1448
|
self.CONFIG['optimization']['tol_fun'] = tol_fun
|
|
1457
1449
|
self.CONFIG['optimization']['tol_x'] = tol_x
|
|
@@ -1462,20 +1454,19 @@ cdef class Evaluation :
|
|
|
1462
1454
|
t = time.time()
|
|
1463
1455
|
with ProgressBar(disable=self.verbose!=3, hide_on_exit=True):
|
|
1464
1456
|
self.x, opt_details = commit.solvers.solve(self.get_y(), self.A, self.A.T, tol_fun=tol_fun, tol_x=tol_x, max_iter=max_iter, verbose=self.verbose, x0=x0, regularisation=self.regularisation_params, confidence_array=confidence_array)
|
|
1457
|
+
if self.verbose < 4:
|
|
1458
|
+
logger.subinfo(f'Stopped after {opt_details["iterations"]} iterations', indent_lvl=1, indent_char='*', with_progress=True)
|
|
1459
|
+
logger.subinfo(f'Stopping condition: \"{opt_details["stopping_criterion"]}\"', indent_lvl=1, indent_char='*')
|
|
1465
1460
|
|
|
1466
1461
|
if (self.regularisation_params['regIC']!=None or self.regularisation_params['regEC']!= None or self.regularisation_params['regISO']!= None) and debias:
|
|
1467
|
-
|
|
1468
1462
|
from commit.operator import operator
|
|
1469
1463
|
temp_verb = self.verbose
|
|
1470
1464
|
logger.info( 'Running debias' )
|
|
1471
1465
|
self.set_verbose(0)
|
|
1472
1466
|
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
xic = self.x[:offset1]
|
|
1477
|
-
|
|
1478
|
-
mask = np.ones(offset1, dtype=np.uint32)
|
|
1467
|
+
offset = self.DICTIONARY['IC']['nSTR'] * self.KERNELS['wmr'].shape[0]
|
|
1468
|
+
xic = self.x[:offset]
|
|
1469
|
+
mask = np.ones(offset, dtype=np.uint32)
|
|
1479
1470
|
mask[xic<0.000000000000001] = 0
|
|
1480
1471
|
|
|
1481
1472
|
self.DICTIONARY["IC"]["eval"] = mask
|
|
@@ -1483,14 +1474,13 @@ cdef class Evaluation :
|
|
|
1483
1474
|
self.A = operator.LinearOperator( self.DICTIONARY, self.KERNELS, self.THREADS, nolut=True if hasattr(self.model, 'nolut') else False )
|
|
1484
1475
|
|
|
1485
1476
|
self.set_regularisation()
|
|
1486
|
-
|
|
1487
1477
|
self.set_verbose(temp_verb)
|
|
1488
1478
|
|
|
1489
1479
|
logger.subinfo('Recomputing coefficients', indent_lvl=1, indent_char='*', with_progress=True)
|
|
1490
1480
|
|
|
1491
1481
|
x_debias = self.x.copy()
|
|
1492
|
-
x_debias[:
|
|
1493
|
-
x_debias[
|
|
1482
|
+
x_debias[:offset] *= mask
|
|
1483
|
+
x_debias[offset:] = 0
|
|
1494
1484
|
|
|
1495
1485
|
y_mask = np.asarray(self.A.dot(x_debias))
|
|
1496
1486
|
# binarize y_debias
|
|
@@ -1505,7 +1495,6 @@ cdef class Evaluation :
|
|
|
1505
1495
|
elif (self.regularisation_params['regIC']!=None or self.regularisation_params['regEC']!= None or self.regularisation_params['regISO']!= None) and not debias:
|
|
1506
1496
|
logger.warning('Fitting with regularisation but without debiasing. The coefficients will be biased, use "debias=True" to debias the coefficients')
|
|
1507
1497
|
|
|
1508
|
-
|
|
1509
1498
|
self.CONFIG['optimization']['fit_details'] = opt_details
|
|
1510
1499
|
self.CONFIG['optimization']['fit_time'] = time.time()-t
|
|
1511
1500
|
|
|
@@ -1531,21 +1520,21 @@ cdef class Evaluation :
|
|
|
1531
1520
|
if self.x is None :
|
|
1532
1521
|
logger.error( 'Model not fitted to the data; call "fit()" first' )
|
|
1533
1522
|
|
|
1534
|
-
|
|
1535
|
-
nE
|
|
1536
|
-
|
|
1523
|
+
nSTR = self.DICTIONARY['IC']['nSTR']
|
|
1524
|
+
nE = self.DICTIONARY['EC']['n']
|
|
1525
|
+
nVOX = self.DICTIONARY['ISO']['n']
|
|
1537
1526
|
|
|
1538
1527
|
if get_normalized and self.get_config('doNormalizeKernels') :
|
|
1539
1528
|
# renormalize the coefficients
|
|
1540
|
-
norm1 = np.repeat(self.KERNELS['wmr_norm'],
|
|
1529
|
+
norm1 = np.repeat(self.KERNELS['wmr_norm'],nSTR)
|
|
1541
1530
|
norm2 = np.repeat(self.KERNELS['wmh_norm'],nE)
|
|
1542
|
-
norm3 = np.repeat(self.KERNELS['iso_norm'],
|
|
1531
|
+
norm3 = np.repeat(self.KERNELS['iso_norm'],nVOX)
|
|
1543
1532
|
norm_fib = np.kron(np.ones(self.KERNELS['wmr'].shape[0]), self.DICTIONARY['TRK']['norm'])
|
|
1544
1533
|
x = self.x / np.hstack( (norm1*norm_fib,norm2,norm3) )
|
|
1545
1534
|
else :
|
|
1546
1535
|
x = self.x
|
|
1547
1536
|
|
|
1548
|
-
offset1 =
|
|
1537
|
+
offset1 = nSTR * self.KERNELS['wmr'].shape[0]
|
|
1549
1538
|
offset2 = offset1 + nE * self.KERNELS['wmh'].shape[0]
|
|
1550
1539
|
kept = np.tile( self.DICTIONARY['TRK']['kept'], self.KERNELS['wmr'].shape[0] )
|
|
1551
1540
|
xic = np.zeros( kept.size )
|
|
@@ -1583,16 +1572,16 @@ cdef class Evaluation :
|
|
|
1583
1572
|
if self.x is None :
|
|
1584
1573
|
logger.error( 'Model not fitted to the data; call "fit()" first' )
|
|
1585
1574
|
|
|
1586
|
-
|
|
1587
|
-
nE
|
|
1588
|
-
|
|
1589
|
-
norm_fib = np.ones(
|
|
1575
|
+
nSTR = self.DICTIONARY['IC']['nSTR']
|
|
1576
|
+
nE = self.DICTIONARY['EC']['n']
|
|
1577
|
+
nVOX = self.DICTIONARY['ISO']['n']
|
|
1578
|
+
norm_fib = np.ones( nSTR )
|
|
1590
1579
|
# NB: x correspond to the original problem, self.x are the preconditioned ones
|
|
1591
1580
|
if self.get_config('doNormalizeKernels') :
|
|
1592
1581
|
# renormalize the coefficients
|
|
1593
|
-
norm1 = np.repeat(self.KERNELS['wmr_norm'],
|
|
1582
|
+
norm1 = np.repeat(self.KERNELS['wmr_norm'],nSTR)
|
|
1594
1583
|
norm2 = np.repeat(self.KERNELS['wmh_norm'],nE)
|
|
1595
|
-
norm3 = np.repeat(self.KERNELS['iso_norm'],
|
|
1584
|
+
norm3 = np.repeat(self.KERNELS['iso_norm'],nVOX)
|
|
1596
1585
|
norm_fib = np.kron(np.ones(self.KERNELS['wmr'].shape[0]), self.DICTIONARY['TRK']['norm'])
|
|
1597
1586
|
x = self.x / np.hstack( (norm1*norm_fib,norm2,norm3) )
|
|
1598
1587
|
else :
|
|
@@ -1618,15 +1607,11 @@ cdef class Evaluation :
|
|
|
1618
1607
|
niiMAP_hdr['db_name'] = ''
|
|
1619
1608
|
|
|
1620
1609
|
if self.debias_mask is not None:
|
|
1621
|
-
|
|
1610
|
+
nVOX = int(np.sum(self.debias_mask)/self.niiDWI_img.shape[3])
|
|
1622
1611
|
ind_mask = np.where(self.debias_mask>0)[0]
|
|
1623
|
-
vox_mask = np.reshape( self.debias_mask[ind_mask], (nV,-1) )
|
|
1624
|
-
|
|
1625
|
-
y_mea = np.reshape( self.get_y()[ind_mask], (nV,-1) )
|
|
1626
|
-
|
|
1627
|
-
y_est_ = np.asarray(self.A.dot(self.x))
|
|
1628
|
-
y_est = np.reshape( y_est_[ind_mask], (nV,-1) )
|
|
1629
1612
|
|
|
1613
|
+
y_mea = np.reshape( self.get_y()[ind_mask], (nVOX,-1) )
|
|
1614
|
+
y_est = np.reshape( np.asarray(self.A.dot(self.x))[ind_mask], (nVOX,-1) )
|
|
1630
1615
|
tmp = np.sqrt( np.mean((y_mea-y_est)**2,axis=1) )
|
|
1631
1616
|
|
|
1632
1617
|
logger.subinfo(f'RMSE: {tmp.mean():.3f} +/- {tmp.std():.3f}', indent_lvl=2, indent_char='-')
|
|
@@ -1638,10 +1623,8 @@ cdef class Evaluation :
|
|
|
1638
1623
|
tmp[ idx ] = 0
|
|
1639
1624
|
logger.subinfo(f'NRMSE: {tmp.mean():.3f} +/- {tmp.std():.3f}', indent_lvl=2, indent_char='-')
|
|
1640
1625
|
|
|
1641
|
-
y_mea = np.reshape( self.get_y(), (self.DICTIONARY['
|
|
1642
|
-
|
|
1643
|
-
y_est_ = np.asarray(self.A.dot(self.x))
|
|
1644
|
-
y_est = np.reshape( y_est_, (self.DICTIONARY['nV'],-1) )
|
|
1626
|
+
y_mea = np.reshape( self.get_y(), (self.DICTIONARY['IC']['nVOX'],-1) )
|
|
1627
|
+
y_est = np.reshape( self.A.dot(self.x), (self.DICTIONARY['IC']['nVOX'],-1) ).astype(np.float32)
|
|
1645
1628
|
tmp = np.sqrt( np.mean((y_mea-y_est)**2,axis=1) )
|
|
1646
1629
|
|
|
1647
1630
|
niiMAP_img[self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz']] = tmp
|
|
@@ -1661,9 +1644,9 @@ cdef class Evaluation :
|
|
|
1661
1644
|
nibabel.save( niiMAP, pjoin(RESULTS_path,'fit_NRMSE.nii.gz') )
|
|
1662
1645
|
|
|
1663
1646
|
else:
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1647
|
+
nVOX = self.DICTIONARY['IC']['nVOX']
|
|
1648
|
+
y_mea = np.reshape( self.niiDWI_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'], : ].flatten().astype(np.float32), (nVOX,-1) )
|
|
1649
|
+
y_est = np.reshape( self.A.dot(self.x), (nVOX,-1) ).astype(np.float32)
|
|
1667
1650
|
tmp = np.sqrt( np.mean((y_mea-y_est)**2,axis=1) )
|
|
1668
1651
|
logger.subinfo(f'RMSE: {tmp.mean():.3f} +/- {tmp.std():.3f}', indent_lvl=2, indent_char='-')
|
|
1669
1652
|
niiMAP_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'] ] = tmp
|
|
@@ -1683,7 +1666,7 @@ cdef class Evaluation :
|
|
|
1683
1666
|
nibabel.save( niiMAP, pjoin(RESULTS_path,'fit_NRMSE.nii.gz') )
|
|
1684
1667
|
|
|
1685
1668
|
if self.confidence_map_img is not None:
|
|
1686
|
-
confidence_array = np.reshape( self.confidence_map_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'], : ].flatten().astype(np.float32), (
|
|
1669
|
+
confidence_array = np.reshape( self.confidence_map_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'], : ].flatten().astype(np.float32), (nVOX,-1) )
|
|
1687
1670
|
|
|
1688
1671
|
tmp = np.sum(confidence_array,axis=1)
|
|
1689
1672
|
idx = np.where( tmp < 1E-12 )
|
|
@@ -1713,35 +1696,35 @@ cdef class Evaluation :
|
|
|
1713
1696
|
|
|
1714
1697
|
log_list = []
|
|
1715
1698
|
ret_subinfo = logger.subinfo('Intra-axonal', indent_lvl=2, indent_char='-', with_progress=True)
|
|
1716
|
-
with ProgressBar(disable=self.verbose
|
|
1699
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
|
|
1717
1700
|
niiIC_img = np.zeros( self.get_config('dim'), dtype=np.float32 )
|
|
1718
1701
|
if len(self.KERNELS['wmr']) > 0 :
|
|
1719
|
-
offset =
|
|
1720
|
-
tmp = ( x[:offset].reshape( (-1,
|
|
1721
|
-
xv = np.bincount( self.DICTIONARY['IC']['
|
|
1722
|
-
weights=tmp[ self.DICTIONARY['IC']['
|
|
1702
|
+
offset = nSTR * self.KERNELS['wmr'].shape[0]
|
|
1703
|
+
tmp = ( x[:offset].reshape( (-1,nSTR) ) * norm_fib.reshape( (-1,nSTR) ) ).sum( axis=0 )
|
|
1704
|
+
xv = np.bincount( self.DICTIONARY['IC']['vox'], minlength=nVOX,
|
|
1705
|
+
weights=tmp[ self.DICTIONARY['IC']['str'] ] * self.DICTIONARY['IC']['len']
|
|
1723
1706
|
).astype(np.float32)
|
|
1724
1707
|
niiIC_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'] ] = xv
|
|
1725
1708
|
|
|
1726
1709
|
log_list = []
|
|
1727
1710
|
ret_subinfo = logger.subinfo('Extra-axonal', indent_lvl=2, indent_char='-', with_progress=True)
|
|
1728
|
-
with ProgressBar(disable=self.verbose
|
|
1711
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
|
|
1729
1712
|
niiEC_img = np.zeros( self.get_config('dim'), dtype=np.float32 )
|
|
1730
1713
|
if len(self.KERNELS['wmh']) > 0 :
|
|
1731
|
-
offset =
|
|
1714
|
+
offset = nSTR * self.KERNELS['wmr'].shape[0]
|
|
1732
1715
|
tmp = x[offset:offset+nE*len(self.KERNELS['wmh'])].reshape( (-1,nE) ).sum( axis=0 )
|
|
1733
|
-
xv = np.bincount( self.DICTIONARY['EC']['
|
|
1716
|
+
xv = np.bincount( self.DICTIONARY['EC']['vox'], weights=tmp, minlength=nVOX ).astype(np.float32)
|
|
1734
1717
|
niiEC_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'] ] = xv
|
|
1735
1718
|
|
|
1736
1719
|
log_list = []
|
|
1737
1720
|
ret_subinfo = logger.subinfo('Isotropic ', indent_lvl=2, indent_char='-', with_progress=True)
|
|
1738
|
-
with ProgressBar(disable=self.verbose
|
|
1721
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
|
|
1739
1722
|
niiISO_img = np.zeros( self.get_config('dim'), dtype=np.float32 )
|
|
1740
1723
|
if len(self.KERNELS['iso']) > 0 :
|
|
1741
|
-
offset =
|
|
1742
|
-
offset_iso = offset + self.DICTIONARY['ISO']['
|
|
1743
|
-
tmp = x[offset:offset_iso].reshape( (-1,self.DICTIONARY['ISO']['
|
|
1744
|
-
xv = np.bincount( self.DICTIONARY['ISO']['
|
|
1724
|
+
offset = nSTR * self.KERNELS['wmr'].shape[0] + nE * self.KERNELS['wmh'].shape[0]
|
|
1725
|
+
offset_iso = offset + self.DICTIONARY['ISO']['n']
|
|
1726
|
+
tmp = x[offset:offset_iso].reshape( (-1,self.DICTIONARY['ISO']['n']) ).sum( axis=0 )
|
|
1727
|
+
xv = np.bincount( self.DICTIONARY['ISO']['vox'], weights=tmp, minlength=nVOX ).astype(np.float32)
|
|
1745
1728
|
niiISO_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'] ] = xv
|
|
1746
1729
|
|
|
1747
1730
|
if self.get_config('doNormalizeMaps') :
|
|
@@ -1801,6 +1784,7 @@ cdef class Evaluation :
|
|
|
1801
1784
|
xic[ self.DICTIONARY['TRK']['kept']==1 ] *= self.DICTIONARY['TRK']['lenTot'] / self.DICTIONARY['TRK']['len']
|
|
1802
1785
|
|
|
1803
1786
|
# call (potential) postprocessing required by the specific model
|
|
1787
|
+
#TODO: in this the right place to call such a function?
|
|
1804
1788
|
if hasattr(self.model, '_postprocess') :
|
|
1805
1789
|
ret_subinfo = logger.subinfo('Calling model-specific postprocessing', indent_lvl=2, indent_char='-', with_progress=True)
|
|
1806
1790
|
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo):
|
|
@@ -1818,15 +1802,19 @@ cdef class Evaluation :
|
|
|
1818
1802
|
# item 2: np.array renormalisation of coeffs in item 1
|
|
1819
1803
|
logger.subinfo('Configuration settings:', indent_lvl=1, indent_char='*')
|
|
1820
1804
|
ret_subinfo = logger.subinfo('results.pickle', indent_lvl=2, indent_char='-', with_progress=True)
|
|
1821
|
-
with ProgressBar(disable=self.verbose
|
|
1805
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo):
|
|
1822
1806
|
with open( pjoin(RESULTS_path,'results.pickle'), 'wb+' ) as fid :
|
|
1823
|
-
self.CONFIG['optimization']['regularisation']
|
|
1824
|
-
self.CONFIG['optimization']['regularisation']
|
|
1807
|
+
tmp_omega = self.CONFIG['optimization']['regularisation']['omega']
|
|
1808
|
+
tmp_prox = self.CONFIG['optimization']['regularisation']['prox']
|
|
1809
|
+
self.CONFIG['optimization']['regularisation']['omega'] = None
|
|
1810
|
+
self.CONFIG['optimization']['regularisation']['prox'] = None
|
|
1825
1811
|
pickle.dump( [self.CONFIG, self.x, x], fid, protocol=2 )
|
|
1812
|
+
self.CONFIG['optimization']['regularisation']['omega'] = tmp_omega
|
|
1813
|
+
self.CONFIG['optimization']['regularisation']['prox'] = tmp_prox
|
|
1826
1814
|
|
|
1827
1815
|
if save_est_dwi:
|
|
1828
1816
|
ret_subinfo = logger.subinfo('Estimated signal', indent_lvl=2, indent_char='-', with_progress=True)
|
|
1829
|
-
with ProgressBar(disable=self.verbose
|
|
1817
|
+
with ProgressBar(disable=self.verbose<3, hide_on_exit=True, subinfo=ret_subinfo):
|
|
1830
1818
|
self.niiDWI_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'], : ] = y_est
|
|
1831
1819
|
nibabel.save( nibabel.Nifti1Image( self.niiDWI_img , affine ), pjoin(RESULTS_path,'fit_signal_estimated.nii.gz') )
|
|
1832
1820
|
self.niiDWI_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'], : ] = y_mea
|