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

♻️ Rename pad to shift #952

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Changes from all commits
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
16 changes: 8 additions & 8 deletions src/pyiem/grid/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
import numpy as np


def grid_smear(grid: np.ndarray, pad: int = 4) -> np.ndarray:
def grid_smear(grid: np.ndarray, shift: int = 4) -> np.ndarray:
"""Smear data around to fill in masked values (likely near coastlines).

Args:
grid: 2D numpy array
pad: number of pixels to smear the data around by in each direction
shift: number of pixels to smear the data around by in each direction

Returns:
2D numpy array with smeared data
"""
# Pad grid
padded = np.ma.masked_all(
(grid.shape[0] + pad * 2, grid.shape[1] + pad * 2)
(grid.shape[0] + shift * 2, grid.shape[1] + shift * 2)
)
# set values from inbound grid
padded[pad:-pad, pad:-pad] = grid
padded[shift:-shift, shift:-shift] = grid

# shift the grid by 4 pixels in each direction to fill in the padded region
for xorigin in [0, pad * 2]:
for yorigin in [0, pad * 2]:
# shift the grid by shift pixels in each direction to fill in the padded
for xorigin in [0, shift * 2]:
for yorigin in [0, shift * 2]:
xslice = slice(xorigin, xorigin + grid.shape[0])
yslice = slice(yorigin, yorigin + grid.shape[1])
padded[xslice, yslice] = np.ma.where(
Expand All @@ -31,4 +31,4 @@ def grid_smear(grid: np.ndarray, pad: int = 4) -> np.ndarray:
padded[xslice, yslice],
)

return padded[pad:-pad, pad:-pad]
return padded[shift:-shift, shift:-shift]
Loading