interpolation

Interpolate values from a grid efficiently in R

只谈情不闲聊 提交于 2019-12-04 08:19:32
I have a grid of ocean depth data by location, and am trying to interpolate depth values for a selection of GPS points. We've been using RSAGA::pick.from.points, which works fine for small data sets. require(RSAGA) depthdata <- cbind.data.frame(x=c(74.136, 74.135, 74.134, 74.133, 74.132, 74.131, 74.130, 74.129, 74.128, 74.127), y=rep(40, times=10), depth=c(-0.6, -0.6, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9, -0.6, -0.6)) mylocs <- rbind(c(-74.1325, 40), c(-74.1305, 40)) colnames(mylocs) <- c("x", "y") results <- pick.from.points(data=mylocs, src=depthdata, pick=c("depth"), method="nearest.neighbour

scipy.ndimage.zoom result depends on image size

烂漫一生 提交于 2019-12-04 07:35:18
I noticed that the result of scipy.ndimage.zoom depends on the size of the original image. In the following code sample a checkerboard image is generated and then zoomed with ndimage.zoom. If one checkerboard tile is just 2x2 pixels, the zoom factor seems to be too large and the resulting image gets cropped. In contrast, if the tile has dimensions 10x10, the result looks good. from __future__ import division import numpy as np from scipy import ndimage, misc import wx y,x = 2,2 # change tile size here imgdata = np.zeros((y,x),dtype='uint8') imgdata[y/2:,x/2:] = 255 imgdata[:y/2,:x/2] = 255

RBF interpolation: LinAlgError: singular matrix

对着背影说爱祢 提交于 2019-12-04 06:09:31
The following call: rbf = Rbf(points[0], points[1], values,epsilon=2) results in an error: LinAlgError: singular matrix with the following values: In [3]: points Out[3]: (array([71, 50, 48, 84, 71, 74, 89, 76, 70, 77, 74, 79, 83, 71, 72, 78, 73, 84, 75, 65, 73, 82, 48, 86, 74, 86, 66, 74, 68, 74, 81, 74, 88, 66, 57, 50, 72, 86, 72, 92, 81, 67, 82, 78, 69, 70, 73, 71, 76, 72, 74, 75]), array([32, 34, 4, 35, 1, 7, 47, 16, 37, 14, 65, 18, 32, 4, 3, 27, 25, 34, 18, 25, 6, 25, 34, 41, 16, 35, 44, 2, 32, 2, 37, 60, 45, 32, 33, 42, 54, 31, 18, 38, 24, 18, 45, 48, 9, 63, 56, 45, 9, 59, 5, 12])) In [4]

How to zoom out an image by Bilinear Interpolation in java?

喜夏-厌秋 提交于 2019-12-04 05:50:19
问题 I am trying to read an image, zoom it in to 80*60 and then zoom out the resulted image 5 times by bilinear Interpolation method. But I get this error : Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4800 . Can anyone help me please? this is what I have done : import java.awt.Color; import java.awt.Graphics2D; import java.awt.Image; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.awt.image.DataBufferByte; import java.awt.image

Lagrange interpolation in Python

五迷三道 提交于 2019-12-04 05:45:14
I want to interpolate a polynomial with the Lagrange method, but this code doesn't work: def interpolate(x_values, y_values): def _basis(j): p = [(x - x_values[m])/(x_values[j] - x_values[m]) for m in xrange(k + 1) if m != j] return reduce(operator.mul, p) assert len(x_values) != 0 and (len(x_values) == len(y_values)), 'x and y cannot be empty and must have the same length' k = len(x_values) return sum(_basis(j) for j in xrange(k)) I followed Wikipedia , but when I run it I receive an IndexError at line 3! Thanks Check the indices, Wikipedia says "k+1 data points", but you're setting k = len(x

Plot specified area of a surface mesh with color

落爺英雄遲暮 提交于 2019-12-04 05:44:27
问题 I have data for 3D facia surface mesh. Data are available here, where vb.xlsx contains coordinates for 7160 3D vertices and it.xlsx contains face information. The color coding.txt is a matrix of 7160*1 with elements of either 1 or 2. I want the surface area (not just vertices!) enclosed by vertices which are coded 1 to be plotted in a different color from areas covered by vertices coded 2. For example, if vertices covering nose and upper lip are coded 1 and other facial areas are coded 2,

Spline interpolation in matlab in order to predict value

允我心安 提交于 2019-12-04 05:13:29
问题 I have the situation like on this image below: This plot is the result of two vectors: fi = [41.309180589278, 41.8087915220215, 42.8081880760916, ... 43.8078181874395, 44.8076823745539, 45.8077808710707, 46.3079179803177] m = [1.00047608139868, 1.00013712198767, 0.999680989440986, ... 0.999524195487826, 0.999671686649694, 1.00012913666266, 1.00047608139868] I need to get the values of fi where m is equal to 1. So approximately that will be 42.2 and 42.5. I tried to do spline interpolation: xq

How to pass arrays into Scipy Interpolate RectBivariateSpline?

∥☆過路亽.° 提交于 2019-12-04 04:10:17
问题 I am creating a Scipy Interpolate RectBivariateSpline as follows: import numpy as np from scipy.interpolate import RectBivariateSpline x = np.array([1,2,3,4]) y = np.array([1,2,3,4,5]) vals = np.array([ [4,1,4,4,2], [4,2,3,2,6], [3,7,4,3,5], [2,4,5,3,4] ]) rect_B_spline = RectBivariateSpline(x, y, vals) I then try to pass-in an array of x and y points: a = np.array([3.2, 3.8, 2.2]) b = np.array([2.4, 4.3, 3.3]) print(rect_B_spline(a, b)) To which I get an error as follows: Traceback (most

Spline representation with scipy.interpolate: Poor interpolation for low-amplitude, rapidly oscillating functions

*爱你&永不变心* 提交于 2019-12-04 04:08:49
问题 I need to (numerically) calculate the first and second derivative of a function for which I've attempted to use both splrep and UnivariateSpline to create splines for the purpose of interpolation the function to take the derivatives. However, it seems that there's an inherent problem in the spline representation itself for functions who's magnitude is order 10^-1 or lower and are (rapidly) oscillating. As an example, consider the following code to create a spline representation of the sine

Using Radial Basis Functions to Interpolate a Function on a Sphere

做~自己de王妃 提交于 2019-12-04 04:08:24
First, a bit of background: I am using spherical harmonics as an example of a function on the surface of a sphere like the front spheres in this image: I produced one of these spheres, coloured according to the value of the harmonic function at points on its surface. I do this first for a very large number of points, so my function is very accurate. I've called this my fine sphere. Now that I have my fine sphere, I take a relatively small number of points on the sphere. These are the points I wish to interpolate from, the training data, and I call them interp points. Here are my interp points,