本文整理汇总了Python中scipy.interpolate.interp1d方法的典型用法代码示例。如果您正苦于以下问题:Python interpolate.interp1d方法的具体用法?Python interpolate.interp1d怎么用?Python interpolate.interp1d使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.interpolate
的用法示例。
在下文中一共展示了interpolate.interp1d方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_on_lfw
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def validate_on_lfw(model, lfw_160_path):
# Read the file containing the pairs used for testing
pairs = lfw.read_pairs('validation-LFW-pairs.txt')
# Get the paths for the corresponding images
paths, actual_issame = lfw.get_paths(lfw_160_path, pairs)
num_pairs = len(actual_issame)
all_embeddings = np.zeros((num_pairs * 2, 512), dtype='float32')
for k in tqdm.trange(num_pairs):
img1 = cv2.imread(paths[k * 2], cv2.IMREAD_COLOR)[:, :, ::-1]
img2 = cv2.imread(paths[k * 2 + 1], cv2.IMREAD_COLOR)[:, :, ::-1]
batch = np.stack([img1, img2], axis=0)
embeddings = model.eval_embeddings(batch)
all_embeddings[k * 2: k * 2 + 2, :] = embeddings
tpr, fpr, accuracy, val, val_std, far = lfw.evaluate(
all_embeddings, actual_issame, distance_metric=1, subtract_mean=True)
print('Accuracy: %2.5f+-%2.5f' % (np.mean(accuracy), np.std(accuracy)))
print('Validation rate: %2.5f+-%2.5f @ FAR=%2.5f' % (val, val_std, far))
auc = metrics.auc(fpr, tpr)
print('Area Under Curve (AUC): %1.3f' % auc)
eer = brentq(lambda x: 1. - x - interpolate.interp1d(fpr, tpr)(x), 0., 1.)
print('Equal Error Rate (EER): %1.3f' % eer)
示例2: calclogf
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def calclogf(self):
"""
# wavelength dependence, from Table 19 in Leinert et al 1998
# interpolated w/ a quadratic in log-log space
Returns:
interpolant (object):
a 1D quadratic interpolant of intensity vs wavelength
"""
self.zodi_lam = np.array([0.2, 0.3, 0.4, 0.5, 0.7, 0.9, 1.0, 1.2, 2.2, 3.5,
4.8, 12, 25, 60, 100, 140]) # um
self.zodi_Blam = np.array([2.5e-8, 5.3e-7, 2.2e-6, 2.6e-6, 2.0e-6, 1.3e-6,
1.2e-6, 8.1e-7, 1.7e-7, 5.2e-8, 1.2e-7, 7.5e-7, 3.2e-7, 1.8e-8,
3.2e-9, 6.9e-10]) # W/m2/sr/um
x = np.log10(self.zodi_lam)
y = np.log10(self.zodi_Blam)
return interp1d(x, y, kind='quadratic')
示例3: apply_sync
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def apply_sync(sync_file, times, forward=True):
"""
:param sync_file: probe sync file (usually of the form _iblrig_ephysData.raw.imec1.sync.npy)
:param times: times in seconds to interpolate
:param forward: if True goes from probe time to session time, from session time to probe time
otherwise
:return: interpolated times
"""
sync_points = np.load(sync_file)
if forward:
fcn = interp1d(sync_points[:, 0],
sync_points[:, 1], fill_value='extrapolate')
else:
fcn = interp1d(sync_points[:, 1],
sync_points[:, 0], fill_value='extrapolate')
return fcn(times)
示例4: resampling_by_interpolate
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def resampling_by_interpolate(self, x):
"""Resampling base on 1st order interpolation
Parameters
---------
x : array, shape ('int(len(x) * f0rate)')
array of wsolaed waveform
Returns
---------
wsolaed: array, shape (`len(x)`)
Array of resampled (F0 transformed) waveform sequence
"""
# interpolate
wedlen = len(x)
intpfunc = interp1d(np.arange(wedlen), x, kind=1)
x_new = np.arange(0.0, wedlen - 1, self.f0rate)
resampled = intpfunc(x_new)
return resampled
示例5: highres
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def highres(y,kind='cubic',res=100):
'''
Interpolate data onto a higher resolution grid by a factor of *res*
Args:
y (1d array/list): signal to be interpolated
kind (str): order of interpolation (see docs for scipy.interpolate.interp1d)
res (int): factor to increase resolution of data via linear interpolation
Returns:
shift (float): offset between target and reference signal
'''
y = np.array(y)
x = np.arange(0, y.shape[0])
f = interp1d(x, y,kind='cubic')
xnew = np.linspace(0, x.shape[0]-1, x.shape[0]*res)
ynew = f(xnew)
return xnew,ynew
示例6: _resample_regressor
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def _resample_regressor(hr_regressor, hr_frame_times, frame_times):
"""this function sub-samples the regressors at frame times
Parameters
----------
hr_regressor : array of shape(n_samples),
the regressor time course sampled at high temporal resolution
hr_frame_times : array of shape(n_samples),
the corresponding time stamps
frame_times: array of shape(n_scans),
the desired time stamps
Returns
-------
regressor: array of shape(n_scans)
the resampled regressor
"""
from scipy.interpolate import interp1d
f = interp1d(hr_frame_times, hr_regressor)
return f(frame_times).T
示例7: _advect_surface
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def _advect_surface(self, dt):
if self.top:
# Extract top surface
x = self.model.mesh.data[self.top.data][:, 0]
y = self.model.mesh.data[self.top.data][:, 1]
# Extract velocities from top
vx = self.model.velocityField.data[self.top.data][:, 0]
vy = self.model.velocityField.data[self.top.data][:, 1]
# Advect top surface
x2 = x + vx * nd(dt)
y2 = y + vy * nd(dt)
# Spline top surface
f = interp1d(x2, y2, kind='cubic', fill_value='extrapolate')
self.TField.data[self.top.data, 0] = f(x)
comm.Barrier()
self.TField.syncronise()
示例8: compute_precision_score_mapping
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def compute_precision_score_mapping(thresh, prec, score):
ind = np.argsort(thresh);
thresh = thresh[ind];
prec = prec[ind];
for i in xrange(1, len(prec)):
prec[i] = max(prec[i], prec[i-1]);
indexes = np.unique(thresh, return_index=True)[1]
indexes = np.sort(indexes);
thresh = thresh[indexes]
prec = prec[indexes]
thresh = np.vstack((min(-1000, min(thresh)-1), thresh[:, np.newaxis], max(1000, max(thresh)+1)));
prec = np.vstack((prec[0], prec[:, np.newaxis], prec[-1]));
f = interp1d(thresh[:,0], prec[:,0])
val = f(score)
return val
示例9: load_spectrum
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def load_spectrum(filename, grid):
"""
Load a single spectrum
"""
file_in = pyfits.open(filename)
wl = np.array(file_in[0].data[2])
flux = np.array(file_in[0].data[0])
ivar = np.array((file_in[0].data[1]))
# correct for radial velocity of star
redshift = file_in[0].header['Z']
wl_shifted = wl - redshift * wl
# resample
flux_rs = (interpolate.interp1d(wl_shifted, flux))(grid)
ivar_rs = (interpolate.interp1d(wl_shifted, ivar))(grid)
ivar_rs[ivar_rs < 0] = 0. # in interpolating you can end up with neg
return flux_rs, ivar_rs
示例10: get_tukeyQcrit
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def get_tukeyQcrit(k, df, alpha=0.05):
'''
return critical values for Tukey's HSD (Q)
Parameters
----------
k : int in {2, ..., 10}
number of tests
df : int
degrees of freedom of error term
alpha : {0.05, 0.01}
type 1 error, 1-confidence level
not enough error checking for limitations
'''
if alpha == 0.05:
intp = interpolate.interp1d(crows, cv005[:,k-2])
elif alpha == 0.01:
intp = interpolate.interp1d(crows, cv001[:,k-2])
else:
raise ValueError('only implemented for alpha equal to 0.01 and 0.05')
return intp(df)
示例11: percentileofscore
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def percentileofscore(data, score):
"""Return the percentile-position of score relative to data.
score: Array of scores at which the percentile is computed.
Return percentiles (0-100).
Example
r = randn(50)
x = linspace(-2,2,100)
percentileofscore(r,x)
Raise an error if the score is outside the range of data.
"""
cdf = empiricalcdf(data)
interpolator = interpolate.interp1d(np.sort(data), np.sort(cdf))
return interpolator(score)*100.
示例12: monotone_fn_inverter
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def monotone_fn_inverter(fn, x, vectorized=True, **keywords):
"""
Given a monotone function fn (no checking is done to verify monotonicity)
and a set of x values, return an linearly interpolated approximation
to its inverse from its values on x.
"""
x = np.asarray(x)
if vectorized:
y = fn(x, **keywords)
else:
y = []
for _x in x:
y.append(fn(_x, **keywords))
y = np.array(y)
a = np.argsort(y)
return interp1d(y[a], x[a])
示例13: _resample_regressor
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def _resample_regressor(hr_regressor, hr_frame_times, frame_times):
""" this function sub-samples the regressors at frame times
Parameters
----------
hr_regressor : array of shape(n_samples),
the regressor time course sampled at high temporal resolution
hr_frame_times : array of shape(n_samples),
the corresponding time stamps
frame_times: array of shape(n_scans),
the desired time stamps
Returns
-------
regressor: array of shape(n_scans)
the resampled regressor
"""
from scipy.interpolate import interp1d
f = interp1d(hr_frame_times, hr_regressor)
return f(frame_times).T
示例14: test_linear
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def test_linear(self):
""" Check the actual implementation of linear interpolation.
"""
interp10 = interp1d(self.x10, self.y10)
assert_array_almost_equal(
interp10(self.x10),
self.y10,
)
assert_array_almost_equal(
interp10(1.2),
np.array([1.2]),
)
assert_array_almost_equal(
interp10([2.4, 5.6, 6.0]),
np.array([2.4, 5.6, 6.0]),
)
示例15: test_cubic
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import interp1d [as 别名]
def test_cubic(self):
""" Check the actual implementation of spline interpolation.
"""
interp10 = interp1d(self.x10, self.y10, kind='cubic')
assert_array_almost_equal(
interp10(self.x10),
self.y10,
)
assert_array_almost_equal(
interp10(1.2),
np.array([1.2]),
)
assert_array_almost_equal(
interp10([2.4, 5.6, 6.0]),
np.array([2.4, 5.6, 6.0]),
)