Parameters

class glotaran.parameter.parameters.Parameters(parameters: dict[str, Parameter])[source]

Bases: object

A container for Parameter.

Create Parameters.

Parameters:

parameters (dict[str, Parameter]) – A parameter list containing parameters

Returns:

The created Parameters.

Return type:

‘Parameters’

Attributes Summary

labels

List of all labels.

Methods Summary

all

Iterate over all parameters.

copy

Create a copy of the Parameters.

from_dataframe

Create a Parameters from a pandas.DataFrame.

from_dict

Create a Parameters from a dictionary.

from_list

Create Parameters from a list.

from_parameter_dict_list

Create Parameters from a list of parameter dictionaries.

get

Get a Parameter by its label.

get_label_value_and_bounds_arrays

Return a arrays of all parameter labels, values and bounds.

has

Check if a parameter with the given label is in the group or in a subgroup.

loader

Create a Parameters instance from the specs defined in a file.

markdown

Format the ParameterGroup as markdown string.

set_from_history

Update the Parameters with values from a parameter history.

set_from_label_and_value_arrays

Update the parameter values from a list of labels and values.

to_dataframe

Create a pandas data frame from the group.

to_parameter_dict_list

Create list of parameter dictionaries from the group.

to_parameter_dict_or_list

Convert to a dict or list of parameter definitions.

update_parameter_expression

Update all parameters which have an expression.

Methods Documentation

all() Generator[Parameter, None, None][source]

Iterate over all parameters.

Yields:

Parameter – A parameter in the parameters.

copy() Parameters[source]

Create a copy of the Parameters.

Returns:

  • Parameters – A copy of the Parameters.

  • .. # noqa (D414)

classmethod from_dataframe(df: DataFrame, source: str = 'DataFrame') Parameters[source]

Create a Parameters from a pandas.DataFrame.

Parameters:
  • df (pd.DataFrame) – The source data frame.

  • source (str) – Optional name of the source file, used for error messages.

Raises:

ValueError – Raised if the columns ‘label’ or ‘value’ doesn’t exist. Also raised if the columns ‘minimum’, ‘maximum’ or ‘values’ contain non numeric values or if the columns ‘non-negative’ or ‘vary’ are no boolean.

Returns:

  • Parameters – The created parameter group.

  • .. # noqa (D414)

classmethod from_dict(parameter_dict: dict[str, dict[str, Any] | list[float | list[Any]]]) Parameters[source]

Create a Parameters from a dictionary.

Parameters:

parameter_dict (dict[str, dict[str, Any] | list[float | list[Any]]]) – A parameter dictionary containing parameters.

Returns:

  • Parameters – The created Parameters

  • .. # noqa (D414)

classmethod from_list(parameter_list: list[float | int | str | list[Any] | dict[str, Any]]) Parameters[source]

Create Parameters from a list.

Parameters:

parameter_list (list[float | list[Any]]) – A parameter list containing parameters

Returns:

  • Parameters – The created Parameters.

  • .. # noqa (D414)

classmethod from_parameter_dict_list(parameter_dict_list: list[dict[str, Any]]) Parameters[source]

Create Parameters from a list of parameter dictionaries.

Parameters:

parameter_dict_list (list[dict[str, Any]]) – A list of parameter dictionaries.

Returns:

  • Parameters – The created Parameters.

  • .. # noqa (D414)

get(label: str) Parameter[source]

Get a Parameter by its label.

Parameters:

label (str) – The label of the parameter, with its path in a ParameterGroup prepended.

Returns:

The parameter.

Return type:

Parameter

Raises:

ParameterNotFoundException – Raised if no parameter with the given label exists.

get_label_value_and_bounds_arrays(exclude_non_vary: bool = False) tuple[list[str], ndarray, ndarray, ndarray][source]

Return a arrays of all parameter labels, values and bounds.

Parameters:

exclude_non_vary (bool) – If true, parameters with vary=False are excluded.

Returns:

A tuple containing a list of parameter labels and an array of the values, lower and upper bounds.

Return type:

tuple[list[str], np.ndarray, np.ndarray, np.ndarray]

has(label: str) bool[source]

Check if a parameter with the given label is in the group or in a subgroup.

Parameters:

label (str) – The label of the parameter, with its path in a ParameterGroup prepended.

Returns:

Whether a parameter with the given label exists in the group.

Return type:

bool

property labels: list[str]

List of all labels.

Return type:

list[str]

loader(format_name: str | None = None, **kwargs) Parameters

Create a Parameters instance from the specs defined in a file.

Parameters:
  • file_name (StrOrPath) – File containing the parameter specs.

  • format_name (str | None) – Format the file is in, if not provided it will be inferred from the file extension.

  • **kwargs (Any) – Additional keyword arguments passes to the load_parameters implementation of the project io plugin.

Returns:

  • ParametersParameters instance created from the file.

  • .. # noqa (D414)

markdown(float_format: str = '.3e') MarkdownStr[source]

Format the ParameterGroup as markdown string.

This is done by recursing the nested ParameterGroup tree.

Parameters:

float_format (str) – Format string for floating point numbers, by default “.3e”

Returns:

The markdown representation as string.

Return type:

MarkdownStr

set_from_history(history: ParameterHistory, index: int)[source]

Update the Parameters with values from a parameter history.

Parameters:
set_from_label_and_value_arrays(labels: list[str], values: ndarray)[source]

Update the parameter values from a list of labels and values.

Parameters:
  • labels (list[str]) – A list of parameter labels.

  • values (np.ndarray) – An array of parameter values.

Raises:

ValueError – Raised if the size of the labels does not match the stize of values.

to_dataframe() DataFrame[source]

Create a pandas data frame from the group.

Returns:

The created data frame.

Return type:

pd.DataFrame

to_parameter_dict_list() list[dict[str, Any]][source]

Create list of parameter dictionaries from the group.

Returns:

A list of parameter dictionaries.

Return type:

list[dict[str, Any]]

to_parameter_dict_or_list(serialize_parameters: bool = False) dict | list[source]

Convert to a dict or list of parameter definitions.

Parameters:

serialize_parameters (bool) – If true, the parameters will be serialized into list representation.

Returns:

A dict or list of parameter definitions.

Return type:

dict | list

update_parameter_expression()[source]

Update all parameters which have an expression.

Raises:

ValueError – Raised if an expression evaluates to a non-numeric value.