[SciPy-user] 2d interpolation (Michael Hearne)

Michael Hearne mhearne@usgs....
Wed Aug 1 16:54:42 CDT 2007


Ummm, how?  If I try "outgrid(arange(1,4.1,.5),arange(1,4.1,.5))", I  
get:

array([[  6.        ,   7.96494318,   7.        ,   6.56906289,
           8.        ,   8.        ,   8.        ],
        [  8.        ,  10.50107083,   9.        ,   8.22836631,
          10.        ,  10.        ,  10.        ],
        [ 10.        ,  13.03719848,  11.        ,   9.88766973,
          12.        ,  12.        ,  12.        ],
        [ 12.        ,  15.57332614,  13.        ,  11.54697315,
          14.        ,  14.        ,  14.        ],
        [ 14.        ,  18.10945379,  15.        ,  13.20627657,
          16.        ,  16.        ,  16.        ],
        [ 14.        ,  18.10945379,  15.        ,  13.20627657,
          16.        ,  16.        ,  16.        ],
        [ 14.        ,  18.10945379,  15.        ,  13.20627657,
          16.        ,  16.        ,  16.        ]])

This doesn't look at all like my Matlab result!

xi and yi are supposed to be arrays of indices, and since Matlab  
starts indexing at 1, and Python/numpy start indexing at 0, I assumed  
that xi and yi in numpy should be one less than the corresponding  
vectors in Matlab.

Still confused,

Mike Hearne

On Aug 1, 2007, at 3:43 PM, Alex Liberzon wrote:

> It doesn't fit because xi and yi are 1:.5:4 in Matlab but 0:.5:3 in  
> Python
> I tested it with
> outgrid(arange(1,4.1,.5),arange(1,4.1,.5)) and the result is the same
> as in Matlab.
>
> Best
> Alex
>
> On 8/2/07, scipy-user-request@scipy.org <scipy-user- 
> request@scipy.org> wrote:
>> Send SciPy-user mailing list submissions to
>>         scipy-user@scipy.org
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>>         http://projects.scipy.org/mailman/listinfo/scipy-user
>> or, via email, send a message with subject or body 'help' to
>>         scipy-user-request@scipy.org
>>
>> You can reach the person managing the list at
>>         scipy-user-owner@scipy.org
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of SciPy-user digest..."
>>
>>
>> Today's Topics:
>>
>>    1. Re: Ant Colony Optimization (Alan G Isaac)
>>    2. Re: General Python Question: nested function calls (Ryan  
>> Krauss)
>>    3. Re: General Python Question: nested function calls
>>       (Gael Varoquaux)
>>    4. Re: Finding Neighboors (Barry Wark)
>>    5. Re: Finding Neighboors (jelle)
>>    6. Re: Testing BOF at scipy'07? (Fernando Perez)
>>    7. 2d interpolation (Michael Hearne)
>>
>>
>> --------------------------------------------------------------------- 
>> -
>>
>> Message: 1
>> Date: Wed, 1 Aug 2007 15:58:34 -0400
>> From: Alan G Isaac <aisaac@american.edu>
>> Subject: Re: [SciPy-user] Ant Colony Optimization
>> To: scipy-user@scipy.org
>> Message-ID: <Mahogany-0.67.0-1600-20070801-155834.00@american.edu>
>> Content-Type: TEXT/PLAIN; CHARSET=UTF-8
>>
>> On Wed, 01 Aug 2007, "Brandon C. Nuttall" apparently wrote:
>>> Is there an implementation of the Ant Colony Optimization
>>> routines available in Python? See
>>> http://www.aco-metaheuristic.org/
>>
>> You could wrap the C code at:
>>    http://www.aco-metaheuristic.org/aco-code/public-software.html
>>
>> fwiw,
>> Alan Isaac
>>
>>
>>
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Wed, 1 Aug 2007 14:56:59 -0500
>> From: "Ryan Krauss" <ryanlists@gmail.com>
>> Subject: Re: [SciPy-user] General Python Question: nested function
>>         calls
>> To: "SciPy Users List" <scipy-user@scipy.org>
>> Message-ID:
>>         <c5b438120708011256x2d0ebbeaw79d2514b285f21b@mail.gmail.com>
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> That would have been a better solution in this case - I have done  
>> that
>> before and don't know why I didn't here.
>>
>> Any thoughts on the same situation with calling a parent class's
>> method.  I just wrote code that did this:
>> def __init__(self, pathin=None, dialect=spreadsheet.tabdelim):
>>         ....
>>         spreadsheet.SpreadSheet.__init__(self, pathin=pathin,
>> skiprows=0, collabels=collabels, colmap=colmap, datafunc=float,
>> picklekeys=['t','lg','a','v0'])
>>
>> Basically, I do a few other things and then call the parent's  
>> __init__
>> somewhere in the middle.
>>
>> On 8/1/07, Robert Kern <robert.kern@gmail.com> wrote:
>>> Ryan Krauss wrote:
>>>> I often write code something like this:
>>>>
>>>> def TruncatePickleFile(pathin, trigname='a', trigtype='sw',
>>>> savepath=None, threshlevel=None, duration=0.05, backup=0.01):
>>>>     """Trunate the pickleddatafile whose path is pathin.  If
>>>>     trigtype=='lg', use a DropDownLightGateTrigger, else use a
>>>>     standard Trigger."""
>>>>     untrunc = pickleddatafiles.PickledDataFile(pathin)
>>>>     mytrunc = pickleddatafiles.TruncateDataObj(untrunc,
>>>> threshlevel=threshlevel, backup=backup, duration=duration)
>>>>     mytrunc.chname = trigname
>>>>     if trigtype == 'lg':
>>>>         mytrunc.SetupTrigger 
>>>> (DataProcMixins.DropDownLightGateTrigger)
>>>>     else:
>>>>         mytrunc.SetupTrigger()
>>>>     mytrunc.SetupTruncChannel()
>>>>     mytrunc.Truncate()
>>>>     pathout = mytrunc.Pickle(savepath)
>>>>     return pathout
>>>>
>>>> def TruncatePickleFiles(listin, trigname='a', trigtype='sw',
>>>> threshlevel=None, duration=0.05, backup=0.01):
>>>>     listout = []
>>>>     for item in listin:
>>>>         print item
>>>>         curpath = TruncatePickleFile(item, trigname=trigname,
>>>> trigtype=trigtype, threshlevel=threshlevel, duration=duration,
>>>> backup=backup)
>>>>         listout.append(curpath)
>>>>     return listout
>>>>
>>>> where TruncatePickleFiles is sort of just a vectorization of
>>>> TruncatePickleFile, but with some of the keyword args set.  My  
>>>> problem
>>>> is not that this might not be the fastest way to execute the  
>>>> code, but
>>>> that I get tired of doing this kind of stuff:
>>>>
>>>> curpath = TruncatePickleFile(item, trigname=trigname,
>>>> trigtype=trigtype, threshlevel=threshlevel, duration=duration,
>>>> backup=backup)
>>>>
>>>> but I also don't want to just do
>>>>
>>>> def TruncatePickleFiles(listin, **kwargs):
>>>>
>>>> because I like to see the defaults and know what keyword  
>>>> arguments are legal.
>>>>
>>>> Does anyone else have this problem or have an elegant solution  
>>>> to it?
>>>> The problem comes up for me also when I want a derived class to  
>>>> call a
>>>> parent class's method in some partially overwritten method of the
>>>> derived class.
>>>>
>>>> Ideally, I think I would like to pass **kwargs to the nested  
>>>> function,
>>>> but without using **kwargs in the definition of the top  
>>>> function, if
>>>> that makes any sense.
>>>
>>> There isn't really a straightforward solution.
>>>
>>> However, for something like this, you may want to consider just  
>>> implementing one
>>> version of the function which can take either a list of filenames  
>>> or a single
>>> filename.
>>>
>>> --
>>> Robert Kern
>>>
>>> "I have come to believe that the whole world is an enigma, a  
>>> harmless enigma
>>>  that is made terrible by our own mad attempt to interpret it as  
>>> though it had
>>>  an underlying truth."
>>>   -- Umberto Eco
>>> _______________________________________________
>>> SciPy-user mailing list
>>> SciPy-user@scipy.org
>>> http://projects.scipy.org/mailman/listinfo/scipy-user
>>>
>>
>>
>> ------------------------------
>>
>> Message: 3
>> Date: Wed, 1 Aug 2007 22:22:32 +0200
>> From: Gael Varoquaux <gael.varoquaux@normalesup.org>
>> Subject: Re: [SciPy-user] General Python Question: nested function
>>         calls
>> To: SciPy Users List <scipy-user@scipy.org>
>> Message-ID: <20070801202232.GB29@clipper.ens.fr>
>> Content-Type: text/plain; charset=iso-8859-1
>>
>> On Wed, Aug 01, 2007 at 02:56:59PM -0500, Ryan Krauss wrote:
>>> That would have been a better solution in this case - I have done  
>>> that
>>> before and don't know why I didn't here.
>>
>>> Any thoughts on the same situation with calling a parent class's
>>> method.  I just wrote code that did this:
>>> def __init__(self, pathin=None, dialect=spreadsheet.tabdelim):
>>>         ....
>>>         spreadsheet.SpreadSheet.__init__(self, pathin=pathin,
>>> skiprows=0, collabels=collabels, colmap=colmap, datafunc=float,
>>> picklekeys=['t','lg','a','v0'])
>>
>>> Basically, I do a few other things and then call the parent's  
>>> __init__
>>> somewhere in the middle.
>>
>> I had a similar problem recently and resolved it using a complex
>> machinery (my requirements where a bit more complex than only  
>> this). I
>> used traits, but you could do this without traits (though it would be
>> harder).
>>
>> The thread concerning this problem and its solution can be found at
>> https://mail.enthought.com/pipermail/enthought-dev/2007-August/ 
>> 007820.html
>>
>> This is heavy machinery, but there are some ideas to steal.
>>
>> Ga?l
>>
>>
>> ------------------------------
>>
>> Message: 4
>> Date: Wed, 1 Aug 2007 13:31:58 -0700
>> From: "Barry Wark" <barrywark@gmail.com>
>> Subject: Re: [SciPy-user] Finding Neighboors
>> To: "SciPy Users List" <scipy-user@scipy.org>
>> Message-ID:
>>         <cd7634ce0708011331pee2ede1y39e2e03fbb0a31bf@mail.gmail.com>
>> Content-Type: text/plain; charset=WINDOWS-1252
>>
>> Hi all,
>>
>> Catching this conversation late. As jelle points out, BioPython has a
>> k-d tree implemetation, but it hasn't been converted to numpy yet (I
>> think it still uses Numeric). I've written a SWIG (with numpy type
>> maps) wrapper around the Approximate Nearest Neighbor library
>> (http://www.cs.umd.edu/~mount/ANN/), which includes both exact and
>> approximate k-d tree searches. Email me off list if you would like a
>> copy of the swig definition files. If there's interest, I will  
>> send it
>> on to the ANN writers for inclusion in the library itself.
>>
>> Barry
>>
>> On 7/31/07, Emanuele Zattin <emanuelez@gmail.com> wrote:
>>> Hi, you might want to take a look at kd-trees. No implementation in
>>> scipy, but it should not be too hard to achieve. As far as i can
>>> remember its definition in wikipedia includes some python code. Just
>>> my 2 cents :)
>>>
>>> On 8/1/07, Matthieu Brucher <matthieu.brucher@gmail.com> wrote:
>>>> Hi,
>>>>
>>>> I have an implementation, but it depends on my own matrix  
>>>> library... That's
>>>> a stopper... But it works.
>>>> I do not know the other templated matrix libraries very well,  
>>>> but I'd say I
>>>> do not need much to make it work with another library.
>>>>
>>>> Matthieu
>>>>
>>>> 2007/8/1, Alan G Isaac <aisaac@american.edu>:
>>>>> On Tue, 17 Apr 2007, Matthieu Brucher apparently wrote:
>>>>>> I wanted to know if there was a module in scipy that is able  
>>>>>> to find the
>>>>>> k-neighboors of a point ?
>>>>>> If so, is there an optimized one - tree-based search - ?
>>>>>> If not, I'm doing the optimized version.
>>>>>
>>>>> Hi Matthieu,
>>>>>
>>>>> Where did you go with this?
>>>>>
>>>>> Thanks!
>>>>> Alan
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> SciPy-user mailing list
>>>>> SciPy-user@scipy.org
>>>>> http://projects.scipy.org/mailman/listinfo/scipy-user
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> SciPy-user mailing list
>>>> SciPy-user@scipy.org
>>>> http://projects.scipy.org/mailman/listinfo/scipy-user
>>>>
>>>>
>>>
>>>
>>> --
>>> Emanuele Zattin
>>> ---------------------------------------------------
>>> -I don't have to know an answer. I don't feel frightened by not
>>> knowing things; by being lost in a mysterious universe without any
>>> purpose ? which is the way it really is, as far as I can tell,
>>> possibly. It doesn't frighten me.- Richard Feynman
>>> _______________________________________________
>>> SciPy-user mailing list
>>> SciPy-user@scipy.org
>>> http://projects.scipy.org/mailman/listinfo/scipy-user
>>>
>>
>>
>> ------------------------------
>>
>> Message: 5
>> Date: Wed, 1 Aug 2007 21:06:22 +0000 (UTC)
>> From: jelle <jelleferinga@gmail.com>
>> Subject: Re: [SciPy-user] Finding Neighboors
>> To: scipy-user@scipy.org
>> Message-ID: <loom.20070801T230532-760@post.gmane.org>
>> Content-Type: text/plain; charset=us-ascii
>>
>> Terrific!
>> ANN seems like a very useful module Barry!
>> Thanks for pointing out!
>>
>> Cheers,
>>
>> -jelle
>>
>>
>>
>> ------------------------------
>>
>> Message: 6
>> Date: Wed, 1 Aug 2007 15:14:25 -0600
>> From: "Fernando Perez" <fperez.net@gmail.com>
>> Subject: Re: [SciPy-user] Testing BOF at scipy'07?
>> To: "SciPy Users List" <scipy-user@scipy.org>
>> Message-ID:
>>         <db6b5ecc0708011414n6545fe0fx359fe3615db310ee@mail.gmail.com>
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> On 8/1/07, Karl Young <Karl.Young@ucsf.edu> wrote:
>>>
>>> Sounds great to me; I need to learn a lot more about developing good
>>> testing practices (given that it doesn't conflict with the  
>>> planned 3D
>>> visualization BOF on Thursday evening as I've already agreed to be
>>> counted for that).
>>
>> No worries, I also said I'd go to the Thursday viz one as well.
>>
>> I wonder if we could plan on 2 bofs a night.  Titus is already signed
>> up as moderator for one on Thursday:
>>
>> http://scipy.org/SciPy2007/BoFs
>>
>> and I'd like to have him in for the testing one as well.  If we could
>> plan something like
>>
>>       bof1             bof2
>>
>> 7-8   vis3d            bio
>> 8-9   testing          astronomy
>>
>> then we could have Titus available for both and those of us who said
>> yes to the vis3d one could also go to testing.
>>
>> Else we put the other bofs on Wednesday night, at the risk of getting
>> less people in.  Friday is probably out, since a lot of people leave
>> then...
>>
>> Opinions?
>>
>> f
>>
>>
>> ------------------------------
>>
>> Message: 7
>> Date: Wed, 1 Aug 2007 15:15:22 -0600
>> From: Michael Hearne <mhearne@usgs.gov>
>> Subject: [SciPy-user] 2d interpolation
>> To: scipy-user@scipy.org
>> Message-ID: <6F6365AF-B63F-4D6D-99BA-39D47179DA31@usgs.gov>
>> Content-Type: text/plain; charset="us-ascii"
>>
>> All:  I'm trying to use interp2d to replicate behavior in Matlab.
>>
>> The Matlab script:
>> x = reshape(1:16,4,4)';
>> xi = 1:0.5:4;
>> yi = [1:0.5:4]';
>> z = interp2(x,xi,yi,'linear')
>>
>> which results in the matrix:
>> z =
>>
>>      1.0000    1.5000    2.0000    2.5000    3.0000    3.5000     
>> 4.0000
>>      3.0000    3.5000    4.0000    4.5000    5.0000    5.5000     
>> 6.0000
>>      5.0000    5.5000    6.0000    6.5000    7.0000    7.5000     
>> 8.0000
>>      7.0000    7.5000    8.0000    8.5000    9.0000    9.5000    
>> 10.0000
>>      9.0000    9.5000   10.0000   10.5000   11.0000   11.5000    
>> 12.0000
>>     11.0000   11.5000   12.0000   12.5000   13.0000   13.5000    
>> 14.0000
>>     13.0000   13.5000   14.0000   14.5000   15.0000   15.5000    
>> 16.0000
>>
>> I had thought the following Python/numpy script would be equivalent,
>> but it is not:
>> from scipy.interpolate import interpolate
>> from numpy.random import randn
>> from numpy import *
>>
>> data = arange(16)
>> data = data+1
>> data = data.reshape(4,4)
>> xrange = arange(4)
>> yrange = arange(4)
>> X,Y = meshgrid(xrange,yrange)
>>
>> outgrid = interpolate.interp2d(X,Y,data,kind='linear')
>> xi = array([0,0.5,1,1.5,2,2.5,3])
>> yi = xi
>>
>> z = outgrid(xi,yi)
>>
>> This results in the matrix:
>> [[  1.           1.10731213   2.           2.89268787   3.
>> 3.25045605
>>      4.        ]
>> [  3.           2.57118448   4.           5.42881552   5.
>> 4.90975947
>>      6.        ]
>> [  5.           4.03505682   6.           7.96494318   7.
>> 6.56906289
>>      8.        ]
>> [  7.           5.49892917   8.          10.50107083   9.
>> 8.22836631
>>     10.        ]
>> [  9.           6.96280152  10.          13.03719848  11.
>> 9.88766973
>>     12.        ]
>> [ 11.           8.42667386  12.          15.57332614  13.
>> 11.54697315
>>     14.        ]
>> [ 13.           9.89054621  14.          18.10945379  15.
>> 13.20627657
>>     16.        ]]
>>
>> (Incidentally, is there a way to pretty-print arrays in numpy?  The
>> above is kind of ugly and hard to read)
>>
>> Is this some kind of spline interpolation that I don't understand?
>>
>> Thanks,
>>
>> Mike Hearne
>>
>>
>>
>>
>>
>>
>> ------------------------------------------------------
>> Michael Hearne
>> mhearne@usgs.gov
>> (303) 273-8620
>> USGS National Earthquake Information Center
>> 1711 Illinois St. Golden CO 80401
>> Senior Software Engineer
>> Synergetics, Inc.
>> ------------------------------------------------------
>>
>>
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL: http://projects.scipy.org/pipermail/scipy-user/attachments/ 
>> 20070801/5ae71590/attachment.html
>>
>> ------------------------------
>>
>> _______________________________________________
>> SciPy-user mailing list
>> SciPy-user@scipy.org
>> http://projects.scipy.org/mailman/listinfo/scipy-user
>>
>>
>> End of SciPy-user Digest, Vol 48, Issue 6
>> *****************************************
>>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user




------------------------------------------------------
Michael Hearne
mhearne@usgs.gov
(303) 273-8620
USGS National Earthquake Information Center
1711 Illinois St. Golden CO 80401
Senior Software Engineer
Synergetics, Inc.
------------------------------------------------------


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20070801/50c08d45/attachment-0001.html 


More information about the SciPy-user mailing list