Skip to content

Commit

Permalink
Added example to documentation for regridding.regrid().
Browse files Browse the repository at this point in the history
  • Loading branch information
byrdie committed Jul 25, 2023
1 parent 7001cf9 commit afc52ae
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions regridding/_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,58 @@ def regrid(
Returns
-------
The regridded histogram
Examples
--------
Define an input curvilinear grid
.. jupyter-execute::
import numpy as np
import matplotlib.pyplot as plt
import regridding
x = np.linspace(-5, 5, num=66)
y = np.linspace(-5, 5, num=66)
x, y = np.meshgrid(x, y, indexing="ij")
angle = 0.4
x_input = x * np.cos(angle) - y * np.sin(angle) + 0.05 * x * x
y_input = x * np.sin(angle) + y * np.cos(angle) + 0.05 * y * y
Define a test patten
.. jupyter-execute::
pitch = 16
a_input = 0 * x[:~0,:~0]
a_input[::pitch, :] = 1
a_input[:, ::pitch] = 1
a_input[pitch//2::pitch, pitch//2::pitch] = 1
plt.figure();
plt.pcolormesh(x_input, y_input, a_input);
Define a new grid
.. jupyter-execute::
x_output = 2 * x
y_output = 2 * y
Regrid the test pattern onto the new grid
.. jupyter-execute::
a_output = regridding.regrid(
vertices_input=(x_input, y_input),
vertices_output=(x_output, y_output),
values_input=a_input,
)
plt.figure();
plt.pcolormesh(x_output, y_output, a_output);
"""
weights = calc_weights(
vertices_input=vertices_input,
Expand Down

0 comments on commit afc52ae

Please sign in to comment.