Skip to content

Commit

Permalink
♻️ Rename pad to shift
Browse files Browse the repository at this point in the history
  • Loading branch information
akrherz committed Sep 5, 2024
1 parent 05358a1 commit 813dd84
Showing 1 changed file with 8 additions and 8 deletions.
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]

0 comments on commit 813dd84

Please sign in to comment.