utils Module#
Utils for plotting, coloring output and progress bar.
- Author:
LENZ ENCODERS, 2020-2025
- class lenz_flashtool.utils.TermColors#
Bases:
object
- BOLD = '\x1b[1m'#
- BackgroundBlack = '\x1b[40m'#
- BackgroundBlue = '\x1b[44m'#
- BackgroundCyan = '\x1b[46m'#
- BackgroundDarkGray = '\x1b[100m'#
- BackgroundDefault = '\x1b[49m'#
- BackgroundGreen = '\x1b[42m'#
- BackgroundLightBlue = '\x1b[104m'#
- BackgroundLightCyan = '\x1b[106m'#
- BackgroundLightGray = '\x1b[47m'#
- BackgroundLightGreen = '\x1b[102m'#
- BackgroundLightMagenta = '\x1b[105m'#
- BackgroundLightRed = '\x1b[101m'#
- BackgroundLightYellow = '\x1b[103m'#
- BackgroundMagenta = '\x1b[45m'#
- BackgroundRed = '\x1b[41m'#
- BackgroundWhite = '\x1b[107m'#
- BackgroundYellow = '\x1b[43m'#
- Black = '\x1b[30m'#
- Blink = '\x1b[5m'#
- Blue = '\x1b[34m'#
- Bold = '\x1b[1m'#
- Cyan = '\x1b[36m'#
- DarkGray = '\x1b[90m'#
- Default = '\x1b[39m'#
- Dim = '\x1b[2m'#
- ENDC = '\x1b[0m'#
- FAIL = '\x1b[91m'#
- GRAY = '\x1b[90m'#
- Green = '\x1b[32m'#
- HEADER = '\x1b[95m'#
- Hidden = '\x1b[8m'#
- LightBlue = '\x1b[94m'#
- LightCyan = '\x1b[96m'#
- LightGray = '\x1b[37m'#
- LightGreen = '\x1b[92m'#
- LightMagenta = '\x1b[95m'#
- LightRed = '\x1b[91m'#
- LightYellow = '\x1b[93m'#
- Magenta = '\x1b[35m'#
- OKBLUE = '\x1b[94m'#
- OKGREEN = '\x1b[92m'#
- Red = '\x1b[31m'#
- ResetBlink = '\x1b[25m'#
- ResetBold = '\x1b[21m'#
- ResetDim = '\x1b[22m'#
- ResetHidden = '\x1b[28m'#
- ResetReverse = '\x1b[27m'#
- ResetUnderlined = '\x1b[24m'#
- Reverse = '\x1b[7m'#
- UNDERLINE = '\x1b[4m'#
- Underlined = '\x1b[4m'#
- WARNING = '\x1b[93m'#
- White = '\x1b[97m'#
- Yellow = '\x1b[33m'#
- lenz_flashtool.utils.percent_complete(step, total_steps, bar_width=60, title='', print_perc=True, color='green')#
Displays a progress bar in the terminal to indicate the percentage of completion.
- Parameters:
step (int) – The current step or iteration.
total_steps (int) – The total number of steps or iterations.
bar_width (int, optional) – The width of the progress bar in characters. Defaults to 60.
title (str, optional) – An optional title to display alongside the progress bar. Defaults to “”.
print_perc (bool, optional) – Whether to print the percentage complete. Defaults to True.
color (str, optional) – The name of the color for the progress bar. Defaults to “green”.
- Returns:
None
- lenz_flashtool.utils.plot(data, filename=None, directory=None)#
Plots a single dataset with annotated max and min values.
- Parameters:
data (
Union
[Sequence
[float
],ndarray
]) – Input data to visualize (list or numpy array of numerical values)filename (
Optional
[str
]) – Name for the output file (including extension). If None, plot won’t be saved.directory (
Optional
[str
]) – Target directory for saving. If None, uses current working directory.
- Returns:
Displays interactive plot and optionally saves to file.
- Return type:
None
Example
>>> data = [1, 3, 2, 4, 3] >>> plot(data, 'trend.png', 'plots') # Saves to 'plots/trend.png'
- lenz_flashtool.utils.plot2(a, b, filename=None, directory=None, label1='After calibration', label2='Before calibration')#
Plots two datasets for comparison with annotated statistics.
- Parameters:
a (
Union
[Sequence
[float
],ndarray
]) – First dataset (list or numpy array)b (
Union
[Sequence
[float
],ndarray
]) – Second dataset (list or numpy array)filename (
Optional
[str
]) – Output filename (including extension). None prevents saving.directory (
Optional
[str
]) – Target directory. None uses current directory.label1 (
str
) – Legend label for first datasetlabel2 (
str
) – Legend label for second dataset
- Returns:
Displays interactive comparison plot
- Return type:
None