km3pipe.math
¶
Maths, Geometry, coordinates.
Module Contents¶
Classes¶
Polygon (vertices) |
A polygon, to implement containment conditions. |
IrregularPrism (xy_vertices, z_min, z_max) |
Like a cylinder, but the top is an irregular Polygon. |
SparseCone (spike_pos, bottom_center_pos, opening_angle) |
A Cone, represented by sparse samples. |
Functions¶
neutrino_to_source_direction (phi, theta, radian=True) |
Flip the direction. |
source_to_neutrino_direction (azimuth, zenith, radian=True) |
Flip the direction. |
theta (v) |
Neutrino direction in polar coordinates. |
theta_separg (dir_z) |
|
phi (v) |
Neutrino direction in polar coordinates. |
phi_separg (dir_x, dir_y) |
|
zenith (v) |
Return the zenith angle in radians. |
azimuth (v) |
Return the azimuth angle in radians. |
cartesian (phi, theta, radius=1) |
|
angle_between (v1, v2) |
Returns the angle in radians between vectors ‘v1’ and ‘v2’. |
innerprod_1d (v1, v2) |
1d Inner product for vector-of-vectors. |
unit_vector (vector, **kwargs) |
Returns the unit vector of the vector. |
pld3 (pos, line_vertex, line_dir) |
Calculate the point-line-distance for given point and line. |
lpnorm (x, p=2) |
|
dist (x1, x2, axis=0) |
Return the distance between two points. |
com (points, masses=None) |
Calculate center of mass for given points. |
circ_permutation (items) |
Calculate the circular permutation for a given list of items. |
hsin (theta) |
haversine |
space_angle (phi1, theta1, phi2, theta2) |
Also called Great-circle-distance – |
rotation_matrix (axis, theta) |
The Euler–Rodrigues formula. |
inertia (x, y, z, weight=None) |
Inertia tensor, stolen of thomas |
g_parameter (time_residual) |
stolen from thomas |
gold_parameter (time_residual) |
stolen from thomas |
log_b (arg, base) |
Logarithm to any base |
qrot (vector, quaternion) |
Rotate a 3D vector using quaternion algebra. |
qeuler (yaw, pitch, roll) |
Convert Euler angle to quaternion. |
qrot_yaw (vector, heading) |
Rotate vectors using quaternion algebra. |
intersect_3d (p1, p2) |
Find the closes point for a given set of lines in 3D. |
-
km3pipe.math.
neutrino_to_source_direction
(phi, theta, radian=True)[source]¶ Flip the direction.
Parameters: - phi, theta: neutrino direction
- radian: bool [default=True]
receive + return angles in radian? (if false, use degree)
-
km3pipe.math.
source_to_neutrino_direction
(azimuth, zenith, radian=True)[source]¶ Flip the direction.
Parameters: - zenith, azimuth: neutrino origin
- radian: bool [default=True]
receive + return angles in radian? (if false, use degree)
-
km3pipe.math.
theta
(v)[source]¶ Neutrino direction in polar coordinates.
Downgoing event: theta = 180deg Horizont: 90deg Upgoing: theta = 0
Angles in radians.
-
km3pipe.math.
phi
(v)[source]¶ Neutrino direction in polar coordinates.
phi
,theta
is the opposite ofzenith
,azimuth
.Angles in radians.
-
km3pipe.math.
zenith
(v)[source]¶ Return the zenith angle in radians.
Defined as ‘Angle respective to downgoing’. Downgoing event: zenith = 0 Horizont: 90deg Upgoing: zenith = 180deg
-
km3pipe.math.
azimuth
(v)[source]¶ Return the azimuth angle in radians.
phi
,theta
is the opposite ofzenith
,azimuth
.This is the ‘normal’ azimuth definition – beware of how you define your coordinates. KM3NeT defines azimuth differently than e.g. SLALIB, astropy, the AAS.org
-
km3pipe.math.
angle_between
(v1, v2)[source]¶ Returns the angle in radians between vectors ‘v1’ and ‘v2’.
>>> angle_between((1, 0, 0), (0, 1, 0)) 1.5707963267948966 >>> angle_between((1, 0, 0), (1, 0, 0)) 0.0 >>> angle_between((1, 0, 0), (-1, 0, 0)) 3.141592653589793
-
km3pipe.math.
pld3
(pos, line_vertex, line_dir)[source]¶ Calculate the point-line-distance for given point and line.
-
km3pipe.math.
dist
(x1, x2, axis=0)[source]¶ Return the distance between two points.
Set axis=1 if x1 is a vector and x2 a matrix to get a vector of distances.
-
km3pipe.math.
com
(points, masses=None)[source]¶ Calculate center of mass for given points. If masses is not set, assume equal masses.
-
km3pipe.math.
circ_permutation
(items)[source]¶ Calculate the circular permutation for a given list of items.
-
km3pipe.math.
space_angle
(phi1, theta1, phi2, theta2)[source]¶ Also called Great-circle-distance – use long-ass formula from wikipedia (last in section): https://en.wikipedia.org/wiki/Great-circle_distance#Computational_formulas
Space angle only makes sense in lon-lat, so convert zenith -> latitude.
-
km3pipe.math.
rotation_matrix
(axis, theta)[source]¶ The Euler–Rodrigues formula.
Return the rotation matrix associated with counterclockwise rotation about the given axis by theta radians.
Parameters: - axis: vector to rotate around
- theta: rotation angle, in rad
-
class
km3pipe.math.
Polygon
(vertices)[source]¶ Bases:
object
A polygon, to implement containment conditions.
-
class
km3pipe.math.
IrregularPrism
(xy_vertices, z_min, z_max)[source]¶ Bases:
object
Like a cylinder, but the top is an irregular Polygon.
-
class
km3pipe.math.
SparseCone
(spike_pos, bottom_center_pos, opening_angle)[source]¶ Bases:
object
A Cone, represented by sparse samples.
This samples evenly spaced points from the base circle.
Parameters: - spike_pos: coordinates of the top
- bottom_center_pos: center of the bottom circle
- opening_angle: cone opening angle, in rad
theta, axis to mantle, not mantle-mantle. So this is the angle to the axis, and mantle-to-mantle (aperture) is 2 theta.
-
km3pipe.math.
qrot
(vector, quaternion)[source]¶ Rotate a 3D vector using quaternion algebra.
Implemented by Vladimir Kulikovskiy.
Parameters: - vector: np.array
- quaternion: np.array
Returns: - np.array
-
km3pipe.math.
qeuler
(yaw, pitch, roll)[source]¶ Convert Euler angle to quaternion.
Parameters: - yaw: number
- pitch: number
- roll: number
Returns: - np.array
-
km3pipe.math.
qrot_yaw
(vector, heading)[source]¶ Rotate vectors using quaternion algebra.
Parameters: - vector: np.array or list-like (3 elements)
- heading: the heading to rotate to [deg]
Returns: - np.array
-
km3pipe.math.
intersect_3d
(p1, p2)[source]¶ Find the closes point for a given set of lines in 3D.
Parameters: - p1 : (M, N) array_like
Starting points
- p2 : (M, N) array_like
End points.
Returns: - x : (N,) ndarray
Least-squares solution - the closest point of the intersections.
Raises: - numpy.linalg.LinAlgError
If computation does not converge.