MetPy icon indicating copy to clipboard operation
MetPy copied to clipboard

hres of interpolate_to_grid not respected

Open fournifl opened this issue 4 years ago • 2 comments

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

fournifl avatar Jan 28 '22 09:01 fournifl

To "solve" this issue, I added +1 to x_steps and y_steps variables in interpolate.grid.get_xy_steps function

fournifl avatar Jan 28 '22 09:01 fournifl

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

huanglii avatar Mar 09 '22 08:03 huanglii

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.

dopplershift avatar Sep 15 '22 23:09 dopplershift