本文整理匯總了Python中numpy.deg2rad方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.deg2rad方法的具體用法?Python numpy.deg2rad怎麽用?Python numpy.deg2rad使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.deg2rad方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: to_radians
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def to_radians(arr, is_delta=False):
"""Force data with units either degrees or radians to be radians."""
# Infer the units from embedded metadata, if it's there.
try:
units = arr.units
except AttributeError:
pass
else:
if units.lower().startswith('degrees'):
warn_msg = ("Conversion applied: degrees -> radians to array: "
"{}".format(arr))
logging.debug(warn_msg)
return np.deg2rad(arr)
# Otherwise, assume degrees if the values are sufficiently large.
threshold = 0.1*np.pi if is_delta else 4*np.pi
if np.max(np.abs(arr)) > threshold:
warn_msg = ("Conversion applied: degrees -> radians to array: "
"{}".format(arr))
logging.debug(warn_msg)
return np.deg2rad(arr)
return arr
示例2: load_RSM
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def load_RSM(filename):
om, tt, psd = xu.io.getxrdml_map(filename)
om = np.deg2rad(om)
tt = np.deg2rad(tt)
wavelength = 1.54056
q_y = (1 / wavelength) * (np.cos(tt) - np.cos(2 * om - tt))
q_x = (1 / wavelength) * (np.sin(tt) - np.sin(2 * om - tt))
xi = np.linspace(np.min(q_x), np.max(q_x), 100)
yi = np.linspace(np.min(q_y), np.max(q_y), 100)
psd[psd < 1] = 1
data_grid = griddata(
(q_x, q_y), psd, (xi[None, :], yi[:, None]), fill_value=1, method="cubic"
)
nx, ny = data_grid.shape
range_values = [np.min(q_x), np.max(q_x), np.min(q_y), np.max(q_y)]
output_data = (
Panel(np.log(data_grid).reshape(nx, ny, 1), minor_axis=["RSM"])
.transpose(2, 0, 1)
.to_frame()
)
return range_values, output_data
示例3: _rotate_system
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def _rotate_system(R, angle_limits, angle_res):
''' Rotates the vector "y" aroud "z" between the given limits and in the given
resolution and return rotation matrices'''
# Define rotation matrix around Z
n_steps = int((angle_limits[1] - angle_limits[0])/angle_res + 1)
angles = np.linspace(angle_limits[0], angle_limits[1], n_steps)
angles = np.deg2rad(angles[(angles > -180.1) * (angles < 180.)])
matrices = []
for a in angles:
Rz = np.array((
(np.cos(a), -np.sin(a), 0),
(np.sin(a), np.cos(a), 0),
(0, 0, 1),
))
matrices.append(R.dot(Rz))
return matrices
示例4: test_both_limit_angle_inactive
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def test_both_limit_angle_inactive(self, optimization_variables_avg):
l, Q, A = optimization_variables_avg
Q_in = 5e1 * np.eye(len(l))
max_angle = 45
m = 2e-3
m1 = 4e-3
f = .02
x = optimization_methods.optimize_focality(l, Q, f,
max_el_current=m,
max_total_current=m1,
Qin=Q_in,
max_angle=max_angle)
x_sp = optimize_focality(
l, Q, f, max_el_current=m, max_total_current=m1,
Qin=Q_in, max_angle=max_angle)
assert np.linalg.norm(x, 1) <= 2 * m1 + 1e-4
assert np.all(np.abs(x) <= m + 1e-4)
assert np.isclose(np.sum(x), 0)
assert np.isclose(l.dot(x), f)
assert np.arccos(l.dot(x) / np.sqrt(x.dot(Q_in).dot(x))) <= np.deg2rad(max_angle)
assert np.allclose(x.dot(Q.dot(x)), x_sp.dot(Q.dot(x_sp)), rtol=1e-4, atol=1e-5)
示例5: test_both_limit_angle_limit
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def test_both_limit_angle_limit(self, optimization_variables_avg):
l, Q, A = optimization_variables_avg
Q_in = 5e1 * np.eye(len(l))
max_angle = 25
m = 2e-3
m1 = 4e-3
f = .02
x = optimization_methods.optimize_focality(l, Q, f,
max_el_current=m,
max_total_current=m1,
Qin=Q_in,
max_angle=max_angle)
x_sp = optimize_focality(
l, Q, f, max_el_current=m, max_total_current=m1,
Qin=Q_in, max_angle=max_angle)
assert np.linalg.norm(x, 1) <= 2 * m1 + 1e-4
assert np.all(np.abs(x) <= m + 1e-4)
assert np.isclose(np.sum(x), 0)
assert np.isclose(l.dot(x), f)
assert np.arccos(l.dot(x) / np.sqrt(x.dot(Q_in).dot(x))) <= np.deg2rad(max_angle)
assert np.allclose(x.dot(Q.dot(x)), x_sp.dot(Q.dot(x_sp)), rtol=1e-4, atol=1e-5)
示例6: test_both_limit_angle_Q_iteration
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def test_both_limit_angle_Q_iteration(self, optimization_variables_avg_QCQP):
l, Q, A, Q_in = optimization_variables_avg_QCQP
# l, Q, A = optimization_variables_avg
# Q_in = 6 * np.eye(len(l)) + np.outer(l, l)
max_angle = 20
m = 2e-3
m1 = 4e-3
f = .01
x = optimization_methods.optimize_focality(l, Q, f,
max_el_current=m,
max_total_current=m1,
Qin=Q_in,
max_angle=max_angle)
x_sp = optimize_focality(
l, Q, f, max_el_current=m, max_total_current=m1,
Qin=Q_in, max_angle=max_angle)
assert np.linalg.norm(x, 1) <= 2 * m1 + 1e-4
assert np.all(np.abs(x) <= m + 1e-4)
assert np.isclose(np.sum(x), 0)
assert np.isclose(l.dot(x), f)
assert np.arccos(l.dot(x) / np.sqrt(x.dot(Q_in).dot(x))) <= np.deg2rad(max_angle)
assert np.allclose(x.dot(Q.dot(x)), x_sp.dot(Q.dot(x_sp)), rtol=1e-4, atol=1e-5)
示例7: test_both_limit_angle_infeasible_field
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def test_both_limit_angle_infeasible_field(self, optimization_variables_avg_QCQP):
l, Q, A, Q_in = optimization_variables_avg_QCQP
max_angle = 15
m = 2e-3
m1 = 4e-3
f = 2
x = optimization_methods.optimize_focality(l, Q, f,
max_el_current=m,
max_total_current=m1,
Qin=Q_in,
max_angle=max_angle)
assert np.linalg.norm(x, 1) <= 2 * m1 + 1e-4
assert np.all(np.abs(x) <= m + 1e-4)
assert np.isclose(np.sum(x), 0)
assert np.arccos(l.dot(x) / np.sqrt(x.dot(Q_in).dot(x))) <= np.deg2rad(max_angle)
示例8: test_limit_nr_angle
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def test_limit_nr_angle(seld, optimization_variables_avg_QCQP):
l, Q, A, Q_in = optimization_variables_avg_QCQP
max_angle = 15
m = 2e-3
m1 = 4e-3
f = 2
n = 4
x = optimization_methods.optimize_focality(l, Q, f,
max_el_current=m,
max_total_current=m1,
Qin=Q_in,
max_angle=max_angle,
max_active_electrodes=n)
assert np.linalg.norm(x, 1) <= 2 * m1 + 1e-4
assert np.all(np.abs(x) <= m + 1e-4)
assert np.isclose(np.sum(x), 0)
assert np.linalg.norm(x, 0) <= n
assert np.arccos(l.dot(x) / np.sqrt(x.dot(Q_in).dot(x))) <= np.deg2rad(max_angle)
示例9: test_limit_nr_angle_change_Q
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def test_limit_nr_angle_change_Q(seld, optimization_variables_avg_QCQP):
l, Q, A, Q_in = optimization_variables_avg_QCQP
max_angle = 15
m = 2e-3
m1 = 4e-3
f = .01
n = 4
x = optimization_methods.optimize_focality(l, Q, f,
max_el_current=m,
max_total_current=m1,
Qin=Q_in,
max_angle=max_angle,
max_active_electrodes=n)
assert np.linalg.norm(x, 1) <= 2 * m1 + 1e-4
assert np.all(np.abs(x) <= m + 1e-4)
assert np.isclose(np.sum(x), 0)
assert np.linalg.norm(x, 0) <= n
assert np.arccos(l.dot(x) / np.sqrt(x.dot(Q_in).dot(x))) <= np.deg2rad(max_angle)
示例10: half_power_radius
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def half_power_radius(r, bwhalf):
"""
Half-power radius [m].
Battan (1973),
Parameters
----------
r : float or array
Range [m]
bwhalf : float
Half-power beam width [degrees]
"""
# Convert earth's radius to km for common dN/dH values and then
# multiply by 1000 to return radius in meters
return (np.asarray(r) * np.deg2rad(bwhalf)) / 2.
示例11: sample_vol_ideal
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def sample_vol_ideal(r, bw_h, bw_v, pulse_length):
"""
Idealized Sample volume [m^3] assuming all power in half-power beamwidths.
From Rinehart (1997), Eqn 5.2
Parameters
----------
r : float or array
Distance to sample volume from radar [m]
bw_h : float
Horizontal beamwidth [deg]
bw_v : float
Vertical beamwidth deg]
pulse_length : float
Pulse length [m]
Notes
-----
This form assumes all transmitted energy is in the half-power beamwidths.
A more realistic solution is found in the sample_vol_gauss function
"""
return (np.pi * (np.asarray(r) * np.deg2rad(bw_h)/2.) * (np.asarray(r) *
np.deg2rad(bw_v)/2.) * (pulse_length/2.))
示例12: camera_info
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def camera_info(param):
theta = np.deg2rad(param[0])
phi = np.deg2rad(param[1])
camY = param[3] * np.sin(phi)
temp = param[3] * np.cos(phi)
camX = temp * np.cos(theta)
camZ = temp * np.sin(theta)
cam_pos = np.array([camX, camY, camZ])
axisZ = cam_pos.copy()
axisY = np.array([0, 1, 0], dtype=np.float32)
axisX = np.cross(axisY, axisZ)
axisY = np.cross(axisZ, axisX)
# cam_mat = np.array([axisX, axisY, axisZ])
cam_mat = np.array([unit(axisX), unit(axisY), unit(axisZ)])
return cam_mat, cam_pos
#####################################################
示例13: rotate
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def rotate(img, magnitude):
img = np.array(img)
magnitudes = np.linspace(-30, 30, 11)
theta = np.deg2rad(random.uniform(magnitudes[magnitude], magnitudes[magnitude+1]))
transform_matrix = np.array([[np.cos(theta), -np.sin(theta), 0],
[np.sin(theta), np.cos(theta), 0],
[0, 0, 1]])
transform_matrix = transform_matrix_offset_center(transform_matrix, img.shape[0], img.shape[1])
affine_matrix = transform_matrix[:2, :2]
offset = transform_matrix[:2, 2]
img = np.stack([ndimage.interpolation.affine_transform(
img[:, :, c],
affine_matrix,
offset) for c in range(img.shape[2])], axis=2)
img = Image.fromarray(img)
return img
示例14: wzeniths
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def wzeniths(zeniths):
n = len(zeniths)
if not n:
return np.array([0, 180]), np.array([1, 1])
inds = np.argsort(zeniths)
zaz = np.deg2rad(zeniths[inds])
cz = np.cos(zaz)
wz = np.zeros((2*n))
za = np.zeros((2*n))
for i in range(n-1):
N = i*2
za[N:N+2] = zaz[i:i+2]
wz[0+N] = wz[1+N] = 0.5 * (cz[i] - cz[i+1])
return za, wz
示例15: prior_realization
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import deg2rad [as 別名]
def prior_realization(f0, a0, phi0, sigmaf, sigmaa, sigmaphi, dt, nt, nfft):
"""Create realization from prior mean and std for amplitude, frequency and
phase
"""
f = np.fft.rfftfreq(nfft, dt)
df = f[1] - f[0]
ifreqs = [int(np.random.normal(f, sigma)/df)
for f, sigma in zip(f0, sigmaf)]
amps = [np.random.normal(a, sigma) for a, sigma in zip(a0, sigmaa)]
phis = [np.random.normal(phi, sigma) for phi, sigma in zip(phi0, sigmaphi)]
# input signal in frequency domain
X = np.zeros(nfft//2+1, dtype='complex128')
X[ifreqs] = np.array(amps).squeeze() * \
np.exp(1j * np.deg2rad(np.array(phis))).squeeze()
# input signal in time domain
FFTop = pylops.signalprocessing.FFT(nt, nfft=nfft, real=True)
x = FFTop.H*X
return x
# Priors