utils module¶
This module, utils.py
contains general
routines.
Containing utilitary functions for T4ME.
-
utils.
check_directory
(path, create=False)¶ Check that a directory exists.
Parameters: - path : string
The path to the directory to be checked.
- create : boolean, optional
If set to True create the directory if it does not exist. Defaults to False and in this case an error is printed if the directory is not found.
Returns: - None
-
utils.
check_file
(filename)¶ Check if a file exists
Parameters: - filename : string
The location and filename of the file to be checked.
Returns: - None
-
utils.
clean_directory
(path)¶ Clean a directory.
Parameters: - path : string
The path to the directory to be cleaned.
Returns: - None
-
utils.
config_logger
(filename='/logging.yaml', level=None)¶ Configure the main logger.
Parameters: - filename : string, optional
The filename for the logging configuration file. Defaults to “logging.yaml” in the current working directory.
- level : object
Sets the logging level of the Python logger. Defaults to INFO if the configuration file is not found.
Returns: - None
-
utils.
create_directory
(path)¶ Check that the directory exists
Parameters: - path : string
The path to the directory to be checked.
Returns: - None
-
utils.
fetch_sorting_indexes
(data, order='C')¶ Fetch the sorting indexes to sort an array to either column or row order.
Parameters: - data : ndarray
- Dimension: (N,M)
The input data array to be sorted.
- order : {“C”, “F”}
The sort order.
Returns: - sort_index : ndarray
- Dimension: (N,M)
The sorting indexes that can be used to order the array.
-
utils.
invert_matrix
(matrix)¶ Inverts a matrix and checks for ill-conditions
Parameters: - matrix : ndarray
- Dimension: (N,N)
The input matrix to be inverted.
Returns: - inv_matrix : ndarray
- Dimension: (N,N)
The inverted matrix. If matrix is ill-conditioned, nan values are filled in the matrix.
-
utils.
is_even
(number)¶ Check if number is even.
Parameters: - number : integer
The integer to be checked
Returns: - boolean
Returns True of number is even, False otherwise.
-
utils.
is_number
(something)¶ Check if something is a number.
Parameters: - something : anything
Something to be checked.
Returns: - boolean
True if something is a number. False otherwise.
-
utils.
is_power_of_two
(number)¶ Check that if a number is a power of two.
Parameters: - number : float
The supplied number to be checked.
Returns: - boolean
Returns True of number is power of two, False otherwise.
-
utils.
pull_points_back_into_zone
(points)¶ Pulls all points outside [-0.5,0.5] in direct coordinates back into [-0.5, 0.5].
Parameters: - points : ndarray
- Dimension: (N, 3)
The N points to be checked and thrown back into the zone (between [-0.5, 0.5]). Should be in direct coordinates.
Returns: - None
-
utils.
pull_vecs_inside_boundary
(vecs, border, shift=None)¶ Pulls vectors into a given cubic boundary box.
Parameters: - vecs : ndarray
- Dimension: (N,3)
Contains N vectors.
- border : ndarray
- Dimension: (6)
Contains the entries x_min, x_max, y_min, y_max, z_min and z_max, respectively of the indexes to be modified, typically the border elements.
- shift : float, optional
An optional shift value which brings the vectors shift more inside the boundary box supplied in border.
Returns: - None