Commit ed5fe8dd authored by Zhang, Chen's avatar Zhang, Chen
Browse files

sorting is no longer required

parent 177698a8
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -18,14 +18,6 @@ class find_rotation_center(param.ParameterizedFunction):
    """
    Automatically find the rotation center from a given radiograph stack.

    If atol_deg is set to None (default), the input radiograph stack MUST BE
    SORTED by rotation angle omega. In most conventional tomography scan, this
    is automatically the case. However, if the radiograph is collected via
    non-conventional method, such as grid scan or sampling scan, the radiograph
    stack must be sorted by omega before using this function.
    Alternatively, the user can specify the tolerance of the search for 180 deg
    pairs, which is useful for non-conventional tomography scan.

    Parameters
    ----------
    arrays: np.ndarray
@@ -34,7 +26,7 @@ class find_rotation_center(param.ParameterizedFunction):
        array of angles in degrees or radians, which must match the order of arrays
    in_degrees: bool = True
        whether angles are in degrees or radians, default is True (degrees)
    atol_deg: Union[float, None] = None
    atol_deg: Optional[float] = None
        tolerance for the search of 180 deg paris, default is None ("auto")
    num_pairs: int = 1
        Number of pairs to look for. Specifying -1 means as many pairs as possible.
+3 −3
Original line number Diff line number Diff line
@@ -26,8 +26,6 @@ def find_180_deg_pairs_idx(
    """
    Return the indices of the 180 degree pairs from given list of angles.

    If atol is set to None (default), the input angles MUST BE SORTED.

    Parameters
    ----------
    angles:
@@ -49,7 +47,9 @@ def find_180_deg_pairs_idx(
    angles = angles if in_degrees else np.degrees(angles)
    # compute atol if not specified
    if atol is None:
        atol = np.min(np.absolute(np.diff(angles))) / 2.0
        sorted_indices = np.argsort(angles)
        atol = np.min(np.diff(angles[sorted_indices])) / 2.0
        del sorted_indices
        logger.debug(f"use computed atol = {atol}")
    # compute the self difference matrix
    angles = angles[..., np.newaxis]
+7 −1
Original line number Diff line number Diff line
@@ -220,13 +220,19 @@ def test_calculate_shift():

def test_find_180_deg_pairs():
    # prepare the input list of angles in radians
    omegas = np.sort(np.random.random(5) * np.pi)
    omegas = np.random.random(5) * np.pi
    omegas = np.array(list(omegas) + list(omegas + np.pi))
    # get the pairs
    low_range_idx, high_range_idx = find_180_deg_pairs_idx(omegas, in_degrees=False)
    # verify
    np.testing.assert_equal(low_range_idx, np.array([0, 1, 2, 3, 4]))
    np.testing.assert_equal(high_range_idx, np.array([5, 6, 7, 8, 9]))
    # test explicit atol
    omegas = np.sort(omegas)
    atol = np.min(np.diff(omegas)) / 2.0
    low_range_idx, high_range_idx = find_180_deg_pairs_idx(omegas, in_degrees=False, atol=atol)
    np.testing.assert_equal(low_range_idx, np.array([0, 1, 2, 3, 4]))
    np.testing.assert_equal(high_range_idx, np.array([5, 6, 7, 8, 9]))
    # test incorrect input
    omegas = np.random.random(5 * 5) * np.pi
    omegas = omegas.reshape(5, 5)