MetPy
MetPy copied to clipboard
hres of interpolate_to_grid not respected
What went wrong?
When using interpolate.interpolate_to_grid, the output grid spacing is not exactly the one specified by 'hres' parameter.
Operating System
Linux
Version
1.2.0
Python Version
3.7
Code to Reproduce
from metpy.interpolate import interpolate_to_grid
import numpy as np
import matplotlib.pyplot as plt
def calculate_z(x, y):
z = []
for i, _ in enumerate(x):
z.append(x[i]**2 + y[i]**2)
return np.array(z)
x = np.random.rand(50) * 10
y = np.random.rand(50) * 10
z = calculate_z(x, y)
grid_x, grid_y, grid_z = interpolate_to_grid(x, y, z, interp_type='linear', hres=1, boundary_coords={'west': 0, 'south': 0, 'east': 10.0, 'north': 10.0})
print(grid_x)
print('\n')
print(grid_y)
Errors, Traceback, and Logs
No response
To "solve" this issue, I added +1 to x_steps and y_steps variables in interpolate.grid.get_xy_steps function
To "solve" this issue, I added +1 to x_steps and y_steps variables in interpolate.grid.get_xy_steps function
The function get_xy_steps should be changed as follows:
x_steps = np.round(x_range / h_dim) + 1
y_steps = np.round(y_range / h_dim) + 1
My apologies that this didn't receive a response sooner.
Thanks for the analysis and the suggested fix, I agree and have implemented the suggested fix in #2674.