Beispiel #1
0
    def test(self):
        normal_gt = {
            'fake_metric_1': {
                'std': 1.0,
                'mean': 1.0
            },
            'fake_metric_2': {
                'std': 0.5,
                'mean': 0.5
            }
        }
        self._test(generate_streamlines(self._tmp_dir), normal_gt)

        gt_density_weighting = {
            'fake_metric_1': {
                'mean': 1.2,
                'std': 0.979795897113
            },
            'fake_metric_2': {
                'mean': 0.4,
                'std': 0.489897948557
            }
        }
        self._test(generate_streamlines_with_duplicates(self._tmp_dir),
                   normal_gt, gt_density_weighting)
Beispiel #2
0
    def test(self):
        self._test(
            generate_streamlines(self._tmp_dir), {
                'fake_metric_1': {
                    'mean': [1.0] * 5,
                    'std': [1.0] * 5,
                    'tractprofile':
                    [[[0.0, 2.0, 0.0, 0.0, 2.0, 0.0, 2.0, 2.0]] * 5]
                },
                'fake_metric_2': {
                    'mean': [0.5] * 5,
                    'std': [0.5] * 5,
                    'tractprofile':
                    [[[1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0]] * 5]
                }
            })

        self._test(
            generate_streamlines_with_duplicates(self._tmp_dir), {
                'fake_metric_1': {
                    'mean': [1.2] * 5,
                    'std': [0.979795897113] * 5,
                    'tractprofile':
                    [[[2.0, 0.0, 2.0, 2.0, 0.0, 2.0, 2.0, 0.0, 2.0, 0.0]] * 5]
                },
                'fake_metric_2': {
                    'mean': [0.4] * 5,
                    'std': [0.489897948557] * 5,
                    'tractprofile':
                    [[[0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0]] * 5]
                }
            })
Beispiel #3
0
    def test_non_weighted_with_itselt(self):
        reference = generate_fa(self._tmp_dir)
        streamlines = generate_streamlines(self._tmp_dir)
        gt_dict = {'dice': 1.0}

        with RedirectStdOut() as output:
            self.call(main_weighted_dice,
                      streamlines, streamlines, reference)

        output_dict = json.loads('\n'.join(output))
        self.assertEqual(
            output_dict, gt_dict,
            "Wrong dice coeff. {} != {}.".format(output_dict['dice'],
                                                 gt_dict['dice']))
Beispiel #4
0
    def test(self):
        spacing = (1.0, 1.0, 1.0)
        tracts_path = generate_streamlines(self._tmp_dir, spacing)
        image_path = os.path.join(self._tmp_dir, 'input.nii.gz')
        output_path = os.path.join(self._tmp_dir, 'output.nii.gz')
        generate_cross_image((10, 10, 10), spacing, image_path)

        self.call(main, tracts_path, image_path, output_path,
                  tp='trackvis')
        self.assertTrue(_check(nib.load(output_path).get_data(), 1),
                        'Wrong voxels values')

        self.call(main, tracts_path, image_path, output_path, '-f',
                  tp='trackvis', binary=42)
        self.assertTrue(_check(nib.load(output_path).get_data(), 42),
                        'Wrong voxels values')
Beispiel #5
0
    def test_weighted(self):
        reference = generate_fa(self._tmp_dir)
        streamlines = generate_streamlines(self._tmp_dir)
        streamlines_missing_corner =\
            generate_streamlines_missing_corner(self._tmp_dir)
        gt_dice = 0.8571  # Confirmed using ANTs ImageMath 3 DiceAndMinDistSum

        with RedirectStdOut() as output:
            self.call(main_weighted_dice, '--weighted',
                      streamlines, streamlines_missing_corner, reference)

        output_dict = json.loads('\n'.join(output))
        output_dice = float(output_dict['dice'])
        self.assertAlmostEqual(
            output_dice, gt_dice, 4,
            "Wrong dice coeff. {} != {}.".format(output_dice,
                                                 gt_dice))
Beispiel #6
0
    def test_distance_weighting(self):
        fake1 = {'mean': 2.0 / 3.0, 'std': 0.942809041582}
        fake2 = {'mean': 2.0 / 3.0, 'std': 0.471404520791}
        bundle_path = generate_streamlines(self._tmp_dir)
        self._create_maps(bundle_path)
        gt = {
            'fake_metric_1': {l: fake1
                              for l in self.labels},
            'fake_metric_2': {l: fake2
                              for l in self.labels}
        }

        with RedirectStdOut() as output:
            self.call(main_meanstdperpoint, '--distance_weighting',
                      bundle_path, self.label_map, self.distance_map,
                      *self.metrics)

        self._compare(bundle_path, gt, output)
Beispiel #7
0
    def test_no_weighting(self):
        fake1 = {'mean': 1.0, 'std': 1.0}
        fake2 = {'mean': 0.5, 'std': 0.5}

        bundle_path = generate_streamlines(self._tmp_dir)
        self._create_maps(bundle_path)
        gt = {
            'fake_metric_1': {l: fake1
                              for l in self.labels},
            'fake_metric_2': {l: fake2
                              for l in self.labels}
        }

        with RedirectStdOut() as output:
            self.call(main_meanstdperpoint, bundle_path, self.label_map,
                      self.distance_map, *self.metrics)

        self._compare(bundle_path, gt, output)