I have values on the surface of a unit sphere for certain angles on a polar grid. I'm trying to interpolate the values for the off-grid sphere points but can't seem to find any way to do this in Tensorflow. Ideally, I would like to use spherical bivariate spline interpolation.
Scipy has an interpolation type named RectSphereBivariateSpline which does exactly what I need but can't seem to find something like this for Tensorflow (can't use Scipy since I need backpropagation). I tried to follow the Scipy's approach but got stuck on trying to comprehend FITPACK which is written in Fortran. On the other side, tensorflow-graphics only has support for 1D B-spline interpolation.
Is there a function in Tensorflow (or some of its extensions) that could do interpolation for spherical values?
Related
I have plotted a 3D radiation plot using Python, with theta on the x-axis and phi on the y-axis and magnitudes along z. I initially used numpy.meshgrid to create the 2d array for thetas and phis. Now how can I find the peak points( main lobe and side lobes) from this graph?
find_peak function of the scipy.signal library seems to deal with 1d array only.
Try to use maximum_filter from scipy.ndimage.filters, or even just a simple thresholding could do the trick, provided prior smoothing/transformations like erosion/dilation.
Hi am trying to calculate a vector of the major axis through a 3d mesh in python (using open3d library to interact with the mesh).
I have turned the mesh into a pointcloud using a poisson distribution (1000 points in a numpy array) and have thought about using scikit learn and its PCA functionality to try and get the value of this vector.
From googling around I think I'm on the right tract but have little idea about how to use the PCA function to get what I want.
I think I need to extract the largest eigenvalue from the pointcloud and its accompanying eigenvector - which should hopefully be what I'm looking for.
Have little idea how to do this as I am completely unfamiliar with scikit learn.
Any help please?
Have found a solution using trimesh library:
used the principal_inertia_vectors function to find the 3 largest eigenvalues and corresponding eigenvectors. The eigen vectors correspond to the 3 axes of the mesh.
This functions runs straight off the mesh therefore not requiring conversion to a point cloud.
I've been tasked to develop an algorithm that, given a set of sparse points representing measurements of an existing surface, would allow us to compute the z coordinate of any point on the surface. The challenge is to find a suitable interpolation method that can recreate the 3D surface given only a few points and extrapolate values also outside of the range containing the initial measurements (a notorious problem for many interpolation methods).
After trying to fit many analytic curves to the points I've decided to use RBF interpolation as I thought this will better reproduce the surface given that the points should all lie on it (I'm assuming the measurements have a negligible error).
The first results are quite impressive considering the few points that I'm using.
Interpolation results
In the picture that I'm showing the blue points are the ones used for the RBF interpolation which produces the shape represented in gray scale. The red points are instead additional measurements of the same shape that I'm trying to reproduce with my interpolation algorithm.
Unfortunately there are some outliers, especially when I'm trying to extrapolate points outside of the area where the initial measurements were taken (you can see this in the upper right and lower center insets in the picture). This is to be expected, especially in RBF methods, as I'm trying to extract information from an area that initially does not have any.
Apparently the RBF interpolation is trying to flatten out the surface while I would just need to continue with the curvature of the shape. Of course the method does not know anything about that given how it is defined. However this causes a large discrepancy from the measurements that I'm trying to fit.
That's why I'm asking if there is any way to constrain the interpolation method to keep the curvature or use a different radial basis function that doesn't smooth out so quickly only on the border of the interpolation range. I've tried different combination of the epsilon parameters and distance functions without luck. This is what I'm using right now:
from scipy import interpolate
import numpy as np
spline = interpolate.Rbf(df.X.values, df.Y.values, df.Z.values,
function='thin_plate')
X,Y = np.meshgrid(np.linspace(xmin.round(), xmax.round(), precision),
np.linspace(ymin.round(), ymax.round(), precision))
Z = spline(X, Y)
I was also thinking of creating some additional dummy points outside of the interpolation range to constrain the model even more, but that would be quite complicated.
I'm also attaching an animation to give a better idea of the surface.
Animation
Just wanted to post my solution in case someone has the same problem. The issue was indeed with scipy implementation of the RBF interpolation. I tried instead to adopt a more flexible library, https://rbf.readthedocs.io/en/latest/index.html#.
The results are pretty cool! Using the following options
from rbf.interpolate import RBFInterpolant
spline = RBFInterpolant(X_obs, U_obs, phi='phs5', order=1, sigma=0.0, eps=1.)
I was able to get the right shape even at the edge.
Surface interpolation
I've played around with the different phi functions and here is the boxplot of the spread between the interpolated surface and the points that I'm testing the interpolation against (the red points in the picture).
Boxplot
With phs5 I get the best result with an average spread of about 0.5 mm on the upper surface and 0.8 on the lower surface. Before I was getting a similar average but with many outliers > 15 mm. Definitely a success :)
I'm new to python. i have a set of autonomous equation, trying to analyse the asymptotic behaviour using phase space analysis.
f(x,y)=a*x*y((y**2)+a+c)
g(x,y)=a+(y**3)+((y**3)+(y**2)(x+a))
where xand y are the variables ? i seek help to find the critical points, jacobian and eigen values, also to get the phase space plot ?
Use the symPy Library.
It has a built in symbolic solver for Jacobians.
You can use the Eq method to solve for your critical points.
Use the eigenvals method to find the eigenvals of your Jacobian.
Lastly you can employ the quiver module from Scipy along with pyplot to plot your phase space plot. Good luck.
Is anybody of you aware of a higher order interpolation method (Catmull-Rom splines, cubic interpolation, etc.) for 2D contouring in Python?
Skimage, Matplotlib, and OpenCV provide the functions measure.find_contours(), contours() and findContours() respectively, but all are based on linear interpolation (also known as marching squares), I'm looking into something with higher accuracy in Python, preferably. Any pointers would be highly appreciated.
https://www.dropbox.com/s/orgr2yqhbbk2xnr/test.PNG
In the image above I'm trying to extract iso-value 25 from the scalar field of f(x,y)=x^3+y^3. I'm looking for 6 points with better accuracy than the 6 red points given by linear interpolation.
For unstructured 2d-data (or triangulated data), you might be interested by the following class:
http://matplotlib.org/api/tri_api.html?highlight=cubictriinterpolator#matplotlib.tri.CubicTriInterpolator
which provides a Clough-Tocher (cubic) interpolator from a user-defined Triangulation and field defined at triangulation nodes. It can also be used through the helper class UniformTriRefiner:
http://matplotlib.org/api/tri_api.html?highlight=refine_field#matplotlib.tri.UniformTriRefiner.refine_field
http://matplotlib.org/mpl_examples/pylab_examples/tricontour_smooth_user.png
Nevertheless the choice of the adapted interpolation depends of course of your data set.