ParameterGroup

class glotaran.parameter.parameter_group.ParameterGroup(label: Optional[str] = None, root_group: Optional[glotaran.parameter.parameter_group.ParameterGroup] = None)[source]

Bases: dict

Represents are group of parameters.

Can contain other groups, creating a tree-like hierarchy.

Initialize a ParameterGroup instance with label.

Parameters
  • label (str) – The label of the group.

  • root_group (ParameterGroup) – The root group

Raises

ValueError – Raised if the an invalid label is given.

Attributes Summary

label

Label of the group.

root_group

Root of the group.

Methods Summary

add_group

Add a ParameterGroup to the group.

add_parameter

Add a Parameter to the group.

all

Iterate over all parameter in the group and it's subgroups together with their labels.

clear

copy

Create a copy of the ParameterGroup.

from_dataframe

Create a ParameterGroup from a pandas.DataFrame.

from_dict

Create a ParameterGroup from a dictionary.

from_list

Create a ParameterGroup from a list.

from_parameter_dict_list

Create a ParameterGroup from a list of parameter dictionaries.

fromkeys

Create a new dictionary with keys from iterable and values set to value.

get

Get a Parameter by its label.

get_group_for_parameter_by_label

Get the group for a parameter by it's label.

get_label_value_and_bounds_arrays

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

get_nr_roots

Return the number of roots of the group.

groups

Return a generator over all groups and their subgroups.

has

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

items

keys

loader

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

markdown

Format the ParameterGroup as markdown string.

pop

If key is not found, d is returned if given, otherwise KeyError is raised

popitem

Remove and return a (key, value) pair as a 2-tuple.

set_from_history

Update the ParameterGroup with values from a parameter history.

set_from_label_and_value_arrays

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

setdefault

Insert key with a value of default if key is not in the dictionary.

to_csv

Save a ParameterGroup to a CSV file.

to_dataframe

Create a pandas data frame from the group.

to_parameter_dict_list

Create list of parameter dictionaries from the group.

update

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

update_parameter_expression

Update all parameters which have an expression.

values

Methods Documentation

add_group(group: glotaran.parameter.parameter_group.ParameterGroup)[source]

Add a ParameterGroup to the group.

Parameters

group (ParameterGroup) – The group to add.

Raises

TypeError – Raised if the group is not an instance of ParameterGroup.

add_parameter(parameter: Parameter | list[Parameter])[source]

Add a Parameter to the group.

Parameters

parameter (Parameter | list[Parameter]) – The parameter to add.

Raises

TypeError – If parameter or any item of it is not an instance of Parameter.

all(root: str | None = None, separator: str = '.') Generator[tuple[str, Parameter], None, None][source]

Iterate over all parameter in the group and it’s subgroups together with their labels.

Parameters
  • root (str) – The label of the root group

  • separator (str) – The separator for the parameter labels.

Yields

tuple[str, Parameter] – A tuple containing the full label of the parameter and the parameter itself.

clear() None.  Remove all items from D.
copy() glotaran.parameter.parameter_group.ParameterGroup[source]

Create a copy of the ParameterGroup.

Returns

A copy of the ParameterGroup.

Return type

ParameterGroup

classmethod from_dataframe(df: pandas.core.frame.DataFrame, source: str = 'DataFrame') glotaran.parameter.parameter_group.ParameterGroup[source]

Create a ParameterGroup from a pandas.DataFrame.

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

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

Returns

The created parameter group.

Return type

ParameterGroup

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.

classmethod from_dict(parameter_dict: dict[str, dict[str, Any] | list[float | list[Any]]], label: str = None, root_group: ParameterGroup = None) ParameterGroup[source]

Create a ParameterGroup from a dictionary.

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

  • label (str) – The label of the group.

  • root_group (ParameterGroup) – The root group

Returns

The created ParameterGroup

Return type

ParameterGroup

classmethod from_list(parameter_list: list[float | list[Any]], label: str = None, root_group: ParameterGroup = None) ParameterGroup[source]

Create a ParameterGroup from a list.

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

  • label (str) – The label of the group.

  • root_group (ParameterGroup) – The root group

Returns

The created ParameterGroup.

Return type

ParameterGroup

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

Create a ParameterGroup from a list of parameter dictionaries.

Parameters

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

Returns

The created ParameterGroup.

Return type

ParameterGroup

fromkeys(iterable, value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(label: str) glotaran.parameter.parameter.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_group_for_parameter_by_label(parameter_label: str, create_if_not_exist: bool = False) glotaran.parameter.parameter_group.ParameterGroup[source]

Get the group for a parameter by it’s label.

Parameters
  • parameter_label (str) – The parameter label.

  • create_if_not_exist (bool) – Create the parameter group if not existent.

Returns

The group of the parameter.

Return type

ParameterGroup

Raises

KeyError – Raised if the group does not exist and create_if_not_exist is False.

get_label_value_and_bounds_arrays(exclude_non_vary: bool = False) tuple[list[str], np.ndarray, np.ndarray, np.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]

get_nr_roots() int[source]

Return the number of roots of the group.

Returns

The number of roots.

Return type

int

groups() Generator[glotaran.parameter.parameter_group.ParameterGroup, None, None][source]

Return a generator over all groups and their subgroups.

Yields

ParameterGroup – A subgroup of ParameterGroup.

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

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
property label: str | None

Label of the group.

Returns

The label of the group.

Return type

str

loader(format_name: str = None, **kwargs) ParameterGroup

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

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

  • format_name (str) – 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

ParameterGroup instance created from the file.

Return type

ParameterGroup

markdown(float_format: str = '.3e') glotaran.utils.ipython.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

pop(k[, d]) v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

property root_group: ParameterGroup | None

Root of the group.

Returns

The root group.

Return type

ParameterGroup

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

Update the ParameterGroup with values from a parameter history.

Parameters
set_from_label_and_value_arrays(labels: list[str], values: np.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.

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

to_csv(filename: str, delimiter: str = ',') None[source]

Save a ParameterGroup to a CSV file.

Warning

Deprecated use glotaran.io.save_parameters(parameters, file_name=<parameters.csv>, format_name="csv") instead.

Parameters
  • filename (str) – File to write the parameter specs to.

  • delimiter (str) – Character to separate columns., by default “,”

to_dataframe(as_optimized: bool = True) pandas.core.frame.DataFrame[source]

Create a pandas data frame from the group.

Parameters

as_optimized (bool) – Whether to include properties which are the result of optimization.

Returns

The created data frame.

Return type

pd.DataFrame

to_parameter_dict_list(as_optimized: bool = True) list[dict[str, Any]][source]

Create list of parameter dictionaries from the group.

Parameters

as_optimized (bool) – Whether to include properties which are the result of optimization.

Returns

Alist of parameter dictionaries.

Return type

list[dict[str, Any]]

update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

update_parameter_expression()[source]

Update all parameters which have an expression.

Raises

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

values() an object providing a view on D's values