Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make interpolate_to_grid more robust #2873

Open
dopplershift opened this issue Jan 6, 2023 · 1 comment
Open

Make interpolate_to_grid more robust #2873

dopplershift opened this issue Jan 6, 2023 · 1 comment
Labels
Area: Gridding Pertains to calculating values on a regular grid Type: Bug Something is not working like it should Type: Enhancement Enhancement to existing functionality

Comments

@dopplershift
Copy link
Member

There are some gremlins lurking in interpolate_to_grid, at least with this dataset:

import metpy.interpolate as minterp
from metpy.io import add_station_lat_lon
from siphon.simplewebservice.iastate import IAStateUpperAir

df = IAStateUpperAir.request_all_data(datetime(1993, 3, 13, 12), pressure=500)
df = add_station_lat_lon(df)
df = df.astype({'latitude': float, 'longitude': float})
df = df.dropna(subset=['latitude', 'longitude'])

methods = ['rbf', 'barnes', 'cressman', 'linear', 'natural_neighbor']
fig, axes = plt.subplots(nrows=2, ncols=len(methods), figsize=(15, 8))
for ind, ax in enumerate(axes.flat):
    method = methods[ind % len(methods)]
    project = ind >= len(methods)
    if project:
        proj = ccrs.LambertConformal()
        x, y, _ = proj.transform_points(ccrs.PlateCarree(), df.longitude.values, df.latitude.values).T
        res = 75000.
    else:
        x = df.longitude.values
        y = df.latitude.values
        res = 1.0
    gridx, gridy, grid_height = minterp.interpolate_to_grid(x, y, df.height, interp_type=method, hres=res)
    ax.imshow(grid_height)
    ax.set_title(f'{method}, project={project}')

image

In my opinions, we need to try to make everything operate sensibly default out of the box. Cressman seems ok here, but I swear I saw weirdness elsewhere. Barnes and RBF are not good here.

  1. Investigate what's going wrong with RBF. Also, internally we are using the Rbf class rather than the newer RBFInterpolator
  2. We already knew the way Barnes was formulated here was problematic, but we really need to fix this up.
  3. Definitely want to make natural neighbor more reasonable performance-wise (Port natural neighbor interpolation to Shapely #2622)
@dopplershift dopplershift added Type: Bug Something is not working like it should Type: Enhancement Enhancement to existing functionality Area: Gridding Pertains to calculating values on a regular grid labels Jan 6, 2023
@ThomasMGeo
Copy link

Another implementation of Barnes Interpolation in Python with a nice paper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Gridding Pertains to calculating values on a regular grid Type: Bug Something is not working like it should Type: Enhancement Enhancement to existing functionality
Projects
None yet
Development

No branches or pull requests

2 participants