How to interpolate from nonuniform 2D locations to regular grid? - r

I have nonuniformly located samples of an image, and would like to interpolate to a regular grid because (among other things) most image graphics functions expect a regular grid.
I notice there are some MatLab functions (see Image interpolation from random pixels for example) which apparently will do this, but couldn't find an R-package that does.
Here's a simple example.
#make up some 2D func
y<-matrix(rep(1:10,10) -.5 + runif(100),nrow=10)
x<-matrix(rep(1:10,10) -.5 + runif(100),nrow=10)
inmat<-sin(x) + cos(y)
So the values of inmat are on random locations. I want some sort of outmat<-interpolate(inmat,x,y,gridx,gridy) function where inmat , x,and y are either all matrices or all vectors (unwrapped matrices).
I see also that SciPy has http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp2d.html which does this. Is there such a function in an R package or do I need to port from SciPy or MatLab code?

The linked pages provide pointers to a gazillion R packages which do Kriging or other interpolation functions.
I'm posting my personal choice as an answer just to close out this question.
I found akima::interp to be a straightforward function to do 2D interpolation on arbitrary collections of sample locations.
That doesn't mean it's going to be best for everyone, and my guess is those working with geodata may prefer packages designed to muck with specific geo-survey-related file types and lat/long coordinate systems.

Related

Is there any real example of dimension reduction of a hyperspectral image?

Can any one suggest me a real example of dimension reduction using any model like PCA,ICA or others of Hyper spectral image with R or Python language.
Dimension reduction is critical when dealing with hyperspectral data and it is quite easily implementable in python.
Import the spectral python library and use principal_components function on your data to get the PCA result.
As for example, you should check out this

How to add zoom option for wordcloud in Shiny (with reproducible example)

Could you please help me to add zooming option for wordcloud
Please find reproducible example #
´http://shiny.rstudio.com/gallery/word-cloud.html´
I tried to incorporate rbokeh and plotly but couldnt find wordcloud equivalent render function
Additionally, I found ECharts from github #
´https://github.com/XD-DENG/ECharts2Shiny/tree/8ac690a8039abc2334ec06f394ba97498b518e81´
But incorporating this ECharts are also not convenient for really zoom.
Thanks in advance,
Abi
Normalisation is required only if the predictors are not meant to be comparable on the original scaling. There's no rule that says you must normalize.
PCA is a statistical method that gives you a new linear transformation. By itself, it loses nothing. All it does is to give you new principal components.
You lose information only if you choose a subset of those principal components.
Usually PCA includes centering the data as a Pre Process Step.
PCA only arranges the data in its own Axis (Eigne Vectors) System.
If you use all axis you lose no information.
Yet, usually we want to apply Dimensionality Reduction, intuitively, having less coordinates for the data.
This process means projecting the data into Sub Space which is spanned by only some of the Eigen Vectors of the data.
If one chose wisely the number of vectors one might end up with a significant reduction in the number of dimensions of the data with negligible loss of data / information.
The way to do so is by choosing Eigen Vectors which their Eigen Values sum to most of the data power.
PCA itself is invertible, so lossless.
But:
It is common to drop some components, which will cause a loss of information.
Numerical issues may cause a loss in precision.

R equivalent to matlab griddata, scatteredInterpolant, and/or TriScatteredInterp

We do a lot of full field 3D numerical simulations (CFD, FEA, etc.). The solutions take a long time to run. We often interpolate from solutions rather than rerun every case. We also interpolate between multiple solutions, which leads to even higher dimensional interpolation (like adding time, so x,y,z,t,v).
Matlab does a great job of reading data V at irregular grid of X,Y,Z coordinates, and interpolating from V using griddata, scatterdInterpolan, and/or TriScatteredInterp. For a variety of reasons, I've switched to R. This remains one key area I've not been able to find as good R equivalent. 'akima' only does x,y,V (not, x,y,z,V, much less even higher dimensions like x,y,z,t,v).
The next best thing I've found has been 'krigging'. But krigging behaves more like model fitting and projection, and often does not behave well between irregular grid points. So it's not nearly as robust as simple direct linear interpolation.
Matlab has had griddata for several decades. It's hard to believe R doesn't have an equivalent out there. Any suggestions? Or is there at least a way to use krigging to yield effectively the same result as a direct linear interpolation?
Jonathan
You might start by looking at the package "tripack" to do Delaunay triangulation, which gives you the first step in duplicating scatteredInterpolant().
R interpp() is equivalent to MATLAB scatteredInterpolant().

Howto implement the inverse Laplace transform in javascript?

I'm writing an javascript applet make it easy for others to see how a system with and without proportional controller works and what the outputs are.
First a little explanation on the applet (You can skip this if you want, the real question is in the last paragraph.):
I managed to implement a way of input for the system (in the frequency domain), so the applet can do the math and show the users their provided system. At the moment the applet computes the poles and zeros of the system, plots them together with the root-Loci, plot the Nyquist curve of the system and plot the Bode plots of the system.
The next thing I want the applet to do is calculating and plotting the impulse response. To do so I need to perform an inverse Laplace transformation on the transferfunction of the system.
Now the real question:
I have a function (the transferfunction) in the frequency domain. The function is a rational function, stored in the program as two polynomes (numerator and denominator stored by their coefficients). What would be the best way of transforming this function to the time domain? (inverse Laplace). Or is there an open-source library which implements this already. I've searched for it already but only found some math libraries for with more simple mathematics.
Thanks in advance
This is a fairly complex and interesting problem. A couple of ideas.
(1) If the solution must be strictly JS: the inverse LT of some rational functions can be found via partial fraction decomposition. You have numerical coefficients for the polynomials, right? You can try implementing a partial fraction decomposition in JS or maybe find one. The difficulty here is that it is not guaranteed that you can find the inverse LT via partial fractions.
(2) Use JS as glue code and send the rational function to another process (running e.g. Sympy or Maxima) to compute the inverse LT. That way you can take advantage of all the functions available, but it will take some work to connect to the other process and parse the result. For Maxima at least, there have been many projects which use Maxima as the computational back-end; see: http://maxima.sourceforge.net/relatedprojects.html
Problem is solved now. After checking out some numerical methods I went for the partial fraction decomposition by using the poles of the system and the least square method to calculate the coeficients. After this the inverse LT wasn't that hard to find.
Thx for your suggestions ;)
Ask me if you want to look at the code.

Best R package for doing Fourier Analysis for three dimensional function

I want to find a function that approximates a function that produces output that looks like:
Blue, Red and Green are the X, Y and Z space dimensions.
What R package should I use?
I realize this question is very old, but has it been resolved yet for you?
First the short answer: You should use
Library TuneR for the function periodogram()
Library strucchange for the function Wave() with which you build an object that will plot nicely
Considering your comment about losing information if you apply a fourier-transform on the 3 dimensions separately instead of, say, on the vector for each point in time: You will lose information anyway in the fourier-transform. The best you can do is make sure the axes are orthogonal. Looking at your data, even running the fourier over only one dimension will give you the major frequency without problems.

Resources