Skip to content

Commit

Permalink
MNT: Eliminate use of numpy legacy calls
Browse files Browse the repository at this point in the history
Turn on check for Ruff and address uses of numpy.random.seed(). In two
of the examples, since the plots are heavily based around fixed
(originally randomly generated points), just embed the required data.
  • Loading branch information
dopplershift committed Jan 12, 2024
1 parent d7f7c10 commit cc2cb57
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions examples/calculations/Smoothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

###########################################
# Start with a base pattern with random noise
np.random.seed(61461542)
rng = np.random.default_rng(61461542)
size = 128
x, y = np.mgrid[:size, :size]
distance = np.sqrt((x - size / 2) ** 2 + (y - size / 2) ** 2)
raw_data = np.random.random((size, size)) * 0.3 + distance / distance.max() * 0.7
raw_data = rng.random((size, size)) * 0.3 + distance / distance.max() * 0.7

fig, ax = plt.subplots(1, 1, figsize=(4, 4))
ax.set_title('Raw Data')
Expand Down
4 changes: 2 additions & 2 deletions examples/gridding/Inverse_Distance_Verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def draw_circle(ax, x, y, r, m, label):
# Generate random x and y coordinates, and observation values proportional to x * y.
#
# Set up two test grid locations at (30, 30) and (60, 60).
np.random.seed(100)

pts = np.random.randint(0, 100, (10, 2))
pts = np.array([[8, 24], [67, 87], [79, 48], [10, 94], [52, 98],
[53, 66], [98, 14], [34, 24], [15, 60], [58, 16]])
xp = pts[:, 0]
yp = pts[:, 1]
zp = xp**2 / 1000
Expand Down
6 changes: 4 additions & 2 deletions examples/gridding/Natural_Neighbor_Verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@
# estimate a value using natural neighbor interpolation.
#
# The locations of these observations are then used to generate a Delaunay triangulation.
np.random.seed(100)

pts = np.random.randint(0, 100, (10, 2))
# Some randomly selected points
pts = np.array([[8, 24], [67, 87], [79, 48], [10, 94], [52, 98],
[53, 66], [98, 14], [34, 24], [15, 60], [58, 16]])

xp = pts[:, 0]
yp = pts[:, 1]
zp = (pts[:, 0] * pts[:, 0]) / 1000
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ filterwarnings = [
[tool.ruff]
line-length = 95
exclude = ["docs", "build", "src/metpy/io/_metar_parser/metar_parser.py"]
select = ["A", "B", "C", "CPY001", "D", "E", "E226", "F", "G", "I", "N", "Q", "R", "S", "T", "U", "W"]
select = ["A", "B", "C", "CPY001", "D", "E", "E226", "F", "G", "I", "N", "NPY", "Q", "R", "S", "T", "U", "W"]
ignore = ["F405", "I001", "RET504", "RET505", "RET506", "RET507", "RUF100"]
preview = true
explicit-preview-rules = true
Expand Down

0 comments on commit cc2cb57

Please sign in to comment.