'How to fill spherical volume with polar coordinates, with resonable interpolation?
I have a set of points in polar coordinates (sample below, angle in degrees, note the irregular radius). The angle is with respect to the Z-axis, and the function I am plotting is symmetric about rotations around the Z-axis.
radius_vec = [0.1, 0.1, 0.1, 0.1, 0.1, 1, 1, 1, 1, 1, 1.5, 1.5, 1.5, 1.5, 1.5]
angle_vec = [36, 72, 108, 144, 180, 36, 72, 108, 144, 180, 36, 72, 108, 144, 180]
value_vec = [1e2, 1.1e2, 1.5e2, 1.8e2, 2.5e2, 1e1, 1.1e1, 1.5e1, 1.8e1, 2.5e1, 1e0, 1.1e0, 1.5e0, 1.8e0, 2.5e0]
Originally, I tried using SciPy's 'interp2d' function, (example below).
interpobj = interp2d(x=ang_vec,
y=rad_vec,
z=dose_vec,
kind='cubic')
img3d = np.zeros((5, 5, 5))
for i in range(-img3d.shape[0] // 2, img3d.shape[0] // 2):
for j in range(-img3d.shape[1] // 2, img3d.shape[1] // 2):
for k in range(-img3d.shape[2] // 2, img3d.shape[2] // 2):
rad, ang, _ = convert_cartesian_to_spherical(i, j, k)
car_img3d[i + img3d.shape[0] // 2,
j + img3d.shape[1] // 2,
k + img3d.shape[2] // 2] = interpobj(rad, ang)
However, I reliably get non-sense results (values exceeding 1e7 all over the place, negative values, etc.), and I also get the following warning:
RuntimeWarning: A theoretically impossible result when finding a smoothing spline
with fp = s. Probable causes: s too small or badly chosen eps.
(abs(fp-s)/s>0.001)
kx,ky=3,3 nx,ny=52,31 m=2304 fp=51707033245.934654 s=0.000000
warnings.warn(RuntimeWarning(_iermess2[ierm][0] + _mess))
If it helps I know my data (very roughly) follows: A*exp(-k*r) cos(theta)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
