PTO.utils package

Submodules

PTO.utils.utilities module

Created on Fri Jun 17 13:24:03 2022

@author: chamaeleontis

Contains utility functions and decorators to use in other script.

PTO.utils.utilities.addLoggingLevel(levelName, levelNum, methodName=None)[source]

Comprehensively adds a new logging level to the logging module and the currently configured logging class.

levelName becomes an attribute of the logging module with the value levelNum. methodName becomes a convenience method for both logging itself and the class returned by logging.getLoggerClass() (usually just logging.Logger). If methodName is not specified, levelName.lower() is used.

To avoid accidental clobberings of existing attributes, this method will raise an AttributeError if the level name is already an attribute of the logging module or if the method name is already present

Example

>>> addLoggingLevel('TRACE', logging.DEBUG - 5)
>>> logging.getLogger(__name__).setLevel("TRACE")
>>> logging.getLogger(__name__).trace('that worked')
>>> logging.trace('so did this')
>>> logging.TRACE
PTO.utils.utilities.disable_func(func)[source]

This decorator disables a function. Use this to check breakability of code by disabling (for removing legacy code pieces).

Parameters:

func (function) – Function to decorate.

Returns:

wrapper – Decorated function.

Return type:

function

PTO.utils.utilities.logger_default(logger_update: Logger) Logger[source]

Updates the Logger to include print level and different set of colors for each level.

Parameters:

logger_update (logging.Logger) – Logger to update

Returns:

Outputed logger

Return type:

logging.Logger

PTO.utils.utilities.plot_different_setting(style)[source]
PTO.utils.utilities.progress_tracker(func)[source]

Decorator function for progress tracking of the function

Parameters:

func (function) – Function to decorate.

Returns:

wrapper – Decorated function.

Return type:

function

PTO.utils.utilities.save_and_load(func)[source]

Decorator function for saving and loading the function

Parameters:

func (function) – Function to decorate.

Returns:

wrapper – Decorated function.

Return type:

function

PTO.utils.utilities.save_figure(func)[source]

Decorator function to save figure in file. Expect the decorated function to give output fig,axs – fig being the fig.Figure class while axs being the artists that were drawn on figure.

Parameters:

func (function) – Function to decorate.

Returns:

wrapper – Decorated function.

Return type:

function

PTO.utils.utilities.save_progress(func, *args, file=None, force_calculate=False, no_save=False)[source]

Function to save progress of other functions

Input:

func ; function - function for which we want to save progress file ; string - pickle file (*.pkl) where to save/load result force_calculate = False ; True/False - Force to recalculate function no_save = False ; True/False - Force not to save data (in case of big files

Output:

result ; *results - resulting arguments that we would normally receive from func(*args)

PTO.utils.utilities.skip_function(func)[source]

This decorator disables a function based on a provided keyword. Use this to of code by disabling for time saving.

Parameters:

func (function) – Function to decorate.

Returns:

wrapper – Decorated function.

Return type:

function

PTO.utils.utilities.time_function(func)[source]

Decorator function for timing the function

Parameters:

func (function) – Function to decorate.

Returns:

wrapper – DESCRIPTION.

Return type:

TYPE

PTO.utils.utilities.todo_function(func)[source]

This decorator warns the use to TODO in function.

Parameters:

func (function) – Function to decorate.

Returns:

wrapper – Decorated function.

Return type:

function

Module contents