simuran.core.param_handler module

This module handles automatic creation of parameter files.

class simuran.core.param_handler.ParamHandler(source_file: Union[str, Path, None] = None, attrs: dict = <factory>, name: str = 'params', dirname_replacement: str = '')

Bases: object

A wrapper around a dictionary describing parameters.

Provides loaders for this and helper functions.

source_file

The path to the file containing the parameters.

Type:Path
attrs

The dictionary of underlying parameters

Type:dict
name

The name of the variable describing the parameters, default is “params”. This is only used if in_loc is not None.

Type:str
dirname_replacement

The directory name to replace __dirname__ by. By default, replaces it by dirname(param_file)

Type:str
clear()

Remove all items from the dictionary.

dirname_replacement = ''
get(key, default=None)

Retrieve the value of key from the parameters.

This mimics regular dictionary get.

Parameters:
  • key (str) – The key to retrieve
  • default (object, optional) – What to return if the key is not found, default is None
Returns:

The value of the key

Return type:

object

items()

Return key, value pairs in the parameters.

keys()

Return all keys in the parameters.

name = 'params'
pop(key, default=<object object>)

Pop key from dictionary, optionally with default value

Parameters:
  • key (Any) – The key to pop
  • default (Any) – If provided, the default value to get
Returns:

The value of the key

Return type:

Any

read()

Read the parameters.

Returns:
Return type:None
setdefault(key, value=<object object>)

Return the value of the key. If the key does not exist, set it to value.

Parameters:
  • key (Any) – The key to pop
  • value (Any) – If provided, the default value to set
Returns:

The value of the key

Return type:

Any

source_file = None
to_str()

Convert the underlying parameters dictionary to string.

Can be useful for printing or writing to a file. Does not overwrite default __str__ as the output is quite verbose.

Returns:The string representation of the dict.
Return type:str
update(dict_)

Update attrs with dict_

Parameters:dict (dict) – The dictionary to update with
Returns:
Return type:None
values()

Return all values in the parameters.

write(out_loc)

Write the parameters out to a python file.

Parameters:out_loc (str) – The path to write to
Returns:
Return type:None