helper_utils module

helper_utils.eval_string_as_list(str_read, separator, dtype)[source]

Parse a string and convert it into a list of lists.

Parameters
  • str_read (string) – String read (from configuration file or command line, for example)

  • separator (character) – Character that specifies the separation between the lists

  • dtype (data type) – Data type to decode the elements of the list

Returns

decoded_list (list) – List extracted from string and with elements of the specified type.

helper_utils.eval_string_as_list_of_lists(str_read, separator_out, separator_in, dtype)[source]

Parse a string and convert it into a list of lists.

Parameters
  • str_read (string) – String read (from configuration file or command line, for example)

  • separator_out (character) – Character that specifies the separation between the outer level lists

  • separator_in (character) – Character that specifies the separation between the inner level lists

  • dtype (data type) – Data type to decode the elements of the lists

Returns

decoded_list (list) – List of lists extracted from string and with elements of the specified type.

helper_utils.fetch_file(link, subdir, unpack=False, md5_hash=None)[source]

Convert URL to file path and download the file if it is not already present in spedified cache.

Parameters
  • link (link path) – URL of the file to download

  • subdir (directory path) – Local path to check for cached file.

  • unpack (boolean) – Flag to specify if the file to download should be decompressed too. (default: False, no decompression)

  • md5_hash (MD5 hash) – Hash used as a checksum to verify data integrity. Verification is carried out if a hash is provided. (default: None, no verification)

Returns

local path to the downloaded, or cached, file.

helper_utils.keras_default_config()[source]

Defines parameters that intervine in different functions using the keras defaults. This helps to keep consistency in parameters between frameworks.

helper_utils.set_up_logger(logfile, logger, verbose=False, fmt_line='[%(asctime)s %(process)d] %(message)s', fmt_date='%Y-%m-%d %H:%M:%S')[source]

Set up the event logging system. Two handlers are created. One to send log records to a specified file and one to send log records to the (defaulf) sys.stderr stream. The logger and the file handler are set to DEBUG logging level. The stream handler is set to INFO logging level, or to DEBUG logging level if the verbose flag is specified. Logging messages which are less severe than the level set will be ignored.

Parameters
  • logfile (filename) – File to store the log records

  • logger (logger object) – Python object for the logging interface

  • verbose (boolean) – Flag to increase the logging level from INFO to DEBUG. It only applies to the stream handler.

helper_utils.str2bool(v)[source]

This is taken from: https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse Because type=bool is not interpreted as a bool and action=’store_true’ cannot be undone.

Parameters

v (string) – String to interpret

Returns

  • Boolean value. It raises and exception if the provided string cannot

  • be interpreted as a boolean type.

  • Strings recognized as boolean True – ‘yes’, ‘true’, ‘t’, ‘y’, ‘1’ and uppercase versions (where applicable).

  • Strings recognized as boolean False – ‘no’, ‘false’, ‘f’, ‘n’, ‘0’ and uppercase versions (where applicable).

helper_utils.verify_path(path)[source]

Verify if a directory path exists locally. If the path does not exist, but is a valid path, it recursivelly creates the specified directory path structure.

Parameters

path (directory path) – Description of local directory path