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
pathstring

The path to the directory to be checked.

createboolean, 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
filenamestring

The location and filename of the file to be checked.

Returns
None
utils.clean_directory(path)

Clean a directory.

Parameters
pathstring

The path to the directory to be cleaned.

Returns
None
utils.config_logger(filename='/logging.yaml', level=None)

Configure the main logger.

Parameters
filenamestring, optional

The filename for the logging configuration file. Defaults to “logging.yaml” in the current working directory.

levelobject

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
pathstring

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
datandarray
Dimension: (N,M)

The input data array to be sorted.

order{“C”, “F”}

The sort order.

Returns
sort_indexndarray
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
matrixndarray
Dimension: (N,N)

The input matrix to be inverted.

Returns
inv_matrixndarray
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
numberinteger

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
somethinganything

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
numberfloat

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
pointsndarray
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
vecsndarray
Dimension: (N,3)

Contains N vectors.

borderndarray
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.

shiftfloat, optional

An optional shift value which brings the vectors shift more inside the boundary box supplied in border.

Returns
None