galaximview.basefuncs module¶
Functions used by other modules.
- class galaximview.basefuncs.BaseTools[source]¶
Bases:
object
Class grouping basic array manipulation tools.
- classmethod average64_1d(arr, weights=None)[source]¶
Computes average of a 1D array weighted by weights, in float64 precision.
- Parameters
arr (ndarray) – (N,) 1D array.
weights (ndarray, optional) – (N,) weights.
- Returns
(Weighted) average of array.
- Return type
float
- Raises
ValueError – If Array and weights are not of same shape.
- classmethod cart_2d_basis()[source]¶
Returns np.vstack((BaseDefs.cart_ex_2d, BaseDefs.cart_ey_2d))
- Returns
(2,2) cartesian 2D basis.
- Return type
ndarray
- classmethod cart_3d_basis()[source]¶
Returns np.vstack((BaseDefs.cart_ex_3d, BaseDefs.cart_ey_3d, BaseDefs.cart_ez_3d))
- Returns
(3,3) cartesian 3D basis.
- Return type
ndarray
- cart_ex_2d = array([1., 0.])¶
- cart_ex_3d = array([1., 0., 0.])¶
- cart_ey_2d = array([0., 1.])¶
- cart_ey_3d = array([0., 1., 0.])¶
- cart_ez_3d = array([0., 0., 1.])¶
- classmethod check_ortho_normed_direct_basis(vects_base)[source]¶
Checks that (N,N) array with N = 2 or 3 (exclusively) contains N vstacked vectors each normed to unity, orthonormal to one another and directly ordered.
- Parameters
vects_base (ndarray) – (N_dims, N_dims) vertically stacked basis arrays. N_dims must be 2 or 3.
- Returns
Returns True if basis passed the check.
- Return type
bool
- Raises
ValueError – If requirements for shapes or values are not satisfied.
- classmethod dispersion64_1d(arr, weights=None)[source]¶
Computes square root of variance of a 1D array weighted by weights, in float64 precision.
- Parameters
arr (ndarray) – (N,) 1D array.
weights (ndarray, optional) – (N,) weights.
- Returns
(Weighted) dispersion of array.
- Return type
float64
- Raises
ValueError – If Array and weights are not of same shape.
- classmethod invert_basis(basis)[source]¶
Returns the inverses basis (or any inverse of a (N,N) array).
- Parameters
basis (ndarray) – (N,N) basis to invert.
- Returns
(N,N) inverse basis.
- Return type
ndarray
- classmethod normalise_vector_to_unity(vect)[source]¶
Normalises array.
- Parameters
vect (ndarray) – Array to normalise.
- Returns
Array normalised to unity.
- Return type
ndarray
- classmethod project_on_orthonormed_direct_basis(vect_to_project, vects_base)[source]¶
Projects pos array of shape (N_elements, N_dims) on vstacked base of shape (N_dim, N_dim).
- Parameters
vect_to_project (ndarray) – (N_elements,N_dims) vertically stacked (N_dims,) arrays to be projecteded.
vects_base (ndarray) – (N_dims, N_dims) vertically stacked basis arrays.
- Returns
(N_elements, N_dims) projected array.
- Return type
ndarray
- classmethod rotate_around_vector(pos, elos, alpharot)[source]¶
Performs rotation of every vector of shape (3,) of the pos array of shape(N,3) of angle alpharot around vector elos of shape (3,).
- Parameters
pos (ndarray) – (N,3) vertically stacked (3,) arrays to be rotated.
elos (ndarray) – (3,) vector around whichrotation is performed.
alpharot (float) – Angle of rotation.
- Returns
(N,3) rotated array.
- Return type
ndarray
- classmethod sph_kernel(r, h)[source]¶
General function for Gadget-2 type SPH kernel. Can check that quad(lambda x: BaseTools.sph_kernel(x, h)*4*pi*x**2, 0,h) = 1 for chosen h.
- Parameters
r (float) – Distance.
h (float) – Smoothing length.
- Returns
SPH kernel.
- Return type
float
- classmethod subset_of_indexes(indexes, fraction, seed=None)[source]¶
Extracts random fraction of indexes with possibility to set the seed for identical reproduction.
- Parameters
indexes (ndarray) – (N,) indexes array.
fraction (float) – Fraction to select.
seed (int, optional) – Seed for random numbers generator.
- Returns
(Nselected,) randomly selected indexes such that Nselected=int(frac * N) with N the number if lembers of 1D input array.
- Return type
ndarray
- class galaximview.basefuncs.CheckArrays[source]¶
Bases:
object
Class grouping methods that check that arrays given to some methods have the right shapes, signs.
- classmethod check_cylposlike_array(arr, allow_nan=False, allow_inf=False)[source]¶
Checks that array is of shape (N,3), that the first column is positive (cylindrical radii) and the second between -pi and pi (phi angle). (Last column is z.) With no inf nor nan values except if allow_inf or allow_nan are set to True.
- Parameters
arr (ndarray) – (N,3) input array.
allow_nan (bool, default = False) – True to allow nan values.
allow_inf (bool, default = False) – True to allow inf values.
- Returns
Returns True if input array passed the check.
- Return type
bool
- Raises
TypeError – If requirements of type and shape are not satisfied.
ValueError – If requirements for values (limits, nan, inf) are not satisfied.
- classmethod check_indslike_array(arr, allow_nan=False, allow_inf=False, allow_neg=False)[source]¶
Checks that array is an array of natural integers with no inf or nan values except if allow_neg, allow_inf or allow_nan are set to True.
- Parameters
arr (ndarray) – (N,) input array.
allow_nan (bool, default = False) – True to allow nan values.
allow_inf (bool, default = False) – True to allow inf values.
allow_neg (bool, default = False) – True to allow negatvie values.
- Returns
Returns True if input array passed the check.
- Return type
bool
- Raises
TypeError – If requirements of type are not satisfied.
ValueError – If requirements for values (nan, inf, negative) are not satisfied.
- classmethod check_masslike_array(arr, allow_nan=False, allow_inf=False)[source]¶
Checks that array is a 1D array with no inf or nan values except if allow_inf or allow_nan are set to True.
- Parameters
arr (ndarray) – (N,) input 1D array.
allow_nan (bool, default = False) – True to allow nan values.
allow_inf (bool, default = False) – True to allow inf values.
- Returns
Returns True if input array passed the check.
- Return type
bool
- Raises
TypeError – If requirements of type and shape are not satisfied.
ValueError – If requirements for values (nan, inf) are not satisfied.
- classmethod check_poslike_array(arr, allow_nan=False, allow_inf=False)[source]¶
Checks that array is of shape (N,3), with no inf nor nan values except if allow_inf or allow_nan are set to True.
- Parameters
arr (ndarray) – (N,3) input array.
allow_nan (bool, default = False) – True to allow nan values.
allow_inf (bool, default = False) – True to allow inf values.
- Returns
Returns True if input array passed the check.
- Return type
bool
- Raises
TypeError – If requirements of type and shape are not satisfied.
ValueError – If requirements for values (limits, nan, inf) are not satisfied.
- classmethod check_spherposlike_array(arr, allow_nan=False, allow_inf=False)[source]¶
Checks that array is of shape (N,3), that the first column is positive (spherical radii), the second between 0 and pi (theta angle) and the third betwwen -pi and pi (phi angle). With no inf nor nan values except if allow_inf or allow_nan are set to True.
- Parameters
arr (ndarray) – (N,3) input array.
allow_nan (bool, default = False) – True to allow nan values.
allow_inf (bool, default = False) – True to allow inf values.
- Returns
Returns True if input array passed the check.
- Return type
bool
- Raises
TypeError – If requirements of type and shape are not satisfied.
ValueError – If requirements for values (limits, nan, inf) are not satisfied.
- galaximview.basefuncs.calc_com(pos, mass)[source]¶
Computes centre of mass of particles.
- Parameters
pos (ndarray) – (N,3) positions.
mass (ndarray) – (N,) masses.
- Returns
(3,) Centre of mass.
- Return type
ndarray
- galaximview.basefuncs.get_basis_los(azim, elev)[source]¶
Gets the basis on which to project to obtain 2D projection when the line-of-sight has an azimuth (angle between unit vector of x-axis and line-of-sight) azim and an elevation (angle between (xy) plane and line-of-sight) elev. When navigating “bove” or “below” z-axis in 3D plot, the elevation still increases (resp. diminishes).
- Parameters
azim (float) – In [-180,180], azimuth of camera in matplotlib 3D plot.
elev (float) – In [-180,180], elevation of camera in matplotlib 3D plot.
- Returns
(3,3) Basis on which to project.
- Return type
ndarray
Notes
For example:
An x vs y projection plot (with ascending x to right and y to top), in original x and y coordinates (‘face-on’) corresponds to a viewing-angle with azim = -90 and elev = 90.
A z vs x plot corresonds to azim = -90 and elev = 0
- galaximview.basefuncs.identity_function(x)[source]¶
Returns the argument.
- Parameters
x (any) – Argument.
- Returns
Argument.
- Return type
any
- galaximview.basefuncs.inverse_function(function, x)[source]¶
Returns the value of the inverse function of ‘function’ at x for a few functions.
- Parameters
function (ufunc) – Function whose inverse function will be computed at x.
x (float (depends on function)) – Argument.
- Returns
Argument.
- Return type
float (depends on function)