interpolation

Python 3D interpolation speedup

你离开我真会死。 提交于 2021-02-18 15:21:55
问题 I have following code used to interpolate 3D volume data. Y, X, Z = np.shape(volume) xs = np.arange(0, X) ys = np.arange(0, Y) zs = np.arange(0, Z) points = list(zip(np.ravel(result[:, :, :, 1]), np.ravel(result[:, :, :, 0]), np.ravel(result[:, :, :, 2]))) interp = interpolate.RegularGridInterpolator((ys, xs, zs), volume, bounds_error=False, fill_value=0, method='linear') new_volume = interp(points) new_volume = np.reshape(new_volume, (Y, X, Z)) This code takes about 37 seconds to execute on

Python 3D interpolation speedup

▼魔方 西西 提交于 2021-02-18 15:21:48
问题 I have following code used to interpolate 3D volume data. Y, X, Z = np.shape(volume) xs = np.arange(0, X) ys = np.arange(0, Y) zs = np.arange(0, Z) points = list(zip(np.ravel(result[:, :, :, 1]), np.ravel(result[:, :, :, 0]), np.ravel(result[:, :, :, 2]))) interp = interpolate.RegularGridInterpolator((ys, xs, zs), volume, bounds_error=False, fill_value=0, method='linear') new_volume = interp(points) new_volume = np.reshape(new_volume, (Y, X, Z)) This code takes about 37 seconds to execute on

Fast Interpolation / Resample of Numpy Array - Python

冷暖自知 提交于 2021-02-18 05:25:09
问题 Currently, I have written some Python code that is inserted into a pipeline. The incoming data comes in in a numpy array of shape (1,512,19,25). I use the scipy.ndimage.interpolation.zoom to bring the array up to shape (1,512,38,50). This can be accomplished with one call to the function. Basically, it resizes each (19,25) piece to size (38,50). Later in the code, when the data is moving the other way, different data is again resized the in the other direction (38,50) to (19,25). Everything

Quotes within HERE document in shell scripts

牧云@^-^@ 提交于 2021-02-17 02:53:31
问题 G'day, I'm getting syntax errors when working with a shell script like the following: ssh root@mm-$user-vm-lenny <<EOF check_dbtag=`grep "<<include /home/$user/cvs/dbtag.conf>>" /etc/dbtag.conf` if [ "$check_dbtag" == "" ] then echo '<<include /home/$user/cvs/dbtag.conf>>' >> /etc/dbtag.conf fi EOF The error I'm getting is -bash: line 21: syntax error near unexpected token 'newline' -bash: line 21: 'check_dbtag=<<include /home/thomasw/cvs/dbtag.conf>>' However, I don't get it anymore if I

Quotes within HERE document in shell scripts

只愿长相守 提交于 2021-02-17 02:52:11
问题 G'day, I'm getting syntax errors when working with a shell script like the following: ssh root@mm-$user-vm-lenny <<EOF check_dbtag=`grep "<<include /home/$user/cvs/dbtag.conf>>" /etc/dbtag.conf` if [ "$check_dbtag" == "" ] then echo '<<include /home/$user/cvs/dbtag.conf>>' >> /etc/dbtag.conf fi EOF The error I'm getting is -bash: line 21: syntax error near unexpected token 'newline' -bash: line 21: 'check_dbtag=<<include /home/thomasw/cvs/dbtag.conf>>' However, I don't get it anymore if I

Vanilla HTML+JS - Dynamic Interpolation?

ⅰ亾dé卋堺 提交于 2021-02-16 18:27:27
问题 I know that in frameworks like Handlebars and ect. it is possible to write HTML similar to the following: <span id="logged-on-username">{{username}}</span> In this contrived example, a JS file loaded when on this page would return the value of a variable called username and interpolate it into the view template. Is anything similar possible in vanilla HTML + JS? Thanks in advance for anyone's time who happens to answer. 回答1: You mean something like this const content = { "username": "Fredy

How can I change the number of basis functions when performing B-Spline fitting in scipy (python)?

风流意气都作罢 提交于 2021-02-11 12:23:56
问题 I have a discrete set of points (x_n, y_n) that I would like to approximate/represent as a linear combination of B-spline basis functions. I need to be able to manually change the number of B-spline basis functions used by the method, and I am trying to implement this in python using scipy. To be specific, below is a bit of code that I am using: import scipy spl = scipy.interpolate.splrep(x, y) However, unless I have misunderstood or missed something in the documentation, it seems I cannot

Interpolating within a grid in python

[亡魂溺海] 提交于 2021-02-11 12:18:19
问题 I have a number of height values across a grid, specified in a series of lists: [3, 1, -2, -3, -3] # x = 0m [2, -7, -14, -30, -39] # x = 10m [46, 22, 5, -2, -8] # x = 20m The example above shows a 40m x 20m grid in the form [x=0y=0, x=0y=10...][x=10y=0, x=10y=10...] etc. I need to calculate the height at a specific x,y coordinate. I have looked at various interpolate functions and example but can't make any sense out of them - please help! An example would be the height at x = 5m, y = 5m in

How to extract the function model (polynomials) from scipy.interpolate.splprep()?

不问归期 提交于 2021-02-10 22:10:57
问题 I now have some discrete points, and I interpolated it using the scipy.interpolate.splprep () function (B-spline interpolation) to get a satisfactory smooth curve. Here's the code (draw on the answer to another question) and the result I got. import numpy as np from scipy import interpolate from matplotlib import pyplot as plt # x and y are points sampled randomly x = sampledx y = sampledy # append the starting x,y coordinates x = np.r_[x, x[0]] y = np.r_[y, y[0]] # fit splines to x=f(u) and

Expanding R Matrix on Date

扶醉桌前 提交于 2021-02-10 20:01:45
问题 I have the following R matrix: Date MyVal 2016 1 2017 2 2018 3 .... 2026 10 What I want to do is "blow it up" so that it goes like this (where monthly values are linearly interpolated): Date MyVal 01/01/2016 1 02/01/2016 .. .... 01/01/2017 2 .... 01/01/2026 10 I realize I can easily generate the sequence using: DateVec <- seq(as.Date(paste(minYear,"/01/01", sep = "")), as.Date(paste(maxYear, "/01/01", sep = "")), by = "month") And I can use that to make a large matrix and then fill things in