interpolation

Differentiate a 2d cubic spline in python

隐身守侯 提交于 2020-05-09 06:56:13
问题 I'm using interpolate.interp2d() to fit a 2-D spline over a function. How can I get the first derivative of the spline w.r.t. each of the dependent variables? Here is my code so far, Z are the descrete points on a mesh-grid that I have from scipy import interpolate YY, XX = np.meshgrid(Y, X) f = interpolate.interp2d(AA, XX, Z, kind='cubic') So, I need df/dx and df/dy. Note also that my Y-grid is not evenly spaced. I guess I can numerically differentiate Z and then fit a new spline, but it

Simple, efficient bilinear interpolation of images in numpy and python

主宰稳场 提交于 2020-04-29 05:45:18
问题 How do I implement bilinear interpolation for image data represented as a numpy array in python? 回答1: I found many questions on this topic and many answers, though none were efficient for the common case that the data consists of samples on a grid (i.e. a rectangular image) and represented as a numpy array. This function can take lists as both x and y coordinates and will perform the lookups and summations without need for loops. def bilinear_interpolate(im, x, y): x = np.asarray(x) y = np

Simple, efficient bilinear interpolation of images in numpy and python

眉间皱痕 提交于 2020-04-29 05:42:49
问题 How do I implement bilinear interpolation for image data represented as a numpy array in python? 回答1: I found many questions on this topic and many answers, though none were efficient for the common case that the data consists of samples on a grid (i.e. a rectangular image) and represented as a numpy array. This function can take lists as both x and y coordinates and will perform the lookups and summations without need for loops. def bilinear_interpolate(im, x, y): x = np.asarray(x) y = np

Spline interpolation in 3D in python

谁说我不能喝 提交于 2020-04-11 08:27:28
问题 I am searching the equivalent Matlab command Vq = interp3(X,Y,Z,V,Xq,Yq,Zq) in Python. In Matlab I can use the method 'spline' interpolation, which I can not find in python for 3D data. There exists scipy.interpolate.griddata, but it doesn't have the option spline for 3D data. The data I want to interpolate is a 3D matrix (51x51x51), which is regularly distributed on a 3D grid. scipy.interpolate.Rbf may be the option, but I don't get it working: xi = yi = zi = np.linspace(1, 132651, 132651)

Spline interpolation in 3D in python

怎甘沉沦 提交于 2020-04-11 08:27:10
问题 I am searching the equivalent Matlab command Vq = interp3(X,Y,Z,V,Xq,Yq,Zq) in Python. In Matlab I can use the method 'spline' interpolation, which I can not find in python for 3D data. There exists scipy.interpolate.griddata, but it doesn't have the option spline for 3D data. The data I want to interpolate is a 3D matrix (51x51x51), which is regularly distributed on a 3D grid. scipy.interpolate.Rbf may be the option, but I don't get it working: xi = yi = zi = np.linspace(1, 132651, 132651)

Scipy interpolate.splprep error “Invalid Inputs”

笑着哭i 提交于 2020-03-18 05:13:08
问题 I am trying to interpolate a curve to a set of (x,y) points using SciPy's interpolate.splprep method, using the procedure followed in this StackOverflow answer. My code (with the data) is given below. Please excuse me for using this large dataset, as the code works perfectly fine on a different dataset. Kindly scroll to the bottom to see the implemetation. #!/usr/bin/env python3 import numpy as np import matplotlib.pyplot as plt from scipy import interpolate # --------------------------------

How can I solve this 3D regular grid interpolation problem

℡╲_俬逩灬. 提交于 2020-03-05 06:01:07
问题 I am a new python user. I have a h5 file, which is a snapshot of gravitational potential at a fixed redshift. I have read the h5 file in python and now I want to write a code which will give the value of the gravitational potential for given values of (x, y, z) by using trilinear interpolation. Can anyone of you please help me to do that? For your kind consideration, the code is given below: In [1]: import numpy as np In [2]: import h5py In [3]: from scipy.interpolate import

Unexpected results from scipy.interpolate.Rbf

血红的双手。 提交于 2020-02-25 13:40:38
问题 I am getting some errors when interpolating with RBF. Here is an example in 1D. I think that it has to do with how close my y values are to each other. Is there any fix for this? import numpy as np from scipy.interpolate import Rbf, interp1d import matplotlib.pyplot as plt x = np.array([0.77639752, 0.8136646, 0.85093168, 0.88819876, 0.92546584, 0.96273292, 1.]) y = np.array([0.97119742, 0.98089758, 0.98937066, 0.99540737, 0.99917735, 1., 0.99779049]) xi = np.linspace(min(x),max(x),1000) fig =

Interpolating irregularly located data to

坚强是说给别人听的谎言 提交于 2020-02-04 00:41:09
问题 I am trying to display a colored surface in Worlwind Java, where the colors depend on latitude/longitude located values (e.g temperature) from a set of irregularly located data. I'm using the example found in the gov.nasa.worldwindx.examples.analytics package. There is a class Interpolator2D there but it doesn't seem to be able to compute irregularly located data. As far as I know I'm missing only one thing in order to do that : a way to generate a grid of regularly placed points from a set

MySQL php Linear Interpolation of Table

微笑、不失礼 提交于 2020-02-03 22:00:23
问题 I have a table titled "psytable_moist_air" shown below: I'm trying to develop a MySQL statement that will interpolate a value that may be between records. (EDIT: If it is easier to do the math in PHP I'm open for that solution too!] Example: I would like to know the "hda" value where "T" = 17.8. Notice there is no record where "T"=17.8. However, because this table is linearly related, I can get the "hda" value where "T"=17 and the "hda" value where "T"=18 and do a linear interpolation of the