wadi.base module

class wadi.base.WadiBaseClass(log_fname='wadi.log', output_dir='wadi_output', silent=False, create_file=False)

Bases: ABC

Base class for WADI DataObject class and its children. Defines functions to provide functionality to log and print messages and warnings.

__init__(log_fname='wadi.log', output_dir='wadi_output', silent=False, create_file=False)

Class initialization method.

Parameters:
  • log_fname (str, optional) – Name of the log file

  • output_dir (str, optional) – Name of the directory with output files

  • silent (bool, optional,) – Flag to indicate if screen output is desired during data processing. When True then no screen output is displayed. Default is False (recommended for large data files when processing can be slow). When True messages will still appear in the log file. Warnings are always displayed on the screen regardless of the value for ‘silent’.

  • create_file (bool, optional) – Flag to indicate if the log file must be created. Must be explicitly set to True when an object of this class is initialized for the first time. In WaDI this happens in the init method of DataObject.

abstract _execute()

This method must be implemented by all WaDI classes that derive from this class.

_log(s, timestamp=False, header=False)

Appends a new line to the log file string.

Parameters:
  • s (str) – Text string to be written to log file.

  • timestamp (bool) – If True the text string is followed by the current time between parentheses. No timestamp is appended when False.

  • header (bool) – If True leading and trailing carriage returns and a banner will be added to the text string.

_msg(s, **kwargs)

Prints a message to the screen and appends it as a new line to the log file string.

Parameters:
  • s (str) – Text string to be printed to the screen and written to the log file.

  • **kwargs (dict, optional) – Any keyword arguments to be passed onto _log_str.

_warn(s)

Throws a UserWarning and appends it as a new line to the log file string.

Parameters:

s (str) – Text string to be passed to the UserWarning and written to the log file.

update_log_file(mode='a')

Saves the log file string to a text file

Parameters:

mode (str) – Python file mode for opening the file. Default is ‘a’, which means that the log file string will be appended to the log file.

_remove_log_file()

Attempts to delete the log file