interpolation

How to improve performance when interpolating on 3d data with SciPy

痴心易碎 提交于 2019-12-04 13:08:52
I have 3d-data representing the atmosphere. Now I want to interpolate this data to a common Z coordinate (what I mean by that should be clear from the function's doctring). The following code works fine, but I was wondering if there were a way to improve the performance ... def interpLevel(grid,value,data,interp='linear'): """ Interpolate 3d data to a common z coordinate. Can be used to calculate the wind/pv/whatsoever values for a common potential temperature / pressure level. grid : numpy.ndarray The grid. For example the potential temperature values for the whole 3d grid. value : float The

Interpolation through fourier space padding

别来无恙 提交于 2019-12-04 12:54:49
I recently tried to implement on matlab a simple example of interpolation method using zéro padding in the fourier domain. But I am not able to get this work properly, I always have a small frequency shift, barely not visible in fourier space, but thay generates a huge error in time space. As zéro padding in the fourier space seems to be a common (and fast) interpolation method, I assume that there is something I am missing: Here is the matlab code: clc; clear all; close all; Fe = 3250; Te = 1/Fe; Nech = 100; F1 = 500; F2 = 1000; FMax = 1500; time = [0:Te:(Nech-1)*Te]; timeDiscrete = [1:1:Nech

What does scipy.interpolate.InterpolatedUnivariateSpline.get_coeffs return?

三世轮回 提交于 2019-12-04 12:37:40
I tried the following: spline= interpolate.InterpolatedUnivariateSpline(X, Y, k=3) coefs= spline.get_coeffs() With five values in each of X and Y , I ended up with coefs also having five values. Given that five data points implies four spline sections, and that a cubic polynomial has four coefficients, I would have expected to get four times four= 16 coefficients. Does anyone know how to interpret the values that are returned by the get_coeffs method? Is there any place where this is documented? These are not the coefficients of x, x**2, and so forth: such monomials are ill-suited to

How to create multiple stop gradient fragment shader?

老子叫甜甜 提交于 2019-12-04 11:22:03
问题 I'm trying to create an OpenGL ES 2.0 fragment shader that outputs multiple stop gradient along one axis. It should interpolate between multiple colors at points defined in percents. I've achieved this by using if s the fragment shader, like this: float y = gl_FragCoord.y; float step1 = resolution.y * 0.20; float step2 = resolution.y * 0.50; if (y < step1) { color = white; } else if (y < step2) { float x = smoothstep(step1, step2, y); color = mix(white, red, x); } else { float x = smoothstep

Python Interpolation with matplotlib/basemap

岁酱吖の 提交于 2019-12-04 11:17:50
I am rather new to programming and am having a very hard time understanding interpolation. Every single source I can find that attempts to explain it is extremely cryptic (especially the package specific sites for basemap/matplotlib). I am mapping using matplotlib's basemap however the nature of my data is that it comes in 5 degree by 5 degree blocks (lat lon blocks). I want to smooth out the map by interpolation. So first here is my code. from netCDF4 import Dataset import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemap, addcyclic #load the netcdf file

Interpolate multiple NA values with R

断了今生、忘了曾经 提交于 2019-12-04 11:06:58
I want to interpolate multiple NA values in a matrix called, tester. This is a part of tester with only 1 column of NA values, in the whole 744x6 matrix other columns have multiple as well: ZONEID TIMESTAMP U10 V10 U100 V100 1 20121022 12:00 -1.324032e+00 -2.017107e+00 -3.278166e+00 -5.880225574 1 20121022 13:00 -1.295168e+00 NA -3.130429e+00 -6.414975148 1 20121022 14:00 -1.285004e+00 NA -3.068829e+00 -7.101699541 1 20121022 15:00 -9.605904e-01 NA -2.332645e+00 -7.478168285 1 20121022 16:00 -6.268261e-01 -3.057278e+00 -1.440209e+00 -8.026791079 I have installed the zoo package and used the

Interpolation and extrapolation for large arrays

痴心易碎 提交于 2019-12-04 11:01:19
I have a large array y defined on a non-uniform, ordered grid x . The length of the array is typically N~2^14 to N~2^18. I want to get a spline-interpolation (or quadratic) of the array. The problem I am facing is that even for lower values of N the interpolation takes very long. import numpy as np from scipy.interpolate import interp1d N = 2 ** 12 # = 4096 x = np.linspace(0, 2*np.pi, N) y = np.sin(x) %time f = interp1d(x, y, 'cubic', ) CPU times: user 8min 5s, sys: 1.39 s, total: 8min 7s Wall time: 8min 7s One option I am seeing is that I need the values of the interpolation only at a very

Smoothing a 2-D figure

久未见 提交于 2019-12-04 09:36:00
问题 I have a number of vaguely rectangular 2D figures that need to be smoothed. A simplified example: fig, ax1 = plt.subplots(1,1, figsize=(3,3)) xs1 = [-0.25, -0.625, -0.125, -1.25, -1.125, -1.25, 0.875, 1.0, 1.0, 0.5, 1.0, 0.625, -0.25] ys1 = [1.25, 1.375, 1.5, 1.625, 1.75, 1.875, 1.875, 1.75, 1.625, 1.5, 1.375, 1.25, 1.25] ax1.plot(xs1, ys1) ax1.set_ylim(0.5,2.5) ax1.set_xlim(-2,2) ; I have tried scipy.interpolate.RectBivariateSpline but that apparently wants data at all the points (e.g. for a

SciPy interp2D for pairs of coordinates

时光毁灭记忆、已成空白 提交于 2019-12-04 09:19:59
I'm using scipy.interpolate.interp2d to create an interpolation function for a surface. I then have two arrays of real data that I want to calculate interpolated points for. If I pass the two arrays to the interp2d function I get an array of all the points, not just the pairs of points. My solution to this is to zip the two arrays into a list of coordinate pairs and pass this to the interpolation function in a loop: f_interp = interpolate.interp2d(X_table, Y_table,Z_table, kind='cubic') co_ords = zip(X,Y) out = [] for i in range(len(co_ords)): X = co_ords[i][0] Y = co_ords[i][1] value = f

What's the difference between single and double quotes in Perl?

Deadly 提交于 2019-12-04 08:37:35
I am just begining to learn Perl. I looked at the beginning perl page and started working. It says: The difference between single quotes and double quotes is that single quotes mean that their contents should be taken literally, while double quotes mean that their contents should be interpreted When I run this program: #!/usr/local/bin/perl print "This string \n shows up on two lines."; print 'This string \n shows up on only one.'; It outputs: This string shows up on two lines. This string shows up on only one. Am I wrong somewhere? the version of perl below: perl -v This is perl, v5.8.5 built