Python 单变量样条插值都是NaN,但没有错误参数的迹象
我创建了一个函数来创建一个样条插值函数,该函数对输入数据进行错误检查,如果通过,则创建一个点数量是原始数量的数倍的样条。但它似乎不起作用,即使我的任何错误检查都没有引起注意 我检查了以下错误:Python 单变量样条插值都是NaN,但没有错误参数的迹象,python,ipython,interpolation,spline,Python,Ipython,Interpolation,Spline,我创建了一个函数来创建一个样条插值函数,该函数对输入数据进行错误检查,如果通过,则创建一个点数量是原始数量的数倍的样条。但它似乎不起作用,即使我的任何错误检查都没有引起注意 我检查了以下错误: x和y数据大小相同 “倍数”(要创建的点的系数)必须大于零,1表示样条曲线中的多个点,1表示相同数量的点 样条曲线的顺序必须介于1和5之间(包括1和5) x数据必须严格单调递增 x或y数据中至少有一个NaN 我觉得这似乎是一个完整的列表,它会导致样条曲线创建一个包含所有NaN的样条曲线,但当我向它提供
- x和y数据大小相同
- “倍数”(要创建的点的系数)必须大于零,1表示样条曲线中的多个点,1表示相同数量的点
- 样条曲线的顺序必须介于1和5之间(包括1和5)
- x数据必须严格单调递增
- x或y数据中至少有一个NaN
##
# Univariate Spline Interpolation
##
## This function interpolates the data by creating multiple times the amount of points in the data set and fitting a spline to it
## Input:
# dataX - X axis that you corresponds to dataset
# dataY - Y axis of data to fit spline on (must be same size as dataX)
# multiple - the multiplication factor, default is 2 ( <1 - Less points, 1 - same amount of points, >1 - more points)
# order - order of spline, default is 4 (3 - Cubic, 4 - Quartic)
## Output
# spline - interpolation spline object to be used for peak detection
# splinedDataX - splined X Axis
# splinedDataY - splined Y Axis
#import scipy modules for spling creation and class methods
from scipy.interpolate import UnivariateSpline, LSQUnivariateSpline
#import numpy module for linear spacing creation
from numpy import linspace, NaN
def univariate_spline_interpolation(dataX, dataY, multiple=2, order=4):
#Libraries
from scipy.interpolate import UnivariateSpline, LSQUnivariateSpline
from myUnivariateSpline import MyUnivariateSpline
#Find sizes of x and y axis for comparison and multiple
sizeX = len(dataX)
sizeY = len(dataY)
#Error catching
if(sizeX != sizeY):
print "Data X axis and Y axis must have same size"
return
if(multiple <= 0):
print "Multiple must be greater than 0"
return
if(order < 1 or order >5):
print "Order must be 1 <= order <= 5"
return
#check for monotonic increasting function
for indx, val in enumerate(dataX): #set first value as largest value, need to have all following increase
if indx == 0:
high = val
highIndx = indx
continue
#if the curent value is lower than
if val <= high:
print "timestamp out of order"
print "value at ", highIndx, "is ", high
print "value at ", indx, "is ", val
break
#check for NaN in x and y
for indx, val in enumerate(dataY):
if(val == NaN):
print "Value in Data Y at indx", indx, "is NaN"
return
for indx, val in enumerate(dataX):
if(val == NaN):
print "Value in Data X at indx", indx, "is NaN"
return
#Create Spline
spline = UnivariateSpline(dataX, dataY, k=order, s=0)
#Create new axis based on numPoints
numPoints = sizeX * multiple #Find number of points for spline
startPt = dataX[0] #find value of first point on x axis
endPt = dataX[-1] #find value of last point on x axis
splinedDataX = linspace(startPt, endPt, numPoints) #create evenly spaced points on axis based on start, end, and number of desired data points
#Create Y axis of splined Data
splinedDataY = spline(splinedDataX) #Create new Y axis with numPoints etnries of data splined to fit the original data
return spline, splinedDataX, splinedDataY
##
#单变量样条插值
##
##此函数通过在数据集中创建数倍的点并拟合样条曲线来插值数据
##输入:
#dataX—与数据集对应的X轴
#dataY-拟合样条曲线的数据Y轴(必须与dataX大小相同)
#倍数-乘法因子,默认值为2(1-更多点数)
#阶数-样条曲线的阶数,默认值为4(3-三次,4-四次)
##输出
#样条曲线-用于峰值检测的插值样条曲线对象
#花键数据-花键X轴
#花键数据-花键Y轴
#导入scipy模块以创建spling和类方法
从scipy.interpolate导入单变量样条线,lsqunivariate样条线
#导入numpy模块以创建线性间距
来自南澳大利亚州numpy import linspace
def单变量样条插值(数据x,数据y,倍数=2,顺序=4):
#图书馆
从scipy.interpolate导入单变量样条线,lsqunivariate样条线
从myUnivariateSpline导入myUnivariateSpline
#查找x轴和y轴的尺寸,以进行比较和多重比较
sizeX=len(dataX)
sizeY=len(数据Y)
#错误捕获
如果(sizeX!=sizeY):
打印“数据X轴和Y轴必须具有相同的大小”
回来
如果(多个5):
打印“顺序必须是1第152行和第153行上的X数据是相同的:5.86868286133。这可能是原因。我不知道为什么您的检查代码没有捕捉到这一点,因为我不熟悉Python。但我想您应该能够找到它