本文整理汇总了Python中numpy.radians方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.radians方法的具体用法?Python numpy.radians怎么用?Python numpy.radians使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.radians方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: orthogonalization_matrix
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def orthogonalization_matrix(lengths, angles):
"""Return orthogonalization matrix for crystallographic cell coordinates.
Angles are expected in degrees.
The de-orthogonalization matrix is the inverse.
>>> O = orthogonalization_matrix((10., 10., 10.), (90., 90., 90.))
>>> numpy.allclose(O[:3, :3], numpy.identity(3, float) * 10)
True
>>> O = orthogonalization_matrix([9.8, 12.0, 15.5], [87.2, 80.7, 69.7])
>>> numpy.allclose(numpy.sum(O), 43.063229)
True
"""
a, b, c = lengths
angles = numpy.radians(angles)
sina, sinb, _ = numpy.sin(angles)
cosa, cosb, cosg = numpy.cos(angles)
co = (cosa * cosb - cosg) / (sina * sinb)
return numpy.array((
( a*sinb*math.sqrt(1.0-co*co), 0.0, 0.0, 0.0),
(-a*sinb*co, b*sina, 0.0, 0.0),
( a*cosb, b*cosa, c, 0.0),
( 0.0, 0.0, 0.0, 1.0)),
dtype=numpy.float64)
示例2: calculate_dayside_reconnection
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def calculate_dayside_reconnection(inst):
""" Calculate the dayside reconnection rate (Milan et al. 2014)
Parameters
-----------
inst : pysat.Instrument
Instrument with OMNI HRO data, requires BYZ_GSM and clock_angle
Notes
--------
recon_day = 3.8 Re (Vx / 4e5 m/s)^1/3 Vx B_yz (sin(theta/2))^9/2
"""
rearth = 6371008.8
sin_htheta = np.power(np.sin(np.radians(0.5 * inst['clock_angle'])), 4.5)
byz = inst['BYZ_GSM'] * 1.0e-9
vx = inst['flow_speed'] * 1000.0
recon_day = 3.8 * rearth * vx * byz * sin_htheta * np.power((vx / 4.0e5),
1.0/3.0)
inst['recon_day'] = pds.Series(recon_day, index=inst.data.index)
return
示例3: coords_to_vec
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def coords_to_vec(lon, lat):
""" Converts longitute and latitude coordinates to a unit 3-vector
return array(3,n) with v_x[i],v_y[i],v_z[i] = directional cosines
"""
phi = np.radians(lon)
theta = (np.pi / 2) - np.radians(lat)
sin_t = np.sin(theta)
cos_t = np.cos(theta)
xVals = sin_t * np.cos(phi)
yVals = sin_t * np.sin(phi)
zVals = cos_t
# Stack them into the output array
out = np.vstack((xVals, yVals, zVals)).swapaxes(0, 1)
return out
示例4: rotipp
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def rotipp(acceleration_x, time_step_x, acceleration_y, time_step_y, periods,
percentile, damping=0.05, units="cm/s/s", method="Nigam-Jennings"):
"""
Returns the rotationally independent spectrum RotIpp as defined by
Boore (2010)
"""
if np.fabs(time_step_x - time_step_y) > 1E-10:
raise ValueError("Record pair must have the same time-step!")
acceleration_x, acceleration_y = equalise_series(acceleration_x,
acceleration_y)
target, rota, rotv, rotd, angles = rotdpp(acceleration_x, time_step_x,
acceleration_y, time_step_y,
periods, percentile, damping,
units, method)
locn, penalty = _get_gmrotd_penalty(
np.hstack([target["PGA"],target["Pseudo-Acceleration"]]),
rota)
target_theta = np.radians(angles[locn])
arotpp = acceleration_x * np.cos(target_theta) +\
acceleration_y * np.sin(target_theta)
spec = get_response_spectrum(arotpp, time_step_x, periods, damping, units,
method)[0]
spec["GMRot{:2.0f}".format(percentile)] = target
return spec
示例5: _latlon_to_cart
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def _latlon_to_cart(lat, lon, R = typhon.constants.earth_radius):
"""
Simple conversion of latitude and longitude to Cartesian coordinates.
Approximates the Earth as sphere with radius :code:`R` and computes
cartesian x, y, z coordinates with the center of the Earth as origin.
Args:
lat: Array of latitude coordinates.
lon: Array of longitude coordinates.
R: The radius to assume.
Returns:
Tuple :code:`(x, y, z)` of arrays :code:`x, y, z` containing the
resulting x-, y- and z-coordinates.
"""
lat = np.radians(lat)
lon = np.radians(lon)
x = R * np.cos(lat) * np.cos(lon)
y = R * np.cos(lat) * np.sin(lon)
z = R * np.sin(lat)
return x, y, z
示例6: HaversineDistance
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def HaversineDistance(lon1,lat1,lon2,lat2):
"""
Function to calculate the great circle distance between two points
using the Haversine formula
"""
R = 6371. #Mean radius of the Earth
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(np.radians, [lon1, lat1, lon2, lat2])
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = np.sin(dlat/2.)**2. + np.cos(lat1) * np.cos(lat2) * np.sin(dlon/2.)**2.
c = 2.*np.arcsin(np.sqrt(a))
distance = R * c
return distance
示例7: orthogonalization_matrix
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def orthogonalization_matrix(lengths, angles):
"""Return orthogonalization matrix for crystallographic cell coordinates.
Angles are expected in degrees.
The de-orthogonalization matrix is the inverse.
>>> O = orthogonalization_matrix([10, 10, 10], [90, 90, 90])
>>> numpy.allclose(O[:3, :3], numpy.identity(3, float) * 10)
True
>>> O = orthogonalization_matrix([9.8, 12.0, 15.5], [87.2, 80.7, 69.7])
>>> numpy.allclose(numpy.sum(O), 43.063229)
True
"""
a, b, c = lengths
angles = numpy.radians(angles)
sina, sinb, _ = numpy.sin(angles)
cosa, cosb, cosg = numpy.cos(angles)
co = (cosa * cosb - cosg) / (sina * sinb)
return numpy.array([
[a * sinb * math.sqrt(1.0 - co * co), 0.0, 0.0, 0.0],
[-a * sinb * co, b * sina, 0.0, 0.0],
[a * cosb, b * cosa, c, 0.0],
[0.0, 0.0, 0.0, 1.0]])
示例8: test_true_to_eccentric
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def test_true_to_eccentric(self):
# Data from NASA-TR-R-158
data = [
# ecc, E (deg), ta(deg)
(0.0, 0.0, 0.0),
(0.05, 10.52321, 11.05994),
(0.10, 54.67466, 59.49810),
(0.35, 142.27123, 153.32411),
(0.61, 161.87359, 171.02189)
]
for row in data:
ecc, expected_E, ta = row
E = angles.ta_to_E(radians(ta), ecc)
self.assertAlmostEqual(degrees(E), expected_E, places=4)
示例9: test_mean_to_true
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def test_mean_to_true(self):
# Data from Schlesinger & Udick, 1912
data = [
# ecc, M (deg), ta (deg)
(0.0, 0.0, 0.0),
(0.05, 10.0, 11.06),
(0.06, 30.0, 33.67),
(0.04, 120.0, 123.87),
(0.14, 65.0, 80.50),
(0.19, 21.0, 30.94),
(0.35, 65.0, 105.71),
(0.48, 180.0, 180.0),
(0.75, 125.0, 167.57)
]
for row in data:
ecc, M, expected_ta = row
ta = angles.M_to_ta(radians(M), ecc)
self.assertAlmostEqual(degrees(ta), expected_ta, places=2)
示例10: test_true_to_mean
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def test_true_to_mean(self):
# Data from Schlesinger & Udick, 1912
data = [
# ecc, M (deg), ta (deg)
(0.0, 0.0, 0.0),
(0.05, 10.0, 11.06),
(0.06, 30.0, 33.67),
(0.04, 120.0, 123.87),
(0.14, 65.0, 80.50),
(0.19, 21.0, 30.94),
(0.35, 65.0, 105.71),
(0.48, 180.0, 180.0),
(0.75, 125.0, 167.57)
]
for row in data:
ecc, expected_M, ta = row
M = angles.ta_to_M(radians(ta), ecc)
self.assertAlmostEqual(degrees(M), expected_M, places=1)
示例11: orthogonalization_matrix
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def orthogonalization_matrix(lengths, angles):
"""Return orthogonalization matrix for crystallographic cell coordinates.
Angles are expected in degrees.
The de-orthogonalization matrix is the inverse.
>>> O = orthogonalization_matrix([10, 10, 10], [90, 90, 90])
>>> numpy.allclose(O[:3, :3], numpy.identity(3, float) * 10)
True
>>> O = orthogonalization_matrix([9.8, 12.0, 15.5], [87.2, 80.7, 69.7])
>>> numpy.allclose(numpy.sum(O), 43.063229)
True
"""
a, b, c = lengths
angles = numpy.radians(angles)
sina, sinb, _ = numpy.sin(angles)
cosa, cosb, cosg = numpy.cos(angles)
co = (cosa * cosb - cosg) / (sina * sinb)
return numpy.array([
[ a*sinb*math.sqrt(1.0-co*co), 0.0, 0.0, 0.0],
[-a*sinb*co, b*sina, 0.0, 0.0],
[ a*cosb, b*cosa, c, 0.0],
[ 0.0, 0.0, 0.0, 1.0]])
示例12: get_displacement_km
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def get_displacement_km(n1, x1, y1, n2, x2, y2):
''' Find displacement in kilometers using Haversine
http://www.movable-type.co.uk/scripts/latlong.html
Parameters
----------
n1 : First Nansat object
x1 : 1D vector - X coordinates of keypoints on image 1
y1 : 1D vector - Y coordinates of keypoints on image 1
n2 : Second Nansat object
x1 : 1D vector - X coordinates of keypoints on image 2
y1 : 1D vector - Y coordinates of keypoints on image 2
Returns
-------
h : 1D vector - total displacement, km
'''
lon1, lat1 = n1.transform_points(x1, y1)
lon2, lat2 = n2.transform_points(x2, y2)
lt1, ln1, lt2, ln2 = map(np.radians, (lat1, lon1, lat2, lon2))
dlat = lt2 - lt1
dlon = ln2 - ln1
d = (np.sin(dlat * 0.5) ** 2 +
np.cos(lt1) * np.cos(lt2) * np.sin(dlon * 0.5) ** 2)
return 2 * AVG_EARTH_RADIUS * np.arcsin(np.sqrt(d))
示例13: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def __init__(self, rotation: Vector, translation: Vector, angle_unit: str, notation: str='XYZ'):
self.rotation = rotation
self.translation = translation
self.angle_unit = angle_unit
if self.angle_unit == 'degrees':
self.rotation = Vector(*[radians(alpha) for alpha in rotation])
self.R_x = None
self.R_y = None
self.R_z = None
self.T = None
self.matrix = None
self.notation = notation
self._update_matrix()
示例14: lb2pix
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def lb2pix(nside, l, b, nest=True):
"""
Converts Galactic (l, b) to HEALPix pixel index.
Args:
nside (:obj:`int`): The HEALPix :obj:`nside` parameter.
l (:obj:`float`, or array of :obj:`float`): Galactic longitude, in degrees.
b (:obj:`float`, or array of :obj:`float`): Galactic latitude, in degrees.
nest (Optional[:obj:`bool`]): If :obj:`True` (the default), nested pixel ordering
will be used. If :obj:`False`, ring ordering will be used.
Returns:
The HEALPix pixel index or indices. Has the same shape as the input :obj:`l`
and :obj:`b`.
"""
theta = np.radians(90. - b)
phi = np.radians(l)
if not hasattr(l, '__len__'):
if (b < -90.) or (b > 90.):
return -1
pix_idx = hp.pixelfunc.ang2pix(nside, theta, phi, nest=nest)
return pix_idx
idx = (b >= -90.) & (b <= 90.)
pix_idx = np.empty(l.shape, dtype='i8')
pix_idx[idx] = hp.pixelfunc.ang2pix(nside, theta[idx], phi[idx], nest=nest)
pix_idx[~idx] = -1
return pix_idx
示例15: _coords2vec
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import radians [as 别名]
def _coords2vec(self, coords):
"""
Converts from sky coordinates to unit vectors. Before conversion to unit
vectors, the coordiantes are transformed to the coordinate system used
internally by the :obj:`UnstructuredDustMap`, which can be set during
initialization of the class.
Args:
coords (:obj:`astropy.coordinates.SkyCoord`): Input coordinates to
convert to unit vectors.
Returns:
Cartesian unit vectors corresponding to the input coordinates, after
transforming to the coordinate system used internally by the
:obj:`UnstructuredDustMap`.
"""
# c = coords.transform_to(self._frame)
# vec = np.empty((c.shape[0], 2), dtype='f8')
# vec[:,0] = coordinates.Longitude(coords.l, wrap_angle=360.*units.deg).deg[:]
# vec[:,1] = coords.b.deg[:]
# return np.radians(vec)
c = coords.transform_to(self._frame).represent_as('cartesian')
vec_norm = np.sqrt(c.x**2 + c.y**2 + c.z**2)
vec = np.empty((c.shape[0], 3), dtype=c.x.dtype)
vec[:,0] = (c.x / vec_norm).value[:]
vec[:,1] = (c.y / vec_norm).value[:]
vec[:,2] = (c.z / vec_norm).value[:]
return vec