示例#1
0
    def _do_match(self, point_selection: grm.PointSelection, zero, polar_vectors):
        '''
        Return a list with matches of all pairwise combinations of polar_vectors
        '''
        match_list = []
        # we test all pairs of candidate vectors
        # and populate match_matrix
        for i in range(len(polar_vectors)):
            for j in range(i + 1, len(polar_vectors)):
                a = polar_vectors[i]
                b = polar_vectors[j]
                # too parallel, not good lattice vectors
                if not angle_check(np.array([a]), np.array([b]), self.min_angle):
                    continue

                if a[0] > b[0]:
                    bb = a
                    aa = b
                else:
                    aa = a
                    bb = b
                aa, bb = make_cartesian(np.array([aa, bb]))
                try:
                    match = self._match_all(
                        point_selection=point_selection, zero=zero, a=aa, b=bb)
                    match = self._tumble(point_selection, match)
                except np.linalg.LinAlgError:
                    continue
                if match is not None:
                    match_list.append(match)
        return match_list
示例#2
0
def test_polar_rotate():
    y, x, radians = np.random.random(3)
    ((r, phi),) = ut.make_polar(np.array([(y, x)]))
    ((r_y, r_x),) = ut.make_cartesian(np.array([(r, phi + radians)]))
    r_y2, r_x2 = ut.rotate_rad(y, x, radians)
    assert np.allclose(r_y, r_y2)
    assert np.allclose(r_x, r_x2)
示例#3
0
def cbed_frame(fy=128, fx=128, zero=None, a=None, b=None, indices=None, radius=4, all_equal=False):
    if zero is None:
        zero = (fy//2, fx//2)
    zero = np.array(zero)
    if a is None:
        a = (fy//8, 0)
    a = np.array(a)
    if b is None:
        b = make_cartesian(make_polar(a) - (0, np.pi/2))
    b = np.array(b)
    if indices is None:
        indices = np.mgrid[-10:11, -10:11]
    indices, peaks = frame_peaks(fy=fy, fx=fx, zero=zero, a=a, b=b, r=radius, indices=indices)

    data = np.zeros((1, fy, fx), dtype=np.float32)

    dists = np.linalg.norm(peaks - zero, axis=-1)
    max_dist = dists.max()

    for i, p in enumerate(peaks):
        data += m.circular(
            centerX=p[1],
            centerY=p[0],
            imageSizeX=fx,
            imageSizeY=fy,
            radius=radius,
            antialiased=True,
        ) * (1 if all_equal else max_dist - dists[i] + i)

    return (data, indices, peaks)
示例#4
0
    def _do_match(cls, point_selection: PointSelection, zero, polar_vectors, parameters):
        '''
        Return a matrix with matches of all pairwise combinations of polar_vectors
        '''
        match_matrix = {}
        # we test all pairs of candidate vectors
        # and populate match_matrix
        for i in range(len(polar_vectors)):
            for j in range(i + 1, len(polar_vectors)):
                a = polar_vectors[i]
                b = polar_vectors[j]
                # too parallel, not good lattice vectors
                if not angle_check(np.array([a]), np.array([b]), parameters['min_angle']):
                    continue
                a, b = make_cartesian(np.array([a, b]))

                match = cls._match_all(
                    point_selection=point_selection, zero=zero, a=a, b=b, parameters=parameters)
                # At least three points matched
                if len(match) > 2:
                    match_matrix[(i, j)] = match
        return match_matrix
示例#5
0
    def _do_match(self, point_selection: grm.PointSelection, zero,
                  polar_vectors):
        '''
        Return a matrix with matches of all pairwise combinations of polar_vectors
        '''
        match_matrix = {}
        # we test all pairs of candidate vectors
        # and populate match_matrix
        for i in range(len(polar_vectors)):
            for j in range(i + 1, len(polar_vectors)):
                a = polar_vectors[i]
                b = polar_vectors[j]
                # too parallel, not good lattice vectors
                if not angle_check(np.array([a]), np.array([b]),
                                   self.min_angle):
                    continue
                if a[0] > b[0]:
                    bb = a
                    aa = b
                    ii = j
                    jj = i
                else:
                    aa = a
                    bb = b
                    ii = i
                    jj = j
                aa, bb = make_cartesian(np.array([aa, bb]))

                match = self._match_all(point_selection=point_selection,
                                        zero=zero,
                                        a=aa,
                                        b=bb)
                # At least three points matched
                if len(match) > 2:
                    match_matrix[(ii, jj)] = match
        return match_matrix
示例#6
0
def test_conversion(points):
    assert(np.allclose(points, ut.make_cartesian(ut.make_polar(points))))