wolfgpu.utils

Author: HECE - University of Liege, Stéphane Champailler, Pierre Archambeau Date: 2024

Copyright (c) 2024 University of Liege. All rights reserved.

This script and its content are protected by copyright law. Unauthorized copying or distribution of this file, via any medium, is strictly prohibited.

Module Contents

class wolfgpu.utils.EveryNSeconds(period: float, trigger_start=True, name: str = '')[source]
has_shot() bool[source]

Calling this method will clear the has_shot flag.

So if you call it twice one after the other, without waiting no more than the period, it will give True one time and False the next time.

wolfgpu.utils.add_logging_level(levelName, levelNum, methodName=None)[source]

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

>>> add_logging_level('TRACE', logging.DEBUG - 5)
>>> logging.getLogger(__name__).setLevel("TRACE")
>>> logging.getLogger(__name__).trace('that worked')
>>> logging.trace('so did this')
>>> logging.TRACE
5
wolfgpu.utils.init_global_logging(lvl=logging.INFO)[source]
wolfgpu.utils.delete_dir_recursion(p)[source]

Delete folder, sub-folders and files.

Taken from: https://stackoverflow.com/questions/70246591/delete-directory-and-all-symlinks-recursively

Use this to remove the content of a directory without removing the directory itself.

wolfgpu.utils.nice_timestamp() str[source]

A nice timestamp which makes sure the day, month and year cannot be mismatched.

wolfgpu.utils.PARSE_DURATION_REGEX[source]
wolfgpu.utils.parse_duration(time_str) datetime.timedelta[source]

Parse a time string e.g. (2h13m) into a timedelta object.

Modified from virhilo’s answer at https://stackoverflow.com/a/4628148/851699

Parameters:

time_str – A string identifying a duration. (eg. 2h13m)

Return datetime.timedelta:

A datetime.timedelta object

Taken from https://stackoverflow.com/a/51916936/2030384

wolfgpu.utils.parse_duration_to_seconds(time_str) float[source]
wolfgpu.utils.seconds_to_duration_str(s: float)[source]
wolfgpu.utils.t[source]