Unidata / MetPy

MetPy is a collection of tools in Python for reading, visualizing and performing calculations with weather data.
https://unidata.github.io/MetPy/
BSD 3-Clause "New" or "Revised" License
1.24k stars 413 forks source link

Cressman Smoothing #666

Open jrleeman opened 6 years ago

jrleeman commented 6 years ago

Add a Cressman smoother.

dopplershift commented 6 years ago

Well, we don't have Cressman smoothing for grids necessarily, but:

https://unidata.github.io/MetPy/latest/search.html?q=cressman&check_keywords=yes&area=default

Although it would probably work already since grids for input are just a specialization of point data...

jrleeman commented 6 years ago

I didn't know if that would do the same job and if it does we'll need that documented somewhere other than gridding, so I went ahead and filed.

ahaberlie commented 6 years ago

Not sure if it is worth a separate function, but here is a toy example of how I think you could do it with existing functionality ('cressman' is default interpolation type for inverse_distance):

from metpy.gridding.interpolation import inverse_distance
from metpy.gridding.points import generate_grid_coords
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

vals = np.random.randint(0, 20, size=(2500))
gx, gy = np.meshgrid(list(range(50)), list(range(50)))

pts = generate_grid_coords(gx, gy)
x, y = pts[:, 0], pts[:, 1]

smoothed_vals = inverse_distance(x, y, vals, gx, gy, r=4)

fig, ax = plt.subplots(2, 1)

ax[0].imshow(vals.reshape(50, 50))
ax[1].imshow(smoothed_vals)