pylbo.automation.generator

Attributes

KEYS_EXPECTED_AS_LIST

Classes

ParfileGenerator

Handles parfile generation.

Functions

_ensure_nb_names_and_nb_runs_matches(→ list[str])

Ensures that the number of names matches the number of runs.

_validate_basenames(→ list[str])

Validates the basenames for given parfiles.

_validate_output_dir(output_dir, subdir)

Validates and returns the output directory for the parfiles.

_handle_expected_item_list(item)

Module Contents

pylbo.automation.generator.KEYS_EXPECTED_AS_LIST = ['basis_functions']
pylbo.automation.generator._ensure_nb_names_and_nb_runs_matches(names: str | list[str], nb_runs: int) list[str]

Ensures that the number of names matches the number of runs.

Parameters:
  • names (str, list[str]) – The basename(s) for the parfile(s).

  • nb_runs (int) – Number of runs for which the parfiles are generated.

Returns:

names – The basename(s) for the parfile(s).

Return type:

list[str]

pylbo.automation.generator._validate_basenames(basenames: list[str]) list[str]

Validates the basenames for given parfiles.

Parameters:

basename (list[str]) – The basenames for the parfiles. If not given, defaults to “parfile[i]”.

Returns:

basename – The basename for a parfile.

Return type:

list[str]

pylbo.automation.generator._validate_output_dir(output_dir, subdir)

Validates and returns the output directory for the parfiles.

Parameters:
  • output_dir (str, PathLike) – The output directory to store the parfiles in. If not given, defaults to the current working directory.

  • subdir (boolean) – If .true., creates a subdirectory called parfiles.

Raises:

NotADirectoryError – If the output directory is not found.

Returns:

output – The resolved path to the output directory with “parfiles” appended.

Return type:

PathLike

pylbo.automation.generator._handle_expected_item_list(item)
class pylbo.automation.generator.ParfileGenerator(parfile_dict, basename=None, output_dir=None, subdir=True, prefix_numbers=True, nb_prefix_digits=4)

Handles parfile generation.

Parameters:
  • parfile_dict (dict) – Dictionary containing the keys to be placed in the parfile.

  • basename (str, list[str]) – The basename for the parfile, the .par suffix is added automatically and is not needed. If not provided, the basename will default to parfile. Can be a list of names as well if multiple parfiles are being generated.

  • output_dir (str, PathLike) – Output directory where the parfiles are saved, defaults to the current working directory if not specified.

  • subdir (boolean) –

    If True (default), creates a subdirectory under output_dir called

    parfiles in which the parfiles will be saved.

  • prefix_numbers (boolean) – If True prepends the basename by a n-digit number (e.g. xxxxmyparfile.par). The number of digits is specified by nb_prefix_digits.

  • nb_prefix_digits (int) – Number of digits to prepend to the basename if prefix_numbers is True. Defaults to 4.

parfile_dict
nb_runs
basenames = ['parfile']
output_dir
_use_prefix = True
_nb_prefix_digits = 4
parfiles = []
container
_get_and_check_item(namelist, name, allowed_dtypes)

Does typechecking on the various dictionary keys supplied to the parfile generator. Pops the key from the dictionary.

Parameters:
  • namelist (str) – One of the namelists (“gridlist”, “savelist”, etc.)

  • name (str) – The key to check.

  • allowed_dtypes (class, tuple) – Allowed types for that particular key. Either a single value or a tuple.

Raises:

TypeError – If the types do not match, e.g. if “gridpoints” is specified as a float value when it should be an integer.

Returns:

item – The item popped from the dictionary corresponding to the given key.

Return type:

any

create_namelist_from_dict()

Creates one major namelist from the given dictionary.

Raises:

ParfileGenerationError

  • If the original dictionary is not empty after everything should be popped

  • If there is an inconsistency between array sizes of dictionary items

generate_parfiles()

Creates separate parfiles from the main namelist container and writes the individual parfiles to disk.

Returns:

parfiles – List containing the paths of the parfiles, can be passed to the legolas runner.

Return type:

list of str