[SciPy-user] Fwd: interpolation question

Michael Hearne mhearne@usgs....
Wed Oct 24 12:51:48 CDT 2007

John - I thought about it some more, and I think part of my bias  
comes from a background of spatial computing, and working with  
remotely sensed images.   Most of the time when I'm working with 2d  
grid data, that grid represents _geographic_ data, where each grid  
"cell" represents a spot on the ground.

For example, it is common to represent gridded spatial data with the  
following parameters:
Upper left X coordinate (i.e. longitude) of the center of the upper  
left grid cell
Upper left Y coordinate (i.e. latitude) of the center of the upper  
left grid cell
X dimension of each grid cell in linear units
Y dimension of each grid cell in linear units
Number of rows
Number of columns

Then if you have a 2d array in numpy, getting geographic coordinates  
from grid coordinates is as simple as:
spatial_x = ulx + col*xdim
spatial_y = uly - row*ydim

For this kind of computing, it is much less confusing if the data at  
[0,ncols] is at a greater longitude than the data at [0,0], and data  
at [0,0] is at a greater latitude than the  data at [nrows,0].

Thinking this way for so many years has probably caused me to think  
that it is "natural" for rows to be the Y dimension, and columns to  
be the X dimension.  I get screwed up going between math angles and  
geographic direction too!

Your points are correct and well taken, and looking at the  
documentation for RectBivariateSpline it _does_ say that x  
corresponds to the first dimension, and y corresponds to the second.   
My bad for not RTFM.


Mike Hearne
On Oct 24, 2007, at 10:00 AM, John Travers wrote:

> Hi Mike,
> On 24/10/2007, Michael Hearne <mhearne@usgs.gov> wrote:
>> John - I guess I have a different bias - in Matlab (and now numpy)  
>> I've
>> always thought of rows being in the y direction, and columns as  
>> being in the
>> x direction.  This explains my confusion with the x and y parameters.
>> Is it uncommon to think of columns as being in the x direction,  
>> and rows in
>> y?
> I think we are just confusing each other. If you look at my bad ascii
> art 2d-array below:
> --------------------
> | 0,0 | 0,1 | 0,2 |
> --------------------
> | 1,0 | 1,1 | 1,2 |
> --------------------
> My understanding is:
> This is a 2 by 3 array. The first index runs from 0 to 1 inclusive.
> This indexes the rows of the array. The second index runs from 0 to 2
> inclusive and indexes the columns of the array. So 1,0 is the 2nd row,
> 1st column.  Now I regard x as the first index (because I think of it
> as the first axis). Therefore x corresponds to the rows. So obviously
> y is the second index and hence corresponds to the columns. I think
> maybe out confusion comes from the fact that for a given column (or y
> value) we index through it by row (or x value) and maybe you think of
> this as each set of x's lies in a column?
> The fortran bias comes from the fact that in fortran it is more
> efficient to change the inner index (row or x) fastest. This agrees
> with my idea of x corresponding to the first index (rows) as x is
> often the fastest changing axis (though this is an arbitrary choice).
> Anyway I think Matlab, numpy and Fortran all work like this in terms
> of indexing.
> But numpy (and Matlab?) is written in c and therefore it is usually
> more efficient to change the second index fastest. I say usually as
> numpy also supports storing arrays in fortran order, but users don't
> normally need to worry about this. So I guess another source of
> confusion is that if users want x to be the most efficiently indexed
> axis, they should consider it to be represented by the second index
> (or columns).
> By the above interpretation I think my implementation of
> RectBivariateSpline is consistent with the first index changing x. If
> you think this is a bad choice or inconsistent with the rest of
> scipy/numpy I'd like to hear.
> I apologise if all this is too basic for you, I don't mean to insult!
> Cheers,
> John
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user

Michael Hearne
(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/20071024/4bc8731a/attachment.html 

More information about the SciPy-user mailing list