Skip to main content

utils.general

path_dirname

def path_dirname(p: str)

Returns the directory component of a pathname.

path_split

def path_split(p)

Split a pathname.

Returns tuple "(head, tail)" where "tail" is everything after the final slash. Either part may be empty.

path_exists

def path_exists(p)

Return True if path exists.

path_join

def path_join(parent: str, child: str)

Joins parent and child path.

path_basename

def path_basename(p: str)

Returns the final component of a pathname.

makedirs

def makedirs(name, exist_ok=False)

Wraps makedirs(name [, mode=0o777][, exist_ok=False]).

Super-mkdir; create a leaf directory and all intermediate ones. Works like mkdir, except that any intermediate path segment (not just the rightmost) will be created if it does not exist. If the target directory already exists, raise an OSError if exist_ok is False. Otherwise no exception is raised. This is recursive.

remove_all

def remove_all(name)

Recursively remove paths.

clip

def clip(x, min_value=0, max_value=1)

Return value, within bounds [min,max]

rescale01

def rescale01(x: float, x0: float, x1: float)

Rescale x from (x0, x1) to (0, 1), with clipping.

rescale

def rescale(x: float, x0: float, x1: float, y0: float, y1: float)

Rescale x from (x0, x1) to (y0, y1), with clipping.

avg

def avg(iterable)

Returns the average of a list or tuple.

Returns 0 if empty.

avg_min_max

def avg_min_max(iterable)

Returns a tuple with the (average, min, max) of a list or tuple.

Returns (0, 0, 0) if empty.

current_write_state

def current_write_state() -> bool

Returns True if the microcontroller is currently booted into a writeable state.

Returns False otherwise.