dmri-commit 2.2.0__tar.gz → 2.3.0__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.
Files changed (30) hide show
  1. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/LICENSE +0 -0
  2. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/MANIFEST.in +1 -0
  3. {dmri-commit-2.2.0/dmri_commit.egg-info → dmri_commit-2.3.0}/PKG-INFO +2 -2
  4. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/README.md +0 -0
  5. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/commit/core.pyx +103 -129
  6. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/commit/models.py +1 -0
  7. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/commit/operator/operator.pyx +76 -22
  8. dmri_commit-2.3.0/commit/operator/operator_c.c +8589 -0
  9. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/commit/proximals.pyx +0 -0
  10. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/commit/solvers.py +40 -40
  11. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/commit/trk2dictionary/ProgressBar.h +0 -0
  12. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/commit/trk2dictionary/Vector.h +0 -0
  13. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/commit/trk2dictionary/trk2dictionary.pyx +57 -46
  14. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/commit/trk2dictionary/trk2dictionary_c.cpp +19 -17
  15. {dmri-commit-2.2.0 → dmri_commit-2.3.0/dmri_commit.egg-info}/PKG-INFO +2 -2
  16. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/dmri_commit.egg-info/SOURCES.txt +2 -4
  17. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/dmri_commit.egg-info/dependency_links.txt +0 -0
  18. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/dmri_commit.egg-info/requires.txt +1 -1
  19. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/dmri_commit.egg-info/top_level.txt +0 -0
  20. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/pyproject.toml +6 -3
  21. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/setup.cfg +0 -0
  22. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/setup.py +28 -6
  23. dmri_commit-2.3.0/setup_operator.py +932 -0
  24. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/tests/test_demo.py +0 -0
  25. dmri-commit-2.2.0/commit/operator/config.py +0 -6
  26. dmri-commit-2.2.0/commit/operator/operator.pyxbld +0 -39
  27. dmri-commit-2.2.0/commit/operator/operator_noLUT.c +0 -187
  28. dmri-commit-2.2.0/commit/operator/operator_withLUT.c +0 -2247
  29. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/commit/__init__.py +0 -0
  30. {dmri-commit-2.2.0 → dmri_commit-2.3.0}/commit/operator/__init__.py +0 -0
File without changes
@@ -2,3 +2,4 @@ recursive-include commit *.c
2
2
  recursive-include commit *.cpp
3
3
  recursive-include commit *.h
4
4
  recursive-include commit *pyx
5
+ include setup_operator.py
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dmri-commit
3
- Version: 2.2.0
3
+ Version: 2.3.0
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>
@@ -106,7 +106,7 @@ Description-Content-Type: text/markdown
106
106
  License-File: LICENSE
107
107
  Requires-Dist: dmri-amico>=2.0.1
108
108
  Requires-Dist: dmri-dicelib>=1.1.0
109
- Requires-Dist: numpy>=1.24.4
109
+ Requires-Dist: numpy<2.0.0,>=1.24.4
110
110
  Requires-Dist: scipy>=1.10.1
111
111
 
112
112
  [![PyPI](https://img.shields.io/pypi/v/dmri-commit)](https://pypi.org/project/dmri-commit/)
File without changes
@@ -27,6 +27,7 @@ from dicelib.utils import format_time
27
27
 
28
28
  import commit.models
29
29
  import commit.solvers
30
+ from commit.operator import operator
30
31
 
31
32
 
32
33
  logger = setup_logger('core')
@@ -78,6 +79,7 @@ cdef class Evaluation :
78
79
  cdef public A
79
80
  cdef public regularisation_params
80
81
  cdef public x
82
+ cdef public x_nnls
81
83
  cdef public CONFIG
82
84
  cdef public temp_data
83
85
  cdef public confidence_map_img
@@ -103,6 +105,7 @@ cdef class Evaluation :
103
105
  self.regularisation_params = None # set by "set_regularisation" method
104
106
  self.x = None # set by "fit" method
105
107
  self.confidence_map_img = None # set by "fit" method
108
+ self.x_nnls = None # set by "fit" method (coefficients of IC compartment estimated without regularization)
106
109
  self.verbose = 3
107
110
 
108
111
  # store all the parameters of an evaluation with COMMIT
@@ -223,8 +226,9 @@ cdef class Evaluation :
223
226
 
224
227
  if self.get_config('doNormalizeSignal') :
225
228
  if self.scheme.b0_count > 0:
226
- logger.subinfo('Normalizing to b0:', with_progress=True, indent_char='*', indent_lvl=1)
227
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
229
+ log_list = []
230
+ ret_subinfo = logger.subinfo('Normalizing to b0:', with_progress=True, indent_char='*', indent_lvl=1)
231
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
228
232
  b0 = np.mean( self.niiDWI_img[:,:,:,self.scheme.b0_idx], axis=3 )
229
233
  idx = b0 <= b0_min_signal * b0[b0>0].mean()
230
234
  b0[ idx ] = 1
@@ -352,8 +356,9 @@ cdef class Evaluation :
352
356
  tic = time.time()
353
357
  logger.subinfo('')
354
358
  logger.info( 'Loading the kernels' )
355
- logger.subinfo( 'Resampling LUT for subject "%s":' % self.get_config('subject'), indent_char='*', indent_lvl=1, with_progress=True ) # TODO: check why not printed
356
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
359
+ log_list = []
360
+ ret_subinfo = logger.subinfo( 'Resampling LUT for subject "%s":' % self.get_config('subject'), indent_char='*', indent_lvl=1, with_progress=True ) # TODO: check why not printed
361
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
357
362
  # auxiliary data structures
358
363
  idx_OUT, Ylm_OUT = amico.lut.aux_structures_resample( self.scheme, self.get_config('lmax') )
359
364
 
@@ -375,8 +380,9 @@ cdef class Evaluation :
375
380
 
376
381
  # De-mean kernels
377
382
  if self.get_config('doDemean') :
378
- logger.subinfo('Demeaning signal', with_progress=True, indent_lvl=2, indent_char='-' )
379
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
383
+ log_list = []
384
+ ret_subinfo = logger.subinfo('Demeaning signal', with_progress=True, indent_lvl=2, indent_char='-' )
385
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
380
386
  for j in xrange(self.get_config('ndirs')) :
381
387
  for i in xrange(nIC) :
382
388
  self.KERNELS['wmr'][i,j,:] -= self.KERNELS['wmr'][i,j,:].mean()
@@ -387,8 +393,9 @@ cdef class Evaluation :
387
393
 
388
394
  # Normalize atoms
389
395
  if self.get_config('doNormalizeKernels') :
390
- logger.subinfo('Normalizing kernels', with_progress=True, indent_lvl=2, indent_char='-' )
391
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
396
+ log_list = []
397
+ ret_subinfo = logger.subinfo('Normalizing kernels', with_progress=True, indent_lvl=2, indent_char='-' )
398
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
392
399
  self.KERNELS['wmr_norm'] = np.zeros( nIC )
393
400
  for i in xrange(nIC) :
394
401
  self.KERNELS['wmr_norm'][i] = np.linalg.norm( self.KERNELS['wmr'][i,0,:] )
@@ -458,8 +465,9 @@ cdef class Evaluation :
458
465
 
459
466
  # segments from the tracts
460
467
  # ------------------------
461
- logger.subinfo('Segments from the tracts:', indent_char='*', indent_lvl=1, with_progress=True )
462
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
468
+ log_list = []
469
+ ret_subinfo = logger.subinfo('Segments from the tracts:', indent_char='*', indent_lvl=1, with_progress=True )
470
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
463
471
  self.DICTIONARY['TRK'] = {}
464
472
  self.DICTIONARY['TRK']['kept'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_TRK_kept.dict'), dtype=np.uint8 )
465
473
  self.DICTIONARY['TRK']['norm'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_TRK_norm.dict'), dtype=np.float32 )
@@ -498,8 +506,9 @@ cdef class Evaluation :
498
506
 
499
507
  # segments from the peaks
500
508
  # -----------------------
501
- logger.subinfo('Segments from the peaks:', indent_char='*', indent_lvl=1, with_progress=True )
502
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
509
+ log_list = []
510
+ ret_subinfo = logger.subinfo('Segments from the peaks:', indent_char='*', indent_lvl=1, with_progress=True )
511
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
503
512
  self.DICTIONARY['EC'] = {}
504
513
  self.DICTIONARY['EC']['v'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_EC_v.dict'), dtype=np.uint32 )
505
514
  self.DICTIONARY['EC']['o'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_EC_o.dict'), dtype=np.uint16 )
@@ -515,8 +524,9 @@ cdef class Evaluation :
515
524
 
516
525
  # isotropic compartments
517
526
  # ----------------------
518
- logger.subinfo('Isotropic contributions:', indent_char='*', indent_lvl=1, with_progress=True )
519
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
527
+ log_list = []
528
+ ret_subinfo = logger.subinfo('Isotropic contributions:', indent_char='*', indent_lvl=1, with_progress=True )
529
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
520
530
  self.DICTIONARY['ISO'] = {}
521
531
 
522
532
  self.DICTIONARY['ISO']['v'] = np.fromfile( pjoin(self.get_config('TRACKING_path'),'dictionary_ISO_v.dict'), dtype=np.uint32 )
@@ -533,8 +543,9 @@ cdef class Evaluation :
533
543
 
534
544
  # post-processing
535
545
  # ---------------
536
- logger.subinfo('Post-processing', indent_char='*', indent_lvl=1, with_progress=True )
537
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
546
+ log_list = []
547
+ ret_subinfo = logger.subinfo('Post-processing', indent_char='*', indent_lvl=1, with_progress=True )
548
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
538
549
  # get the indices to extract the VOI as in MATLAB (in place of DICTIONARY.MASKidx)
539
550
  idx = self.DICTIONARY['MASK'].ravel(order='F').nonzero()[0]
540
551
  self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'] = np.unravel_index( idx, self.DICTIONARY['MASK'].shape, order='F' )
@@ -557,7 +568,7 @@ cdef class Evaluation :
557
568
  ----------
558
569
  n : integer
559
570
  Number of threads to use (default : number of CPUs in the system)
560
- """
571
+ """
561
572
  if n is None :
562
573
  # Use the same number of threads used in trk2dictionary
563
574
  n = self.DICTIONARY['n_threads']
@@ -574,7 +585,7 @@ cdef class Evaluation :
574
585
  self.THREADS['n'] = n
575
586
 
576
587
  cdef :
577
- long [:] C
588
+ long long [:] C
578
589
  long t, tot, i1, i2, N, c
579
590
  int i
580
591
 
@@ -584,8 +595,9 @@ cdef class Evaluation :
584
595
  logger.subinfo('Number of threads: %d' % n , indent_char='*', indent_lvl=1 )
585
596
 
586
597
  # Distribute load for the computation of A*x product
587
- logger.subinfo('A operator ', indent_char='*', indent_lvl=1, with_progress=True )
588
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
598
+ log_list = []
599
+ ret_subinfo = logger.subinfo('A operator ', indent_char='*', indent_lvl=1, with_progress=True )
600
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
589
601
  if self.DICTIONARY['IC']['n'] > 0 :
590
602
  self.THREADS['IC'] = np.zeros( n+1, dtype=np.uint32 )
591
603
  if n > 1 :
@@ -636,8 +648,9 @@ cdef class Evaluation :
636
648
 
637
649
 
638
650
  # Distribute load for the computation of At*y product
639
- logger.subinfo('A\' operator', indent_char='*', indent_lvl=1, with_progress=True )
640
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
651
+ log_list = []
652
+ ret_subinfo = logger.subinfo('A\' operator', indent_char='*', indent_lvl=1, with_progress=True )
653
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
641
654
  if self.DICTIONARY['IC']['n'] > 0 :
642
655
  self.THREADS['ICt'] = np.full( self.DICTIONARY['IC']['n'], n-1, dtype=np.uint8 )
643
656
  if n > 1 :
@@ -692,19 +705,9 @@ cdef class Evaluation :
692
705
  logger.info( f'[ {format_time(time.time() - tic)} ]' )
693
706
 
694
707
 
695
- def build_operator( self, build_dir=None ) :
696
- """Compile/build the operator for computing the matrix-vector multiplications by A and A'
708
+ def build_operator( self ) :
709
+ """Build the operator for computing the matrix-vector multiplications by A and A'
697
710
  using the informations from self.DICTIONARY, self.KERNELS and self.THREADS.
698
- NB: needs to call this function to update pointers to data structures in case
699
- the data is changed in self.DICTIONARY, self.KERNELS or self.THREADS.
700
-
701
- Parameters
702
- ----------
703
- build_dir : string
704
- The folder in which to store the compiled files.
705
- If None (default), they will end up in the .pyxbld directory in the user’s home directory.
706
- If using this option, it is recommended to use a temporary directory, quit your python
707
- console between each build, and delete the content of the temporary directory.
708
711
  """
709
712
  if self.DICTIONARY is None :
710
713
  logger.error( 'Dictionary not loaded; call "load_dictionary()" first' )
@@ -722,49 +725,7 @@ cdef class Evaluation :
722
725
  logger.subinfo('')
723
726
  logger.info( 'Building linear operator A' )
724
727
 
725
- # need to pass these parameters at runtime for compiling the C code
726
- from commit.operator import config
727
-
728
- compilation_is_needed = False
729
-
730
- if config.nTHREADS is None or config.nTHREADS != self.THREADS['n']:
731
- compilation_is_needed = True
732
- if config.nIC is None or config.nIC != self.KERNELS['wmr'].shape[0]:
733
- compilation_is_needed = True
734
- if config.model is None or config.model != self.model.id:
735
- compilation_is_needed = True
736
- if config.nEC is None or config.nEC != self.KERNELS['wmh'].shape[0]:
737
- compilation_is_needed = True
738
- if config.nISO is None or config.nISO != self.KERNELS['iso'].shape[0]:
739
- compilation_is_needed = True
740
- if config.build_dir != build_dir:
741
- compilation_is_needed = True
742
-
743
- if compilation_is_needed or not 'commit.operator.operator' in sys.modules :
744
-
745
- if build_dir is not None:
746
- if isdir(build_dir) and not len(listdir(build_dir)) == 0:
747
- logger.error( '\nbuild_dir is not empty, unsafe build option.' )
748
- elif config.nTHREADS is not None:
749
- logger.error( '\nThe parameter build_dir has changed, unsafe build option.' )
750
- else:
751
- logger.warning( '\nUsing build_dir, always quit your python console between COMMIT Evaluation.' )
752
-
753
- config.nTHREADS = self.THREADS['n']
754
- config.model = self.model.id
755
- config.nIC = self.KERNELS['wmr'].shape[0]
756
- config.nEC = self.KERNELS['wmh'].shape[0]
757
- config.nISO = self.KERNELS['iso'].shape[0]
758
- config.build_dir = build_dir
759
-
760
- sys.dont_write_bytecode = True
761
- pyximport.install( reload_support=True, language_level=3, build_dir=build_dir, build_in_temp=True, inplace=False )
762
-
763
- if 'commit.operator.operator' in sys.modules :
764
- del sys.modules['commit.operator.operator']
765
- import commit.operator.operator
766
-
767
- self.A = commit.operator.operator.LinearOperator( self.DICTIONARY, self.KERNELS, self.THREADS )
728
+ self.A = operator.LinearOperator( self.DICTIONARY, self.KERNELS, self.THREADS, True if hasattr(self.model, 'nolut') else False )
768
729
 
769
730
  logger.info( f'[ {format_time(time.time() - tic)} ]' )
770
731
 
@@ -869,7 +830,7 @@ cdef class Evaluation :
869
830
  This field can be specified only if regularisers[0] is 'group_lasso' or 'sparse_group_lasso'.
870
831
  NB: this array must have the same size as the number of groups in the IC compartment and contain only non-negative values.
871
832
  'coeff_weights' - np.array(np.float64) :
872
- weights associated to each individual element of the compartment (implemented for all compartments).
833
+ weights associated to each individual element of the compartment (for the moment implemented only for IC compartment).
873
834
  This field can be specified only if the chosen regulariser is 'lasso' or 'sparse_group_lasso'.
874
835
  NB: this array must have the same size as the number of elements in the compartment and contain only non-negative values.
875
836
 
@@ -960,7 +921,7 @@ cdef class Evaluation :
960
921
  logger.error('Regularisation parameters for the IC compartment ara not exactly two')
961
922
  elif lambdas[0][0] < 0 or lambdas[0][1] < 0:
962
923
  logger.error('Regularisation parameters for the IC compartment must be greater than 0')
963
- elif lambdas[0][0] == 0 or lambdas[0][1] == 0:
924
+ elif lambdas[0][0] == 0 and lambdas[0][1] == 0:
964
925
  logger.warning('Regularisation parameters for the IC compartment are both 0, the solution will be the same as the one without regularisation')
965
926
  regularisation['lambdaIC_perc'] = lambdas[0]
966
927
  else:
@@ -972,7 +933,7 @@ cdef class Evaluation :
972
933
 
973
934
  # check if coeff_weights is consistent with the regularisation
974
935
  if regularisation['regIC'] not in ['lasso', 'sparse_group_lasso'] and dictIC_params is not None and 'coeff_weights' in dictIC_params:
975
- logger.warning('Coefficients weights are allowed only for lasso and sparse_group_lasso regularisation')
936
+ logger.warning('Coefficients weights are allowed only for lasso and sparse_group_lasso regularisations. Ignoring "coeff_weights"')
976
937
 
977
938
  # check if coeff_weights is consistent with the compartment size
978
939
  if regularisation['regIC'] == 'lasso' or regularisation['regIC'] == 'sparse_group_lasso':
@@ -981,7 +942,7 @@ cdef class Evaluation :
981
942
  logger.error('All coefficients weights must be non-negative')
982
943
  if dictIC_params['coeff_weights'].size != len(self.DICTIONARY['TRK']['kept']):
983
944
  logger.error(f'"coeff_weights" must have the same size as the number of elements in the IC compartment (got {dictIC_params["coeff_weights"].size} but {len(self.DICTIONARY["TRK"]["kept"])} expected)')
984
- dictIC_params['coeff_weights'] = dictIC_params['coeff_weights'][self.DICTIONARY['TRK']['kept']==1]
945
+ dictIC_params['coeff_weights_kept'] = dictIC_params['coeff_weights'][self.DICTIONARY['TRK']['kept']==1]
985
946
 
986
947
  # check if group parameters are consistent with the regularisation
987
948
  if regularisation['regIC'] not in ['group_lasso', 'sparse_group_lasso'] and dictIC_params is not None:
@@ -1058,24 +1019,25 @@ cdef class Evaluation :
1058
1019
  newweightsIC_group.append(weightsIC_group[count])
1059
1020
 
1060
1021
  newweightsIC_group = np.array(newweightsIC_group, dtype=np.float64)
1061
- dictIC_params['group_idx'] = np.array(newICgroup_idx, dtype=np.object_)
1022
+ dictIC_params['group_idx_kept'] = np.array(newICgroup_idx, dtype=np.object_)
1062
1023
  if weightsIC_group.size != newweightsIC_group.size:
1063
1024
  logger.warning(f"""\
1064
1025
  Not all the original groups are kept.
1065
- {weightsIC_group.size - newweightsIC_group.size} groups have been removed because their streamlines didn't satify the criteria set in trk2dictionary.""")
1026
+ {weightsIC_group.size - newweightsIC_group.size} groups have been removed because their streamlines didn't satisfy the criteria set in trk2dictionary.""")
1066
1027
  else:
1067
1028
  newweightsIC_group = weightsIC_group
1029
+ dictIC_params['group_idx_kept'] = dictIC_params['group_idx']
1068
1030
 
1069
1031
  # compute group weights
1070
1032
  if regularisation['regIC'] == 'group_lasso' or regularisation['regIC'] == 'sparse_group_lasso':
1071
1033
  if dictIC_params['group_weights_cardinality']:
1072
- group_size = np.array([g.size for g in dictIC_params['group_idx']], dtype=np.int32)
1034
+ group_size = np.array([g.size for g in dictIC_params['group_idx_kept']], dtype=np.int32)
1073
1035
  newweightsIC_group *= np.sqrt(group_size)
1074
1036
  if dictIC_params['group_weights_adaptive']:
1075
- if self.x is None or self.regularisation_params['regIC'] is not None:
1037
+ if self.x_nnls is None: #or self.regularisation_params['regIC'] is not None:
1076
1038
  logger.error('Group weights cannot be computed if the fit without regularisation has not been performed before')
1077
- x_nnls, _, _ = self.get_coeffs(get_normalized=False)
1078
- group_x_norm = np.array([np.linalg.norm(x_nnls[g])+1e-12 for g in dictIC_params['group_idx']], dtype=np.float64)
1039
+ # x_nnls, _, _ = self.get_coeffs(get_normalized=False)
1040
+ group_x_norm = np.array([np.linalg.norm(self.x_nnls[g])+1e-12 for g in dictIC_params['group_idx_kept']], dtype=np.float64)
1079
1041
  newweightsIC_group /= group_x_norm
1080
1042
  dictIC_params['group_weights'] = newweightsIC_group
1081
1043
 
@@ -1083,21 +1045,24 @@ cdef class Evaluation :
1083
1045
 
1084
1046
  # update lambdas using lambda_max
1085
1047
  if regularisation['regIC'] == 'lasso':
1086
- if dictIC_params is not None and 'coeff_weights' in dictIC_params:
1087
- regularisation['lambdaIC_max'] = compute_lambda_max_lasso(regularisation['startIC'], regularisation['sizeIC'], dictIC_params['coeff_weights'])
1048
+ if dictIC_params is not None and 'coeff_weights_kept' in dictIC_params:
1049
+ regularisation['lambdaIC_max'] = compute_lambda_max_lasso(regularisation['startIC'], regularisation['sizeIC'], dictIC_params['coeff_weights_kept'])
1088
1050
  else:
1089
1051
  regularisation['lambdaIC_max'] = compute_lambda_max_lasso(regularisation['startIC'], regularisation['sizeIC'], np.ones(regularisation['sizeIC'], dtype=np.float64))
1090
1052
  regularisation['lambdaIC'] = regularisation['lambdaIC_perc'] * regularisation['lambdaIC_max']
1091
1053
  if regularisation['regIC'] == 'group_lasso':
1092
- regularisation['lambdaIC_max'] = compute_lambda_max_group(dictIC_params['group_weights'], dictIC_params['group_idx'])
1054
+ regularisation['lambdaIC_max'] = compute_lambda_max_group(dictIC_params['group_weights'], dictIC_params['group_idx_kept'])
1093
1055
  regularisation['lambdaIC'] = regularisation['lambdaIC_perc'] * regularisation['lambdaIC_max']
1094
1056
  if regularisation['regIC'] == 'sparse_group_lasso':
1095
- regularisation['lambdaIC_max'] = ( compute_lambda_max_lasso(regularisation['startIC'], regularisation['sizeIC']), compute_lambda_max_group(dictIC_params['group_weights'], dictIC_params['group_idx']) )
1057
+ if 'coeff_weights_kept' in dictIC_params:
1058
+ regularisation['lambdaIC_max'] = ( compute_lambda_max_lasso(regularisation['startIC'], regularisation['sizeIC'], dictIC_params['coeff_weights_kept']), compute_lambda_max_group(dictIC_params['group_weights'], dictIC_params['group_idx_kept']) )
1059
+ else:
1060
+ regularisation['lambdaIC_max'] = ( compute_lambda_max_lasso(regularisation['startIC'], regularisation['sizeIC'], np.ones(regularisation['sizeIC'], dtype=np.float64)), compute_lambda_max_group(dictIC_params['group_weights'], dictIC_params['group_idx_kept']) )
1096
1061
  regularisation['lambdaIC'] = ( regularisation['lambdaIC_perc'][0] * regularisation['lambdaIC_max'][0], regularisation['lambdaIC_perc'][1] * regularisation['lambdaIC_max'][1] )
1097
1062
 
1098
1063
  # print
1099
1064
  if regularisation['regIC'] is not None:
1100
- if (regularisation['regIC'] == 'lasso' or regularisation['regIC'] == 'sparse_group_lasso') and dictIC_params is not None and 'coeff_weights' in dictIC_params:
1065
+ if (regularisation['regIC'] == 'lasso' or regularisation['regIC'] == 'sparse_group_lasso') and dictIC_params is not None and 'coeff_weights_kept' in dictIC_params:
1101
1066
  logger.subinfo( f'Regularisation type: {regularisation["regIC"]} (weighted version)', indent_lvl=2, indent_char='-' )
1102
1067
  else:
1103
1068
  logger.subinfo( f'Regularisation type: {regularisation["regIC"]}', indent_lvl=2, indent_char='-' )
@@ -1108,7 +1073,7 @@ cdef class Evaluation :
1108
1073
  logger.debug( f'% lambda: {regularisation["lambdaIC_perc"]}' )
1109
1074
  logger.debug( f'Lambda used: {regularisation["lambdaIC"]}' )
1110
1075
  if regularisation['regIC'] == 'group_lasso' or regularisation['regIC'] == 'sparse_group_lasso':
1111
- logger.debug( f'Number of groups: {len(dictIC_params["group_idx"])}' )
1076
+ logger.debug( f'Number of groups: {len(dictIC_params["group_idx_kept"])}' )
1112
1077
  if dictIC_params['group_weights_cardinality']==False and dictIC_params['group_weights_adaptive']==False and dictIC_params['group_weights_extra'] is None:
1113
1078
  logger.debug( 'Group weights are not considered (all ones)' )
1114
1079
  else:
@@ -1139,9 +1104,9 @@ cdef class Evaluation :
1139
1104
  regularisation['lambdaEC_perc'] = lambdas[1]
1140
1105
  else:
1141
1106
  regularisation['lambdaEC_perc'] = lambdas[1]
1142
- if dictEC_params is not None and 'coeff_weights' in dictEC_params:
1143
- if dictEC_params['coeff_weights'].size != regularisation['sizeEC']:
1144
- logger.error(f'"coeff_weights" must have the same size as the number of elements in the EC compartment (got {dictEC_params["coeff_weights"].size} but {regularisation["sizeEC"]} expected)')
1107
+ # if dictEC_params is not None and 'coeff_weights' in dictEC_params:
1108
+ # if dictEC_params['coeff_weights'].size != regularisation['sizeEC']:
1109
+ # logger.error(f'"coeff_weights" must have the same size as the number of elements in the EC compartment (got {dictEC_params["coeff_weights"].size} but {regularisation["sizeEC"]} expected)')
1145
1110
  elif regularisation['regEC'] == 'smoothness':
1146
1111
  logger.error('Not yet implemented')
1147
1112
  elif regularisation['regEC'] == 'group_lasso':
@@ -1155,18 +1120,18 @@ cdef class Evaluation :
1155
1120
 
1156
1121
  # update lambdas using lambda_max
1157
1122
  if regularisation['regEC'] == 'lasso':
1158
- if dictEC_params is not None and 'coeff_weights' in dictEC_params:
1159
- regularisation['lambdaEC_max'] = compute_lambda_max_lasso(regularisation['startEC'], regularisation['sizeEC'], dictEC_params['coeff_weights'])
1160
- else:
1161
- regularisation['lambdaEC_max'] = compute_lambda_max_lasso(regularisation['startEC'], regularisation['sizeEC'], np.ones(regularisation['sizeEC'], dtype=np.float64))
1123
+ # if dictEC_params is not None and 'coeff_weights' in dictEC_params:
1124
+ # regularisation['lambdaEC_max'] = compute_lambda_max_lasso(regularisation['startEC'], regularisation['sizeEC'], dictEC_params['coeff_weights'])
1125
+ # else:
1126
+ regularisation['lambdaEC_max'] = compute_lambda_max_lasso(regularisation['startEC'], regularisation['sizeEC'], np.ones(regularisation['sizeEC'], dtype=np.float64))
1162
1127
  regularisation['lambdaEC'] = regularisation['lambdaEC_perc'] * regularisation['lambdaEC_max']
1163
1128
 
1164
1129
  # print
1165
1130
  if regularisation['regEC'] is not None:
1166
- if regularisation['regEC'] == 'lasso' and dictEC_params is not None and 'coeff_weights' in dictEC_params:
1167
- logger.subinfo( f'Regularisation type: {regularisation["regEC"]} (weighted version)', indent_lvl=2, indent_char='-' )
1168
- else:
1169
- logger.subinfo( f'Regularisation type: {regularisation["regEC"]}', indent_lvl=2, indent_char='-' )
1131
+ # if regularisation['regEC'] == 'lasso' and dictEC_params is not None and 'coeff_weights' in dictEC_params:
1132
+ # logger.subinfo( f'Regularisation type: {regularisation["regEC"]} (weighted version)', indent_lvl=2, indent_char='-' )
1133
+ # else:
1134
+ logger.subinfo( f'Regularisation type: {regularisation["regEC"]}', indent_lvl=2, indent_char='-' )
1170
1135
 
1171
1136
  logger.subinfo( f'Non-negativity constraint: {regularisation["nnEC"]}', indent_char='-', indent_lvl=2 )
1172
1137
 
@@ -1194,9 +1159,9 @@ cdef class Evaluation :
1194
1159
  regularisation['lambdaISO_perc'] = lambdas[2]
1195
1160
  else:
1196
1161
  regularisation['lambdaISO_perc'] = lambdas[2]
1197
- if dictISO_params is not None and 'coeff_weights' in dictISO_params:
1198
- if dictISO_params['coeff_weights'].size != regularisation['sizeISO']:
1199
- logger.error(f'"coeff_weights" must have the same size as the number of elements in the ISO compartment (got {dictISO_params["coeff_weights"].size} but {regularisation["sizeISO"]} expected)')
1162
+ # if dictISO_params is not None and 'coeff_weights' in dictISO_params:
1163
+ # if dictISO_params['coeff_weights'].size != regularisation['sizeISO']:
1164
+ # logger.error(f'"coeff_weights" must have the same size as the number of elements in the ISO compartment (got {dictISO_params["coeff_weights"].size} but {regularisation["sizeISO"]} expected)')
1200
1165
  elif regularisation['regISO'] == 'smoothness':
1201
1166
  logger.error('Not yet implemented')
1202
1167
  elif regularisation['regISO'] == 'group_lasso':
@@ -1210,18 +1175,18 @@ cdef class Evaluation :
1210
1175
 
1211
1176
  # update lambdas using lambda_max
1212
1177
  if regularisation['regISO'] == 'lasso':
1213
- if dictISO_params is not None and 'coeff_weights' in dictISO_params:
1214
- regularisation['lambdaISO_max'] = compute_lambda_max_lasso(regularisation['startISO'], regularisation['sizeISO'], dictISO_params['coeff_weights'])
1215
- else:
1216
- regularisation['lambdaISO_max'] = compute_lambda_max_lasso(regularisation['startISO'], regularisation['sizeISO'], np.ones(regularisation['sizeISO'], dtype=np.float64))
1178
+ # if dictISO_params is not None and 'coeff_weights' in dictISO_params:
1179
+ # regularisation['lambdaISO_max'] = compute_lambda_max_lasso(regularisation['startISO'], regularisation['sizeISO'], dictISO_params['coeff_weights'])
1180
+ # else:
1181
+ regularisation['lambdaISO_max'] = compute_lambda_max_lasso(regularisation['startISO'], regularisation['sizeISO'], np.ones(regularisation['sizeISO'], dtype=np.float64))
1217
1182
  regularisation['lambdaISO'] = regularisation['lambdaISO_perc'] * regularisation['lambdaISO_max']
1218
1183
 
1219
1184
  # print
1220
1185
  if regularisation['regISO'] is not None:
1221
- if regularisation['regISO'] == 'lasso' and dictISO_params is not None and 'coeff_weights' in dictISO_params:
1222
- logger.subinfo( f'Regularisation type: {regularisation["regISO"]} (weighted version)', indent_lvl=2, indent_char='-' )
1223
- else:
1224
- logger.subinfo( f'Regularisation type: {regularisation["regISO"]}', indent_lvl=2, indent_char='-' )
1186
+ # if regularisation['regISO'] == 'lasso' and dictISO_params is not None and 'coeff_weights' in dictISO_params:
1187
+ # logger.subinfo( f'Regularisation type: {regularisation["regISO"]} (weighted version)', indent_lvl=2, indent_char='-' )
1188
+ # else:
1189
+ logger.subinfo( f'Regularisation type: {regularisation["regISO"]}', indent_lvl=2, indent_char='-' )
1225
1190
 
1226
1191
  logger.subinfo( f'Non-negativity constraint: {regularisation["nnISO"]}', indent_char='-', indent_lvl=2 )
1227
1192
  if regularisation['regISO'] is not None:
@@ -1353,12 +1318,15 @@ cdef class Evaluation :
1353
1318
 
1354
1319
  # run solver
1355
1320
  t = time.time()
1356
- with ProgressBar(disable=self.verbose!=3, hide_on_exit=True) as pb:
1321
+ with ProgressBar(disable=self.verbose!=3, hide_on_exit=True):
1357
1322
  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)
1358
1323
 
1359
1324
  self.CONFIG['optimization']['fit_details'] = opt_details
1360
1325
  self.CONFIG['optimization']['fit_time'] = time.time()-t
1361
1326
 
1327
+ if self.regularisation_params['regIC'] is None and self.x_nnls is None:
1328
+ self.x_nnls, _, _ = self.get_coeffs(get_normalized=False)
1329
+
1362
1330
  logger.info( f'[ {format_time(self.CONFIG["optimization"]["fit_time"])} ]' )
1363
1331
 
1364
1332
 
@@ -1515,8 +1483,9 @@ cdef class Evaluation :
1515
1483
  # Map of compartment contributions
1516
1484
  logger.subinfo('Voxelwise contributions:', indent_char='*', indent_lvl=1)
1517
1485
 
1518
- logger.subinfo('Intra-axonal', indent_lvl=2, indent_char='-', with_progress=True)
1519
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
1486
+ log_list = []
1487
+ ret_subinfo = logger.subinfo('Intra-axonal', indent_lvl=2, indent_char='-', with_progress=True)
1488
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
1520
1489
  niiIC_img = np.zeros( self.get_config('dim'), dtype=np.float32 )
1521
1490
  if len(self.KERNELS['wmr']) > 0 :
1522
1491
  offset = nF * self.KERNELS['wmr'].shape[0]
@@ -1526,8 +1495,9 @@ cdef class Evaluation :
1526
1495
  ).astype(np.float32)
1527
1496
  niiIC_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'] ] = xv
1528
1497
 
1529
- logger.subinfo('Extra-axonal', indent_lvl=2, indent_char='-', with_progress=True)
1530
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
1498
+ log_list = []
1499
+ ret_subinfo = logger.subinfo('Extra-axonal', indent_lvl=2, indent_char='-', with_progress=True)
1500
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
1531
1501
  niiEC_img = np.zeros( self.get_config('dim'), dtype=np.float32 )
1532
1502
  if len(self.KERNELS['wmh']) > 0 :
1533
1503
  offset = nF * self.KERNELS['wmr'].shape[0]
@@ -1535,8 +1505,9 @@ cdef class Evaluation :
1535
1505
  xv = np.bincount( self.DICTIONARY['EC']['v'], weights=tmp, minlength=nV ).astype(np.float32)
1536
1506
  niiEC_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'] ] = xv
1537
1507
 
1538
- logger.subinfo('Isotropic ', indent_lvl=2, indent_char='-', with_progress=True)
1539
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
1508
+ log_list = []
1509
+ ret_subinfo = logger.subinfo('Isotropic ', indent_lvl=2, indent_char='-', with_progress=True)
1510
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
1540
1511
  niiISO_img = np.zeros( self.get_config('dim'), dtype=np.float32 )
1541
1512
  if len(self.KERNELS['iso']) > 0 :
1542
1513
  offset = nF * self.KERNELS['wmr'].shape[0] + nE * self.KERNELS['wmh'].shape[0]
@@ -1560,8 +1531,9 @@ cdef class Evaluation :
1560
1531
 
1561
1532
  # Configuration and results
1562
1533
  logger.subinfo('Configuration and results:', indent_char='*', indent_lvl=1)
1563
- logger.subinfo('streamline_weights.txt', indent_lvl=2, indent_char='-', with_progress=True)
1564
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
1534
+ log_list = []
1535
+ ret_subinfo = logger.subinfo('streamline_weights.txt', indent_lvl=2, indent_char='-', with_progress=True)
1536
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
1565
1537
  xic, _, _ = self.get_coeffs()
1566
1538
  if stat_coeffs != 'all' and xic.size > 0 :
1567
1539
  xic = np.reshape( xic, (-1,self.DICTIONARY['TRK']['kept'].size) )
@@ -1620,8 +1592,9 @@ cdef class Evaluation :
1620
1592
  # item 0: dictionary with all the configuration details
1621
1593
  # item 1: np.array obtained through the optimisation process with the normalised kernels
1622
1594
  # item 2: np.array renormalisation of coeffs in item 1
1623
- logger.subinfo('results.pickle', indent_char='-', indent_lvl=2, with_progress=True)
1624
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
1595
+ log_list = []
1596
+ ret_subinfo = logger.subinfo('results.pickle', indent_char='-', indent_lvl=2, with_progress=True)
1597
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
1625
1598
  xic, xec, xiso = self.get_coeffs()
1626
1599
  x = self.x
1627
1600
  if self.get_config('doNormalizeKernels') :
@@ -1631,9 +1604,10 @@ cdef class Evaluation :
1631
1604
  self.CONFIG['optimization']['regularisation'].pop('prox', None)
1632
1605
  pickle.dump( [self.CONFIG, x, self.x], fid, protocol=2 )
1633
1606
 
1634
- if save_est_dwi :
1635
- logger.subinfo('Estimated signal:', indent_char='-', indent_lvl=2, with_progress=True)
1636
- with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=True) as pbar:
1607
+ if save_est_dwi:
1608
+ log_list = []
1609
+ ret_subinfo = logger.subinfo('Estimated signal:', indent_char='-', indent_lvl=2, with_progress=True)
1610
+ with ProgressBar(disable=self.verbose < 3, hide_on_exit=True, subinfo=ret_subinfo, log_list=log_list):
1637
1611
  self.niiDWI_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'], : ] = y_est
1638
1612
  nibabel.save( nibabel.Nifti1Image( self.niiDWI_img , affine ), pjoin(RESULTS_path,'fit_signal_estimated.nii.gz') )
1639
1613
  self.niiDWI_img[ self.DICTIONARY['MASK_ix'], self.DICTIONARY['MASK_iy'], self.DICTIONARY['MASK_iz'], : ] = y_mea
@@ -74,6 +74,7 @@ class VolumeFractions(BaseModel):
74
74
  self.name = 'Volume fractions'
75
75
  self.maps_name = []
76
76
  self.maps_descr = []
77
+ self.nolut = True
77
78
 
78
79
  def set(self):
79
80
  return