本文整理匯總了Python中scipy.interpolate.CubicSpline方法的典型用法代碼示例。如果您正苦於以下問題:Python interpolate.CubicSpline方法的具體用法?Python interpolate.CubicSpline怎麽用?Python interpolate.CubicSpline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scipy.interpolate
的用法示例。
在下文中一共展示了interpolate.CubicSpline方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: cubic_spline
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def cubic_spline(orbit_data):
'''
Compute component wise cubic spline of points of input data
Args:
orbit_data (numpy array): array of orbit data points of the
format [time, x, y, z]
Returns:
list: component wise cubic splines of orbit data points of the format [spline_x, spline_y, spline_z]
'''
time = orbit_data[:,:1]
coordinates = list([orbit_data[:,1:2], orbit_data[:,2:3], orbit_data[:,3:4]])
splines = list(map(lambda a:CubicSpline(time.ravel(),a.ravel()), coordinates))
return splines
示例2: modbc
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def modbc(self):
self.resorx = 0.0
self.resory = 0.0
for i in range(2, self.ni):
xp = self.x(i, nj - 1)
yp = self.y(i, nj - 1)
xb = self.x(i, nj)
yb = self.y(i, nj)
ifail = 0
call e02bcf(nicap7, xkn, cn, xb, 1, sn, ifail)
interpolate.CubicSpline(x, y, axis=0, bc_type='not-a-knot', extrapolate=None)
dydxb = min(sn(2), 1.d10)
dydxb = max(sn(2), 1.d-10)
if(sn(2).lt.0.0) dydxb = max(sn(2), -1.d10)
if(sn(2).lt.0.0) dydxb = min(sn(2), -1.d-10)
x(i, nj) = (yb-yp-xb*dydxb-xp/dydxb)/(-dydxb-1.0/dydxb)
ifail = 0.0
call e02bcf(nicap7, xkn, cn, x(i, nj), 1, sn, ifail)
y(i, nj) = sn(1)
resxb = abs(xb-x(i, nj))/xl
resorx = resorx+resxb
resyb = abs(yb-y(i, nj))/yl
resory = resory+resyb
示例3: dedh
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def dedh(self, pseudo_enthalpy, rel_dh=1e-5, interp_type='CubicSpline'):
"""
Value of [depsilon/dh](p)
:param pseudo_enthalpy (`float`): Dimensionless pseudo-enthalpy.
:param interp_type (`str`): String specifying interpolation type.
Current implementations are 'CubicSpline', 'linear'.
:param rel_dh (`float`): Relative step size in pseudo-enthalpy space.
:return dedh (`float`): Derivative of energy-density with respect to pseudo-enthalpy
evaluated at `pseudo_enthalpy` in geometerized units.
"""
# step size=fraction of value
dh = pseudo_enthalpy * rel_dh
eps_upper = self.energy_density_from_pseudo_enthalpy(pseudo_enthalpy + dh, interp_type=interp_type)
eps_lower = self.energy_density_from_pseudo_enthalpy(pseudo_enthalpy - dh, interp_type=interp_type)
return (eps_upper - eps_lower) / (2. * dh)
示例4: velocity_from_pseudo_enthalpy
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def velocity_from_pseudo_enthalpy(self, pseudo_enthalpy, interp_type='CubicSpline'):
"""
Returns the speed of sound in geometerized units in the
neutron star at the specified pressure.
Assumes the equation
vs = c (de/dp)^{-1/2}
:param pseudo_enthalpy (`float`): Dimensionless pseudo-enthalpy.
:param interp_type (`str`): String specifying interpolation type.
Current implementations are 'CubicSpline', 'linear'.
:return v_s (`float`): Speed of sound at `pseudo-enthalpy` in geometerized units.
"""
pressure = self.pressure_from_pseudo_enthalpy(pseudo_enthalpy, interp_type=interp_type)
return self.dedp(pressure, interp_type=interp_type) ** -0.5
示例5: __init__
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def __init__(self, p_1, p_2, duration=1.0):
self.cs = CubicSpline(np.array([0.0, duration]), np.array([p_1, p_2]), bc_type='clamped')
示例6: test_cubic_bc_natural
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def test_cubic_bc_natural():
np.random.seed(1234)
x = np.linspace(0, 5, 20)
xi = np.linspace(0, 5, 100)
y = np.sin(x) + np.random.randn(x.size) * 0.3
cs = CubicSpline(x, y, bc_type='natural')
ss = csaps.CubicSmoothingSpline(x, y, smooth=1.0)
y_cs = cs(xi)
y_ss = ss(xi)
assert cs.c == pytest.approx(ss.spline.c)
assert y_cs == pytest.approx(y_ss)
示例7: __init__
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def __init__(self, gate_poses):
self.gates = gate_poses
self.n_gates = np.size(gate_poses, 0)
positions = np.array([pose.position.to_numpy_array() for pose in gate_poses])
dists = np.linalg.norm(positions[1:, :] - positions[:-1, :], axis=1)
self.arc_length = np.zeros(shape=self.n_gates)
self.arc_length[1:] = np.cumsum(dists)
# tangents from quaternion
# by rotating default gate direction with quaternion
self.tangents = np.zeros(shape=(self.n_gates, 3))
for i, pose in enumerate(gate_poses):
self.tangents[i, :] = rotate_vector(pose.orientation, gate_facing_vector).to_numpy_array()
self.track_spline = CubicHermiteSpline(self.arc_length, positions, self.tangents, axis=0)
# gate width to track (half) width
gate_widths = [gate_dimensions[0] / 2.0 for gate in gate_poses]
gate_heights = [gate_dimensions[1] / 2.0 for gate in gate_poses]
self.track_width_spline = CubicSpline(self.arc_length, gate_widths, axis=0)
self.track_height_spline = CubicSpline(self.arc_length, gate_heights, axis=0)
# sample 2048 points, the 2048 are arbitrary and should really be a parameter
taus = np.linspace(self.arc_length[0], self.arc_length[-1], 2**12)
self.track_centers = self.track_spline(taus)
self.track_tangents = self.track_spline.derivative(nu=1)(taus)
self.track_tangents /= np.linalg.norm(self.track_tangents, axis=1)[:, np.newaxis]
self.track_normals = np.zeros_like(self.track_tangents)
self.track_normals[:, 0] = -self.track_tangents[:, 1]
self.track_normals[:, 1] = self.track_tangents[:, 0]
self.track_normals /= np.linalg.norm(self.track_normals, axis=1)[:, np.newaxis]
self.track_widths = self.track_width_spline(taus)
self.track_heights = self.track_height_spline(taus)
示例8: interpolation
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def interpolation(data, ori_t_unit=0.02, tar_t_unit=0.01):
assert(len(data.shape)==2)
ori_x = np.arange(len(data))
tar_x = np.arange(0, len(data), tar_t_unit/ori_t_unit)
func = CubicSpline(ori_x, data, axis=0)
return func(tar_x)
示例9: energy_from_pressure
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def energy_from_pressure(self, pressure, interp_type='CubicSpline'):
"""
Find value of energy_from_pressure
as in lalsimulation, return e = K * p**(3./5.) below min pressure
:param pressure (`float`): pressure in geometerized units.
:param interp_type (`str`): String specifying which interpolation type to use.
Currently implemented: 'CubicSpline', 'linear'.
:param energy_density (`float`): energy-density in geometerized units.
"""
pressure = np.atleast_1d(pressure)
energy_returned = np.zeros(pressure.size)
indices_less_than_min = np.nonzero(pressure < self.minimum_pressure)
indices_greater_than_min = np.nonzero(pressure >= self.minimum_pressure)
# We do this special for less than min pressure
energy_returned[indices_less_than_min] = 10 ** (np.log10(self.energy_density[0]) +
(3. / 5.) * (np.log10(pressure[indices_less_than_min]) -
np.log10(self.pressure[0])))
if interp_type == 'CubicSpline':
energy_returned[indices_greater_than_min] = (
10. ** self.interp_energy_density_from_pressure(np.log10(pressure[indices_greater_than_min])))
elif interp_type == 'linear':
energy_returned[indices_greater_than_min] = np.interp(pressure[indices_greater_than_min],
self.pressure,
self.energy_density)
else:
raise ValueError('Interpolation scheme must be linear or CubicSpline')
if energy_returned.size == 1:
return energy_returned[0]
else:
return energy_returned
示例10: pressure_from_pseudo_enthalpy
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def pressure_from_pseudo_enthalpy(self, pseudo_enthalpy, interp_type='CubicSpline'):
"""
Find p(h)
as in lalsimulation, return p = K * h**(5./2.) below min enthalpy
:param pseudo_enthalpy (`float`): Dimensionless pseudo-enthalpy.
:interp_type (`str`): String specifying interpolation type.
Current implementations are 'CubicSpline', 'linear'.
:return pressure (`float`): pressure in geometerized units.
"""
pseudo_enthalpy = np.atleast_1d(pseudo_enthalpy)
pressure_returned = np.zeros(pseudo_enthalpy.size)
indices_less_than_min = np.nonzero(pseudo_enthalpy < self.minimum_pseudo_enthalpy)
indices_greater_than_min = np.nonzero(pseudo_enthalpy >= self.minimum_pseudo_enthalpy)
pressure_returned[indices_less_than_min] = 10. ** (np.log10(self.pressure[0]) +
2.5 * (np.log10(pseudo_enthalpy[indices_less_than_min]) -
np.log10(self.pseudo_enthalpy[0])))
if interp_type == 'CubicSpline':
pressure_returned[indices_greater_than_min] = (
10. ** self.interp_pressure_from_pseudo_enthalpy(np.log10(pseudo_enthalpy[indices_greater_than_min])))
elif interp_type == 'linear':
pressure_returned[indices_greater_than_min] = np.interp(pseudo_enthalpy[indices_greater_than_min],
self.pseudo_enthalpy,
self.pressure)
else:
raise ValueError('Interpolation scheme must be linear or CubicSpline')
if pressure_returned.size == 1:
return pressure_returned[0]
else:
return pressure_returned
示例11: energy_density_from_pseudo_enthalpy
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def energy_density_from_pseudo_enthalpy(self, pseudo_enthalpy, interp_type='CubicSpline'):
"""
Find energy_density_from_pseudo_enthalpy(pseudo_enthalpy)
as in lalsimulation, return e = K * h**(3./2.) below min enthalpy
:param pseudo_enthalpy (`float`): Dimensionless pseudo-enthalpy.
:param interp_type (`str`): String specifying interpolation type.
Current implementations are 'CubicSpline', 'linear'.
:return energy_density (`float`): energy-density in geometerized units.
"""
pseudo_enthalpy = np.atleast_1d(pseudo_enthalpy)
energy_returned = np.zeros(pseudo_enthalpy.size)
indices_less_than_min = np.nonzero(pseudo_enthalpy < self.minimum_pseudo_enthalpy)
indices_greater_than_min = np.nonzero(pseudo_enthalpy >= self.minimum_pseudo_enthalpy)
energy_returned[indices_less_than_min] = 10 ** (np.log10(self.energy_density[0]) +
1.5 * (np.log10(pseudo_enthalpy[indices_less_than_min]) -
np.log10(self.pseudo_enthalpy[0])))
if interp_type == 'CubicSpline':
x = np.log10(pseudo_enthalpy[indices_greater_than_min])
energy_returned[indices_greater_than_min] = 10 ** self.interp_energy_density_from_pseudo_enthalpy(x)
elif interp_type == 'linear':
energy_returned[indices_greater_than_min] = np.interp(pseudo_enthalpy[indices_greater_than_min],
self.pseudo_enthalpy,
self.energy_density)
else:
raise ValueError('Interpolation scheme must be linear or CubicSpline')
if energy_returned.size == 1:
return energy_returned[0]
else:
return energy_returned
示例12: pseudo_enthalpy_from_energy_density
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def pseudo_enthalpy_from_energy_density(self, energy_density, interp_type='CubicSpline'):
"""
Find h(epsilon)
as in lalsimulation, return h = K * e**(2./3.) below min enthalpy
:param energy_density (`float`): energy-density in geometerized units.
:param interp_type (`str`): String specifying interpolation type.
Current implementations are 'CubicSpline', 'linear'.
:return pseudo_enthalpy (`float`): Dimensionless pseudo-enthalpy.
"""
energy_density = np.atleast_1d(energy_density)
pseudo_enthalpy_returned = np.zeros(energy_density.size)
indices_less_than_min = np.nonzero(energy_density < self.minimum_energy_density)
indices_greater_than_min = np.nonzero(energy_density >= self.minimum_energy_density)
pseudo_enthalpy_returned[indices_less_than_min] = 10 ** (np.log10(self.pseudo_enthalpy[0]) + (2. / 3.) *
(np.log10(energy_density[indices_less_than_min]) -
np.log10(self.energy_density[0])))
if interp_type == 'CubicSpline':
x = np.log10(energy_density[indices_greater_than_min])
pseudo_enthalpy_returned[indices_greater_than_min] = 10**self.interp_pseudo_enthalpy_from_energy_density(x)
elif interp_type == 'linear':
pseudo_enthalpy_returned[indices_greater_than_min] = np.interp(energy_density[indices_greater_than_min],
self.energy_density,
self.pseudo_enthalpy)
else:
raise ValueError('Interpolation scheme must be linear or CubicSpline')
if pseudo_enthalpy_returned.size == 1:
return pseudo_enthalpy_returned[0]
else:
return pseudo_enthalpy_returned
示例13: radius_from_mass
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def radius_from_mass(self, m):
"""
:param m: mass of neutron star in solar masses
:return: radius of neutron star in meters
"""
f = CubicSpline(self.mass, self.radius, bc_type='natural', extrapolate=True)
mass_converted_to_geom = m * MSUN_SI * G_SI / C_SI ** 2.
return f(mass_converted_to_geom)
示例14: k2_from_mass
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def k2_from_mass(self, m):
"""
:param m: mass of neutron star in solar masses.
:return: dimensionless second tidal love number.
"""
f = CubicSpline(self.mass, self.k2love_number, bc_type='natural', extrapolate=True)
m_geom = m * MSUN_SI * G_SI / C_SI ** 2.
return f(m_geom)
示例15: _interpolate_packed_pixels
# 需要導入模塊: from scipy import interpolate [as 別名]
# 或者: from scipy.interpolate import CubicSpline [as 別名]
def _interpolate_packed_pixels(dataset, max_nans_interpolation):
given_pos = np.arange(5, 409, 8)
new_pos = np.arange(1, 410)
lat_in = np.deg2rad(dataset["lat"].values)
lon_in = np.deg2rad(dataset["lon"].values)
# We cannot define given positions for each scanline, but we have to
# set them for all equally. Hence, we skip every scan position of all
# scan lines even if only one contains a NaN value:
nan_scnpos = \
np.isnan(lat_in).sum(axis=0) + np.isnan(lon_in).sum(axis=0)
valid_pos = nan_scnpos == 0
if valid_pos.sum() < 52 - max_nans_interpolation:
raise ValueError(
"Too many NaNs in latitude and longitude of this AVHRR file. "
"Cannot guarantee a good interpolation!"
)
# Filter NaNs because CubicSpline cannot handle it:
lat_in = lat_in[:, valid_pos]
lon_in = lon_in[:, valid_pos]
given_pos = given_pos[valid_pos]
x_in = np.cos(lon_in) * np.cos(lat_in)
y_in = np.sin(lon_in) * np.cos(lat_in)
z_in = np.sin(lat_in)
xf = CubicSpline(given_pos, x_in, axis=1, extrapolate=True)(new_pos)
yf = CubicSpline(given_pos, y_in, axis=1, extrapolate=True)(new_pos)
zf = CubicSpline(given_pos, z_in, axis=1, extrapolate=True)(new_pos)
lon = np.rad2deg(np.arctan2(yf, xf))
lat = np.rad2deg(np.arctan2(zf, np.sqrt(xf ** 2 + yf ** 2)))
dataset["lat"] = ("scnline", "scnpos"), lat
dataset["lon"] = ("scnline", "scnpos"), lon
# The other packed variables will be simply padded:
for var_name, var in dataset.data_vars.items():
if "packed_pixels" not in var.dims:
continue
nan_scnpos = np.isnan(var).sum(axis=0)
valid_pos = nan_scnpos == 0
given_pos = np.arange(5, 409, 8)[valid_pos]
dataset[var_name] = xr.DataArray(
CubicSpline(
given_pos, var.values[:, valid_pos], axis=1,
extrapolate=True)(new_pos),
dims=("scnline", "scnpos")
)