Skip to content

parameter_space

This module provides functions to generate parameter spaces for studies.

Functions:

Name Description
convert_for_subvariables

list[str], parameter_list: list) -> list: Convert the parameter list to a list of dictionaries with subvariables as keys.

linspace

list) -> np.ndarray: Generate a list of evenly spaced values over a specified interval.

logspace

list) -> np.ndarray: Generate a list of values that are evenly spaced on a log scale.

list_values_path

list[str], dic_common_parameters: dict[str, Any]) -> list[str]: Generate a list of path names from an initial path name.

convert_for_subvariables(l_subvariables, parameter_list)

Convert the parameter list to a list of dictionaries with subvariables as keys.

Parameters:

Name Type Description Default
l_subvariables list[str]

List of subvariables.

required
parameter_list list

List with the parameter values.

required

Returns:

Name Type Description
list list

List of dictionaries with subvariables as keys.

Source code in study_da/generate/parameter_space.py
def convert_for_subvariables(l_subvariables: list[str], parameter_list: list) -> list:
    """Convert the parameter list to a list of dictionaries with subvariables as keys.

    Args:
        l_subvariables (list[str]): List of subvariables.
        parameter_list (list): List with the parameter values.

    Returns:
        list: List of dictionaries with subvariables as keys.
    """
    return [{subvar: value for subvar in l_subvariables} for value in parameter_list]

linspace(l_values_linspace)

Generate a list of evenly spaced values over a specified interval.

Parameters:

Name Type Description Default
l_values_linspace list

List with the values for the linspace function.

required

Returns:

Type Description
ndarray

np.ndarray: List of evenly spaced values.

Source code in study_da/generate/parameter_space.py
def linspace(l_values_linspace: list) -> np.ndarray:
    """Generate a list of evenly spaced values over a specified interval.

    Args:
        l_values_linspace (list): List with the values for the linspace function.

    Returns:
        np.ndarray: List of evenly spaced values."""

    # Check that all values in the list are floats or integers
    if not all(isinstance(value, (float, int)) for value in l_values_linspace):
        raise ValueError(
            "All values in the list for the linspace function must be floats or integers."
        )
    return np.round(
        np.linspace(
            l_values_linspace[0],
            l_values_linspace[1],
            l_values_linspace[2],
            endpoint=True,
        ),
        8,
    )

list_values_path(l_values_path_list, dic_common_parameters)

Generate a list of path names from an inital path name.

Parameters:

Name Type Description Default
l_values_path_list list

List with the initial path names and number of paths.

required
dic_common_parameters dict

Dictionary with the parameters common to the whole study.

required

Returns:

Name Type Description
list list[str]

List of final path values from the initial paths.

Source code in study_da/generate/parameter_space.py
def list_values_path(
    l_values_path_list: list[str], dic_common_parameters: dict[str, Any]
) -> list[str]:
    """Generate a list of path names from an inital path name.

    Args:
        l_values_path_list (list): List with the initial path names and number of paths.
        dic_common_parameters (dict): Dictionary with the parameters common to the whole study.

    Returns:
        list: List of final path values from the initial paths.
    """
    # Check that all values in the list are strings
    if not all(isinstance(value, str) for value in l_values_path_list):
        raise ValueError(
            "All values in the list for the list_values_path function must be strings."
        )
    n_path_arg = l_values_path_list[1]
    n_path = find_item_in_dic(dic_common_parameters, n_path_arg)
    if n_path is None:
        raise ValueError(f"Parameter {n_path_arg} is not defined in the scan configuration.")
    return [l_values_path_list[0].replace("____", f"{n:02d}") for n in range(n_path)]

logspace(l_values_logspace)

Generate a list of values that are evenly spaced on a log scale.

Parameters:

Name Type Description Default
l_values_logspace list

List with the values for the logspace function.

required

Returns:

Type Description
ndarray

np.ndarray: List of values that are evenly spaced on a log scale.

Source code in study_da/generate/parameter_space.py
def logspace(l_values_logspace: list) -> np.ndarray:
    """Generate a list of values that are evenly spaced on a log scale.

    Args:
        l_values_logspace (list): List with the values for the logspace function.

    Returns:
        np.ndarray: List of values that are evenly spaced on a log scale.
    """

    # Check that all values in the list are floats or integers
    if not all(isinstance(value, (float, int)) for value in l_values_logspace):
        raise ValueError(
            "All values in the list for the logspace function must be floats or integers."
        )
    return np.round(
        np.logspace(
            l_values_logspace[0],
            l_values_logspace[1],
            l_values_logspace[2],
            endpoint=True,
        ),
        8,
    )