The following are 30 code examples for showing how to use numpy.radians(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module , or try the search function .

Example 1
```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
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) ```
Example 2
```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 ```
Example 3
```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
"""
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 ```
Example 4
```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)
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 ```
Example 5
```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.
Returns:
Tuple :code:`(x, y, z)` of arrays :code:`x, y, z` containing the
resulting x-, y- and z-coordinates.
"""
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 ```
Example 6
```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 ```
Example 7
```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
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]]) ```
Example 8
```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

self.assertAlmostEqual(degrees(E), expected_E, places=4) ```
Example 9
```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

self.assertAlmostEqual(degrees(ta), expected_ta, places=2) ```
Example 10
```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

self.assertAlmostEqual(degrees(M), expected_M, places=1) ```
Example 11
```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
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]]) ```
Example 12
```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
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]]) ```
Example 13
```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)) ```
Example 14
```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() ```
Example 15
```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
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]]) ```
Example 16
```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
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]]) ```
Example 17
```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
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]]) ```
Example 18
```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
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]]) ```
Example 19
```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`.
"""

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 ```
Example 20
```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[:]

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 ```
Example 21
```def equat2eclip(self, r_equat, currentTime, rotsign=1):
"""Rotates heliocentric coordinates from equatorial to ecliptic frame.

Args:
r_equat (astropy Quantity nx3 array):
Positions vector in heliocentric equatorial frame in units of AU
currentTime (astropy Time array):
Current absolute mission time in MJD
rotsign (integer):
Optional flag, default 1, set -1 to reverse the rotation

Returns:
astropy Quantity nx3 array:
Positions vector in heliocentric ecliptic frame in units of AU

"""

# check size of arrays
assert currentTime.size == 1 or currentTime.size == len(r_equat), \
"If multiple times and positions, currentTime and r_equat sizes must match"
# find Julian centuries from J2000
TDB = self.cent(currentTime)
# find obliquity of the ecliptic
# positions vector in heliocentric ecliptic frame
if currentTime.size == 1:
r_eclip = np.array([np.dot(self.rot(obe[0], 1),
r_equat[x,:].to('AU').value) for x in range(len(r_equat))])*u.AU
else:
r_eclip = np.array([np.dot(self.rot(obe[x], 1),
r_equat[x,:].to('AU').value) for x in range(len(r_equat))])*u.AU

return r_eclip ```
Example 22
```def rot(self, th, axis):
"""Finds the rotation matrix of angle th about the axis value

Args:
th (float):
axis (int):
Integer value denoting rotation axis (1,2, or 3)

Returns:
float 3x3 ndarray:
Rotation matrix

"""

if axis == 1:
rot_th = np.array([[1., 0., 0.],
[0., np.cos(th), np.sin(th)],
[0., -np.sin(th), np.cos(th)]])
elif axis == 2:
rot_th = np.array([[np.cos(th), 0., -np.sin(th)],
[0., 1., 0.],
[np.sin(th), 0., np.cos(th)]])
elif axis == 3:
rot_th = np.array([[np.cos(th), np.sin(th), 0.],
[-np.sin(th), np.cos(th), 0.],
[0., 0., 1.]])

return rot_th ```
Example 23
```def mass_dec(self, dF_lateral, t_int):
"""Returns mass_used and deltaV

The values returned by this method are used to decrement spacecraft
mass for station-keeping.

Args:
dF_lateral (astropy Quantity):
Lateral disturbance force in units of N
t_int (astropy Quantity):
Integration time in units of day

Returns:
tuple:
intMdot (astropy Quantity):
Mass flow rate in units of kg/s
mass_used (astropy Quantity):
Mass used in station-keeping units of kg
deltaV (astropy Quantity):
Change in velocity required for station-keeping in units of km/s

"""

dF_lateral/const.g0/self.skIsp).to('kg/s')
mass_used = (intMdot*t_int).to('kg')
deltaV = (dF_lateral/self.scMass*t_int).to('km/s')

return intMdot, mass_used, deltaV ```
Example 24
```def rotated(self,
verts,
deg,
cam=None,
axis='y',
img=None,
do_alpha=True,
far=None,
near=None,
color_id=0,
img_size=None):
import math
if axis == 'y':
elif axis == 'x':
else:
center = verts.mean(axis=0)
new_v = np.dot((verts - center), around) + center

return self.__call__(
new_v,
cam,
img=img,
do_alpha=do_alpha,
far=far,
near=near,
img_size=img_size,
color_id=color_id) ```
Example 25
```def simple_renderer(rn,
verts,
faces,
color=colors['light_pink']):
# Rendered model color
rn.set(v=verts, f=faces, vc=color, bgcolor=np.ones(3))
albedo = rn.vc

# Construct Back Light (on back right corner)
rn.vc = LambertianPointLight(
f=rn.f,
v=rn.v,
num_verts=len(rn.v),
light_pos=_rotateY(np.array([-200, -100, -100]), yrot),
vc=albedo,
light_color=np.array([1, 1, 1]))

# Construct Left Light
rn.vc += LambertianPointLight(
f=rn.f,
v=rn.v,
num_verts=len(rn.v),
light_pos=_rotateY(np.array([800, 10, 300]), yrot),
vc=albedo,
light_color=np.array([1, 1, 1]))

# Construct Right Light
rn.vc += LambertianPointLight(
f=rn.f,
v=rn.v,
num_verts=len(rn.v),
light_pos=_rotateY(np.array([-500, 500, 1000]), yrot),
vc=albedo,
light_color=np.array([.7, .7, .7]))

return rn.r ```
Example 26
```def haversine_array(lat1, lng1, lat2, lng2):
lat1, lng1, lat2, lng2 = map(np.radians, (lat1, lng1, lat2, lng2))
AVG_EARTH_RADIUS = 6371  # in km
lat = lat2 - lat1
lng = lng2 - lng1
d = np.sin(lat * 0.5) ** 2 + np.cos(lat1) * np.cos(lat2) * np.sin(lng * 0.5) ** 2
h = 2 * AVG_EARTH_RADIUS * np.arcsin(np.sqrt(d))
return h ```
Example 27
```def bearing_array(lat1, lng1, lat2, lng2):
AVG_EARTH_RADIUS = 6371  # in km
lat1, lng1, lat2, lng2 = map(np.radians, (lat1, lng1, lat2, lng2))
x = np.cos(lat1) * np.sin(lat2) - np.sin(lat1) * np.cos(lat2) * np.cos(lng_delta_rad)
return np.degrees(np.arctan2(y, x)) ```
Example 28
```def add_drift_sat_coord(inst):
""" Calculate the ion velocity in satellite x,y,z coordinates

Parameters
----------
inst : pysat.Instrument
DEMETER IAP instrument class object

Return
------

"""

# Because np.radians isn't working for data coming from the DataFrame :(
vxy = - inst['iv_Oz'] * np.tan(rad)

inst.meta.data.units['iv_Ox'] = inst.meta.data.units['iv_Oz']
inst.meta.data.units['iv_Oy'] = inst.meta.data.units['iv_Oz']

# Because the ADV instrument is not fully aligned with the axis of the
# satellite, reposition into satellite coordinates
# (IS THIS ALREADY CORRECTED IN FILES?)
print("WARNING the ADV instrument is not fully aligned with the axis of "
+ "the satellite and this may not have been corrected")

return ```
Example 29
```def test_adjust_cyclic_data_default(self):
```def to_radians(self):