Commit 57045b8b authored by Zhang, Chen's avatar Zhang, Chen
Browse files

enable auto atol for tilt

parent 759c45f6
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ logger = logging.getLogger(__name__)

def find_180_deg_pairs_idx(
    angles: np.ndarray,
    atol: float = 1e-3,
    atol: float = None,
    in_degrees: bool = True,
) -> Tuple[np.ndarray, np.ndarray]:
    """
@@ -29,7 +29,7 @@ def find_180_deg_pairs_idx(
    Parameters
    ----------
    angles:
        The list of angles as a 1d array.
        The list of sorted angles as a 1d array.
    atol:
        The absolute tolerance in degree for the 180 degree pairs.
    in_degrees:
@@ -45,6 +45,10 @@ def find_180_deg_pairs_idx(
        raise ValueError("angles must be a 1d array")
    # ensure angles are in degrees
    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
        logger.debug(f"use computed atol = {atol}")
    # compute the self difference matrix
    angles = angles[..., np.newaxis]
    diff_matrix = angles.T - angles
+1 −1
Original line number Diff line number Diff line
@@ -220,7 +220,7 @@ def test_calculate_shift():

def test_find_180_deg_pairs():
    # prepare the input list of angles in radians
    omegas = np.random.random(5) * np.pi
    omegas = np.sort(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)