本文整理汇总了Python中scipy.interp函数的典型用法代码示例。如果您正苦于以下问题:Python interp函数的具体用法?Python interp怎么用?Python interp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了interp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_allkfolds_ROC
def plot_allkfolds_ROC(timestamp, cv, fpr_arr, tpr_arr):
sns.set(style="white", palette="muted", color_codes=True)
mean_tpr = 0.0
mean_fpr = 0.0
all_roc_auc = []
bins_roc = np.linspace(0, 1, 300)
with plt.style.context(('seaborn-muted')):
fig, ax = plt.subplots(figsize=(10, 8))
for i, (train, test) in enumerate(cv):
mean_tpr += interp(bins_roc, fpr_arr[i], tpr_arr[i])
mean_tpr[0] = 0.0
mean_fpr += interp(bins_roc, fpr_arr[i], tpr_arr[i])
mean_fpr[0] = 0.0
roc_auc = metrics.auc(fpr_arr[i], tpr_arr[i])
all_roc_auc.append(roc_auc)
ax.plot(fpr_arr[i], tpr_arr[i], lw=1, label='KFold %d (AUC = %0.2f)' % (i, roc_auc))
ax.plot([0, 1], [0, 1], '--', color=(0.6, 0.6, 0.6), label='Random')
mean_tpr /= len(cv)
mean_tpr[-1] = 1.0
mean_auc = np.mean(all_roc_auc)
ax.plot(bins_roc, mean_tpr, 'k--',
label='Mean ROC (AUC = %0.2f)' % mean_auc, lw=2)
ax.set_xlim([-0.05, 1.05])
ax.set_ylim([-0.05, 1.05])
ax.set_xlabel('False Positive Rate')
ax.set_ylabel('True Positive Rate')
ax.set_title('Receiver Operating Characteristic')
ax.legend(loc="lower right")
plt.savefig('{}_roc.png'.format(timestamp))
plt.close('all')
return mean_auc
示例2: e_r_read
def e_r_read(self, waves):
p = open("MaterialsDataFiles/" + self.material + ".txt", "r")
string = p.read()
p.close()
e_r = []
w = []
n = []
k = []
linecounter = 0
for thisline in string.split("\n"):
for x in thisline.split():
if linecounter == 0 and len(x) > 0:
w.append(float(x))
if linecounter == 1 and len(x) > 0:
n.append(float(x))
if linecounter == 2 and len(x) > 0:
k.append(float(x))
linecounter += 1
# interpolate n&k walues
n_new = sp.interp(waves, w, n)
k_new = sp.interp(waves, w, k)
e_r_new = []
# calculate epsilon from n&k for every wavelength
for i in range(len(waves)):
e_r_new.append(
n_new[i] ** 2 - k_new[i] ** 2 + 2j * n_new[i] * k_new[i]
) # calculate the complex epsilon from n&k
# not sure anymore why e_r (permittivity) gets appended the waves and e_r_new (complex epsilon)
e_r.append(waves)
e_r.append(e_r_new)
self.permittivity = e_r
示例3: test_calc_mean
def test_calc_mean(self):
vulnerability_set = self.from_xml()
intensity_level = 9
expected_w1timbermetal_mean = interp(intensity_level, [8.99, 9.05], [0.13, 0.15])
expected_w1timbermetal_sigma = expected_w1timbermetal_mean * 0.3
(w1timbermetal_mean, w1timbermetal_sigma) = vulnerability_set.calc_mean("W1TIMBERMETAL", intensity_level)
self.assertEqual(
expected_w1timbermetal_mean,
w1timbermetal_mean,
self.msg % (expected_w1timbermetal_mean, w1timbermetal_mean),
)
self.assertEqual(
expected_w1timbermetal_sigma,
w1timbermetal_sigma,
self.msg % (expected_w1timbermetal_sigma, w1timbermetal_sigma),
)
expected_w1bvmetal_mean = interp(intensity_level, [8.99, 9.05], [0.84, 0.85])
expected_w1bvmetal_sigma = expected_w1bvmetal_mean * 0.3
(w1bvmetal_mean, w1bvmetal_sigma) = vulnerability_set.calc_mean("W1BVMETAL", intensity_level)
self.assertEqual(expected_w1bvmetal_mean, w1bvmetal_mean, self.msg % (expected_w1bvmetal_mean, w1bvmetal_mean))
self.assertEqual(
expected_w1bvmetal_sigma, w1bvmetal_sigma, self.msg % (expected_w1bvmetal_sigma, w1bvmetal_sigma)
)
示例4: __call__
def __call__(self,x):
if issubclass(type(x),list):
y=scipy.interp(x,self['x'],self['y']);
else:
y=scipy.interp([x],self['x'],self['y']);
y=y[0];
return y;
示例5: e_r_read
def e_r_read(self,waves):
p = open('MaterialsDataFiles/'+self.material + '.txt','r')
string=p.read()
p.close()
e_r=[]
w=[]
n=[]
k=[]
linecounter=0
for thisline in string.split('\n'):
for x in thisline.split():
if linecounter==0 and len(x)>0:
w.append(float(x))
if linecounter==1 and len(x)>0:
n.append(float(x))
if linecounter==2 and len(x)>0:
k.append(float(x))
linecounter+=1
# interpolate n&k walues
n_new=sp.interp(waves,w,n)
k_new=sp.interp(waves,w,k)
e_r_new=[]
# calculate epsilon from n&k for every wavelength
for i in range(len(waves)):
e_r_new.append(n_new[i]**2-k_new[i]**2+2j*n_new[i]*k_new[i]) # calculate the complex epsilon from n&k
e_r.append(waves)
e_r.append(e_r_new)
self.permittivity=e_r
示例6: w_integral
def w_integral(s,W_ax,Y_ax):
"""
The integral part of the Bellman-equation.
"""
function = lambda theta,eps,s: max(interp(s*(theta+eps),W_ax,Y_ax), \
interp(s*(theta+eps)-COST,W_ax,v_func))*aggPDF(theta)*idiPDF(eps)
return dblquad(function,MIN_VAL_E,MAX_VAL_E,lambda x: MIN_VAL_AG, lambda x: MAX_VAL_AG, args=(s,))
示例7: calc_mean
def calc_mean(self, intensity):
"""
Calculate mean loss ratio and sigma based on the specified points on
the curve:
|
| +
| +
Mean loss ratio | +
| +
| +
| +
| +
| +
| +
| +
| +
+-----------------------------------
Intensity measure level
For a given intensity, mean loss and sigma is determined by linearly
interpolating the points on the curve.
Note that sigma is calculated as cv * mean loss as cv = mean loss/sigma
"""
mean_loss = interp(intensity,
self.intensity_measure_level,
self.mean_loss)
cv = interp(intensity,
self.intensity_measure_level,
self.coefficient_of_variation)
# cv = sigma / mean
sigma = cv * mean_loss
return (mean_loss, sigma)
示例8: __call__
def __call__(self, z):
"""Parameters: z is a number, sequence or array.
This method makes an instance f of LinInterp callable,
so f(z) returns the interpolation value(s) at z.
"""
if isinstance(z, int) or isinstance(z, float):
return interp ([z], self.X, self.Y)[0]
else:
return interp(z, self.X, self.Y)
示例9: interpolate_data
def interpolate_data(data, interpolation_timestep_ms):
'''
Interpolates all axes of the data array such that samples occur at equidistant timestamps.
'''
samples_count = len(data[:,TIME_AXIS_INDEX])
timestamps = np.arange(0.0, data[samples_count-1,TIME_AXIS_INDEX], interpolation_timestep_ms, dtype=np.float64)
interx = scipy.interp(timestamps, data[:,0], data[:,X_AXIS_INDEX])
intery = scipy.interp(timestamps, data[:,0], data[:,Y_AXIS_INDEX])
interz = scipy.interp(timestamps, data[:,0], data[:,Z_AXIS_INDEX])
return np.array([timestamps, interx, intery, interz]).transpose()
示例10: get_water_level
def get_water_level(costs_all,link,proba,climat):
'''extracts water levels. the 'proba' argument is how much frequency is increased because of climate change or el nino'''
water = DataFrame(columns=['return_period','water_level','proba'])
for RP in [5,10,25,50,100,250,500,1000]:
col = "{}_RP{} (dm)".format(climat,RP)
water.loc[len(water),:]=[RP/proba,costs_all.ix[(costs_all.scenarioID==str(link))&(costs_all.partial_or_full=="full")&(costs_all.improved_2nd==0),col].values[0],proba]
inter = water.copy()
#s = InterpolatedUnivariateSpline(water['return period'], water['water level'],k=1)
water.loc[len(water),:] = [500,interp([500],inter['return_period'].astype(float), inter['water_level'].astype(float))[0],proba]
water.loc[len(water),:] = [1000,interp([1000],inter['return_period'].astype(float), inter['water_level'].astype(float))[0],proba]
return water
示例11: ROC
def ROC(scores):
# Generate an ROC curve for each fold, ordered by increasing threshold
roc = scores.groupby('user').apply(lambda x: pd.DataFrame(np.c_[roc_curve(x['genuine'], x['score'])][::-1],
columns=['far', 'frr', 'threshold']))
# interpolate to get the same threshold values in each fold
thresholds = np.sort(roc['threshold'].unique())
roc = roc.groupby(level='user').apply(lambda x: pd.DataFrame(np.c_[thresholds,
interp(thresholds, x['threshold'], x['far']),
interp(thresholds, x['threshold'], x['frr'])],
columns=['threshold', 'far', 'frr']))
roc = roc.reset_index(level=1, drop=True).reset_index()
return roc
示例12: tophatfold
def tophatfold(lam, flux, FWHM=0.035):
lammin=min(lam)
lammax=max(lam)
dlambda=FWHM/17.
interlam=np.arange(lammin,lammax,dlambda)
interflux=interp(interlam,lam,flux)
#convovle flux array with gaussian--use smooth
fold=sp.ndimage.filters.uniform_filter(interflux,size=17)
#interpolate back to original grid
fluxfold=interp(lam,interlam,fold)
return fluxfold
示例13: execute
def execute(self):
#print 'in CPCT_Interpolate'
wind_speed_ax = np.cos(self.yaw*np.pi/180.0)**(self.pP/3.0)*self.wind_speed_hub
# use interpolation on precalculated CP-CT curve
wind_speed_ax = np.maximum(wind_speed_ax, self.windSpeedToCPCT.wind_speed[0])
wind_speed_ax = np.minimum(wind_speed_ax, self.windSpeedToCPCT.wind_speed[-1])
self.CP = interp(wind_speed_ax, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CP)
self.CT = interp(wind_speed_ax, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CT)
# normalize on incoming wind speed to correct coefficients for yaw
self.CP = self.CP * np.cos(self.yaw*np.pi/180.0)**self.pP
self.CT = self.CT * np.cos(self.yaw*np.pi/180.0)**2
示例14: populate_wing_sections
def populate_wing_sections(avl_wing,suave_wing):
symm = avl_wing.symmetric
sweep = avl_wing.sweep
dihedral = avl_wing.dihedral
span = suave_wing.spans.projected
semispan = suave_wing.spans.projected * 0.5 * (2 - symm)
origin = suave_wing.origin
root_section = Section()
root_section.tag = 'root_section'
root_section.origin = origin
root_section.chord = suave_wing.chords.root
root_section.twist = suave_wing.twists.root
tip_section = Section()
tip_section.tag = 'tip_section'
tip_section.chord = suave_wing.chords.tip
tip_section.twist = suave_wing.twists.tip
tip_section.origin = [origin[0]+semispan*np.tan(sweep),origin[1]+semispan,origin[2]+semispan*np.tan(dihedral)]
if avl_wing.vertical:
temp = tip_section.origin[2]
tip_section.origin[2] = tip_section.origin[1]
tip_section.origin[1] = temp
avl_wing.append_section(root_section)
avl_wing.append_section(tip_section)
if suave_wing.control_surfaces:
for ctrl in suave_wing.control_surfaces:
num = 1
for section in ctrl.sections:
semispan_fraction = (span/semispan) * section.origins.span_fraction
s = Section()
s.chord = scipy.interp(semispan_fraction,[0.,1.],[root_section.chord,tip_section.chord])
s.tag = '{0}_section{1}'.format(ctrl.tag,num)
s.origin = section.origins.dimensional
s.origin[0] = s.origin[0] - s.chord*section.origins.chord_fraction
s.twist = scipy.interp(semispan_fraction,[0.,1.],[root_section.twist,tip_section.twist])
c = Control_Surface()
c.tag = ctrl.tag
c.x_hinge = 1. - section.chord_fraction
c.sign_duplicate = ctrl.deflection_symmetry
s.append_control_surface(c)
avl_wing.append_section(s)
num += 1
return avl_wing
示例15: provideJ
def provideJ(self):
#print 'in CPCT_Interpolate - provideJ'
# standard central differencing
# set step size for finite differencing
h = 1e-6
# calculate upper and lower function values
wind_speed_ax_high_yaw = np.cos((self.yaw+h)*np.pi/180.0)**(self.pP/3.0)*self.wind_speed_hub
wind_speed_ax_low_yaw = np.cos((self.yaw-h)*np.pi/180.0)**(self.pP/3.0)*self.wind_speed_hub
wind_speed_ax_high_wind = np.cos(self.yaw*np.pi/180.0)**(self.pP/3.0)*(self.wind_speed_hub+h)
wind_speed_ax_low_wind = np.cos(self.yaw*np.pi/180.0)**(self.pP/3.0)*(self.wind_speed_hub-h)
# use interpolation on precalculated CP-CT curve
wind_speed_ax_high_yaw = np.maximum(wind_speed_ax_high_yaw, self.windSpeedToCPCT.wind_speed[0])
wind_speed_ax_low_yaw = np.maximum(wind_speed_ax_low_yaw, self.windSpeedToCPCT.wind_speed[0])
wind_speed_ax_high_wind = np.maximum(wind_speed_ax_high_wind, self.windSpeedToCPCT.wind_speed[0])
wind_speed_ax_low_wind = np.maximum(wind_speed_ax_low_wind, self.windSpeedToCPCT.wind_speed[0])
wind_speed_ax_high_yaw = np.minimum(wind_speed_ax_high_yaw, self.windSpeedToCPCT.wind_speed[-1])
wind_speed_ax_low_yaw = np.minimum(wind_speed_ax_low_yaw, self.windSpeedToCPCT.wind_speed[-1])
wind_speed_ax_high_wind = np.minimum(wind_speed_ax_high_wind, self.windSpeedToCPCT.wind_speed[-1])
wind_speed_ax_low_wind = np.minimum(wind_speed_ax_low_wind, self.windSpeedToCPCT.wind_speed[-1])
CP_high_yaw = interp(wind_speed_ax_high_yaw, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CP)
CP_low_yaw = interp(wind_speed_ax_low_yaw, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CP)
CP_high_wind = interp(wind_speed_ax_high_wind, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CP)
CP_low_wind = interp(wind_speed_ax_low_wind, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CP)
CT_high_yaw = interp(wind_speed_ax_high_yaw, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CT)
CT_low_yaw = interp(wind_speed_ax_low_yaw, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CT)
CT_high_wind = interp(wind_speed_ax_high_wind, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CT)
CT_low_wind = interp(wind_speed_ax_low_wind, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CT)
# normalize on incoming wind speed to correct coefficients for yaw
CP_high_yaw = CP_high_yaw * np.cos((self.yaw+h)*np.pi/180.0)**self.pP
CP_low_yaw = CP_low_yaw * np.cos((self.yaw-h)*np.pi/180.0)**self.pP
CP_high_wind = CP_high_wind * np.cos((self.yaw)*np.pi/180.0)**self.pP
CP_low_wind = CP_low_wind * np.cos((self.yaw)*np.pi/180.0)**self.pP
CT_high_yaw = CT_high_yaw * np.cos((self.yaw+h)*np.pi/180.0)**2
CT_low_yaw = CT_low_yaw * np.cos((self.yaw-h)*np.pi/180.0)**2
CT_high_wind = CT_high_wind * np.cos((self.yaw)*np.pi/180.0)**2
CT_low_wind = CT_low_wind * np.cos((self.yaw)*np.pi/180.0)**2
# compute derivative via central differencing and arrange in sub-matrices of the Jacobian
dCP_dyaw = np.eye(self.nTurbines)*(CP_high_yaw-CP_low_yaw)/(2.0*h)
dCP_dwind = np.eye(self.nTurbines)*(CP_high_wind-CP_low_wind)/(2.0*h)
dCT_dyaw = np.eye(self.nTurbines)*(CT_high_yaw-CT_low_yaw)/(2.0*h)
dCT_dwind = np.eye(self.nTurbines)*(CT_high_wind-CT_low_wind)/(2.0*h)
# compile full Jacobian from sub-matrices
dCP = np.hstack((dCP_dyaw, dCP_dwind))
dCT = np.hstack((dCT_dyaw, dCT_dwind))
J = np.vstack((dCP, dCT))
return J