Ejemplo n.º 1
0
    def test_set_precalculated(self):
        self.model.data_model._points = [
            Point(50, 1),
            Point(40, 2),
            Point(30, 3),
            Point(20, 4)
        ]

        # a line with a slope of 'below' gives 4 degree tilt
        expected_slope = -0.06992681194351041
        self.model.set_precalculated(ScalarCoR(1000.0), Degrees(4.0))
        cor, angle, slope = self.model.get_results()
        self.assertEqual(cor.value, 1000.0)
        self.assertEqual(angle.value, 4.0)
        self.assertEqual(slope.value, expected_slope)

        # pre-calculated by hand
        expected_cors_with_this_gradient = [
            996.5036594028245, 997.2029275222595, 997.9021956416947,
            998.6014637611298
        ]
        for i, point in enumerate(self.model.data_model._points):
            self.assertEqual(point.cor, expected_cors_with_this_gradient[i])

        some_cor = self.model.data_model.get_cor_from_regression(1555)

        self.assertEqual(some_cor, 891.2638074278414)
Ejemplo n.º 2
0
def find_center(images: Images,
                progress: Progress) -> Tuple[ScalarCoR, Degrees]:
    # assume the ROI is the full image, i.e. the slices are ALL rows of the image
    slices = np.arange(images.height)
    shift = pu.create_array((images.height, ))

    search_range = get_search_range(images.width)
    min_correlation_error = pu.create_array((len(search_range), images.height))
    shared_search_range = pu.create_array((len(search_range), ),
                                          dtype=np.int32)
    shared_search_range[:] = np.asarray(search_range, dtype=np.int32)
    _calculate_correlation_error(images, shared_search_range,
                                 min_correlation_error, progress)

    # Originally the output of do_search is stored in dimensions
    # corresponding to (search_range, square sum). This is awkward to navigate
    # we transpose store to make the array hold (square sum, search range)
    # so that each store[row] accesses the information for the row's square sum across all search ranges
    _find_shift(images, search_range, min_correlation_error, shift)

    par = np.polyfit(slices, shift, deg=1)
    m = par[0]
    q = par[1]
    LOG.debug(f"m={m}, q={q}")
    theta = Degrees(np.rad2deg(np.arctan(0.5 * m)))
    offset = np.round(m * images.height * 0.5 + q) * 0.5
    LOG.info(f"found offset: {-offset} and tilt {theta}")
    return ScalarCoR(images.h_middle + -offset), theta
def find_center(images: Images,
                progress: Progress) -> Tuple[ScalarCoR, Degrees]:
    # assume the ROI is the full image, i.e. the slices are ALL rows of the image
    slices = np.arange(images.height)
    with pu.temp_shared_array((images.height, )) as shift:
        # this is the area that is looked into for the shift after overlapping the images
        search_range = get_search_range(images.width)

        func = shared_mem.create_partial(do_search,
                                         shared_mem.fwd_index_only,
                                         image_width=images.width,
                                         p0=images.projection(0),
                                         p180=np.fliplr(
                                             images.proj180deg.data[0]),
                                         search_range=search_range)
        shared_mem.execute(shift,
                           func,
                           progress=progress,
                           msg="Finding correlation on row")
        par = np.polyfit(slices, shift, deg=1)
        m = par[0]
        q = par[1]
        LOG.debug(f"m={m}, q={q}")
        theta = Degrees(np.rad2deg(np.arctan(0.5 * m)))
        offset = np.round(m * images.height * 0.5 + q) * 0.5
        LOG.info(f"found offset: {-offset} and tilt {theta}")
        return ScalarCoR(images.h_middle + -offset), theta
Ejemplo n.º 4
0
 def setUp(self, model) -> None:
     self.view = mock.MagicMock()
     self.model = model.return_value
     self.recon_params = ReconstructionParameters("", "", 0, ScalarCoR(2),
                                                  Degrees(2), 2, 2)
     self.presenter = CORInspectionDialogPresenter(self.view,
                                                   th.generate_images(), 5,
                                                   ScalarCoR(2),
                                                   self.recon_params, False)
Ejemplo n.º 5
0
 def recon_params(self) -> ReconstructionParameters:
     return ReconstructionParameters(
         algorithm=self.algorithm_name,
         filter_name=self.filter_name,
         num_iter=self.num_iter,
         cor=ScalarCoR(self.rotation_centre),
         tilt=Degrees(self.tilt),
         pixel_size=self.pixel_size,
         max_projection_angle=self.max_proj_angle)
Ejemplo n.º 6
0
    def test_update_projection(self, _):
        image_data = mock.Mock()
        preview_slice_idx = 13
        tilt_angle = Degrees(30)

        self.view.previewSliceIndex = preview_slice_index_mock = mock.Mock()
        self.view.update_projection(image_data, preview_slice_idx, tilt_angle)

        preview_slice_index_mock.setValue.assert_called_once_with(preview_slice_idx)
        self.image_view.update_projection.assert_called_once_with(image_data, preview_slice_idx, tilt_angle)
Ejemplo n.º 7
0
 def test_recon_params(self, recon_params_mock):
     self.view.recon_params()
     recon_params_mock.assert_called_once_with(
         algorithm=self.algorithmName.currentText.return_value,
         filter_name=self.filterName.currentText.return_value,
         num_iter=self.numIter.value.return_value,
         cor=ScalarCoR(self.resultCor.value.return_value),
         tilt=Degrees(self.resultTilt.value.return_value),
         pixel_size=self.pixelSize.value.return_value,
         max_projection_angle=self.maxProjAngle.value.return_value)
Ejemplo n.º 8
0
    def test_initial_select_data(self):
        test_cor = ScalarCoR(50)
        test_tilt = Degrees(1.5)
        self.model.preview_projection_idx = 150
        self.model.preview_slice_idx = 150
        self.model.set_precalculated(test_cor, test_tilt)

        self.model.initial_select_data(self.stack)

        self.assertNotEqual(test_cor, self.model.last_cor)
        self.assertNotEqual(test_tilt, self.model.tilt_angle)
        self.assertEqual(0, self.model.preview_projection_idx)
        self.assertEqual(64, self.model.preview_slice_idx)
Ejemplo n.º 9
0
    def test_get_me_a_cor(self):
        self.assertEqual(15, self.model.get_me_a_cor(cor=15))

        self.model.data_model.clear_results()
        self.model.last_cor = ScalarCoR(26)
        self.assertEqual(26, self.model.get_me_a_cor().value)

        self.model.data_model.set_precalculated(ScalarCoR(150), Degrees(1.5))
        self.model.preview_slice_idx = 5
        cor = self.model.get_me_a_cor()

        # expected cor value obtained by running the test
        self.assertAlmostEqual(149.86, cor.value, delta=1e-2)
Ejemplo n.º 10
0
    def test_set_results(self):
        cor_val = 20
        tilt_val = 30
        slope_val = 40
        cor = ScalarCoR(cor_val)
        tilt = Degrees(tilt_val)
        slope = Slope(slope_val)

        self.view.set_results(cor, tilt, slope)
        self.resultCor.setValue.assert_called_once_with(cor_val)
        self.resultTilt.setValue.assert_called_once_with(tilt_val)
        self.resultSlope.setValue.assert_called_once_with(slope_val)
        self.image_view.set_tilt.assert_called_once_with(tilt)
Ejemplo n.º 11
0
    def test_tilt_line_data(self):
        # TODO move into data_model test
        self.model.data_model._points = [
            Point(50, 1),
            Point(40, 2),
            Point(30, 3),
            Point(20, 4)
        ]
        self.model.data_model._cached_cor = 1
        self.model.data_model._cached_gradient = 2

        data = self.model.tilt_angle

        self.assertEqual(data, Degrees(-63.43494882292201))
Ejemplo n.º 12
0
 def do_calculate_cors_from_manual_tilt(self):
     cor = ScalarCoR(self.view.rotation_centre)
     tilt = Degrees(self.view.tilt)
     self._set_precalculated_cor_tilt(cor, tilt)
Ejemplo n.º 13
0
 def test_tilt_angle(self):
     self.assertIsNone(self.model.tilt_angle)
     exp_deg = Degrees(1.5)
     self.model.set_precalculated(ScalarCoR(1), exp_deg)
     self.assertAlmostEqual(self.model.tilt_angle.value, exp_deg.value)
Ejemplo n.º 14
0
 def recon_params(self) -> ReconstructionParameters:
     return ReconstructionParameters(self.algorithm_name, self.filter_name,
                                     self.num_iter,
                                     ScalarCoR(self.rotation_centre),
                                     Degrees(self.tilt))