本文整理汇总了Python中scipy.interpolate.UnivariateSpline.roots方法的典型用法代码示例。如果您正苦于以下问题:Python UnivariateSpline.roots方法的具体用法?Python UnivariateSpline.roots怎么用?Python UnivariateSpline.roots使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.interpolate.UnivariateSpline
的用法示例。
在下文中一共展示了UnivariateSpline.roots方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: grad_dist
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def grad_dist(curdata,ax):
#gaussian kernel density estimation
x=np.linspace(0,90,91)
kde=gaussian_kde(curdata)
line,=ax.plot(x,kde(x), '-', label=hl[j][0:-2]+"0")
curcolor=plt.getp(line,'color')
## #plotting histogram
## ax.hist(curdata,bins=int(max(curdata))+1,
## normed=True, histtype='step',
## color=curcolor, linewidth=0.5)
#defining splines for kd function and corresponding 1st and seconde derivatives
x=np.linspace(0,90,901)
s=UnivariateSpline(x,kde(x),s=0,k=3)
s1=UnivariateSpline(x,s(x,1),s=0,k=3)
s2=UnivariateSpline(x,s1(x,1),s=0,k=3)
#identifying local maxima (where s1=0, s2<0, and s>0.005)
maxima=s1.roots()[np.where(s2(s1.roots())<0)[0]]
maxima=maxima[np.where(s(maxima)>0.005)[0]]
#s_max=maxima[-1]
s_max=maxima[np.argmax(s(maxima))]
ax.plot(s_max, s(s_max),'o', color=curcolor)
#identifying steepest segment after maxima (where x>=maxima, s1<0)
x2=x[np.where(x>=s_max)[0]]
slope=s1(x2)
s1_min=x2[np.argmin(slope)]
ax.plot(s1_min,s(s1_min),'o', color=curcolor)
print round(s_max,1),round(s1_min,1)
return round(s_max,1),round(s1_min,1)
示例2: kde_minmode
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def kde_minmode(data,x,max_num_mode,min_mode_pdf):
kde=gaussian_kde(data)
f=kde.factor
f_list=np.linspace(f,(data.max()-data.min()),100)
s=UnivariateSpline(x,kde(x),s=0)
s1=UnivariateSpline(x,s(x,1),s=0)
s2=UnivariateSpline(x,s1(x,1),s=0)
extrema=s1.roots()
maxima=extrema[np.where((s2(extrema)<0)*(s(extrema)>=min_mode_pdf))]
if len(maxima)>max_num_mode:
for q in range(1,len(f_list)):
f=f_list[q]
kde2=gaussian_kde(data,bw_method=f)
s=UnivariateSpline(x,kde2(x),s=0)
s1=UnivariateSpline(x,s(x,1),s=0)
s2=UnivariateSpline(x,s1(x,1),s=0)
extrema=s1.roots()
maxima=extrema[np.where((s2(extrema)<0)*(s(extrema)>=min_mode_pdf))]
if len(maxima)<=max_num_mode:
## print 'modes: ',maxima
break
kde=gaussian_kde(data,bw_method=f)
## else:
## print maxima
return kde,maxima
示例3: fwhm
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def fwhm(x, y, bg=[0, 100, 150, 240]):
"""
Evaluates the full width half maximum of y in units of x.
Parameters
----------
x : numpy.array
y : numpy.array
bg : list
Background sampling limits
Returns
-------
fwhm : number
Full width half maximum
"""
# xnew = copy(x)
# ynew = copy(y)
# xc = x[(x>bg[0])&(x<bg[1]) | (x>bg[2])&(x<bg[3])]
# yc = y[(x>bg[0])&(x<bg[1]) | (x>bg[2])&(x<bg[3])]
# bgfit = polyfit(xc,yc,1)
# ynew = ynew-polyval(bgfit,xnew)
xnew, ynew = rmbg(x, y, bg)
f = UnivariateSpline(xnew, ynew / max(ynew) - 0.5, s=0)
fwhm = f.roots()[1] - f.roots()[0]
return fwhm
示例4: imageSlice
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def imageSlice(image, xc, yc, width):
ylen, xlen = image.shape
xstart = max(0, xc - width / 2)
xend = min(xlen, xc + width / 2)
# I cannot get array slicing to work for the life of me
slice = []
for i in range(int(xstart), int(xend)):
slice.append(image[yc, i])
# https://stackoverflow.com/questions/10582795/finding-the-full-width-half-maximum-of-a-peak/10583774#10583774
shiftedSlice = []
halfMax = max(slice) / 2
baseline = numpy.mean(image)
for y in slice:
shiftedSlice.append(y - halfMax - baseline)
x = numpy.linspace(0, width, width)
spline = UnivariateSpline(x, shiftedSlice, s=0)
r1, r2 = spline.roots()
#r1 = 0
#r2 = 0
return (slice, r2 - r1)
示例5: halbwertsbreite
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def halbwertsbreite(x, y):
spline = UnivariateSpline(x, y-np.max(y)/2, s=0)
r1, r2 = spline.roots() # find the roots
lambda1 = 2*d*np.sin(np.deg2rad(r1))
lambda2 = 2*d*np.sin(np.deg2rad(r2))
E1 = h*c/lambda1
E2 = h*c/lambda2
DE = E1 - E2
print ('Halbwertswinkel: {0:.5e} deg, {1:.5e} deg'.format(r1, r2))
print ('Halbwertsbreite: {0:.5e}'.format(np.abs(r1-r2)))
print (u'Energieaufloesung: {0:.5e} eV'.format(DE))
xnew = np.linspace(min(x), max(x))
ynew = spline(xnew)
plt.plot(x, y, 'rx', label='Messdaten')
plt.plot(xnew, ynew+np.max(y)/2,'b-', label='Interpolation')
plt.axvline(r1)
plt.axvline(r2)
plt.grid()
plt.legend()
plt.xlabel("doppelter Kristallwinkel in Grad")
plt.ylabel(u"Zählrate")
示例6: fwhm
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def fwhm(x, y, k=10, ret_roots=False):
"""
Determine full-with-half-maximum of a peaked set of points, x and y.
Assumes that there is only one peak present in the dataset. The function
uses a spline interpolation with smoothing parameter k ('s' in scipy.interpolate.UnivariateSpline).
"""
class MultiplePeaks(Exception):
pass
class NoPeaksFound(Exception):
pass
half_max = np.max(y) / 2.0
s = UnivariateSpline(x, y - half_max, s=k)
roots = s.roots()
if len(roots) > 2:
# Multiple peaks. Use the two that straddle the maximum value
maxvel = x[np.argmax(y)]
left_idx = np.argmin(maxvel - roots)
right_idx = np.argmin(roots - maxvel)
roots = np.array((roots[left_idx], roots[right_idx]))
elif len(roots) < 2:
raise NoPeaksFound("No proper peaks were found in the data set; likely "
"the dataset is flat (e.g. all zeros).")
if ret_roots:
return roots[0], roots[1]
return abs(roots[1] - roots[0])
示例7: get_t_for_vols
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def get_t_for_vols(self, vols, t_max=1000):
"""
Find the temperatures corresponding to a specific volume.
The search is performed interpolating the V(T) dependence with a spline and
finding the roots with of V(t) - v.
It may return more than one temperature for a volume in case of non monotonic behavior.
Args:
vols: list of volumes
t_max: maximum temperature considered for the fit
Returns:
A list of lists of temperatures. For each volume more than one temperature can
be identified.
"""
if not isinstance(vols, (list, tuple, np.ndarray)):
vols = [vols]
f = self.fit_energies(0, t_max, t_max+1)
temps = []
for v in vols:
spline = UnivariateSpline(f.temp, f.min_vol - v, s=0)
temps.append(spline.roots())
return temps
示例8: fwhm
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def fwhm(data, ypos=0.5):
spatial = data.sum(1)
spatial = spatial-np.min(spatial)
spatial_range = range(0, len(spatial))
spline = UnivariateSpline(spatial_range, (spatial -np.max(spatial)*ypos), s=0.1, k=3)
roots = spline.roots()
if len(roots) < 2:
return np.inf, (-np.inf, +np.inf)
return roots[-1]-roots[0], roots
示例9: FWHM_scipy
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def FWHM_scipy(X, Y):
"""Computing FWHM (Full width at half maximum)"""
try:
from scipy.interpolate import UnivariateSpline
spline = UnivariateSpline(X, Y, s=0)
r1, r2 = spline.roots() # find the roots
return r2 - r1 # return the difference (full width)
except ImportError:
return FWHM(X, Y)
示例10: find_critical_temperature
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def find_critical_temperature(df, offset):
curve = []
temps = np.round(df.temperature,2).unique()
for temp in temps:
curve.append([temp,df.loc[np.round(df.temperature,2) == temp].TTc.mean()])
curve = np.array(curve)
curve = curve[curve[:,0].argsort()]
f = UnivariateSpline(curve[:,0],curve[:,1]-offset)
root = f.roots()
return root[0]
示例11: MTF50
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def MTF50(self, MTFx,MTFy):
'''
return object resolution as [line pairs/mm]
where MTF=50%
see http://www.imatest.com/docs/sharpness/
'''
if self.mtf_x is None:
self.MTF()
f = UnivariateSpline(self.mtf_x, self.mtf_y-0.5)
return f.roots()[0]
示例12: interpolate_to_find_crossover
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def interpolate_to_find_crossover(frequencies,spl):
from scipy.interpolate import UnivariateSpline
s = UnivariateSpline(frequencies,spl,s=0)
root = []
for r in s.roots():
if r>=1000 and r<=5000:
root.append(r)
if len(root)==1: return root[0]
else: return 0
示例13: calculate_fwhm
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def calculate_fwhm(stimuli):
"""
Returns a tuple with positions on the x axis
Assumes that stimuli exists in self.smooth_responses
"""
top = peaks[stimuli][1]
low = float(self.smoothed_responses[stimuli](0))
half_max = (top - low)/2
y = self.mean_responses[stimuli]
spline = UnivariateSpline(self.x_axis, y - half_max - low, s=factor)
roots = spline.roots()
if np.any(roots):
for i in range(1, len(roots)):
if roots[i] > peaks[stimuli][0]:
break
roots = (roots[i - 1], roots[i])
return roots
示例14: integral
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def integral(x, y, I, k=10):
"""
Integrate y = f(x) for x = 0 to a such that the integral = I
I can be an array
"""
I = np.atleast_1d(I)
f = UnivariateSpline(x, y, s=k)
# Integrate as a function of x
F = f.antiderivative()
Y = F(x)
a = []
for intval in I:
F2 = UnivariateSpline(x, Y/Y[-1] - intval, s=0)
a.append(F2.roots())
return np.hstack(a)
示例15: get_profile_func_ab
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import roots [as 别名]
def get_profile_func_ab(self, profile_x, profile_y):
from scipy.interpolate import UnivariateSpline
profile_ = UnivariateSpline(profile_x, profile_y, k=3, s=0,
bbox=[0, 1])
roots = list(profile_.roots())
#assert(len(roots) == 1)
integ_list = []
from itertools import izip, cycle
for ss, int_r1, int_r2 in izip(cycle([1, -1]),
[0] + roots,
roots + [1]):
#print ss, int_r1, int_r2
integ_list.append(profile_.integral(int_r1, int_r2))
integ = np.abs(np.sum(integ_list))
def profile(o, x, slitpos):
return profile_(slitpos) / integ
return profile