Skip to content
Snippets Groups Projects
Commit 2f88ee1e authored by Mahir Khan's avatar Mahir Khan
Browse files

optimized combine_indices function by using numpy's intersect1d for better performance

parent d29b8110
Branches
Tags
No related merge requests found
Pipeline #60955 failed
......@@ -131,15 +131,15 @@ def restoral_flag(bits: np.ndarray) -> np.ndarray:
return np.logical_not(np.logical_and(qa_bit, np.logical_not(test_bit)))
# attempt at optimizing combine_indices
def combine_indices(index1: tuple, index2: tuple, shape: tuple) -> tuple:
"""Combine two sets of indices and returns their intersection."""
idx1 = list(np.ravel_multi_index(index1, shape))
idx2 = list(np.ravel_multi_index(index2, shape))
idx1 = np.ravel_multi_index(index1, shape)
idx2 = np.ravel_multi_index(index2, shape)
intersect_idx = list(set(idx1).intersection(set(idx2)))
return tuple(np.unravel_index(np.array(intersect_idx, dtype=np.intp), shape))
intersect_idx = np.intersect1d(idx1, idx2)
return tuple(np.unravel_index(intersect_idx, shape))
def set_cm_bytes(cloud_mask: np.ndarray, bits: dict, pixel_type: xr.Dataset) -> np.ndarray:
"""Compute cloud mask bytes."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment