示例#1
0
    def run(self, args, extra_args):
        meta_info = mdt.get_models_meta_info()
        models = mdt.get_models_list()

        max_model_name = max(map(len, models))

        for model in models:
            if args.long:
                print(('%-' + str(max_model_name + 2) + 's%-s') %
                      (model, meta_info[model]['description']))
            else:
                print(model)
示例#2
0
    def run(self, args):
        mdt.init_user_settings(pass_if_exists=True)

        meta_info = mdt.get_models_meta_info()
        models = mdt.get_models_list()

        max_model_name = max(map(len, models))

        for model in models:
            if args.long:
                print(('%-' + str(max_model_name + 2) + 's%-s') %
                      (model, meta_info[model]['description']))
            else:
                print(model)
示例#3
0
    def setupUi(self, tab_content):
        super().setupUi(tab_content)
        self._tab_content = tab_content

        self.selectDWI.clicked.connect(lambda: self._select_dwi())
        self.selectMask.clicked.connect(lambda: self._select_mask())
        self.selectProtocol.clicked.connect(lambda: self._select_protocol())
        self.selectOutputFolder.clicked.connect(lambda: self._select_output())

        self.selectedDWI.textChanged.connect(self._check_enable_action_buttons)
        self.selectedMask.textChanged.connect(
            self._check_enable_action_buttons)
        self.selectedProtocol.textChanged.connect(
            self._check_enable_action_buttons)
        self.selectedOutputFolder.textChanged.connect(
            self._check_enable_action_buttons)
        self.modelSelection.currentIndexChanged.connect(
            self._check_enable_action_buttons)

        self.runButton.clicked.connect(lambda: self._run_model())
        self.viewResultsButton.clicked.connect(
            lambda: self._start_maps_visualizer())
        self.optimizationOptionsButton.clicked.connect(
            self._run_optimization_options_dialog)
        self.additionalDataButton.clicked.connect(self._extra_data_dialog)

        self.modelSelection.addItems(mdt.get_models_list())
        initial_model = 'BallStick_r1'

        self.modelSelection.setCurrentText(initial_model)

        if self._input_data_info.dwi:
            self.selectedDWI.setText(self._input_data_info.dwi)
        if self._input_data_info.mask:
            self.selectedMask.setText(self._input_data_info.mask)
        if self._input_data_info.protocol:
            self.selectedProtocol.setText(self._input_data_info.protocol)

        self.update_output_folder_text()
        self._check_enable_action_buttons()
示例#4
0
    def setupUi(self, tab_content):
        super(FitModelTab, self).setupUi(tab_content)
        self._tab_content = tab_content

        self.selectDWI.clicked.connect(lambda: self._select_dwi())
        self.selectMask.clicked.connect(lambda: self._select_mask())
        self.selectProtocol.clicked.connect(lambda: self._select_protocol())
        self.selectOutputFolder.clicked.connect(lambda: self._select_output())

        self.selectedDWI.textChanged.connect(self._check_enable_action_buttons)
        self.selectedMask.textChanged.connect(
            self._check_enable_action_buttons)
        self.selectedProtocol.textChanged.connect(
            self._check_enable_action_buttons)

        self.runButton.clicked.connect(lambda: self.run_model())
        self.optimizationOptionsButton.clicked.connect(
            self._run_optimization_options_dialog)

        self.modelSelection.addItems(list(sorted(mdt.get_models_list())))
        self.modelSelection.setCurrentText('BallStick_r1 (Cascade)')

        self._check_enable_action_buttons()
示例#5
0
    def _get_arg_parser(self, doc_parser=False):
        description = textwrap.dedent(__doc__)

        examples = textwrap.dedent('''
            mdt-model-fit "BallStick_r1 (Cascade)" data.nii.gz data.prtcl roi_mask_0_50.nii.gz
            mdt-model-fit "BallStick_r1 (Cascade)" data.nii.gz data.prtcl data_mask.nii.gz --no-recalculate
            mdt-model-fit ... --cl-device-ind 1
            mdt-model-fit ... --cl-device-ind {0, 1}
            mdt-model-fit ... --protocol-maps T1=T1_map.nii.gz T2=T2_map.nii.gz
           ''')
        epilog = self._format_examples(doc_parser, examples)

        parser = argparse.ArgumentParser(
            description=description,
            epilog=epilog,
            formatter_class=argparse.RawTextHelpFormatter)
        parser.add_argument('model',
                            metavar='model',
                            choices=mdt.get_models_list(),
                            help='model name, see mdt-list-models')
        parser.add_argument(
            'dwi',
            action=mdt.shell_utils.get_argparse_extension_checker(
                ['.nii', '.nii.gz', '.hdr', '.img']),
            help='the diffusion weighted image').completer = FilesCompleter(
                ['nii', 'gz', 'hdr', 'img'], directories=False)
        parser.add_argument(
            'protocol',
            action=mdt.shell_utils.get_argparse_extension_checker(['.prtcl']),
            help='the protocol file, see mdt-generate-protocol'
        ).completer = FilesCompleter(['prtcl'], directories=False)
        parser.add_argument(
            'mask',
            action=mdt.shell_utils.get_argparse_extension_checker(
                ['.nii', '.nii.gz', '.hdr', '.img']),
            help='the (brain) mask to use').completer = FilesCompleter(
                ['nii', 'gz', 'hdr', 'img'], directories=False)
        parser.add_argument(
            '-o',
            '--output_folder',
            help=
            'the directory for the output, defaults to "output/<mask_name>" '
            'in the same directory as the dwi volume'
        ).completer = FilesCompleter()

        parser.add_argument(
            '-n',
            '--noise-std',
            default=None,
            help=
            'the noise std, defaults to None for automatic noise estimation.'
            'Either set this to a value, or to a filename.')

        parser.add_argument('--gradient-deviations',
                            action=mdt.shell_utils.get_argparse_extension_checker(['.nii', '.nii.gz', '.hdr', '.img']),
                            help="The volume with the gradient deviations to use, in HCP WUMINN format.").\
            completer = FilesCompleter(['nii', 'gz', 'hdr', 'img'], directories=False)

        parser.add_argument(
            '--cl-device-ind',
            type=int,
            nargs='*',
            choices=self.available_devices,
            help=
            "The index of the device we would like to use. This follows the indices "
            "in mdt-list-devices and defaults to the first GPU.")

        parser.add_argument(
            '--recalculate',
            dest='recalculate',
            action='store_true',
            help="Recalculate the model(s) if the output exists. (default)")
        parser.add_argument(
            '--no-recalculate',
            dest='recalculate',
            action='store_false',
            help="Do not recalculate the model(s) if the output exists.")
        parser.set_defaults(recalculate=True)

        parser.add_argument(
            '--only-recalculate-last',
            dest='only_recalculate_last',
            action='store_true',
            help="Only recalculate the last model in a cascade. (default)")
        parser.add_argument('--recalculate-all',
                            dest='only_recalculate_last',
                            action='store_false',
                            help="Recalculate all models in a cascade.")
        parser.set_defaults(only_recalculate_last=True)

        parser.add_argument('--double',
                            dest='double_precision',
                            action='store_true',
                            help="Calculate in double precision.")
        parser.add_argument('--float',
                            dest='double_precision',
                            action='store_false',
                            help="Calculate in single precision. (default)")
        parser.set_defaults(double_precision=False)

        parser.add_argument(
            '--use-cascade-subdir',
            dest='cascade_subdir',
            action='store_true',
            help=
            "Set if you want to create a subdirectory for the given cascade model"
            ", default is False.")
        parser.set_defaults(cascade_subdir=False)

        parser.add_argument(
            '--tmp-results-dir',
            dest='tmp_results_dir',
            default='True',
            type=str,
            help=
            'The directory for the temporary results. The default ("True") uses the config file '
            'setting. Set to the literal "None" to disable.'
        ).completer = FilesCompleter()

        parser.add_argument(
            '--config-context',
            dest='config_context',
            type=str,
            help='The configuration context to use during fitting the model. '
            'Same syntax as config files')

        parser.add_argument(
            '--protocol-maps',
            dest='protocol_maps',
            type=str,
            nargs='+',
            help='The protocol maps, provide as <key>=<value> pairs')

        return parser
示例#6
0
    def _get_arg_parser(self, doc_parser=False):
        description = textwrap.dedent(__doc__)

        examples = textwrap.dedent('''
            mdt-model-fit BallStick_r1 data.nii.gz data.prtcl roi_mask_0_50.nii.gz
            mdt-model-fit ... --cl-device-ind 1
            mdt-model-fit ... --cl-device-ind {0, 1}
            mdt-model-fit ... --extra-protocol T1=T1_map.nii.gz T2=10
           ''')
        epilog = self._format_examples(doc_parser, examples)

        parser = argparse.ArgumentParser(
            description=description,
            epilog=epilog,
            formatter_class=argparse.RawTextHelpFormatter)
        parser.add_argument('model',
                            metavar='model',
                            choices=mdt.get_models_list(),
                            help='model name, see mdt-list-models')
        parser.add_argument(
            'dwi',
            action=mdt.lib.shell_utils.get_argparse_extension_checker(
                ['.nii', '.nii.gz', '.hdr', '.img']),
            help='the diffusion weighted image').completer = FilesCompleter(
                ['nii', 'gz', 'hdr', 'img'], directories=False)
        parser.add_argument(
            'protocol',
            action=mdt.lib.shell_utils.get_argparse_extension_checker(
                ['.prtcl']),
            help='the protocol file, see mdt-create-protocol'
        ).completer = FilesCompleter(['prtcl'], directories=False)
        parser.add_argument(
            'mask',
            action=mdt.lib.shell_utils.get_argparse_extension_checker(
                ['.nii', '.nii.gz', '.hdr', '.img']),
            help='the (brain) mask to use').completer = FilesCompleter(
                ['nii', 'gz', 'hdr', 'img'], directories=False)
        parser.add_argument(
            '-o',
            '--output_folder',
            help=
            'the directory for the output, defaults to "output/<mask_name>" '
            'in the same directory as the dwi volume'
        ).completer = FilesCompleter()

        parser.add_argument(
            '-n',
            '--noise-std',
            default=None,
            help=
            'the noise std, defaults to None for automatic noise estimation.'
            'Either set this to a value, or to a filename.')

        parser.add_argument('--gradient-deviations',
                            action=mdt.lib.shell_utils.get_argparse_extension_checker(['.nii', '.nii.gz', '.hdr', '.img']),
                            help="The volume with the gradient deviations to use, in HCP WUMINN format.").\
            completer = FilesCompleter(['nii', 'gz', 'hdr', 'img'], directories=False)

        parser.add_argument(
            '--cl-device-ind',
            type=int,
            nargs='*',
            choices=self.available_devices,
            help=
            "The index of the device we would like to use. This follows the indices "
            "in mdt-list-devices and defaults to the first GPU.")

        parser.add_argument(
            '--recalculate',
            dest='recalculate',
            action='store_true',
            help="Recalculate the model(s) if the output exists. (default)")
        parser.add_argument(
            '--no-recalculate',
            dest='recalculate',
            action='store_false',
            help="Do not recalculate the model(s) if the output exists.")
        parser.set_defaults(recalculate=True)

        parser.add_argument(
            '--dont-use-cascaded-inits',
            dest='use_cascaded_inits',
            action='store_false',
            help="Do not initialize the model with a better starting point.")
        parser.add_argument(
            '--use-cascaded-inits',
            dest='use_cascaded_inits',
            action='store_true',
            help="Initialize the model with a better starting point (default). "
            "Only works for default MDT models.")
        parser.set_defaults(use_cascaded_inits=True)

        parser.add_argument(
            '--method',
            default='Powell',
            choices=[
                'Powell', 'Nelder-Mead', 'Levenberg-Marquardt', 'Subplex'
            ],
            help='The optimization method to use, defaults to Powell.')

        parser.add_argument('--patience',
                            type=int,
                            default=None,
                            help='The patience for the optimization routine')

        parser.add_argument('--double',
                            dest='double_precision',
                            action='store_true',
                            help="Calculate in double precision.")
        parser.add_argument('--float',
                            dest='double_precision',
                            action='store_false',
                            help="Calculate in single precision. (default)")
        parser.set_defaults(double_precision=False)

        parser.add_argument(
            '--tmp-results-dir',
            dest='tmp_results_dir',
            default='True',
            type=str,
            help=
            'The directory for the temporary results. The default ("True") uses the config file '
            'setting. Set to the literal "None" to disable.'
        ).completer = FilesCompleter()

        parser.add_argument(
            '--config-context',
            dest='config_context',
            type=str,
            help='The configuration context to use during fitting the model. '
            'Same syntax as config files')

        parser.add_argument(
            '--extra-protocol',
            dest='extra_protocol',
            type=str,
            nargs='+',
            help='Additional protocol values, provide as <key>=<value> pairs')

        return parser