当前位置: 首页>>代码示例>>Python>>正文


Python numpy.deg2rad方法代码示例

本文整理汇总了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 
开发者ID:spencerahill,项目名称:aospy,代码行数:23,代码来源:vertcoord.py

示例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 
开发者ID:materialsproject,项目名称:MPContribs,代码行数:27,代码来源:pre_submission.py

示例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 
开发者ID:simnibs,项目名称:simnibs,代码行数:18,代码来源:optimize_tms.py

示例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) 
开发者ID:simnibs,项目名称:simnibs,代码行数:24,代码来源:test_optimization_methods.py

示例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) 
开发者ID:simnibs,项目名称:simnibs,代码行数:23,代码来源:test_optimization_methods.py

示例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) 
开发者ID:simnibs,项目名称:simnibs,代码行数:24,代码来源:test_optimization_methods.py

示例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) 
开发者ID:simnibs,项目名称:simnibs,代码行数:18,代码来源:test_optimization_methods.py

示例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) 
开发者ID:simnibs,项目名称:simnibs,代码行数:21,代码来源:test_optimization_methods.py

示例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) 
开发者ID:simnibs,项目名称:simnibs,代码行数:21,代码来源:test_optimization_methods.py

示例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. 
开发者ID:nguy,项目名称:PyRadarMet,代码行数:18,代码来源:geometry.py

示例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.)) 
开发者ID:nguy,项目名称:PyRadarMet,代码行数:26,代码来源:geometry.py

示例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


##################################################### 
开发者ID:nv-tlabs,项目名称:DIB-R,代码行数:24,代码来源:utils_perspective.py

示例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 
开发者ID:ngessert,项目名称:isic2019,代码行数:18,代码来源:auto_augment.py

示例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 
开发者ID:atmtools,项目名称:typhon,代码行数:18,代码来源:ppath.py

示例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 
开发者ID:equinor,项目名称:pylops,代码行数:24,代码来源:bayesian.py


注:本文中的numpy.deg2rad方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。