bloc.utils#
Attributes#
Functions#
|
Return the full path of the Bloc folder. |
|
Return the absolute path to the data folder, or file inside. |
|
Return path (str) of a file. |
|
Return path (str) of Cantera mechanism. |
|
Make folders if not there. |
|
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):
An absolute path (if exists) or relative path from the working directory
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):
An absolute path (if exists) or relative path from the working directory
A relative path from the calling script’s folder.
The /bloc/data/mechanism directory
The /cantera/data directory
Mechanism can then be fed to a
cantera.Solutionobject.Examples
- bloc.utils.make_folders(path, folders)#
Make folders if not there.
- Parameters:
path (
str) – where to create foldersfolders (
listorstr) – 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