:py:mod:`pylbo.automation.generator` ==================================== .. py:module:: pylbo.automation.generator Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: pylbo.automation.generator.ParfileGenerator Functions ~~~~~~~~~ .. autoapisummary:: pylbo.automation.generator._ensure_nb_names_and_nb_runs_matches pylbo.automation.generator._validate_basenames pylbo.automation.generator._validate_output_dir pylbo.automation.generator._handle_expected_item_list Attributes ~~~~~~~~~~ .. autoapisummary:: pylbo.automation.generator.KEYS_EXPECTED_AS_LIST .. py:data:: KEYS_EXPECTED_AS_LIST :value: ['basis_functions'] .. py:function:: _ensure_nb_names_and_nb_runs_matches(names: Union[str, list[str]], nb_runs: int) -> list[str] Ensures that the number of names matches the number of runs. :param names: The basename(s) for the parfile(s). :type names: str, list[str] :param nb_runs: Number of runs for which the parfiles are generated. :type nb_runs: int :returns: **names** -- The basename(s) for the parfile(s). :rtype: list[str] .. !! processed by numpydoc !! .. py:function:: _validate_basenames(basenames: list[str]) -> list[str] Validates the basenames for given parfiles. :param basename: The basenames for the parfiles. If not given, defaults to "parfile[i]". :type basename: list[str] :returns: **basename** -- The basename for a parfile. :rtype: list[str] .. !! processed by numpydoc !! .. py:function:: _validate_output_dir(output_dir, subdir) Validates and returns the output directory for the parfiles. :param output_dir: The output directory to store the parfiles in. If not given, defaults to the current working directory. :type output_dir: str, ~os.PathLike :param subdir: If `.true.`, creates a subdirectory called `parfiles`. :type subdir: boolean :raises NotADirectoryError: If the output directory is not found. :returns: **output** -- The resolved path to the output directory with "parfiles" appended. :rtype: ~os.PathLike .. !! processed by numpydoc !! .. py:function:: _handle_expected_item_list(item) .. py:class:: ParfileGenerator(parfile_dict, basename=None, output_dir=None, subdir=True, prefix_numbers=True, nb_prefix_digits=4) Handles parfile generation. :param parfile_dict: Dictionary containing the keys to be placed in the parfile. :type parfile_dict: dict :param basename: 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. :type basename: str, list[str] :param output_dir: Output directory where the parfiles are saved, defaults to the current working directory if not specified. :type output_dir: str, ~os.PathLike :param subdir: If `True` (default), creates a subdirectory under `output_dir` called `parfiles` in which the parfiles will be saved. :type subdir: boolean :param prefix_numbers: If `True` prepends the `basename` by a n-digit number (e.g. xxxxmyparfile.par). The number of digits is specified by `nb_prefix_digits`. :type prefix_numbers: boolean :param nb_prefix_digits: Number of digits to prepend to the `basename` if `prefix_numbers` is `True`. Defaults to 4. :type nb_prefix_digits: int .. !! processed by numpydoc !! .. py:method:: _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. :param namelist: One of the namelists ("gridlist", "savelist", etc.) :type namelist: str :param name: The key to check. :type name: str :param allowed_dtypes: Allowed types for that particular key. Either a single value or a tuple. :type allowed_dtypes: class, 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. :rtype: any .. !! processed by numpydoc !! .. py:method:: 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 .. !! processed by numpydoc !! .. py:method:: 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. :rtype: list of str .. !! processed by numpydoc !!