comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Reverse interpolation?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Reverse interpolation? [message #21201] Thu, 17 August 2000 00:00
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Martin Schultz <martin.schultz@dkrz.de> writes:
>
> I had looked into SPL_INTERP and SPL_INIT, but I found the
> problem was that it does not allow for "smoothing" (more
> correctly: controlling "the amount of tension that is applied to
> the curve"). I certainly like the idea of controllin the
> endpoints (which you can do only in SPL_INTERP). Are you aware of
> a solution that can do both?

Sorry, I've never needed any extra smoothing, and I have always had
control over the endpoints of my original function.

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Reverse interpolation? [message #21207 is a reply to message #21201] Thu, 17 August 2000 00:00 Go to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
Craig Markwardt wrote:
>
> Martin Schultz <martin.schultz@dkrz.de> writes:
>
> Craig wrote:
>
>>
> ...
>> newxx = Spline( oldy, oldx, newy, 5. )
> ...
>
> If you are trying to match a lot of values, then I agree that the
> spline interpolation is one of the best solutions. However, I have
> had bad experiences with the SPLINE function. It tends to have
> problems when the points are too far apart, and it's also pretty slow.
> I found the Numerical Recipes version of spline interpolation to be
> much better (built in functions SPL_INTERP and SPL_INIT).
>
> If v1 is vector of values sampled at original altitudes a1, and you
> want to resample at new altitudes a2, then you do something like this:
>
> v2 = spl_interp(a1, v1, spl_init(a1, v1), a2)
>
> Now v2 has the newly sampled values. In principle a2 can be one value
> so even if you want a single value the spline interpolation can be
> useful, and even pretty fast.
>

I had looked into SPL_INTERP and SPL_INIT, but I found the
problem was that it does not allow for "smoothing" (more
correctly: controlling "the amount of tension that is applied to
the curve"). I certainly like the idea of controllin the
endpoints (which you can do only in SPL_INTERP). Are you aware of
a solution that can do both?


Martin

--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie
[[
[[ Bundesstr. 55, 20146 Hamburg
[[
[[ phone: +49 40 41173-308
[[
[[ fax: +49 40 41173-298
[[
[[ martin.schultz@dkrz.de
[[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
Re: Reverse interpolation? [message #21278 is a reply to message #21201] Wed, 16 August 2000 00:00 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Martin Schultz <martin.schultz@dkrz.de> writes:

> Simon de Vet wrote:
...
>> I want to get better results. Instead of finding that entry #5 is the
>> closest match to my known altitude, and using #5 as the subscript in my
>> data array, I'd like to find that, based on a linear interpolation,
>> entry #5.32850 is an exact match, and using this value in an
>> interpolation on my data array.
>>
>> I understand how to use a subscript to find an interpolated value. How
>> would I go in the opposite direction, using a value to find a subscript?
>>
>> Thanks. I hope this isn't too confusing. I'm having a bad brane day.
>>
>> Simon
>
>
> Hi Simon,
>
> I have dealt with similar problems (vertical regridding, to
> give the kid a name), and I tend to resort on the spline routine
> in these instances. Please find attached a piece of code that I
> used to vertically regrid OH concentration fields. Just be
> careful about end effects. For this application I overwrote the
> topmostfour levels of the target grid with the values from the
> top level of the old grid.
>
...
> newxx = Spline( oldy, oldx, newy, 5. )
...

If you are trying to match a lot of values, then I agree that the
spline interpolation is one of the best solutions. However, I have
had bad experiences with the SPLINE function. It tends to have
problems when the points are too far apart, and it's also pretty slow.
I found the Numerical Recipes version of spline interpolation to be
much better (built in functions SPL_INTERP and SPL_INIT).

If v1 is vector of values sampled at original altitudes a1, and you
want to resample at new altitudes a2, then you do something like this:

v2 = spl_interp(a1, v1, spl_init(a1, v1), a2)

Now v2 has the newly sampled values. In principle a2 can be one value
so even if you want a single value the spline interpolation can be
useful, and even pretty fast.

IDL version 5.3 apparently has a new function called VALUE_LOCATE
which can do fast search of a reference array. From there you can do
a linear interpolation. The IDL Astronomy Library procedure called
TABINV may do what you want. The versions that use VALUE_LOCATE and
don't use it are here, and here, respectively:

http://idlastro.gsfc.nasa.gov/ftp/v53/tabinv.pro
http://idlastro.gsfc.nasa.gov/ftp/pro/math/tabinv.pro

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Reverse interpolation? [message #21288 is a reply to message #21278] Wed, 16 August 2000 00:00 Go to previous message
promashkin is currently offline  promashkin
Messages: 169
Registered: December 1999
Senior Member
I'd recommend checking out VALUE_LOCATE function. Overall, solving the
proportion in a triangle will be the simpliest approach (unless you want
to do a more sophisticated spline as suggested by Martin), but
VALUE_LOCATE eliminates the need for subtracting and finding near-zero
elements of the array.
Also, once you have X, there is a library function INTERPOL that will
take X for input and locate the interpolated value for you.
Cheers,
Pavel

Simon de Vet wrote:
>
> Simon de Vet wrote:
>
>> I understand how to use a subscript to find an interpolated value. How
>> would I go in the opposite direction, using a value to find a subscript?
>
> I have an idea (I used this for a similar problem with Matlab) that may
> work. It's ackward and bulky, but I can understand it.
>
> First, I subtract the known altitude from the altitude list. Some of the
> values will be positive, and some negative. I use this to find the points
> on either side of known altitude. I can use their subscripts as x-values
> and their altitudes as y-values to find the equation of a line connecting
> the two points. I can then substitute my known altitude (y value) into the
> equation, and solve for x (the required subscript).
>
> I hope it works.
>
> Simon
Re: Reverse interpolation? [message #21290 is a reply to message #21278] Wed, 16 August 2000 00:00 Go to previous message
Simon de Vet is currently offline  Simon de Vet
Messages: 36
Registered: May 2000
Member
Simon de Vet wrote:

> I understand how to use a subscript to find an interpolated value. How
> would I go in the opposite direction, using a value to find a subscript?

I have an idea (I used this for a similar problem with Matlab) that may
work. It's ackward and bulky, but I can understand it.

First, I subtract the known altitude from the altitude list. Some of the
values will be positive, and some negative. I use this to find the points
on either side of known altitude. I can use their subscripts as x-values
and their altitudes as y-values to find the equation of a line connecting
the two points. I can then substitute my known altitude (y value) into the
equation, and solve for x (the required subscript).

I hope it works.


Simon
Re: Reverse interpolation? [message #21292 is a reply to message #21278] Wed, 16 August 2000 00:00 Go to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
Simon de Vet wrote:
>
> I have a little problem :)
>
> I have three sets of data - a list of altitudes (which are not evenly
> spaced, and are calculated with a long, confusing formula), an altitude
> I want to match, and a set of data that depends on altitude (ie: entry 1
> corresponds to altitude 1, entry 2 to altitude 2, etc...).
>
> Currently, I am calculating the differences between each entry in the
> altitude list and my known altitude, and using this to find the closest
> match, who's subscript I use in the data array. However, since there
> aren't very many values in my altitude list, the closest matches are
> often not very close at all, and the results become inaccurate.
>
> I want to get better results. Instead of finding that entry #5 is the
> closest match to my known altitude, and using #5 as the subscript in my
> data array, I'd like to find that, based on a linear interpolation,
> entry #5.32850 is an exact match, and using this value in an
> interpolation on my data array.
>
> I understand how to use a subscript to find an interpolated value. How
> would I go in the opposite direction, using a value to find a subscript?
>
> Thanks. I hope this isn't too confusing. I'm having a bad brane day.
>
> Simon


Hi Simon,

I have dealt with similar problems (vertical regridding, to
give the kid a name), and I tend to resort on the spline routine
in these instances. Please find attached a piece of code that I
used to vertically regrid OH concentration fields. Just be
careful about end effects. For this application I overwrote the
topmostfour levels of the target grid with the values from the
top level of the old grid.

Cheers,
Martin



FOR i=0,N_Elements(grid.lon)-1 DO BEGIN
FOR j=0,N_Elements(grid.lat)-1 DO BEGIN

oldx = reverse( reform( newoh[i,j,*,month-1] ) )
oldy = reverse( reform( data.p ) )
newy = reform( pgrid[i,j,*,month-1] )

;; Smooth spline interpolation onto new grid
newxx = Spline( oldy, oldx, newy, 5. )

;; Enter new values in result field
resultoh[i,j,*,month-1] =
reform(newxx,1,1,N_Elements(newxx))
ENDFOR
ENDFOR
--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie
[[
[[ Bundesstr. 55, 20146 Hamburg
[[
[[ phone: +49 40 41173-308
[[
[[ fax: +49 40 41173-298
[[
[[ martin.schultz@dkrz.de
[[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Coastal boundaries over sat data
Next Topic: Re: VIRUS ALERT (was: Ghost object)

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 10:35:36 PDT 2025

Total time taken to generate the page: 3.44406 seconds