qom.io module

Module for miscellaneous IO operations.

class qom.io.Updater(name, cb_update, parallel: bool = False, p_index: int = 0, p_start: float = None)

Bases: object

Class to update the logs and progress callbacks.

Initializes logger and cb_update.

Parameters:
  • name (str) – Name of the module or class.

  • cb_update (callable, optional) – Callback function to update status and progress, formatted as cb_update(status, progress, reset), where status is a string, progress is a float and reset is a boolean.

  • parallel (bool, default=False) – Option to format outputs when running in parallel.

  • p_index (int, default=0) – Index of the process.

  • p_start (float, optional) – Time at which the process was started. If not provided, the value is initialized to current time.

create_directory(file_path: str)

Method to update the directory of the data file.

Parameters:

file_path (str) – Full path of the file.

exists(file_path: str)

Function to validate the data file.

If a file with an '.npy' extension is found, the same is converted to '.npz'.

Parameters:

file_path (str) – Full path of the file.

Returns:

exists – Whether the file exists.

Return type:

bool

load(file_path: str)

Function to load from a data file.

Parameters:

file_path (str) – Full path of the file.

Returns:

array – Data loaded from the file.

Return type:

numpy.ndarray

save(file_path: str, array)

Function to save to a data file.

Parameters:
  • file_path (str) – Full path of the file.

  • array (numpy.ndarray) – Data to save to the file.

update_debug(message: str)

Method to update debug message.

Parameters:

message (str) – Debug message.

update_info(status: str)

Method to update status information.

Parameters:

status (str) – Status information.

update_progress(pos: int, dim: int, status: str, reset: bool)

Method to update progress.

Parameters:
  • pos (int) – Index of current iteration.

  • dim (int) – Total number of iterations.

  • status (str) – Status information.

  • reset (bool) – Option to reset the console or callback.