本文整理汇总了Python中scipy.interpolate.UnivariateSpline.set_smoothing_factor方法的典型用法代码示例。如果您正苦于以下问题:Python UnivariateSpline.set_smoothing_factor方法的具体用法?Python UnivariateSpline.set_smoothing_factor怎么用?Python UnivariateSpline.set_smoothing_factor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.interpolate.UnivariateSpline
的用法示例。
在下文中一共展示了UnivariateSpline.set_smoothing_factor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: smooth
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
def smooth(self, genome, which_x, which_y):
interpolationPointsQty = SMOOTHING_WINDOW
which_y_InterpolationNeighborhood = interpolationPointsQty / 2
minimunInterpolationNeighborhoodSize = interpolationPointsQty / 4
if which_y - interpolationPointsQty / 2 < 0:
interpolationPointsQty -= abs(which_y - which_y_InterpolationNeighborhood) * 2
which_y_InterpolationNeighborhood = interpolationPointsQty / 2
elif which_y + interpolationPointsQty / 2 > genome.getHeight() - 1:
interpolationPointsQty -= (which_y + which_y_InterpolationNeighborhood - (genome.getHeight() - 1)) * 2
which_y_InterpolationNeighborhood = interpolationPointsQty / 2
if which_y_InterpolationNeighborhood >= minimunInterpolationNeighborhoodSize:
x = np.ndarray(interpolationPointsQty)
y = np.ndarray(interpolationPointsQty)
for k in xrange(interpolationPointsQty):
poseToSmooth = which_y - which_y_InterpolationNeighborhood + k
x[k] = poseToSmooth
y[k] = genome[poseToSmooth][which_x]
spl = UnivariateSpline(x, y)
spl.set_smoothing_factor(SPLINE_SMOOTHING_FACTOR_SPLINE/10)
for k in xrange(interpolationPointsQty):
if y[k] != sysConstants.JOINT_SENTINEL:
newValue = spl(int(x[k]))
genome.setItem(int(x[k]), which_x, newValue)
示例2: smoothfit
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
def smoothfit(x, y, smooth=0, res=1000):
"""
Smooth data of the form f(x) = y with a spline
"""
z = y.copy()
w = isnan(z)
z[w] = 0
spl = UnivariateSpline(x, z, w=~w)
spl.set_smoothing_factor(smooth)
xs = linspace(min(x), max(x), res)
ys = spl(xs)
ys[ys < 0] = 0
if w[0]:
if len(where(~w)[0]):
first = where(~w)[0][0]
first = x[first]
first = where(xs >= first)[0][0] - 1
ys[:first] = nan
if w[-1]:
if len(where(~w)[0]):
last = where(~w)[0][-1]
last = x[last]
last = where(xs >= last)[0][0] + 1
ys[last:] = nan
return xs, ys
示例3: interpolate
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
def interpolate(self, genome, which_x, which_y, wich_y_is_fixed_data=0):
interpolationPointsQty = SMOOTHING_WINDOW
which_y_InterpolationNeighborhood = interpolationPointsQty / 2
minimunInterpolationNeighborhoodSize = interpolationPointsQty / 4
array_size = 0
if which_y - which_y_InterpolationNeighborhood < 0:
interpolationPointsQty -= abs(which_y - which_y_InterpolationNeighborhood) * 2
which_y_InterpolationNeighborhood = interpolationPointsQty / 2
elif which_y + interpolationPointsQty / 2 > genome.getHeight() - 1:
interpolationPointsQty -= (which_y + which_y_InterpolationNeighborhood - (genome.getHeight() - 1)) * 2
which_y_InterpolationNeighborhood = interpolationPointsQty / 2
interpolationWindowRadius = interpolationPointsQty / 4
if which_y_InterpolationNeighborhood >= minimunInterpolationNeighborhoodSize:
array_size = interpolationPointsQty - interpolationWindowRadius * 2
if wich_y_is_fixed_data:
array_size += 1
x = np.ndarray(array_size)
y = np.ndarray(array_size)
splineIndexCounter = 0
for k in xrange(interpolationPointsQty + 1):
poseToSmooth = which_y - which_y_InterpolationNeighborhood + k
if poseToSmooth <= which_y - interpolationWindowRadius or poseToSmooth > which_y + interpolationWindowRadius:
x[splineIndexCounter] = poseToSmooth
y[splineIndexCounter] = genome[poseToSmooth][which_x]
splineIndexCounter += 1
if wich_y_is_fixed_data:
x[splineIndexCounter] = which_y
y[splineIndexCounter] = genome[which_y][which_x]
splineIndexCounter += 1
if genome[which_y - interpolationWindowRadius][which_x] == genome[which_y + interpolationWindowRadius][wich_x]:
spl = interp1d(x, y)
else:
x_order = np.argsort(x)
spl = UnivariateSpline(x_order, y)
spl.set_smoothing_factor(SPLINE_SMOOTHING_FACTOR_INTERPOLATION/10)
for k in xrange(interpolationPointsQty):
iter = which_y - which_y_InterpolationNeighborhood + k
if genome[iter][which_x] != sysConstants.JOINT_SENTINEL:
if iter > which_y - interpolationWindowRadius and iter <= which_y + interpolationWindowRadius:
if wich_y_is_fixed_data: #if fixed data do not change the which_y point
if iter != which_y:
newValue = spl(iter)
genome.setItem(iter, which_x, newValue)
else:
newValue = spl(iter)
genome.setItem(iter, which_x, newValue)
示例4: do_the_job
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
def do_the_job(file_name):
data_x, data_y, data_z = get_data(file_name)
shape_x = len(np.unique(data_x))
shape_y = len(np.unique(data_y))
X = data_x.reshape(shape_x, shape_y)
Y = data_y.reshape(shape_x, shape_y)
Z = data_z.reshape(shape_x, shape_y)
fig = plt.figure(figsize=(20, 10))
ax1 = fig.add_subplot(121)
ax1.pcolormesh(X,Y,Z)
#ax1.pcolor(X, Y, Z, norm=LogNorm())
angle_and_intensity_average = radial_average(data_x, data_y, data_z)
# normalize to 1
angle_and_intensity_average = (angle_and_intensity_average - angle_and_intensity_average.min()) / (angle_and_intensity_average.max() - angle_and_intensity_average.min())
x = np.arange(450)
ax2 = fig.add_subplot(122)
ax2.plot(x,angle_and_intensity_average,'b.',label="raw")
# histogram / rebinning
# the histogram of the data
# Integration
n_bins = 50
bin_means, bin_edges, binnumber = stats.binned_statistic(x, angle_and_intensity_average, statistic='sum', bins=n_bins)
bin_width = (bin_edges[1] - bin_edges[0])
bin_centers = bin_edges[1:] - bin_width/2
# normalize to 1
bin_means = (bin_means - bin_means.min()) / (bin_means.max() - bin_means.min())
ax2.plot(bin_centers,bin_means,'r--', label="binning")
# Spline interpolation
spl = UnivariateSpline(bin_centers, bin_means)
spl.set_smoothing_factor(0.5)
xs = np.linspace(bin_centers.min(), bin_centers.max(), 1000)
ax2.plot(xs, spl(xs), 'g',label="spline")
## Fit 2 gaussians: [center, amplitude, width]
guess = [180, 1, 30, 360, 1, 30]
popt, pcov = curve_fit(multiple_gaussian, xs, spl(xs), p0=guess)
print 80*"-"
print "Gaussian1 center = %.2f, amplitude = %.2f, std = %.2f, FWHM = %.2f"%(popt[0],popt[1],popt[2], 2 * np.sqrt(2*np.log(2))*popt[2])
print "Gaussian2 center = %.2f, amplitude = %.2f, std = %.2f, FWHM = %.2f"%(popt[3],popt[4],popt[5], 2 * np.sqrt(2*np.log(2))*popt[5])
fit = multiple_gaussian(xs, *popt)
ax2.plot(xs, fit , 'y', label="gaussian")
ax2.legend()
plt.show()
示例5: cubic_spline_interpolation
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
def cubic_spline_interpolation(arr, factor):
new_time, expanded_time = expand_time(arr, factor)
t = arr[:, 0]
x = arr[:, 1]
y = arr[:, 2]
z = arr[:, 3]
qx = arr[:, 4]
qy = arr[:, 5]
qz = arr[:, 6]
qw = arr[:, 7]
to_expand = [x, y, z, qx, qy, qz, qw]
for i in range(len(to_expand)):
spl = UnivariateSpline(t, to_expand[i])
spl.set_smoothing_factor(0)
to_expand[i] = np.matrix(spl(new_time))
new_matrix = np.matrix(expanded_time)
for i in to_expand:
new_matrix = np.concatenate((new_matrix, np.matrix(i)), axis = 0)
return new_matrix.T
示例6: __init__
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
def __init__(self, log_file):
times = []
self.temps = []
self.ons = []
with open(log_file, 'r') as f:
state = 0
tail = 0
for line in f:
s = line.strip().split()
if state == 0 and bool(int(s[3])):
state = 1
elif state == 1 and not bool(int(s[3])):
state = 2
if state == 1:
tail += 2
if state == 2:
tail -= 1
if tail == 0:
state = 3
if state == 1 or state == 2:
times.append(s[0])
self.temps.append(float(s[1]))
self.ons.append(bool(int(s[3])))
self.seconds = []
first = None
for t in times:
s = t.split(':')
v = int(s[0]) * 3600 + int(s[1]) * 60 + int(s[2])
if first is None:
first = v
self.seconds.append(v - first)
if len(self.temps) > 0:
x = numpy.linspace(0, len(self.temps), len(self.temps))
spl = UnivariateSpline(x, self.temps)
spl.set_smoothing_factor(0.75)
self.smoothed_temps = spl(x)
else:
self.smoothed_temps = []
示例7: spline
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
def spline(x, y, axis='y', s=3.0, **kwargs):
"""Replace y (x) data with a spline fit.
See scipy.interpolate.UnivariateSpline for spline details.
Args:
axis: Either 'x' or 'y'. Indicates the axis to be fit.
"""
from scipy.interpolate import UnivariateSpline as Spline
_verify_axis(axis)
if axis == 'y':
xlin = np.arange(0, len(x))
spl = Spline(xlin, y)
spl.set_smoothing_factor(s)
return x, spl(xlin)
if axis == 'x':
ylin = np.arange(0, len(y))
spl = Spline(ylin, x)
spl.set_smoothing_factor(s)
return spl(ylin), y
示例8: agregarPuntosCamino
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
def agregarPuntosCamino(self,x,y,puntos = [], pan = 0, tilt = 0, tiempo = None):
if len(x) > 3 and point_between_point > 1:
spl = UnivariateSpline(x, y)
xs = np.linspace(min(x),max(x),len(x)*point_between_point)
spl.set_smoothing_factor(0.5)
ys = spl(xs)
pans = []
tilts = []
tiempos = []
for i in range(len(pan)):
pans += [pan[i]/point_between_point]*point_between_point
tilts += [tilt[i]/point_between_point]*point_between_point
tiempos += [tiempo[i]/point_between_point]*point_between_point
else:
xs = x
ys = y
pans = pan
tilts = tilt
tiempos = tiempo
if len(puntos) == 0:
self.puntos_a_seguir = []
self.pan_tilt = []
self.lista_tiempos = []
ang_pos_final = 0
q = None
for i in range(len(xs)):
if i == (len(xs) - 1):
#q = Quat((ang_pos_final,0,0))
self.puntos_a_seguir.append(Pose(Point(xs[i], ys[i], 0.000), Quaternion(q.q[0], q.q[1], q.q[2], q.q[3]))) #
self.pan_tilt.append([pans[i],tilts[i]])
self.lista_tiempos.append(tiempos[i])
else:
ang_pos_final = degrees(atan(float(abs(ys[i+1]-ys[i]))/float(abs(xs[i+1]-xs[i]))))
q = Quat((ang_pos_final,0,0))
self.puntos_a_seguir.append(Pose(Point(xs[i], ys[i], 0.000), Quaternion(q.q[0], q.q[1], q.q[2], q.q[3]))) #q.q[0], q.q[1], q.q[2], q.q[3]
self.pan_tilt.append([pans[i],tilts[i]])
self.lista_tiempos.append(tiempos[i])
示例9: mainFun
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
def mainFun(pointList,nVsteps=100,minVdep=1,Graph=0):
polygonXSorig = Polygon(pointList)
#~ definition line of XS
borderXS = LineString(pointList)
minY=polygonXSorig.bounds[1]
maxY=polygonXSorig.bounds[-1]
#~ definition polygon of XS
pointList.insert(0,(polygonXSorig.bounds[0],maxY+1))
pointList.append((polygonXSorig.bounds[2],maxY+1))
polygonXS = Polygon(pointList)
depts = np.linspace(minY+0.1, maxY-0.1, nVsteps)
HydRad = np.array([])
HydDept = np.array([])
for dept in depts:
wdep=hdepth(polygonXSorig,dept)
wdepLine = WTable(polygonXSorig,dept)
wetArea = polygonXS.intersection(wdep)
wetPerimeter=borderXS.intersection(wdep)
wetWTLine = wdepLine.intersection(polygonXS)
HydRad = np.append(HydRad,wetArea.area/wetPerimeter.length)
HydDept = np.append(HydDept,wetArea.area/wetWTLine.length)
#smoothing function
#estract local maxima of HydDept and depts using smoothing function in R
deptsLM, HydDeptLM , spar = splineR(depts,HydDept)
from scipy.interpolate import UnivariateSpline
splHydDept= UnivariateSpline(depts, HydDept)
splHydDept.set_smoothing_factor(spar)
HydDept_smth=splHydDept(depts)
xfine = np.linspace(min(depts),max(depts),1000)
HydDept_smthfine= splHydDept(xfine)
#~ first maxima location of HydDept
if len(deptsLM)>0:
#~ skip local maxima_locations if lower then value set by user
#~ previous method now replaced
max_loc_filtered = [i for i in range(len(HydDeptLM)) if HydDeptLM[i] >= minVdep]
#~ shapely polygon for bankfull
bankfullIndex = max_loc_filtered[0]
bankfullLine = WTable(polygonXSorig,deptsLM[bankfullIndex])
wdep=hdepth(polygonXSorig,deptsLM[bankfullIndex])
else:
bankfullLine = WTable(polygonXSorig,depts[-1])
wdep=hdepth(polygonXSorig,depts[-1])
#~ new method
turning_points = local_maxmin(HydDept)
terrace = []
for i in range(len(turning_points['maxima_locations'])):
if turning_points['maxima_ranks'][i] == max(turning_points['maxima_ranks']) :
terrace.append(turning_points['maxima_locations'][i])
#~ max_loc_filtered = [i for i in max_loc_filtered if HydDept[i] > minVdep]
#~ --
#~ shapely polygon for terrace
terraceIndex=terrace[0]
terraceLine=WTable(polygonXSorig,depts[terraceIndex])
tdep=hdepth(polygonXSorig,depts[terraceIndex])
tArea = polygonXS.intersection(tdep)
wetArea = polygonXS.intersection(wdep)
boundsOK = ()
Area = 0
if wetArea.type is 'MultiPolygon':
nchannel=str(len(wetArea))
for wetPolygon in wetArea:
if wetPolygon.area > Area:
Area = wetPolygon.area
boundsOK = wetPolygon.bounds
else:
boundsOK = wetArea.bounds
nchannel='1'
if Graph == 1:
#~ definition of figure for XS plot
from matplotlib import pyplot
from descartes.patch import PolygonPatch
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
fig = pyplot.figure(1, figsize=(4,3), dpi=300)
fig = pyplot.figure()
ax = fig.add_subplot(211)
ax.clear()
#~ plot_coords(ax, borderXS,'#999999') # plot single points on XS
plot_line(ax,borderXS,'#6699cc') # plot line of XS
plot_line(ax,bankfullLine,'#0000F5') # plot hor line of bankfull
#~ plot_line(ax,terraceLine,'#FFE066') # plot hor line of terrace
ax.set_title('Cross Section')
if wetArea.type is 'MultiPolygon':
for wetPolygon in wetArea:
patch = PolygonPatch(wetPolygon, fc='#00FFCC', ec='#B8B8B8', alpha=0.5, zorder=2)
ax.add_patch(patch)
#.........这里部分代码省略.........
示例10: read_in_WHAM_file
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
def read_in_WHAM_file(filename,base_dir='./'):
""" subroutine to read in the WHAM file - note, the format must be distance is first column, and RDF is the third column
ASSUMPTION: ALL WHAM FILES HAVE THE SAME NUMBER OF BINS AND CUTOFF AS THE POTENTIAL FILES. """
print "reading WHAM %s" % (filename)
#numofbins, cutoff, o = lmp_io.get_number_of_bins_and_cutoff("%s" % (filename), 0)
numofbins=0
# TODO - what if we have a NAN in our data set, due to incomplete sampling?
LIST_IN = open("%s" % (os.path.join(base_dir,filename)), 'r')
index = 0
x = []
y = []
number_of_inf=0
number_of_non_inf=0
print numofbins
wham_array = [] #np.zeros(numofbins+1)
wham_array_distance= [] #np.zeros(numofbins+1)
extrapolate_list=[]
interpolate_list=[]
for line in LIST_IN:
NewRow = (line.strip()).split()
mystring = NewRow[0][0:1]
if mystring != "#":
if len(NewRow)>2:
if NewRow[1] != "inf":
# wham_array[index] = float(NewRow[1])
number_of_non_inf +=1
x.append(float(NewRow[0]))
y.append(float(NewRow[1]))
else:
if number_of_non_inf == 0:
extrapolate_list.append(index)
else:
interpolate_list.append(index)
if number_of_non_inf > 0:
wham_array_distance.append(float(NewRow[0]))
if NewRow[1] == "inf":
wham_array.append(0.0)
else :
wham_array.append(float(NewRow[1]))
index += 1
LIST_IN.close()
np.asarray(x)
np.asarray(y)
np.asarray(wham_array_distance)
np.asarray(wham_array)
spl = UnivariateSpline(x, y)
spl.set_smoothing_factor(0.2)
for i, distance in enumerate(wham_array_distance):
if i in interpolate_list:
wham_array[i]=float(spl(distance))
print "WHAM INTER", distance, wham_array[i]
#print wham_array_distance
#print wham_array
np.trim_zeros(wham_array, 'b')
np.trim_zeros(wham_array_distance, 'b')
last_element=wham_array[index-1]
np.subtract(wham_array,last_element)
# check whether this is the same as the the one in the potential file
cutoff=wham_array_distance[index-1]
print wham_array_distance
print wham_array
print len(wham_array_distance)
print len(wham_array)
# need to fill in the infs
return wham_array, wham_array_distance, len(wham_array_distance), float(cutoff)
示例11: UnivariateSpline
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
1.01120868, 0.86717364, 1.05338103, 0.99149619, 0.68564621, 0.76683369,
0.63125403, 0.47328888, 0.37570884, 0.44782711, 0.30278194, 0.23449642,
-0.00893587, 0.12843641, -0.07914852, 0.05046878, 0.03702803, 0.08291754,
0.05008077, -0.09366895, -0.05902218, 0.19701947, -0.03468384, -0.06500214,
-0.07205329, 0.2006148 ]
y2 = [ 0.05743072, 0.00940577, 0.05848502, -0.16221342, 0.07314822, 0.08029109,
-0.05064357, 0.0695457, 0.05350962, 0.03007541, 0.28596007, 0.05292537,
0.20403795, 0.13377805, 0.30783861, 0.21393345, 0.403338, 0.37650354,
0.5565254, 0.7653728, 0.73612424, 0.83256118, 0.96323466, 0.96258791,
1.01120868, 0.86717364, 1.25338103, 0.99149619, 0.68564621, 0.76683369,
0.63125403, 0.47328888, 0.37570884, 0.44782711, 0.30278194, 0.23449642,
-0.00893587, 0.12843641, -0.07914852, 0.05046878, 0.03702803, 0.08291754,
0.05008077, -0.09366895, -0.05902218, 0.19701947, -0.03468384, -0.06500214,
-0.07205329, 0.2006148 ]
xs = np.linspace(-3, 3, 1000)
spl = UnivariateSpline(x, y)
spl2 = UnivariateSpline(x, y2)
for i in range(1,11):
plt.plot(x, y, 'ro', ms=5)
smoothing_factor = i / 10.0
print smoothing_factor
spl.set_smoothing_factor(smoothing_factor)
spl2.set_smoothing_factor(smoothing_factor)
plt.plot(xs, spl(xs), 'g', lw=3)
plt.plot(xs, spl2(xs), 'ro', lw=3)
plt.show()
示例12: calculateGapByCubicInterpolation
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
def calculateGapByCubicInterpolation(self, referenceWindowRadius, interpolationWindow, splineSmoothingFactor, cycleSize, cycleRepetition, graphicalRepresentation=False):
x = np.ndarray(referenceWindowRadius * 2)
y = np.ndarray(referenceWindowRadius * 2)
poseQty = len(self.geneticMatrix)
poseLength = len(self.geneticMatrix[0])
#print "poseQty: ", poseQty, "poseLength: ", poseLength, "lp.getFrameQty(): ", lp.getFrameQty()
for joint in range(poseLength):
interpolationDataIter = referenceWindowRadius - 1
for k in xrange(referenceWindowRadius + 1):
referenceFrame = cycleSize + k
x[interpolationDataIter] = referenceFrame
y[interpolationDataIter] = self.geneticMatrix[referenceFrame][joint]
interpolationDataIter += 1
interpolationDataIter = referenceWindowRadius - 2
for k in xrange(referenceWindowRadius + 1):
referenceFrame= cycleSize -1 - (interpolationWindow + k)
x[interpolationDataIter] = referenceFrame
y[interpolationDataIter] = self.geneticMatrix[referenceFrame][joint]
interpolationDataIter -= 1
x = np.sort(x)
if abs(self.geneticMatrix[cycleSize - interpolationWindow][joint] - self.geneticMatrix[cycleSize][joint]) < 3:
spl = interp1d(x, y)
else:
spl = UnivariateSpline(x, y)
spl.set_smoothing_factor(splineSmoothingFactor/10.0)
if graphicalRepresentation:
px = linspace(x[0], x[len(x)-1], len(x))
py = spl(px)
plt.plot(x, y, '.-')
plt.plot(px, py)
xinter = np.ndarray(interpolationWindow)
yinter = np.ndarray(interpolationWindow)
for k in xrange(interpolationWindow):
smoothFrameIter = cycleSize - 1 - k
xinter[k] = smoothFrameIter
yinter[k] = self.geneticMatrix[smoothFrameIter][joint]
plt.plot(xinter, yinter, '.-') #original data
for k in xrange(interpolationWindow):
smoothFrameIter = cycleSize - 1 - k
xinter[k] = smoothFrameIter
yinter[k] = spl(smoothFrameIter)
plt.plot(xinter, yinter, '*-') #interpolated data
plt.title(self.jointNameIDMapping[joint])
plt.show()
print "gap between first and last: ", self.getConcatenationGap()
for i in xrange(cycleRepetition):
for k in range(cycleSize - 1 - interpolationWindow, cycleSize):
newValue = spl(k)
self.geneticMatrix[cycleSize * i + k][joint] = newValue
示例13: nanmasked
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
s_0_5_6 = lut.sp[0,:,0,5,6]
s,n = nanmasked(s_0_5_6)
snorm = norm2max(s_0_5_6)
[i1000,i1077,i1493,i1600,i1200,i1300,i530,i610,
i1565,i1634,i1193,i1198,i1236,i1248,i1270,i1644,
i1050,i1040,i1065,i600,i870,i515] = find_closest(lut.wvl,np.array([1000,1077,1493,1600,1200,1300,530,
610,1565,1634,1193,1198,1236,1248,
1270,1644,1050,1040,1065,600,870,515]))
norm2 = s_0_5_6/s_0_5_6[i1000]
dsp = smooth(np.gradient(norm2,lut.wvl/1000.),2)
# <codecell>
norm2_uni = UnivariateSpline(lut.wvl/1000.0,norm2,k=5)
norm2_uni.set_smoothing_factor(1)
dnorm2 = norm2_uni.derivative()
# <codecell>
norm2_bspline = splrep(lut.wvl/1000.0,norm2,k=5)
norm2_b = splev(lut.wvl/1000.0,norm2_bspline,der=0)
dbnorm2 = splev(lut.wvl/1000.0,norm2_bspline,der=1)
# <codecell>
dsp2 = smooth(deriv(norm2,lut.wvl/1000.),2)
# <codecell>
plt.figure()
示例14: max
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
y = histo[0]
xBinSize = x[1] - x[0]
indexMax, valueMax = max(enumerate(x), key=operator.itemgetter(1))
np.insert(x,0,(x[0] - xBinSize))
np.insert(y,0,y[indexMax])
indexMin, valueMin = min(enumerate(x), key=operator.itemgetter(1))
np.append(x,(x[-1] + xBinSize))
np.append(y,y[indexMin])
f2 = UnivariateSpline(x, y, k=5)
m = len(x)
var = np.var(y)
plt.hist(dist,50,color=flatColorDBlue)
plt.xlabel('Keyspace Position')
plt.ylabel('Number of Nodes in Bin')
plt.title('Curve Fitting of Keyspace Distribution')
ax = plt.gca()
ax.set_xlim([0,k])
vals = [1,1.5,4]
n = 0
for i in vals:
print i
scalingFactor = int((m * var)/i)
f2.set_smoothing_factor(scalingFactor)
pltHandle = plt.plot(xsto,f2(xsto),lw=2,label=('S = ' + str(scalingFactor)),color=flatColorMatrix[n])
n += 1
plt.legend(loc='best',fancybox=True, framealpha=0.8)
plt.savefig('histogram.pdf',format='pdf')
plt.show()
示例15: open
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import set_smoothing_factor [as 别名]
enabled = []
with open('17-01-2015.log', 'r') as f:
for line in f:
s = line.strip().split()
time.append(s[0])
temp.append(float(s[1]))
target.append(float(s[2]))
on.append(bool(int(s[3])))
enabled.append(bool(int(s[4])))
N = len(temp)
x = numpy.linspace(0, N, N)
spl = UnivariateSpline(x, temp)
spl.set_smoothing_factor(0.75)
xi = numpy.linspace(0, N, N * 4)
smoothed = spl(xi)
gradient = numpy.gradient(smoothed)
gradient2 = numpy.gradient(gradient)
# M = len(stemp)
# dtemp = numpy.zeros(M)
# dtemp[0] = (stemp[2] + 4 * stemp[1] - 3 * stemp[0]) / 2
# for i in range(1, M - 1):
# dtemp[i] = (stemp[i + 1] - stemp[i - 1]) / 2
# dtemp[M - 1] = (stemp[M - 3] - 4 * stemp[M - 2] + 3 * stemp[M - 1]) / 2
# dtemp[0] = 0