[SciPy-User] How can I interpolate array from spherical to cartesian coordinates?
Joseph Smidt
josephsmidt at gmail.com
Tue Feb 12 01:30:11 EST 2013
Chuck and everyone,
Okay, I will give a more specific example. Consider the following
script:
from pylab import *
# Build 3D arrays for spherical coordinates.
r, theta, phi = mgrid[0:201,0:201,0:201]
r = r/20.0 # r goes from 0 to 10.
theta = theta/200.0*pi # Theta goes from 0 to pi
phi = phi/200.0*2*pi # Phi goes from 0 to 2pi
# Density is spherically symmetric. Only depends on r.
density = exp(-r**2/20.0)
# Plot density. Doesn't look spherical because
# not in cartesian coordinates.
imshow(squeeze(f[:,:,1]))
Okay, so density is defined in terms of spherical coordinates. I would
like a function that transforms density to density_prime to
cartesian coordinate arrays x, y, and z such that the r = 0 line
gets mapped to x = 0, y = 0 z = 0. The r = 1 line gets mapped to x =
sin(theta)*cos(phi), y = sin(theta)*sin(phi), z = cos(phi), the r = 2 line
gets mapped to... etc. So that when I plot density_prime it looks like a
nice spherical function peaking at x = 0, y = 0 z = 0 and getting small for
x, y, and z large.
If anyone knows how I could do such a transformation to get density_prime
with scipy.ndimage.interpolation.map_coordinates or any other interpolator
for N-dim data I would appreciate it.
On Mon, Feb 11, 2013 at 11:07 PM, Charles R Harris <
charlesr.harris at gmail.com> wrote:
>
>
> On Mon, Feb 11, 2013 at 8:48 PM, Joseph Smidt <josephsmidt at gmail.com>wrote:
>
>> I have an array of density values in spherical coordinates. More
>> specifically I have an array called density with shape (180,200,200). I
>> also have an array called r_coord, theta_coord and phi_coord also with
>> shape (180,200,200) being the spherical coordinates for the density array.
>>
>> I would like to map this density to cartesian coordinates using python. I
>> will need therefore a new array density_prime which is interpolated over
>> cartesian coordinates x_coord, y_coord and z_coord. I found
>> scipy.ndimage.interpolation.map_coordinates which looks promising but I
>> can't figure out how to get it to work.
>>
>>
> I'm not clear on what you are trying to do, but I'm guessing you have
> sample points on a sphere and you want to find interpolated values at other
> points on the sphere, the cartesian coordinates being a means rather than
> an end. Is that the case? If not, can you be more explicit.
>
> Chuck
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
--
------------------------------------------------------------------------
Joseph Smidt <josephsmidt at gmail.com>
Theoretical Division
P.O. Box 1663, Mail Stop B283
Los Alamos, NM 87545
Office: 505-665-9752
Fax: 505-667-1931
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20130211/b321809e/attachment.html>
More information about the SciPy-User
mailing list