:mod:`km3pipe.math` =================== .. py:module:: km3pipe.math .. autoapi-nested-parse:: Maths, Geometry, coordinates. .. !! processed by numpydoc !! Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: km3pipe.math.Polygon km3pipe.math.IrregularPrism km3pipe.math.SparseCone Functions ~~~~~~~~~ .. autoapisummary:: km3pipe.math.neutrino_to_source_direction km3pipe.math.source_to_neutrino_direction km3pipe.math.theta km3pipe.math.theta_separg km3pipe.math.phi km3pipe.math.phi_separg km3pipe.math.zenith km3pipe.math.azimuth km3pipe.math.cartesian km3pipe.math.angle_between km3pipe.math.innerprod_1d km3pipe.math.unit_vector km3pipe.math.pld3 km3pipe.math.lpnorm km3pipe.math.dist km3pipe.math.com km3pipe.math.circ_permutation km3pipe.math.hsin km3pipe.math.space_angle km3pipe.math.rotation_matrix km3pipe.math.inertia km3pipe.math.g_parameter km3pipe.math.gold_parameter km3pipe.math.log_b km3pipe.math.qrot km3pipe.math.qeuler km3pipe.math.qrot_yaw km3pipe.math.intersect_3d .. data:: log .. function:: neutrino_to_source_direction(phi, theta, radian=True) Flip the direction. :Parameters: **phi, theta: neutrino direction** .. **radian: bool [default=True]** receive + return angles in radian? (if false, use degree) .. !! processed by numpydoc !! .. function:: source_to_neutrino_direction(azimuth, zenith, radian=True) Flip the direction. :Parameters: **zenith, azimuth: neutrino origin** .. **radian: bool [default=True]** receive + return angles in radian? (if false, use degree) .. !! processed by numpydoc !! .. function:: theta(v) Neutrino direction in polar coordinates. Downgoing event: theta = 180deg Horizont: 90deg Upgoing: theta = 0 Angles in radians. .. !! processed by numpydoc !! .. function:: theta_separg(dir_z) .. function:: phi(v) Neutrino direction in polar coordinates. ``phi``, ``theta`` is the opposite of ``zenith``, ``azimuth``. Angles in radians. .. !! processed by numpydoc !! .. function:: phi_separg(dir_x, dir_y) .. function:: zenith(v) Return the zenith angle in radians. Defined as 'Angle respective to downgoing'. Downgoing event: zenith = 0 Horizont: 90deg Upgoing: zenith = 180deg .. !! processed by numpydoc !! .. function:: azimuth(v) Return the azimuth angle in radians. ``phi``, ``theta`` is the opposite of ``zenith``, ``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 .. !! processed by numpydoc !! .. function:: cartesian(phi, theta, radius=1) .. function:: angle_between(v1, v2) 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 .. !! processed by numpydoc !! .. function:: innerprod_1d(v1, v2) 1d Inner product for vector-of-vectors. .. !! processed by numpydoc !! .. function:: unit_vector(vector, **kwargs) Returns the unit vector of the vector. .. !! processed by numpydoc !! .. function:: pld3(pos, line_vertex, line_dir) Calculate the point-line-distance for given point and line. .. !! processed by numpydoc !! .. function:: lpnorm(x, p=2) .. function:: dist(x1, x2, axis=0) Return the distance between two points. Set axis=1 if x1 is a vector and x2 a matrix to get a vector of distances. .. !! processed by numpydoc !! .. function:: com(points, masses=None) Calculate center of mass for given points. If masses is not set, assume equal masses. .. !! processed by numpydoc !! .. function:: circ_permutation(items) Calculate the circular permutation for a given list of items. .. !! processed by numpydoc !! .. function:: hsin(theta) haversine .. !! processed by numpydoc !! .. function:: space_angle(phi1, theta1, phi2, theta2) 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. .. !! processed by numpydoc !! .. function:: rotation_matrix(axis, theta) 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** .. .. !! processed by numpydoc !! .. py:class:: Polygon(vertices) Bases::class:`object` A polygon, to implement containment conditions. .. !! processed by numpydoc !! .. method:: contains(self, points) .. method:: contains_xy(self, x, y) .. py:class:: IrregularPrism(xy_vertices, z_min, z_max) Bases::class:`object` Like a cylinder, but the top is an irregular Polygon. .. !! processed by numpydoc !! .. method:: contains(self, points) .. method:: contains_xyz(self, x, y, z) .. py:class:: SparseCone(spike_pos, bottom_center_pos, opening_angle) Bases::class:`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. .. !! processed by numpydoc !! .. attribute:: sample_axis .. method:: sample_circle(self, n_angles=4) .. method:: sample(self, n_circle=4) .. function:: inertia(x, y, z, weight=None) Inertia tensor, stolen of thomas .. !! processed by numpydoc !! .. function:: g_parameter(time_residual) stolen from thomas .. !! processed by numpydoc !! .. function:: gold_parameter(time_residual) stolen from thomas .. !! processed by numpydoc !! .. function:: log_b(arg, base) Logarithm to any base .. !! processed by numpydoc !! .. function:: qrot(vector, quaternion) Rotate a 3D vector using quaternion algebra. Implemented by Vladimir Kulikovskiy. :Parameters: **vector: np.array** .. **quaternion: np.array** .. :Returns: **np.array** .. .. !! processed by numpydoc !! .. function:: qeuler(yaw, pitch, roll) Convert Euler angle to quaternion. :Parameters: **yaw: number** .. **pitch: number** .. **roll: number** .. :Returns: **np.array** .. .. !! processed by numpydoc !! .. function:: qrot_yaw(vector, heading) Rotate vectors using quaternion algebra. :Parameters: **vector: np.array or list-like (3 elements)** .. **heading: the heading to rotate to [deg]** .. :Returns: **np.array** .. .. !! processed by numpydoc !! .. function:: intersect_3d(p1, p2) 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. .. !! processed by numpydoc !!