comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: correct way to use INTERPOLATE function

Re: correct way to use INTERPOLATE function
type: item
description: Ryan. writes: > I want to plot two arrays of different sizes so I am trying to use > INTERPOLATE on the smaller array to make it the same size as the large > one. I can't seem to use the INTERPOLATE function correctly and there > isn't very much documentation on how to generalize it's use. I need > help in generalizing its use. All I get as a result is the first > element repeated (the same result I would get if I used the REPLICATE > function). I want to do this in the general case because I need to do > it a few times. Here is a simpler version of what I am doing: > > smallarray = [10.3, 9.6, 9.2, 8.5, 7.7, 6.9, 5.8, 5.4, 4.7, 4.1] > largearray = FINDGEN(1000)*0.5 > > smsize = N_ELEMENTS(smallarray) > lasize = N_ELEMENTS(largearray) > > interpped = INTERPOLATE(smallarray, smsize/(lasize-1)*FINDGEN(lasize)) > > PLOT, interpped, largearray > > One feature of the small array is that it is decreasing throughout and > has approximately 100 elements. The large array has several thousand > elements. I believe there is an error in the equation I have in the > second argument. It's not clear to me exactly what you are hoping to do, but it seems clear INTERPOLATE isn't the way to do it. :-) I think something like this will work: PLOT, Congrid(smallarray, N_Elements(largearray)), largearray This will not change the values in smallarray that get plotted. If you want to interpolate the values, set the INTERP keyword to CONGRID. Cheers, David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.dfanning.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.")
creator: David Fanning
date: 2007-09-21T18:42:52-00:00

Re: correct way to use INTERPOLATE function
type: item
description: > PLOT, Congrid(smallarray, N_Elements(largearray)), largearray If I do that I get the same result: PLOT, CONGRID(smallarray, N_ELEMENTS(largearray), 1, 1) <- With our without the INTERP keyword I want to *stretch* the small array so that it has the same number of elements as the large one so I can plot it and all the new points to be interpolated linearly between each point. Evenly spaced points is fine for my purposes. Ryan.
creator: rchughes
date: 2007-09-21T19:24:05-00:00

Re: correct way to use INTERPOLATE function
type: item
description: Ryan. writes: > If I do that I get the same result: > PLOT, CONGRID(smallarray, N_ELEMENTS(largearray), 1, 1) <- With our > without the INTERP keyword The INTERP keyword will be set like this: Plot, Congrid(sm, N_Elements(large), /INTERP) Or, like this: Plot, Congrid(sm, N_Elements(large), INTERP=1) Cheers, David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.dfanning.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.")
creator: David Fanning
date: 2007-09-21T19:30:45-00:00

Re: correct way to use INTERPOLATE function
type: item
description: > The INTERP keyword will be set like this: > > Plot, Congrid(sm, N_Elements(large), /INTERP) > > Or, like this: > > Plot, Congrid(sm, N_Elements(large), INTERP=1) I'm aware of how to set it. I guess my comment wasn't too clear. I meant to say that I get the same result whether I use the INTERP keyword or not. Does your statement work as it is? If I use the statement like you wrote it, it asks me for additional arguments (Error: % Variable is undefined: Y. % Error occurred at: CONGRID 135). Therefore I need to add the Y and Z arguments which I just put values of 1. Ryan.
creator: rchughes
date: 2007-09-21T19:37:57-00:00

Re: correct way to use INTERPOLATE function
type: item
description: Ryan. writes: > I'm aware of how to set it. I guess my comment wasn't too clear. I > meant to say that I get the same result whether I use the INTERP > keyword or not. > > Does your statement work as it is? No, this is pseudocode. :-) Try this: s = [10.3, 9.6, 9.2, 8.5, 7.7, 6.9, 5.8, 5.4, 4.7, 4.1] l = Findgen(100) * 0.5 P.MULTI=[0,1,2] Window Plot, Congrid(s, N_Elements(l)) Plot, Congrid(s, N_Elements(l), /INTERP) !P.MULTI=0 Cheers, David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.dfanning.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.")
creator: David Fanning
date: 2007-09-21T19:51:28-00:00

Re: correct way to use INTERPOLATE function
type: item
description: Ryan. wrote: >> PLOT, Congrid(smallarray, N_Elements(largearray)), largearray > > If I do that I get the same result: > PLOT, CONGRID(smallarray, N_ELEMENTS(largearray), 1, 1) <- With our > without the INTERP keyword > > I want to *stretch* the small array so that it has the same number of > elements as the large one so I can plot it and all the new points to > be interpolated linearly between each point. Evenly spaced points is > fine for my purposes. For that purpose, you can also use INTERPOL (rather than INTERPOLATE). Here's an example: x=findgen(6)/5 y=[0.,2,2,5,6,10] ;first data set plot,x,y,psym=-6 x2=findgen(100)/100 z=interpol(y,x,x2) ;the z array is interpolated linearly from the point in y oplot,x2,z,psym=-4 Is that waht you are trying to do? Cheers, Paolo PS: switching to google groups as it turns out newsgroup server are not supported at my new institution... at least the RSS feed can be shown in thunderbird in such a way as to look kind of similar as it should when using a real newsgroup server... but I am wondering whether there is a way of using a fixed size font in the google groups "post message" interface... > > Ryan.
creator: pgrigis
date: 2007-09-21T20:26:10-00:00

Re: correct way to use INTERPOLATE function
type: item
description: pgrigis@gmail.com writes: > For that purpose, you can also use INTERPOL (rather than INTERPOLATE). > Here's an example: > > x=findgen(6)/5 > y=[0.,2,2,5,6,10] > > ;first data set > plot,x,y,psym=-6 > > x2=findgen(100)/100 > z=interpol(y,x,x2) > ;the z array is interpolated linearly from the point in y > > oplot,x2,z,psym=-4 > > Is that waht you are trying to do? Ah, interesting. After some playing around with CONGRID keywords, I discovered that this interpolation method is virtually identical to this: nelem = N_Elements(x2) OPLOT, x2, CONGRID(y, nelem, /INTERP, /MINUS_ONE) Could be an interesting article in here somewhere. :-) Cheers, David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.dfanning.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.")
creator: David Fanning
date: 2007-09-21T20:49:19-00:00

Re: correct way to use INTERPOLATE function
type: item
description: > Is that waht you are trying to do? Thanks Paolo and David. That's not what I wanted to do but it did help me out to produce the plot I want. I want to create a smallarray vs. largearray plot but If I just tried to plot it, IDL will do what it does best and plot only the first N_ELEMENTS(smallarray) points. The code that I did come up with is as follows (It is very close to what Paolo had): l = FINDGEN(100)*0.5 s = [10.3, 9.6, 9.2, 8.5, 7.7, 6.9, 5.8, 5.4, 4.7, 4.1] ns = N_ELEMENTS(s) nl = N_ELEMENTS(l) x = FINDGEN(ns)/(ns-1) x2 = FINDGEN(nl)/nl z = INTERPOL(s, x, x2) PLOT, z, l, PSYM=-6 Thanks for your help, Ryan.
creator: rchughes
date: 2007-09-21T21:06:13-00:00

Re: correct way to use INTERPOLATE function
type: item
description: "Ryan." <rchughes@gmail.com> wrote in message news:1190408773.723336.302670@o80g2000hse.googlegroups.com.. . >> Is that waht you are trying to do? > > Thanks Paolo and David. That's not what I wanted to do but it did > help me out to produce the plot I want. I want to create a smallarray > vs. largearray plot but If I just tried to plot it, IDL will do what > it does best and plot only the first N_ELEMENTS(smallarray) points. > The code that I did come up with is as follows (It is very close to > what Paolo had): > > l = FINDGEN(100)*0.5 > s = [10.3, 9.6, 9.2, 8.5, 7.7, 6.9, 5.8, 5.4, 4.7, 4.1] > ns = N_ELEMENTS(s) > nl = N_ELEMENTS(l) > > x = FINDGEN(ns)/(ns-1) > x2 = FINDGEN(nl)/nl > > z = INTERPOL(s, x, x2) > > PLOT, z, l, PSYM=-6 Hi Ryan, I took a quick glance, and for the life of me i can't figure out what it is that you really want to do. You are plotting the "l" array here as a function of your "z" (which is based on your original "s"). I don't think that means anything. I assume you have a watered down example of your original problem, but it just seems like 1) you have it backwards (i.e. you want to plot > plot l,z and 2) you probably shouldn't be doing that in the first place. My point would be that the elements of "s" should have some ordinate related to them. Select the proper ordinate to pair with the "s"es and just plot that. Or if you need to interpolate, then interpolate both in the exact same way. Cheers, bob
creator: R.G.Stockwell
date: 2007-09-21T21:16:37-00:00

Re: correct way to use INTERPOLATE function
type: item
description: R.G. Stockwell wrote: > "Ryan." <rchughes@gmail.com> wrote in message > news:1190408773.723336.302670@o80g2000hse.googlegroups.com.. . >>> Is that waht you are trying to do? >> >> Thanks Paolo and David. That's not what I wanted to do but it did >> help me out to produce the plot I want. I want to create a smallarray >> vs. largearray plot but If I just tried to plot it, IDL will do what >> it does best and plot only the first N_ELEMENTS(smallarray) points. >> The code that I did come up with is as follows (It is very close to >> what Paolo had): >> >> l = FINDGEN(100)*0.5 >> s = [10.3, 9.6, 9.2, 8.5, 7.7, 6.9, 5.8, 5.4, 4.7, 4.1] >> ns = N_ELEMENTS(s) >> nl = N_ELEMENTS(l) >> >> x = FINDGEN(ns)/(ns-1) >> x2 = FINDGEN(nl)/nl >> >> z = INTERPOL(s, x, x2) >> >> PLOT, z, l, PSYM=-6 > > > Hi Ryan, > > I took a quick glance, and for the life of me i can't figure out > what it is that you really want to do. You are plotting the > "l" array here as a function of your "z" (which is > based on your original "s"). I don't think that means > anything. Maybe I know what's happening here... Let's assume you have a low-resolution circle given by x1 and y1 coordinates: n=10 t1=findgen(n)/(n-1)*!Pi*2 x1=sin(t1) y1=cos(t1) and a high resolution circle given by x2 and y2 n=64 t2=findgen(n)/(n-1)*!Pi*2 x2=sin(t2) y2=cos(t2) Then, assume that for some reason you have access to x1 and to y2 and not to x2, and you want to try to plot the best possible approximation of the high-res circle. Then one may need to do something like: xx2=interpol(x1,t1,t2) and plotting (xx2,y2) is an approximation to the circle (of course, in such a case, use of the /spline keyword to interpol may make the plot nicer). So, this may be something along the line of what the OP is doing... Ciao, Paolo > > I assume you have a watered down example of your > original problem, but it just seems like > 1) you have it backwards (i.e. you want to plot >> plot l,z > > and 2) > you probably shouldn't be doing that in the f…
creator: pgrigis
date: 2007-09-21T21:35:31-00:00

Re: correct way to use INTERPOLATE function
type: item
description: > you probably shouldn't be doing that in the first place. Hi Bob, I was actually looking over the validity of what I was doing after I posted it. I wasn't certain that what I was doing correctly represented what I wanted. Thanks for confirming my thoughts. I got sidetracked on what I originally wanted to show. I got busy trying to debug my code and ended up doing something I shouldn't. I got sidetracked with IDL repeatedly crashing out on me because I was unintentionally Interpolating a string (Not a good idea, by the way) and spent much time on this. Then I got busy trying to get the INTERPOLATE or CONGRID functions to work properly. I will rethink my original intentions and hopefully stay on track this time. =) Thanks for pointing it out, Ryan.
creator: rchughes
date: 2007-09-21T21:50:12-00:00

Re: correct way to use INTERPOLATE function
type: item
description: "Ryan." <rchughes@gmail.com> wrote in message news:1190411412.834849.94160@g4g2000hsf.googlegroups.com... >> you probably shouldn't be doing that in the first place. > > Hi Bob, > > I was actually looking over the validity of what I was doing after I > posted it. I wasn't certain that what I was doing correctly > represented what I wanted. Thanks for confirming my thoughts. I got > sidetracked on what I originally wanted to show. I got busy trying to > debug my code and ended up doing something I shouldn't. I got > sidetracked with IDL repeatedly crashing out on me because I was > unintentionally Interpolating a string (Not a good idea, by the way) > and spent much time on this. Then I got busy trying to get the > INTERPOLATE or CONGRID functions to work properly. I will rethink my > original intentions and hopefully stay on track this time. =) > > Thanks for pointing it out, > Ryan. You are welcome. I don't mean to overstate the "shouldn't do it" part. Interpolation is common and usually a fine thing to do. The part that stood out for me was taking the original array with 10 elements and no x-values related to those 10 elements. That is fine, because most people use the index number as the x-coordinate of the data. So you have x = 0,1,2...9. Then the example is "interpolating" the original data "s" onto an array "l" that goes from 0 to 49.5. That is outside the bounds of the original index (the 0,1,..9) so it doesn't make sense. If you interpolated onto a finer scale than the integer index, (from 0,1,2...9 to a new x-value array of 0,0.1,0.2,0.3....... 9.0 then that would be fine). That's all I was really getting at. Cheers, bob PS interpolating strings should be able to work for instance x = 'liberal' x2='conservative' z = interpol([x,x2], 0.5) print, result > moderate sorry, dumb attempt at a joke
creator: R.G.Stockwell
date: 2007-09-21T21:59:30-00:00

Re: correct way to use INTERPOLATE function
type: item
description: Ryan. writes: > I was actually looking over the validity of what I was doing after I > posted it. I wasn't certain that what I was doing correctly > represented what I wanted. Thanks for confirming my thoughts. I got > sidetracked on what I originally wanted to show. I got busy trying to > debug my code and ended up doing something I shouldn't. I got > sidetracked with IDL repeatedly crashing out on me because I was > unintentionally Interpolating a string (Not a good idea, by the way) > and spent much time on this. Then I got busy trying to get the > INTERPOLATE or CONGRID functions to work properly. I will rethink my > original intentions and hopefully stay on track this time. =) I experience the same problem when I try to write IDL programs with the EMACS editor. :-) Cheers, David -- David Fanning, Ph.D. Fanning Software Consulting, Inc. Coyote's Guide to IDL Programming: http://www.dfanning.com/ Sepore ma de ni thui. ("Perhaps thou speakest truth.")
creator: David Fanning
date: 2007-09-21T22:45:16-00:00