cellmil.utils.tools¶
Functions
|
Closing a logger savely |
|
Create a color gradient from initial_color to final_color. |
|
Prints the time passed from start_time. |
Get the number of available CPU cores. |
|
|
Try to import optional dependencies. |
|
Plot a PyTorch Geometric graph using Plotly. |
|
Plot a 1D vector using matplotlib. |
Returns the number of seconds passed since epoch. |
|
|
Convert tensor to float32 |
Convert tensor to float32 and normalize to [0, 1] |
|
|
Unflatten a flattened dictionary (created a nested dictionary) |
- cellmil.utils.tools.to_float_normalized(x: Tensor) Tensor[source]¶
Convert tensor to float32 and normalize to [0, 1]
- cellmil.utils.tools.start_timer() float[source]¶
Returns the number of seconds passed since epoch. The epoch is the point where the time starts, and is platform dependent.
- Returns:
The number of seconds passed since epoch
- Return type:
- cellmil.utils.tools.end_timer(start_time: float, timed_event: str = 'Time usage') None[source]¶
Prints the time passed from start_time.
- cellmil.utils.tools.module_exists(*names: Union[List[str], str], error: str = 'ignore', warn_every_time: bool = False, __INSTALLED_OPTIONAL_MODULES: Dict[str, bool] = {}) Optional[Union[Tuple[module | None, ...], module]][source]¶
Try to import optional dependencies. Ref: https://stackoverflow.com/a/73838546/4900327
- Parameters:
names (Union(List(str), str)) – The module name(s) to import. Str or list of strings.
error (str, optional) –
- What to do when a dependency is not found:
raise : Raise an ImportError.
warn: print a warning.
ignore: If any module is not installed, return None, otherwise, return the module(s).
Defaults to “ignore”.
warn_every_time (bool, optional) – Whether to warn every time an import is tried. Only applies when error=”warn”. Setting this to True will result in multiple warnings if you try to import the same library multiple times. Defaults to False.
- Raises:
ImportError – ImportError of Module
- Returns:
- The imported module(s), if all are found.
None is returned if any module is not found and error!=”raise”.
- Return type:
Optional[ModuleType, Tuple[ModuleType…]]
- cellmil.utils.tools.close_logger(logger: Logger) None[source]¶
Closing a logger savely
- Parameters:
logger (logging.Logger) – Logger to close
- cellmil.utils.tools.unflatten_dict(d: dict[str, Any], sep: str = '.') dict[str, Any][source]¶
Unflatten a flattened dictionary (created a nested dictionary)
- cellmil.utils.tools.create_color_gradient(bins: int, initial_color: list[int], final_color: list[int]) list[list[int]][source]¶
Create a color gradient from initial_color to final_color.