Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/issue 41 #46

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
optimize fill in pixel functions
sliu008 committed Jan 25, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit e66e54df9c8a046a660f987b63ab5b2acea9026f
11 changes: 5 additions & 6 deletions podaac/tig/tig.py
Original file line number Diff line number Diff line change
@@ -546,23 +546,22 @@ def fill_swath_with_neighboring_pixel(self, output_array):

def non_nan_neighbors(arr, x, y):
"""
Check if the neighboring values of a given position are not NaN.
Check if there is at least one non-NaN neighbor for a given position.

Parameters:
- arr (numpy.ndarray): Input array.
- x (int): x-coordinate of the position to check.
- y (int): y-coordinate of the position to check.
- x (int): x-coordinate of the position.
- y (int): y-coordinate of the position.

Returns:
bool: True if there is at least one non-NaN neighbor, False otherwise.

"""
neighbors = [
(x-1, y), (x+1, y), # Left and right neighbors
(x, y-1), (x, y+1) # Up and down neighbors
]
non_nan_count = sum(1 for i, j in neighbors if 0 <= i < arr.shape[0] and 0 <= j < arr.shape[1] and not np.isnan(arr[i, j]))
return non_nan_count >= 1

return any(0 <= i < arr.shape[0] and 0 <= j < arr.shape[1] and not np.isnan(arr[i, j]) for i, j in neighbors)

# Get the indices of NaN values
img_with_neighbor_filled = output_array.copy()