bloc.utils#

Attributes#

Functions#

get_root()

Return the full path of the Bloc folder.

get_path_to_data(*paths[, force_return])

Return the absolute path to the data folder, or file inside.

get_file_path(file_str)

Return path (str) of a file.

get_mechanism_path(mechanism_str)

Return path (str) of Cantera mechanism.

make_folders(path, folders)

Make folders if not there.

add_prefix_to_dict_keys(d, prefix)

Add a prefix to the keys of a dictionary.

Module Contents#

bloc.utils.ROOT_FOLDER_PATH#
bloc.utils.get_root()#

Return the full path of the Bloc folder.

Used not to worry about the project architecture.

Returns:

the abspath to root folder (ends with ‘/bloc’)

Return type:

Path

Examples

>>> from bloc.utils import get_root
>>> path = get_root() / "data" / "mechanisms" / "Fincke_GRC.yaml"
bloc.utils.get_path_to_data(*paths, force_return=False)#

Return the absolute path to the data folder, or file inside.

Parameters:
  • *paths (str) – You can add a path to precise the folder inside.

  • force_return (bool, optional) – If True, return path even if does not exists, by default False.

Returns:

The abspath to the data (or file).

Return type:

Path

Examples

>>> from bloc.utils import get_path_to_data
>>> path = get_path_to_data("mechanisms", "Fincke_GRC.yaml")
>>> path = get_path_to_data("mechanisms", "gri30_+C(s).yaml")
Raises:

FileNotFoundError – If the file or folder is not found.

bloc.utils.get_file_path(file_str)#

Return path (str) of a file.

File is looked up from (in order):

  1. An absolute path (if exists) or relative path from the working directory

  2. A relative path from the calling script’s folder.

bloc.utils.get_mechanism_path(mechanism_str)#

Return path (str) of Cantera mechanism.

Mechanism is looked up from (in order):

  1. An absolute path (if exists) or relative path from the working directory

  2. A relative path from the calling script’s folder.

  3. The /bloc/data/mechanism directory

  4. The /cantera/data directory

Mechanism can then be fed to a cantera.Solution object.

Examples

Carbon Black Reactor.

Carbon Black Reactor.

Plug Flow Reactor.

Plug Flow Reactor.
bloc.utils.make_folders(path, folders)#

Make folders if not there.

Parameters:
  • path (str) – where to create folders

  • folders (list or str) – folders to create

bloc.utils.add_prefix_to_dict_keys(d, prefix)#

Add a prefix to the keys of a dictionary.

Parameters:
  • d (dict) – The dictionary to modify.

  • prefix (str) – The prefix to add to the keys.

Returns:

A new dictionary with the prefixed keys.

Return type:

dict