<p>As @gansub implicitly suggested, you may have a better outcome by defining the output grid as well. 
Check this very similar question: 
<a href="https://earthscience.stackexchange.com/questions/12057/how-to-interpolate-scattered-data-to-a-regular-grid-in-python">How to interpolate scattered data to a regular grid in Python?</a></p>

<p>After comments, I realize I missed the irregular target grid. Maybe this answer helps:
<a href="https://stackoverflow.com/questions/3242382/interpolation-over-an-irregular-grid">https://stackoverflow.com/questions/3242382/interpolation-over-an-irregular-grid</a></p>

CC BY-SA 4.0
2019-07-30T10:11:33.327Z
2019-07-31T08:58:30.927Z
2019-07-31T08:58:30.927Z
EarlGrey
<ol>
<li>I have an NC file that has global data with a high resolution (about 25 minutes) so a lot of coordinates.</li>
<li>I have some measured values of some region with irregularly spaced coordinates.</li>
<li>In order to mathematically operate between the two, I am aiming to interpolate the global data to the local irregular grid, instead of the opposite, to minimize the uncertainty.</li>
<li>How do I achieve this? I was thinking of Scipy's griddata module but cannot seem to initiate the process. Thanks a lot.</li>
</ol>

<p><strong>EDIT:</strong></p>

<p>I tried the following, a little heavy on resources but I think it works.</p>

<pre><code>from scipy.interpolate import interp2d   
f = interp2d(longw,latw,Zw)
</code></pre>

<p>where longw,latw,Zw are the world coordinates of the NETCDF file and the 2D variable respectively.</p>

<p>Then I applied <code>f(lon,lat)</code> to all my irregular observations y iteration to interpolate. The lon and lat are the observed coordinates of the local region. </p>

CC BY-SA 4.0
2019-07-24T16:09:07.773Z
Thanks for the link, but it is for 1D data. I do not find an equivalent function that converts 2D variable from the old to new grid.
cwanderroycbooks
CC BY-SA 4.0
2019-07-24T18:22:32.030Z
If you're interpolating from a regular, rectilinear, grid to an irregular one, pretty much any interpolation method - e.g. linear - ought to be reasonable. Be more careful if going the other way ;-) A lat/lon grid isn't actually rectilinear, but so long as you're working at a scale of a degree or two and you're not really close to a pole, it's probably near enough.
If you're after how to do this in a particular language (eg Python) then best to explicitly say that.
Semidiurnal Simon
CC BY-SA 4.0
2019-07-25T03:35:20.750Z
Well, Python is my go to medium now. Is the method alright?
cwanderroycbooks
CC BY-SA 4.0
2019-07-30T10:11:15.060Z
Possible duplicate of [How to interpolate scattered data to a regular grid in Python?](https://earthscience.stackexchange.com/questions/12057/how-to-interpolate-scattered-data-to-a-regular-grid-in-python)
EarlGrey
CC BY-SA 4.0
2019-07-30T16:05:00.567Z
Without much knowledge of python, your edited-in method makes sense. For future reference, on Stackexchange it's quite OK (even encouraged sometimes) to answer your own question. So if you ask something and then figure it out, rather than editing the question you can just add an answer.
Semidiurnal Simon
CC BY-SA 4.0
2019-07-30T16:06:46.227Z
@earlgray if I read this right, this question is the *opposite* of that: Chayan has regular data and needs to interpolate to irregular points. Not a dupe IMHO.
Semidiurnal Simon
CC BY-SA 4.0
2019-07-31T08:56:33.730Z
@SemidiurnalSimon You are right. Still, this is a possible duplicate, of this (other) question
https://stackoverflow.com/questions/3242382/interpolation-over-an-irregular-grid (very old, so interesting to see if answer holds)
EarlGrey
CC BY-SA 4.0
2019-07-31T17:12:52.173Z
@EarlGrey true, but I don't think we normally close questions when they are duplicates of questions *on other sites* ;-)
Semidiurnal Simon
CC BY-SA 4.0
2019-08-01T20:00:17.913Z
Thanks both of you. The link you shared later about interpolation over an irregular grid is quite complex doesn't seem to help, atleast according to my tiny brain. But thanks a lot for all of your help. Anyway, I was at this stuff for days until my professor dismissed by program went according to his own way. But atleast I learnt something.
cwanderroycbooks
<meteorology><python><grid-spacing><interpolation>
Interpolating world data to a local grid in Python
cwanderroycbooks
# Interpolating world data to a local grid in Python

(Asked by: username_0 on 2019-07-24)

1. I have an NC file that has global data with a high resolution (about 25 minutes) so a lot of coordinates.
2. I have some measured values of some region with irregularly spaced coordinates.
3. In order to mathematically operate between the two, I am aiming to interpolate the global data to the local irregular grid, instead of the opposite, to minimize the uncertainty.
4. How do I achieve this? I was thinking of Scipy's griddata module but cannot seem to initiate the process. Thanks a lot.

**EDIT:**

I tried the following, a little heavy on resources but I think it works.

```
from scipy.interpolate import interp2d   
f = interp2d(longw,latw,Zw)

```

where longw,latw,Zw are the world coordinates of the NETCDF file and the 2D variable respectively.

Then I applied `f(lon,lat)` to all my irregular observations y iteration to interpolate. The lon and lat are the observed coordinates of the local region.

**Tags:** meteorology, python, grid-spacing, interpolation

> **Comments:**
> **username_0**: Thanks for the link, but it is for 1D data. I do not find an equivalent function that converts 2D variable from the old to new grid.  
> **username_1**: If you're interpolating from a regular, rectilinear, grid to an irregular one, pretty much any interpolation method - e.g. linear - ought to be reasonable. Be more careful if going the other way ;-) A lat/lon grid isn't actually rectilinear, but so long as you're working at a scale of a degree or two and you're not really close to a pole, it's probably near enough. If you're after how to do this in a particular language (eg Python) then best to explicitly say that.  
> **username_0**: Well, Python is my go to medium now. Is the method alright?  
> **username_2**: Possible duplicate of [How to interpolate scattered data to a regular grid in Python?](https://earthscience.stackexchange.com/questions/12057/how-to-interpolate-scattered-data-to-a-regular-grid-in-python)  
> **username_1**: Without much knowledge of python, your edited-in method makes sense. For future reference, on Stackexchange it's quite OK (even encouraged sometimes) to answer your own question. So if you ask something and then figure it out, rather than editing the question you can just add an answer.  
> **username_1**: @earlgray if I read this right, this question is the *opposite* of that: Chayan has regular data and needs to interpolate to irregular points. Not a dupe IMHO.  
> **username_2**: @username_1 You are right. Still, this is a possible duplicate, of this (other) question https://stackoverflow.com/questions/3242382/interpolation-over-an-irregular-grid (very old, so interesting to see if answer holds)  
> **username_1**: @username_2 true, but I don't think we normally close questions when they are duplicates of questions *on other sites* ;-)  
> **username_0**: Thanks both of you. The link you shared later about interpolation over an irregular grid is quite complex doesn't seem to help, atleast according to my tiny brain. But thanks a lot for all of your help. Anyway, I was at this stuff for days until my professor dismissed by program went according to his own way. But atleast I learnt something.  

---

## 1 answers

### Answer by username_2 on 2019-07-30. Score: 1

As @gansub implicitly suggested, you may have a better outcome by defining the output grid as well.
Check this very similar question:
[How to interpolate scattered data to a regular grid in Python?](https://earthscience.stackexchange.com/questions/12057/how-to-interpolate-scattered-data-to-a-regular-grid-in-python)

After comments, I realize I missed the irregular target grid. Maybe this answer helps:
<https://stackoverflow.com/questions/3242382/interpolation-over-an-irregular-grid>


---

