Exemple #1
0
    def test_constraint_global_noisy(self):
        hard_radius = 1.
        constraints = dimer_global(1, self.im.ndim)
        self.im.clear()
        self.im.draw_clusters(10, 2, hard_radius, 2*self.separation,
                              2*self.diameter)

        f0 = self.im.f(noise=self.pos_err)
        f0['signal'] = 180
        f0['size'] = 6.

        result = refine_leastsq(f0, self.im.noisy_image(0.2*self.signal),
                                self.diameter, self.separation,
                                constraints=constraints,
                                param_mode=dict(signal='global',
                                                size='global'),
                                options=dict(maxiter=1000))

        dists = []
        for _, f_cl in result.groupby('cluster'):
            pos = result[['y', 'x']].values
            dists.append(np.sqrt(np.sum(((pos[0] - pos[1])/np.array(self.im.size))**2)))

        assert_allclose(dists, 2*hard_radius, atol=0.1)

        assert_coordinates_close(result[self.im.pos_columns].values,
                                 self.im.coords, 0.1)
        assert_allclose(result['signal'].values, 200, atol=2)
        assert_allclose(result['size'].values, 5.25, atol=1)
Exemple #2
0
    def test_constraint_global_noisy(self):
        hard_radius = 1.
        constraints = dimer_global(1, self.im.ndim)
        self.im.clear()
        self.im.draw_clusters(10, 2, hard_radius, 2 * self.separation,
                              2 * self.diameter)

        f0 = self.im.f(noise=self.pos_err)
        f0['signal'] = 180
        f0['size'] = 6.

        result = refine_leastsq(f0,
                                self.im.noisy_image(0.2 * self.signal),
                                self.diameter,
                                self.separation,
                                constraints=constraints,
                                param_mode=dict(signal='global',
                                                size='global'),
                                options=dict(maxiter=1000))

        dists = []
        for _, f_cl in result.groupby('cluster'):
            pos = result[['y', 'x']].values
            dists.append(
                np.sqrt(np.sum(
                    ((pos[0] - pos[1]) / np.array(self.im.size))**2)))

        assert_allclose(dists, 2 * hard_radius, atol=0.1)

        assert_coordinates_close(result[self.im.pos_columns].values,
                                 self.im.coords, 0.1)
        assert_allclose(result['signal'].values, 200, atol=2)
        assert_allclose(result['size'].values, 5.25, atol=1)
Exemple #3
0
    def test_constraint_global_dimer(self):
        hard_radius = 1.
        constraints = dimer_global(1, self.im.ndim)
        self.im.clear()
        self.im.draw_clusters(10, 2, hard_radius, 2 * self.separation,
                              2 * self.diameter)

        f0 = self.im.f(noise=self.pos_err)
        result = refine_leastsq(f0,
                                self.im(),
                                self.diameter,
                                self.separation,
                                constraints=constraints,
                                options=dict(maxiter=1000))

        dists = []
        for _, f_cl in result.groupby('cluster'):
            pos = result[['y', 'x']].values
            dists.append(
                np.sqrt(np.sum(
                    ((pos[0] - pos[1]) / np.array(self.im.size))**2)))

        assert_allclose(dists, 2 * hard_radius, atol=0.01)

        assert_coordinates_close(result[self.im.pos_columns].values,
                                 self.im.coords, 0.1)
Exemple #4
0
    def test_multiple_overlapping(self):
        self.im.clear()
        self.im.draw_features(100, 15, self.diameter)

        f0 = self.im.f(noise=self.pos_err)

        result = refine_leastsq(f0, self.im(), self.diameter, self.separation)

        assert_coordinates_close(result[self.im.pos_columns].values,
                                 self.im.coords, 0.1)
Exemple #5
0
    def test_multiple_overlapping(self):
        self.im.clear()
        self.im.draw_features(100, 15, self.diameter)

        f0 = self.im.f(noise=self.pos_err)

        result = refine_leastsq(f0, self.im(), self.diameter, self.separation)

        assert_coordinates_close(result[self.im.pos_columns].values,
                                 self.im.coords, 0.1)
Exemple #6
0
    def test_var_global(self):
        self.im.clear()
        self.im.draw_features(100, 15, self.diameter)

        f0 = self.im.f(noise=self.pos_err)
        f0['signal'] = 180

        result = refine_leastsq(f0, self.im(), self.diameter, self.separation,
                                param_mode=dict(signal='global'),
                                options=dict(maxiter=10000))

        assert_coordinates_close(result[self.im.pos_columns].values,
                                 self.im.coords, 0.1)
        assert (result['signal'].values[1:] == result['signal'].values[:-1]).all()
        assert_allclose(result['signal'].values, 200, atol=5)
Exemple #7
0
    def test_float_image(self):
        separation = 20
        angle = 45
        im = np.zeros((128, 128), dtype=np.float64)
        pos = [[64, 64], [64 + separation * np.sin(angle/180*np.pi),
                          64 + separation * np.cos(angle/180*np.pi)]]

        # setup features: features with equal signal will always be
        # detected by a grey dilation, so make them unequal
        draw_feature(im, pos[0], 3, 240)
        draw_feature(im, pos[1], 3, 250)

        # find both of them
        f = grey_dilation(im, separation - 1, precise=False)
        assert_coordinates_close(f, pos, atol=1)
Exemple #8
0
    def test_var_global(self):
        self.im.clear()
        self.im.draw_features(100, 15, self.diameter)

        f0 = self.im.f(noise=self.pos_err)
        f0['signal'] = 180

        result = refine_leastsq(f0, self.im(), self.diameter, self.separation,
                                param_mode=dict(signal='global'),
                                options=dict(maxiter=10000))

        assert_coordinates_close(result[self.im.pos_columns].values,
                                 self.im.coords, 0.1)
        assert (result['signal'].values[1:] == result['signal'].values[:-1]).all()
        assert_allclose(result['signal'].values, 200, atol=5)
Exemple #9
0
    def test_float_image(self):
        separation = 20
        angle = 45
        im = np.zeros((128, 128), dtype=np.float64)
        pos = [[64, 64],
               [
                   64 + separation * np.sin(angle / 180 * np.pi),
                   64 + separation * np.cos(angle / 180 * np.pi)
               ]]

        # setup features: features with equal signal will always be
        # detected by a grey dilation, so make them unequal
        draw_feature(im, pos[0], 3, 240)
        draw_feature(im, pos[1], 3, 250)

        # find both of them
        f = grey_dilation(im, separation - 1, precise=False)
        assert_coordinates_close(f, pos, atol=1)
Exemple #10
0
    def test_separation_anisotropic(self):
        separation = (10, 20)
        for angle in np.arange(0, 360, 15):
            im = np.zeros((128, 128), dtype=np.uint8)
            pos = [[64, 64], [64 + separation[0] * np.sin(angle/180*np.pi),
                              64 + separation[1] * np.cos(angle/180*np.pi)]]

            # setup features: features with equal signal will always be
            # detected by a grey dilation, so make them unequal
            draw_feature(im, pos[0], 3, 240)
            draw_feature(im, pos[1], 3, 250)

            # find both of them
            f = grey_dilation(im, (9, 19))
            assert_coordinates_close(f, pos, atol=1)

            # find only the brightest
            f = grey_dilation(im, (11, 21))
            assert_coordinates_close(f, pos[1:], atol=1)
Exemple #11
0
    def test_separation(self):
        separation = 20
        for angle in np.arange(0, 360, 15):
            im = np.zeros((128, 128), dtype=np.uint8)
            pos = [[64, 64], [64 + separation * np.sin(angle/180*np.pi),
                              64 + separation * np.cos(angle/180*np.pi)]]

            # setup features: features with equal signal will always be
            # detected by grey_dilation_legacy, so make them unequal
            draw_feature(im, pos[0], 3, 240)
            draw_feature(im, pos[1], 3, 250)

            # find both of them
            f = grey_dilation_legacy(im, separation - 1)
            assert_coordinates_close(f, pos, atol=1)

            # find only the brightest
            f = grey_dilation_legacy(im, separation + 1)
            assert_coordinates_close(f, pos[1:], atol=1)
Exemple #12
0
    def test_constraint_global_dimer(self):
        hard_radius = 1.
        constraints = dimer_global(1, self.im.ndim)
        self.im.clear()
        self.im.draw_clusters(10, 2, hard_radius, 2*self.separation,
                              2*self.diameter)

        f0 = self.im.f(noise=self.pos_err)
        result = refine_leastsq(f0, self.im(), self.diameter,
                                self.separation, constraints=constraints,
                                options=dict(maxiter=1000))

        dists = []
        for _, f_cl in result.groupby('cluster'):
            pos = result[['y', 'x']].values
            dists.append(np.sqrt(np.sum(((pos[0] - pos[1])/np.array(self.im.size))**2)))

        assert_allclose(dists, 2*hard_radius, atol=0.01)

        assert_coordinates_close(result[self.im.pos_columns].values,
                                 self.im.coords, 0.1)
Exemple #13
0
    def test_separation_fast(self):
        separation = 20
        for angle in np.arange(0, 360, 15):
            im = np.zeros((128, 128), dtype=np.uint8)
            pos = [[64, 64],
                   [
                       64 + separation * np.sin(angle / 180 * np.pi),
                       64 + separation * np.cos(angle / 180 * np.pi)
                   ]]

            # setup features: features with equal signal will always be
            # detected by a grey dilation, so make them unequal
            draw_feature(im, pos[0], 3, 240)
            draw_feature(im, pos[1], 3, 250)

            # find both of them
            f = grey_dilation(im, separation - 1, precise=False)
            assert_coordinates_close(f, pos, atol=1)

            # find only the brightest
            if angle in [45, 135, 225, 315]:
                # for unprecise, a too small square kernel is used, which is
                # perfect for 45-degree angles
                f = grey_dilation(im, separation + 1, precise=False)
                assert_coordinates_close(f, pos[1:], atol=1)
            else:
                # but too small by a factor of sqrt(ndim) for 90-degree angles
                f = grey_dilation(im,
                                  separation * np.sqrt(2) + 1,
                                  precise=False)
                assert_coordinates_close(f, pos[1:], atol=1)
Exemple #14
0
    def test_separation_fast(self):
        separation = 20
        for angle in np.arange(0, 360, 15):
            im = np.zeros((128, 128), dtype=np.uint8)
            pos = [[64, 64], [64 + separation * np.sin(angle/180*np.pi),
                              64 + separation * np.cos(angle/180*np.pi)]]

            # setup features: features with equal signal will always be
            # detected by a grey dilation, so make them unequal
            draw_feature(im, pos[0], 3, 240)
            draw_feature(im, pos[1], 3, 250)

            # find both of them
            f = grey_dilation(im, separation - 1, precise=False)
            assert_coordinates_close(f, pos, atol=1)

            # find only the brightest
            if angle in [45, 135, 225, 315]:
                # for unprecise, a too small square kernel is used, which is
                # perfect for 45-degree angles
                f = grey_dilation(im, separation + 1, precise=False)
                assert_coordinates_close(f, pos[1:], atol=1)
            else:
                # but too small by a factor of sqrt(ndim) for 90-degree angles
                f = grey_dilation(im, separation*np.sqrt(2) + 1, precise=False)
                assert_coordinates_close(f, pos[1:], atol=1)
Exemple #15
0
    def test_separation_anisotropic(self):
        separation = (10, 20)
        for angle in np.arange(0, 360, 15):
            im = np.zeros((128, 128), dtype=np.uint8)
            pos = [[64, 64],
                   [
                       64 + separation[0] * np.sin(angle / 180 * np.pi),
                       64 + separation[1] * np.cos(angle / 180 * np.pi)
                   ]]

            # setup features: features with equal signal will always be
            # detected by a grey dilation, so make them unequal
            draw_feature(im, pos[0], 3, 240)
            draw_feature(im, pos[1], 3, 250)

            # find both of them
            f = grey_dilation(im, (9, 19))
            assert_coordinates_close(f, pos, atol=1)

            # find only the brightest
            f = grey_dilation(im, (11, 21))
            assert_coordinates_close(f, pos[1:], atol=1)
Exemple #16
0
    def test_separation(self):
        separation = 20
        for angle in np.arange(0, 360, 15):
            im = np.zeros((128, 128), dtype=np.uint8)
            pos = [[64, 64],
                   [
                       64 + separation * np.sin(angle / 180 * np.pi),
                       64 + separation * np.cos(angle / 180 * np.pi)
                   ]]

            # setup features: features with equal signal will always be
            # detected by grey_dilation_legacy, so make them unequal
            draw_feature(im, pos[0], 3, 240)
            draw_feature(im, pos[1], 3, 250)

            # find both of them
            f = grey_dilation_legacy(im, separation - 1)
            assert_coordinates_close(f, pos, atol=1)

            # find only the brightest
            f = grey_dilation_legacy(im, separation + 1)
            assert_coordinates_close(f, pos[1:], atol=1)