本文整理匯總了Python中numpy.unwrap方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.unwrap方法的具體用法?Python numpy.unwrap怎麽用?Python numpy.unwrap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.unwrap方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: act
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def act(self, obs):
quad_to_obj_pos, quad_to_obj_rot = obs[:2]
quad_to_obj_T = transformations.quaternion_matrix(np.r_[quad_to_obj_rot[3], quad_to_obj_rot[:3]])
quad_to_obj_T[:3, 3] = quad_to_obj_pos
obj_to_quad_T = transformations.inverse_matrix(quad_to_obj_T)
if self.tightness == 1.0:
des_offset_hra = self.target_hra
else:
offset = obj_to_quad_T[:3, 3]
offset_hra = xyz_to_hra(offset)
target_hra = self.target_hra.copy()
offset_hra[-1], target_hra[-1] = np.unwrap([offset_hra[-1], target_hra[-1]])
des_offset_hra = (1 - self.tightness) * offset_hra + self.tightness * target_hra
des_offset = hra_to_xyz(des_offset_hra)
des_obj_to_quad_T = transformations.rotation_matrix(des_offset_hra[2], np.array([0, 0, 1]))
des_obj_to_quad_T[:3, 3] = des_offset
self.pbvs_pol.target_to_obj_T = transformations.inverse_matrix(des_obj_to_quad_T)
return self.pbvs_pol.act(obs)
示例2: test_specgram_complex_phase_equivalent
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def test_specgram_complex_phase_equivalent(self):
freqs = self.freqs_specgram
specc, freqspecc, tc = mlab.specgram(x=self.y,
NFFT=self.NFFT_specgram,
Fs=self.Fs,
noverlap=self.nover_specgram,
pad_to=self.pad_to_specgram,
sides=self.sides,
mode='complex')
specp, freqspecp, tp = mlab.specgram(x=self.y,
NFFT=self.NFFT_specgram,
Fs=self.Fs,
noverlap=self.nover_specgram,
pad_to=self.pad_to_specgram,
sides=self.sides,
mode='phase')
assert_array_equal(freqspecc, freqspecp)
assert_array_equal(tc, tp)
assert_allclose(np.unwrap(np.angle(specc), axis=0), specp,
atol=1e-06)
示例3: test_specgram_angle_phase_equivalent
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def test_specgram_angle_phase_equivalent(self):
freqs = self.freqs_specgram
speca, freqspeca, ta = mlab.specgram(x=self.y,
NFFT=self.NFFT_specgram,
Fs=self.Fs,
noverlap=self.nover_specgram,
pad_to=self.pad_to_specgram,
sides=self.sides,
mode='angle')
specp, freqspecp, tp = mlab.specgram(x=self.y,
NFFT=self.NFFT_specgram,
Fs=self.Fs,
noverlap=self.nover_specgram,
pad_to=self.pad_to_specgram,
sides=self.sides,
mode='phase')
assert_array_equal(freqspeca, freqspecp)
assert_array_equal(ta, tp)
assert_allclose(np.unwrap(speca, axis=0), specp,
atol=1e-06)
示例4: unwrap
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def unwrap(p, discont=numpy.pi, axis=-1):
"""Unwrap by changing deltas between values to 2*pi complement.
Args:
p (cupy.ndarray): Input array.
discont (float): Maximum discontinuity between values, default is
``pi``.
axis (int): Axis along which unwrap will operate, default is the last
axis.
Returns:
cupy.ndarray: The result array.
.. seealso:: :func:`numpy.unwrap`
"""
p = cupy.asarray(p)
nd = p.ndim
dd = sumprod.diff(p, axis=axis)
slice1 = [slice(None, None)]*nd # full slices
slice1[axis] = slice(1, None)
slice1 = tuple(slice1)
ph_correct = _unwrap_correct(dd, discont)
up = cupy.array(p, copy=True, dtype='d')
up[slice1] = p[slice1] + cupy.cumsum(ph_correct, axis=axis)
return up
示例5: testInstantaneousFrequency
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def testInstantaneousFrequency(self, shape, axis):
# Instantaneous Frequency in numpy
phase_np = np.pi * (2 * np.random.rand(*shape) - 1)
unwrapped_np = np.unwrap(phase_np, axis=axis)
dphase_np = np.diff(unwrapped_np, axis=axis)
# Append with initial phase
s = [slice(None),] * unwrapped_np.ndim
s[axis] = slice(0, 1)
slice_np = unwrapped_np[s]
dphase_np = np.concatenate([slice_np, dphase_np], axis=axis) / np.pi
phase_tf = tf.convert_to_tensor(phase_np)
with self.cached_session() as sess:
dphase_tf = sess.run(spectral_ops.instantaneous_frequency(phase_tf,
time_axis=axis))
self.assertAllClose(dphase_np, dphase_tf)
示例6: smoothness_score
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def smoothness_score(angles):
"""Computes the smoothness score of a line interpolation according to the
angles of each line.
Args:
- angles: Array of shape (n_interpolations, n_lines_per_interpolation)
giving the angle of each line in each interpolation.
Returns:
- smoothness_scores: Array of shape (n_interpolations,) giving the
average smoothness score for all of the provided interpolations.
"""
angles = np.atleast_2d(angles)
# Remove discontinuities larger than np.pi
angles = np.unwrap(angles)
diffs = np.abs(np.diff(angles, axis=-1))
# Compute the angle difference from the first and last point
total_diff = np.abs(angles[:, :1] - angles[:, -1:])
# When total_diff is zero, there's no way to compute this score
zero_diff = (total_diff < 1e-4).flatten()
normalized_diffs = diffs/total_diff
deviation = np.max(normalized_diffs, axis=-1) - 1./(angles.shape[1] - 1)
# Set score to NaN when we aren't able to compute it
deviation[zero_diff] = np.nan
return deviation
示例7: real_spectrum
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def real_spectrum(signal, axis=-1, **kwargs):
try:
import matplotlib.pyplot as plt
except ImportError:
import warnings
warnings.warn("Matplotlib is required for plotting")
return
S = np.fft.rfft(signal, axis=axis)
f = np.arange(S.shape[axis]) / float(2 * S.shape[axis])
plt.subplot(2, 1, 1)
P = dB(S)
plt.plot(f, P, **kwargs)
plt.subplot(2, 1, 2)
phi = np.unwrap(np.angle(S))
plt.plot(f, phi, **kwargs)
示例8: phaseanalysis
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def phaseanalysis(firstharmonic, displayplots=False):
print('entering phaseanalysis')
analytic_signal = hilbert(firstharmonic)
amplitude_envelope = np.abs(analytic_signal)
instantaneous_phase = np.angle(analytic_signal)
if displayplots:
print('making plots')
fig = pl.figure()
ax1 = fig.add_subplot(311)
ax1.set_title('Analytic signal')
X = np.linspace(0.0, 1.0, num=len(firstharmonic))
pl.plot(X, analytic_signal.real, 'k', X, analytic_signal.imag, 'r')
ax2 = fig.add_subplot(312)
ax2.set_title('Phase')
pl.plot(X, instantaneous_phase, 'g')
ax3 = fig.add_subplot(313)
ax3.set_title('Amplitude')
pl.plot(X, amplitude_envelope, 'b')
pl.show()
pl.savefig('phaseanalysistest.jpg')
instantaneous_phase = np.unwrap(instantaneous_phase)
return instantaneous_phase, amplitude_envelope
示例9: phase_from_frequencyseries
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def phase_from_frequencyseries(htilde, remove_start_phase=True):
"""Returns the phase from the given frequency-domain waveform. This assumes
that the waveform has been sampled finely enough that the phase cannot
change by more than pi radians between each step.
Parameters
----------
htilde : FrequencySeries
The waveform to get the phase for; must be a complex frequency series.
remove_start_phase : {True, bool}
Subtract the initial phase before returning.
Returns
-------
FrequencySeries
The phase of the waveform as a function of frequency.
"""
p = numpy.unwrap(numpy.angle(htilde.data)).astype(
real_same_precision_as(htilde))
if remove_start_phase:
p += -p[0]
return FrequencySeries(p, delta_f=htilde.delta_f, epoch=htilde.epoch,
copy=False)
示例10: calc_inst_info
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def calc_inst_info(modes,samplerate):
"""
Calculate the instantaneous frequency, amplitude, and phase of
each mode.
"""
amp=np.zeros(modes.shape,np.float32)
phase=np.zeros(modes.shape,np.float32)
f=np.zeros(modes.shape,np.float32)
print("Mode 1:", len(modes), samplerate)
for m in range(len(modes)):
h=scipy.signal.hilbert(modes[m])
print(len(modes[m]))
print("Mean Amplitude of mode ", m, np.mean(np.abs(h)))
print("Mean Phase of mode ", m, np.mean(np.angle(h)))
phase[m,:]=np.angle(h)
print("Frequ", np.diff(np.unwrap(phase[:,np.r_[0,0:len(modes[m])]]))/(2*np.pi)*samplerate)
amp[m,:]=np.abs(h)
phase[m,:]=np.angle(h)
f[m,:] = np.r_[np.nan,
0.5*(np.angle(-h[2:]*np.conj(h[0:-2]))+np.pi)/(2*np.pi) * samplerate,
np.nan]
print("Mean Frequ of mode ", m, np.mean(np.diff(np.unwrap(phase[:,np.r_[0,0:len(modes[0])]]))/(2*np.pi)*samplerate))
#f(m,:) = [nan 0.5*(angle(-h(t+1).*conj(h(t-1)))+pi)/(2*pi) * sr nan];
# calc the freqs (old way)
#f=np.diff(np.unwrap(phase[:,np.r_[0,0:len(modes[0])]]))/(2*np.pi)*samplerate
# clip the freqs so they don't go below zero
#f = f.clip(0,f.max())
return f,amp,phase
示例11: save_xhrss_dump_proj
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def save_xhrss_dump_proj(dump_proj, filePath):
# saves the dfl_hxrss_filt radiation projections dump to text files
(t_l_scale, _, t_l_int_a, t_l_pha_a), (f_l_scale, f_l_filt, _, f_l_int_a) = dump_proj
f = open(filePath + '.t.txt', 'wb')
header = 'Distance Power Phase'
np.savetxt(f, np.c_[t_l_scale, t_l_int_a, t_l_pha_a], header=header, fmt="%e", newline='\n', comments='')
f.close()
f = open(filePath + '.f.txt', 'wb')
header = 'Wavelength Spectrum Filter_Abs Filter_Ang'
np.savetxt(f, np.c_[f_l_scale, f_l_int_a, np.abs(f_l_filt), np.unwrap(np.angle(f_l_filt))], header=header, fmt="%.8e", newline='\n', comments='')
f.close()
示例12: test_vertices_2d
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def test_vertices_2d(self):
# The vertices should be in counterclockwise order in 2-D
np.random.seed(1234)
points = np.random.rand(30, 2)
hull = qhull.ConvexHull(points)
assert_equal(np.unique(hull.simplices), np.sort(hull.vertices))
# Check counterclockwiseness
x, y = hull.points[hull.vertices].T
angle = np.arctan2(y - y.mean(), x - x.mean())
assert_(np.all(np.diff(np.unwrap(angle)) > 0))
示例13: follow_joint_trajectory
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def follow_joint_trajectory(self, traj):
traj = np.r_[np.atleast_2d(self.get_joint_positions()), traj]
for i in [2, 4, 6]:
traj[:, i] = np.unwrap(traj[:, i])
times = retiming.retime_with_vel_limits(traj, self.vel_limits)
times_up = np.arange(0, times[-1], .1)
traj_up = mu.interp2d(times_up, times, traj)
vels = resampling.get_velocities(traj_up, times_up, .001)
self.follow_timed_joint_trajectory(traj_up, vels, times_up)
示例14: unwrap_arm_traj_in_place
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def unwrap_arm_traj_in_place(traj):
assert traj.shape[1] == 7
for i in [2, 4, 6]:
traj[:, i] = np.unwrap(traj[:, i])
return traj
示例15: act
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unwrap [as 別名]
def act(self, obs):
quad_pos = np.array(self.env.quad_node.getPos())
if self.tightness == 1.0:
des_offset_hra = self.target_hra
else:
hor_car_T = self.env.hor_car_T
hor_car_inv_T = tf.inverse_matrix(hor_car_T)
offset = hor_car_inv_T[:3, :3].dot(quad_pos) + hor_car_inv_T[:3, 3]
offset_hra = xyz_to_hra(offset)
target_hra = self.target_hra.copy()
offset_hra[-1], target_hra[-1] = np.unwrap([offset_hra[-1], target_hra[-1]])
des_offset_hra = (1 - self.tightness) * offset_hra + self.tightness * target_hra
des_offset = hra_to_xyz(des_offset_hra)
# desired quad transform in world coordinates
des_quad_T = tf.pose_matrix(*self.env.compute_desired_quad_pos_quat(offset=des_offset)[::-1])
# quad transform in world coordinates
quad_T = tf.pose_matrix(self.env.quad_node.getQuat(), self.env.quad_node.getPos())
# desired quad transform relative to the quad
quad_to_des_quad_T = tf.inverse_matrix(quad_T).dot(des_quad_T)
linear_vel, angular_vel = np.split(tf.position_axis_angle_from_matrix(quad_to_des_quad_T) / self.env.dt, [3])
if self.env.action_space.axis is not None:
angular_vel = angular_vel.dot(self.env.action_space.axis)
action = np.append(linear_vel, angular_vel)
return action