<p>I have another question, is there a package that interpolates precipitation data taking into account mountains and oceans? I have so far used Numpy and Basemap but as you can see in the code, the data from Europe affect the data from North America! This distorts the results and must be prevented at all costs.</p>
<p>(I am aware that my interpolation is just very simplified)</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import griddata
from mpl_toolkits.basemap import Basemap
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.patches import Path, PathPatch

# data coordinates and values
x = np.array([6.47, 4.8, 1.94, -4.57, 5.78, 3.95, 5.45, 0.38, 7.13, 12.43, 11.59, -1.083333333, -60.996, -83.144 ])
y = np.array([46.37, 43.9, 47.83, 48.36, 44.95, 43.57, 43.45, 43.12, 43.92, 51.35, 48.22, 52.88333333, 50.958, 37.02])
z = np.array([-29.5, -27.6, -32.5, -32.4, -16.0, -0.1, -12.3, -15.2, -36.2,  -20.6,-38.2, -38.2, -2.0, -4.0  ])

# target grid to interpolate to
xi =np.arange(-100, 100, 1, dtype='float64')
yi =np.arange(-100,100, 1, dtype='float64')
xi, yi = np.meshgrid(xi, yi)

# interpolate
zi = griddata((x,y),z,(xi,yi),method='cubic')

fig, ax = plt.subplots(figsize=(10,10))
m = Basemap(llcrnrlon=x.min()-0.1,llcrnrlat=y.min()-0.1,urcrnrlon=x.max()+0.1,urcrnrlat=y.max()+0.1, projection='merc', resolution='h',area_thresh=1000.,ax=ax)

m.drawcoastlines() #draw coastlines on the map
x,y=m(xi, yi) # convert the coordinates into the map scales
cs=ax.contourf(x, y, zi, np.linspace(-40, 0),extend='both',cmap='jet') #plot the data on the map.
plt.scatter(x, y)
plt.show()
</code></pre>
<p>Oh and if someone knows how I can delete these meshgrid points from Numpy, I would be very happy about a short answer, because this I have somehow not found (which I myself find very strange)</p>
<p>Edit: Normally the ocean is covered with a mask, but this would make the code much too long</p>
<p>Result:<a href="https://i.sstatic.net/drw6s.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/drw6s.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2022-05-14T00:17:10.247Z
Have you considered putting constraints on the data? Such as creating a zone for Europe & another for North America & specifying that only data from within each zone can only be used for each land mass.
Fred
CC BY-SA 4.0
2022-05-14T07:26:37.273Z
Hi @Fred, thanks for your reply that sounds promising, do you have a website or link explaining this step? All the best
Weiss
CC BY-SA 4.0
2022-05-14T08:12:24.193Z
Depending on the application & what software is available, some packages allow regions to be specified using a screen digitized polygon & then specifying whether everything inside or outside of the polygon is to be included or excluded. A more laborious way would be to write a script to split the data file. One criteria that could be used in this situation is the co-ordinate for longitude. Choose something west of Iceland & everything west of that reports to the US date file & everything east of that reports to the Europe data file.
Fred
CC BY-SA 4.0
2022-05-14T19:31:55.210Z
May I suggest checking out [`verde`](https://www.fatiando.org/verde/latest/)? It's much more suitable than `griddata` for the sort of thing you're doing. And I suggest  replacing `basemap`, which is deprecated, with [`cartopy`](https://scitools.org.uk/cartopy/docs/latest/).
Matt Hall
<models><climate-models><mapping><python><interpolation>
Complex interpolation for Isotopic data
Weiss
# Complex interpolation for Isotopic data

(Asked by: username_0 on 2022-05-13)

I have another question, is there a package that interpolates precipitation data taking into account mountains and oceans? I have so far used Numpy and Basemap but as you can see in the code, the data from Europe affect the data from North America! This distorts the results and must be prevented at all costs.

(I am aware that my interpolation is just very simplified)

```
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import griddata
from mpl_toolkits.basemap import Basemap
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.patches import Path, PathPatch

# data coordinates and values
x = np.array([6.47, 4.8, 1.94, -4.57, 5.78, 3.95, 5.45, 0.38, 7.13, 12.43, 11.59, -1.083333333, -60.996, -83.144 ])
y = np.array([46.37, 43.9, 47.83, 48.36, 44.95, 43.57, 43.45, 43.12, 43.92, 51.35, 48.22, 52.88333333, 50.958, 37.02])
z = np.array([-29.5, -27.6, -32.5, -32.4, -16.0, -0.1, -12.3, -15.2, -36.2,  -20.6,-38.2, -38.2, -2.0, -4.0  ])

# target grid to interpolate to
xi =np.arange(-100, 100, 1, dtype='float64')
yi =np.arange(-100,100, 1, dtype='float64')
xi, yi = np.meshgrid(xi, yi)

# interpolate
zi = griddata((x,y),z,(xi,yi),method='cubic')

fig, ax = plt.subplots(figsize=(10,10))
m = Basemap(llcrnrlon=x.min()-0.1,llcrnrlat=y.min()-0.1,urcrnrlon=x.max()+0.1,urcrnrlat=y.max()+0.1, projection='merc', resolution='h',area_thresh=1000.,ax=ax)

m.drawcoastlines() #draw coastlines on the map
x,y=m(xi, yi) # convert the coordinates into the map scales
cs=ax.contourf(x, y, zi, np.linspace(-40, 0),extend='both',cmap='jet') #plot the data on the map.
plt.scatter(x, y)
plt.show()

```

Oh and if someone knows how I can delete these meshgrid points from Numpy, I would be very happy about a short answer, because this I have somehow not found (which I myself find very strange)

Edit: Normally the ocean is covered with a mask, but this would make the code much too long

Result:[![enter image description here](https://i.sstatic.net/drw6s.png)](https://i.sstatic.net/drw6s.png)

**Tags:** models, climate-models, mapping, python, interpolation

> **Comments:**
> **username_1**: Have you considered putting constraints on the data? Such as creating a zone for Europe & another for North America & specifying that only data from within each zone can only be used for each land mass.  
> **username_0**: Hi @username_1, thanks for your reply that sounds promising, do you have a website or link explaining this step? All the best  
> **username_1**: Depending on the application & what software is available, some packages allow regions to be specified using a screen digitized polygon & then specifying whether everything inside or outside of the polygon is to be included or excluded. A more laborious way would be to write a script to split the data file. One criteria that could be used in this situation is the co-ordinate for longitude. Choose something west of Iceland & everything west of that reports to the US date file & everything east of that reports to the Europe data file.  
> **username_2**: May I suggest checking out [`verde`](https://www.fatiando.org/verde/latest/)? It's much more suitable than `griddata` for the sort of thing you're doing. And I suggest  replacing `basemap`, which is deprecated, with [`cartopy`](https://scitools.org.uk/cartopy/docs/latest/).  

---

## 0 answers

