1
$\begingroup$
  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.

$\endgroup$
9
  • $\begingroup$ 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. $\endgroup$ Jul 24, 2019 at 16:09
  • 1
    $\begingroup$ Possible duplicate of How to interpolate scattered data to a regular grid in Python? $\endgroup$
    – EarlGrey
    Jul 30, 2019 at 10:11
  • 2
    $\begingroup$ 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. $\endgroup$ Jul 30, 2019 at 16:05
  • 2
    $\begingroup$ @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. $\endgroup$ Jul 30, 2019 at 16:06
  • 1
    $\begingroup$ @EarlGrey true, but I don't think we normally close questions when they are duplicates of questions on other sites ;-) $\endgroup$ Jul 31, 2019 at 17:12

1 Answer 1

1
$\begingroup$

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?

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.