示例#1
0
def main():
    parser = _build_arg_parser()
    args = parser.parse_args()

    if not len(args.t1_warped) == len(args.rgb) == len(args.wm) ==\
        len(args.gm) == len(args.csf):
        parser.error("Not the same number of images in input.")

    all_images = np.concatenate(
        [args.t1_warped, args.rgb, args.wm, args.gm, args.csf])
    assert_inputs_exist(parser, all_images)
    assert_outputs_exist(parser, args, [args.output_report, "data", "libs"])

    if os.path.exists("data"):
        shutil.rmtree("data")
    os.makedirs("data")

    if os.path.exists("libs"):
        shutil.rmtree("libs")

    name = "Register T1"
    curr_metrics = [
        'Mean {} in WM'.format(name), 'Mean {} in GM'.format(name),
        'Mean {} in CSF'.format(name), 'Max {} in WM'.format(name)
    ]

    warning_dict = {}
    summary, stats = stats_mean_in_tissues(curr_metrics, args.t1_warped,
                                           args.wm, args.gm, args.csf)
    warning_dict[name] = analyse_qa(summary, stats, curr_metrics[:3])
    warning_list = np.concatenate(
        [filenames for filenames in warning_dict[name].values()])
    warning_dict[name]['nb_warnings'] = len(np.unique(warning_list))

    graphs = []
    graph = graph_mean_in_tissues('Mean {}'.format(name), curr_metrics[:3],
                                  summary)
    graphs.append(graph)

    stats_html = dataframe_to_html(stats)
    summary_dict = {}
    summary_dict[name] = stats_html

    pool = Pool(args.nb_threads)
    subjects_dict_pool = pool.starmap(
        _subj_parralel,
        zip(args.t1_warped, args.rgb, itertools.repeat(summary),
            itertools.repeat(name), itertools.repeat(args.skip),
            itertools.repeat(args.nb_columns)))
    pool.close()
    pool.join()

    metrics_dict = {}
    subjects_dict = {}
    for dict_sub in subjects_dict_pool:
        for key in dict_sub:
            subjects_dict[key] = dict_sub[key]
    metrics_dict[name] = subjects_dict

    nb_subjects = len(args.t1_warped)
    report = Report(args.output_report)
    report.generate(title="Quality Assurance registration",
                    nb_subjects=nb_subjects,
                    summary_dict=summary_dict,
                    graph_array=graphs,
                    metrics_dict=metrics_dict,
                    warning_dict=warning_dict)
示例#2
0
def main():
    parser = _build_arg_parser()
    args = parser.parse_args()

    if not len(args.fa) == len(args.md) == len(args.rd) == len(args.ad) ==\
        len(args.residual) == len(args.evecs_v1) == len(args.wm) ==\
        len(args.gm) == len(args.csf):
        parser.error("Not the same number of images in input.")

    all_images = np.concatenate([
        args.fa, args.md, args.rd, args.ad, args.residual, args.evecs_v1,
        args.wm, args.gm, args.csf
    ])
    assert_inputs_exist(parser, all_images)
    assert_outputs_exist(parser, args, [args.output_report, "data", "libs"])

    if os.path.exists("data"):
        shutil.rmtree("data")
    os.makedirs("data")

    if os.path.exists("libs"):
        shutil.rmtree("libs")

    metrics_names = [[args.fa, 'FA'], [args.md, 'MD'], [args.rd, 'RD'],
                     [args.ad, 'AD'], [args.residual, "Residual"]]
    metrics_dict = {}
    summary_dict = {}
    graphs = []
    warning_dict = {}
    for metrics, name in metrics_names:
        subjects_dict = {}
        curr_metrics = [
            'Mean {} in WM'.format(name), 'Mean {} in GM'.format(name),
            'Mean {} in CSF'.format(name), 'Max {} in WM'.format(name)
        ]

        summary, stats = stats_mean_in_tissues(curr_metrics, metrics, args.wm,
                                               args.gm, args.csf)

        warning_dict[name] = analyse_qa(summary, stats, curr_metrics[:3])
        warning_list = np.concatenate(
            [filenames for filenames in warning_dict[name].values()])
        warning_dict[name]['nb_warnings'] = len(np.unique(warning_list))

        graph = graph_mean_in_tissues('Mean {}'.format(name), curr_metrics[:3],
                                      summary)
        graphs.append(graph)

        stats_html = dataframe_to_html(stats)
        summary_dict[name] = stats_html

        pool = Pool(args.nb_threads)
        subjects_dict_pool = pool.starmap(
            _subj_parralel,
            zip(metrics, itertools.repeat(summary), itertools.repeat(name),
                itertools.repeat(args.skip),
                itertools.repeat(args.nb_columns)))

        pool.close()
        pool.join()

        for dict_sub in subjects_dict_pool:
            for key in dict_sub:
                subjects_dict[key] = dict_sub[key]
        metrics_dict[name] = subjects_dict

    subjects_dict = {}
    name = "Peaks"
    for fa, evecs in zip(args.fa, args.evecs_v1):
        screenshot_path = screenshot_fa_peaks(fa, evecs, "data")

        subjects_dict[evecs] = {}
        subjects_dict[evecs]['screenshot'] = screenshot_path
    metrics_dict[name] = subjects_dict

    nb_subjects = len(args.fa)
    report = Report(args.output_report)
    report.generate(title="Quality Assurance DTI metrics",
                    nb_subjects=nb_subjects,
                    summary_dict=summary_dict,
                    graph_array=graphs,
                    metrics_dict=metrics_dict,
                    warning_dict=warning_dict)