Пример #1
0
def get_models_list():
    """Get a list of all available composite models

    Returns:
        list of str: A list of available model names.
    """
    from mdt.lib.components import get_component_list
    return list(sorted(get_component_list('composite_models')))
Пример #2
0
def get_models_meta_info():
    """Get the meta information tags for all the models returned by get_models_list()

    Returns:
        dict of dict: The first dictionary indexes the model names to the meta tags, the second holds the meta
            information.
    """
    from mdt.lib.components import get_meta_info, get_component_list
    return {model: get_meta_info('composite_models', model) for model in get_component_list('composite_models')}
Пример #3
0
def get_models_meta_info():
    """Get the meta information tags for all the models returned by get_models_list()

    Returns:
        dict of dict: The first dictionary indexes the model names to the meta tags, the second holds the meta
            information.
    """
    from mdt.lib.components import list_cascade_models, list_composite_models, get_meta_info, get_component_list
    meta_info = {}
    for model_type in ('composite_models', 'cascade_models'):
        model_list = get_component_list(model_type)
        for model in model_list:
            meta_info.update({model: get_meta_info(model_type, model)})
    return meta_info
Пример #4
0
def get_best_batch_profile(data_folder):
    """Get the batch profile that best matches the given directory.

    Args:
        data_folder (str): the directory for which to get the best batch profile.

    Returns:
        BatchProfile: the best matching batch profile.
    """
    profiles = [
        get_batch_profile(name)()
        for name in get_component_list('batch_profiles')
    ]

    best_crawler = None
    best_subjects_count = 0
    for profile in profiles:
        if profile.is_suitable(data_folder):
            tmp_count = len(profile.get_subjects(data_folder))
            if tmp_count > best_subjects_count:
                best_crawler = profile
                best_subjects_count = tmp_count

    return best_crawler
Пример #5
0
    def _get_arg_parser(self, doc_parser=False):
        description = textwrap.dedent(__doc__)

        examples = textwrap.dedent('''
            mdt-batch-fit . NODDI
            mdt-batch-fit /data/mgh 'BallStick_r1' --batch-profile 'HCP_MGH'
            mdt-batch-fit . CHARMED_r1 --subjects-id 1003 1004 --subjects-index 0 1 2
            mdt-batch-fit . BallStick_r1 Tensor --dry-run
        ''')
        epilog = self._format_examples(doc_parser, examples)

        batch_profiles = get_component_list('batch_profiles')

        parser = argparse.ArgumentParser(
            description=description,
            epilog=epilog,
            formatter_class=argparse.RawTextHelpFormatter)

        parser.add_argument('data_folder',
                            help='the directory with the subject to fit'
                            ).completer = FilesCompleter()

        parser.add_argument('models_to_fit',
                            type=str,
                            nargs='*',
                            help="The models to fit")

        parser.add_argument('-o', '--output_folder',
                            help='the directory for the output, defaults to an output dir next to the input dir.')\
            .completer = FilesCompleter()

        parser.add_argument(
            '-b',
            '--batch_profile',
            default=None,
            choices=batch_profiles,
            help=
            'The batch profile (by name) to use during fitting. If not given a'
            'batch profile is auto-detected.')

        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.")
        parser.add_argument(
            '--no-recalculate',
            dest='recalculate',
            action='store_false',
            help=
            "Do not recalculate the model(s) if the output exists. (default)")
        parser.set_defaults(recalculate=False)

        parser.add_argument(
            '--use-gradient-deviations',
            dest='use_gradient_deviations',
            action='store_true',
            help=
            "Uses the gradient deviations. If not set, the default in the profile is used."
        )
        parser.add_argument(
            '--no-gradient-deviations',
            dest='use_gradient_deviations',
            action='store_false',
            help=
            "Disable the use of gradient deviations. If not set, the default "
            "in the profile is used.")
        parser.set_defaults(use_gradient_deviations=None)

        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(
            '--subjects-index',
            type=int,
            nargs='*',
            help=
            "The indices of the subjects we would like to fit. This reduces the set of "
            "subjects.")

        parser.add_argument(
            '--subjects-id',
            type=str,
            nargs='*',
            help=
            "The id of the subjects we would like to fit. This reduces the set of "
            "subjects.")

        parser.add_argument(
            '--dry-run',
            dest='dry_run',
            action='store_true',
            help="Shows what it will do without the dry run argument.")
        parser.set_defaults(dry_run=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()

        return parser