pylbo.automation.generator

Module Contents

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.

pylbo.automation.generator._ensure_nb_names_and_nb_runs_matches(names: str | list[str], nb_runs: int) list[str][source]

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][source]

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)[source]

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

class pylbo.automation.generator.ParfileGenerator(parfile_dict, basename=None, output_dir=None, subdir=True, prefix_numbers=True, nb_prefix_digits=4)[source]

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.

_get_and_check_item(namelist, name, allowed_dtypes)[source]

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()[source]

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()[source]

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