DataProviderLinked

class glotaran.optimization.data_provider.DataProviderLinked(scheme: Scheme, dataset_group: DatasetGroup)[source]

Bases: DataProvider

A class to provide aligned data for optimization.

Initialize a linked data provider for a scheme and a dataset_group.

Parameters:
  • scheme (Scheme) – The optimization scheme.

  • dataset_group (DatasetGroup) – The dataset group.

Attributes Summary

aligned_global_axis

Get the aligned global axis for the dataset group.

group_definitions

Get the group definitions for the dataset group.

Methods Summary

add_model_weight

Add model weight to data.

align_data

Align the data in a dataset group.

align_dataset_indices

Align the global indices in a dataset group.

align_groups

Align the groups in a dataset group.

align_index

Align an index on a target axis.

align_weights

Align the weights in a dataset group.

create_aligned_global_axes

Create aligned global axes for the dataset group.

get_aligned_data

Get the aligned data for an index.

get_aligned_dataset_indices

Get the aligned dataset indices for an index.

get_aligned_group_label

Get the group label for an index.

get_aligned_weight

Get the aligned weight for an index.

get_axis_slice_from_interval

Get a slice of indices from a min max tuple and for an axis.

get_data

Get data for a dataset.

get_flattened_data

Get flattened data for a dataset.

get_flattened_weight

Get flattened weight for a dataset.

get_from_dataset

Get a copy of data from a dataset with dimensions (model, global).

get_global_axis

Get the global axis for a dataset.

get_global_dimension

Get the global dimension for a dataset.

get_model_axis

Get the model axis for a dataset.

get_model_dimension

Get the model dimension for a dataset.

get_weight

Get weight for a dataset.

infer_global_dimension

Infer the name of the global dimension from tuple of dimensions.

Methods Documentation

add_model_weight(model: Model, dataset_label: str, model_dimension: str, global_dimension: str)

Add model weight to data.

Parameters:
  • model (Model) – The model.

  • dataset_label (str) – The label of the data.

  • model_dimension (str) – The model dimension.

  • global_dimension (str) – The global dimension.

align_data(aligned_global_axes: dict[str, ArrayLike]) tuple[ArrayLike, list[ArrayLike]][source]

Align the data in a dataset group.

Parameters:

aligned_global_axes (dict[str, ArrayLike]) – The aligned global axes.

Returns:

The aligned global axis and data.

Return type:

tuple[ArrayLike, list[ArrayLike]]

align_dataset_indices(aligned_global_axes: dict[str, ArrayLike]) list[ArrayLike][source]

Align the global indices in a dataset group.

Parameters:

aligned_global_axes (dict[str, ArrayLike]) – The aligned global axes.

Returns:

  • list[ArrayLike]

  • The aligned dataset indices.

static align_groups(aligned_global_axes: dict[str, ArrayLike]) tuple[ArrayLike, dict[str, list[str]]][source]

Align the groups in a dataset group.

Parameters:

aligned_global_axes (dict[str, ArrayLike]) – The aligned global axes.

Returns:

The aligned grouplabels and group definitions.

Return type:

tuple[ArrayLike, dict[str, list[str]]]

static align_index(index: int, target_axis: ArrayLike, tolerance: float, method: Literal['nearest', 'backward', 'forward']) int[source]

Align an index on a target axis.

Parameters:
  • index (int) – The index to align.

  • target_axis (ArrayLike) – The axis to align the index on.

  • tolerance (float) – The alignment tolerance.

  • method (Literal["nearest", "backward", "forward"]) – The alignment method.

Returns:

The aligned index.

Return type:

int

align_weights(aligned_global_axes: dict[str, ArrayLike]) list[ArrayLike | None][source]

Align the weights in a dataset group.

Parameters:

aligned_global_axes (dict[str, ArrayLike]) – The aligned global axes.

Returns:

The aligned weights.

Return type:

list[ArrayLike | None]

property aligned_global_axis: ArrayLike

Get the aligned global axis for the dataset group.

Returns:

The aligned global axis.

Return type:

ArrayLike

create_aligned_global_axes(scheme: Scheme) dict[str, ArrayLike][source]

Create aligned global axes for the dataset group.

Parameters:

scheme (Scheme) – The optimization scheme.

Returns:

The aligned global axes.

Return type:

dict[str, ArrayLike]

Raises:

AlignDatasetError – Raised when dataset alignment is ambiguous.

get_aligned_data(index: int) ArrayLike[source]

Get the aligned data for an index.

Parameters:

index (int) – The index on the aligned global axis.

Returns:

The aligned data.

Return type:

ArrayLike

get_aligned_dataset_indices(index: int) ArrayLike[source]

Get the aligned dataset indices for an index.

Parameters:

index (int) – The index on the aligned global axis.

Returns:

The aligned dataset indices.

Return type:

ArrayLike

get_aligned_group_label(index: int) str[source]

Get the group label for an index.

Parameters:

index (int) – The index on the aligned global axis.

Returns:

The aligned group label.

Return type:

str

get_aligned_weight(index: int) ArrayLike | None[source]

Get the aligned weight for an index.

Parameters:

index (int) – The index on the aligned global axis.

Returns:

The aligned weight.

Return type:

ArrayLike | None

static get_axis_slice_from_interval(interval: tuple[float, float], axis: ArrayLike) slice

Get a slice of indices from a min max tuple and for an axis.

Parameters:
  • interval (tuple[float, float]) – The min max tuple.

  • axis (ArrayLike) – The axis to slice.

Returns:

The slice of indices.

Return type:

slice

get_data(dataset_label: str) ArrayLike

Get data for a dataset.

Parameters:

dataset_label (str) – The label of the data.

Returns:

The data.

Return type:

ArrayLike

get_flattened_data(dataset_label: str) ArrayLike

Get flattened data for a dataset.

Parameters:

dataset_label (str) – The label of the data.

Returns:

The flattened data.

Return type:

ArrayLike

get_flattened_weight(dataset_label: str) ArrayLike | None

Get flattened weight for a dataset.

Parameters:

dataset_label (str) – The label of the data.

Returns:

The flattened weight.

Return type:

ArrayLike | None

static get_from_dataset(dataset: xr.Dataset, name: str, model_dimension: str, global_dimension: str) ArrayLike | None

Get a copy of data from a dataset with dimensions (model, global).

Parameters:
  • dataset (xr.Dataset) – The dataset to retrieve from.

  • name (str) – The name of the data to retrieve.

  • model_dimension (str) – The model dimension.

  • global_dimension (str) – The global dimension.

Returns:

The copy of the data. None if name is not present in dataset.

Return type:

ArrayLike | None

get_global_axis(dataset_label: str) ArrayLike

Get the global axis for a dataset.

Parameters:

dataset_label (str) – The label of the data.

Returns:

The global axis.

Return type:

ArrayLike

get_global_dimension(dataset_label: str) str

Get the global dimension for a dataset.

Parameters:

dataset_label (str) – The label of the data.

Returns:

The global dimension.

Return type:

str

get_model_axis(dataset_label: str) ArrayLike

Get the model axis for a dataset.

Parameters:

dataset_label (str) – The label of the data.

Returns:

The model axis.

Return type:

ArrayLike

get_model_dimension(dataset_label: str) str

Get the model dimension for a dataset.

Parameters:

dataset_label (str) – The label of the data.

Returns:

The model dimension.

Return type:

str

get_weight(dataset_label: str) ArrayLike | None

Get weight for a dataset.

Parameters:

dataset_label (str) – The label of the data.

Returns:

The weight.

Return type:

ArrayLike | None

property group_definitions: dict[str, list[str]]

Get the group definitions for the dataset group.

Returns:

The group definitions.

Return type:

dict[str, list[str]]

static infer_global_dimension(model_dimension: str, dimensions: tuple[str]) str

Infer the name of the global dimension from tuple of dimensions.

Parameters:
  • model_dimension (str) – The model dimension.

  • dimensions (tuple[str]) – The dimensions tuple to infer from.

Returns:

The inferred name of the global dimension.

Return type:

str