ewoksxas.converters.orange.Converter#

class ewoksxas.converters.orange.Converter[source]#

Bases: object

Helper class to convert between spectroscopic data and Orange Tables.

add_features(names, data, replace=False)[source]#

Add or update feature data (spectral x-axis and y-values).

Args:

names: 1D array of x-axis values (e.g., energy, wavenumber). data: 2D array of spectral intensities with shape (n_samples, n_features).

If 1D, treated as a single sample and reshaped to (1, n_features).

replace: If True, replaces existing features. If False (default), appends

rows to existing features (requires matching names).

Returns:

Self for method chaining.

Raises:
ValueError: If shape mismatch between names and data columns,

or if appending with mismatched names.

Parameters:
  • names (ndarray[tuple[int, ...], dtype[float64]])

  • data (ndarray[tuple[int, ...], dtype[float64]])

  • replace (bool)

Return type:

Converter

add_meta(name, data, var_type=None, **kwargs)[source]#

Add a metadata variable.

Args:

name: Name of the metadata variable. data: Array of values, one for each sample. var_type: Optional Orange Variable type (ContinuousVariable or

StringVariable). If None, inferred from data.

**kwargs: Additional arguments for the Variable constructor.

Returns:

Self for chaining.

Raises:

ValueError: If data length mismatch or incompatible data type.

Parameters:
  • name (str)

  • data (ndarray[tuple[int, ...], dtype[Any]])

  • var_type (type[Variable] | None)

  • kwargs (Any)

Return type:

Converter

add_target(name, data, var_type=None, **kwargs)[source]#

Add a target variable.

Targets can only be of ContinuousVariable or DiscreteVariable type.

Args:

name: Name of the target variable. data: Array of values, one for each sample. var_type: Optional Orange Variable type (ContinuousVariable or

DiscreteVariable). If None, inferred from data.

**kwargs: Additional arguments for the Variable constructor.

Returns:

Self for chaining.

Raises:
ValueError: If incompatible data type or too many unique values for

inference.

Parameters:
  • name (str)

  • data (ndarray[tuple[int, ...], dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]])

  • var_type (type[Variable] | None)

  • kwargs (Any)

Return type:

Converter

property features: tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]]]#

Get the feature names and data.

Returns:

A tuple containing feature names and feature data.

Raises:

ValueError: If no features have been set.

classmethod from_table(table)[source]#

Create a Converter instance from an existing Orange Table.

Extracts features, targets, and metadata from the table. Feature names are recovered from the table domain attributes.

Args:

table: The source Orange Table.

Returns:

A Converter instance containing data from the table.

Raises:

ValueError: If the table has no features.

Parameters:

table (Table)

Return type:

Converter

get_meta(name)[source]#
Parameters:

name (str)

Return type:

Any

property metas: list[dict[str, Any]]#

Get the list of metadata variable definitions.

Returns:

List of metadata variable definitions.

property targets: list[dict[str, Any]]#

Get the list of target variable definitions.

Returns:

List of target variable definitions.

to_table()[source]#

Construct and return the Orange Table.

The table will have: - features: spectral intensities as ContinuousVariables. - metas: metadata variables (e.g., motor positions, filenames). - attributes: feature names as ContinuousVariables.

Targets included if added via add_target, but typically not used in spectroscopic data.

Return type:

Table

Returns:

An Orange.data.Table object.