ewoksxas.converters.orange#

Utilities for working with Orange Tables for spectroscopic data.

This module provides classes to convert between Orange Tables and spectroscopic data representations. While using Orange Tables for this purpose is not ideal, it allows reusing existing Orange components for data manipulation and analysis.

Data Representation#

The names used in the module are inherited from machine learning terminology: - features: Variables that describe the data (x-axis: e.g., energy or wavenumber). - targets: The desired predictions, typically not required for spectroscopy. - metas: Additional variables that provide extra information about the data, but

are not used for prediction (e.g., motor positions).

For spectroscopic data: - The x-axis values (e.g., energy) are represented as feature names. - The intensity values are stored in the feature data, the bulk of the table. - Metas can store experiment-related information like motor positions.

Example Table Structure#

location | motor_1 | energy_1 | energy_2 | … | energy_n |
——– | ——- | ——— | ——— | ——— | ——— |
(meta) | (meta) | (feature) | (feature) | (feature) | (feature) |
root | 12.65 | 1.2 | 0.5 | … | 0.4 |
leaf | 15.34 | 0.8 | 1.1 | … | 1.6 |
stem | 11.07 | 2.0 | 0.3 | … | 2.8 |
leaf | 12.13 | 1.5 | 0.7 | … | 3.1 |
… | … | … | … | … | … |

Variable types#

Each meta or target is materialized as an Orange Variable: - ContinuousVariable for numeric data. - DiscreteVariable for categorical data (a small set of repeated labels). - StringVariable for free-form text (metas only).

When var_type is not given it is inferred from the data: numeric data becomes continuous; non-numeric data with at most MAX_DISCRETE_VALUES unique values becomes discrete (so it can be used directly by Orange widgets that group by category); otherwise it falls back to a string for metas, and raises for targets (which cannot be strings).

Usage#

Creating a simple table with the builder pattern:
>>> x = np.linspace(0, 10, 100)
>>> spectra = np.array([...])  # shape: (n_rows, n_features)
>>> table = Converter().add_features(x, spectra).to_table()
Adding metadata and targets:
>>> areas = np.trapezoid(spectra, x)
>>> table = (
...     Converter()
...     .add_features(x, spectra)
...     .add_meta("Area", areas)
...     .add_meta("Location", locations)
...     .add_target("Quality", predictions)
...     .to_table()
... )
Deriving a task output (new spectra, metadata carried over):
>>> input_converter = Converter.from_table(table)
>>> x, y = input_converter.features
>>> table = (
...     input_converter.with_features(x, y * 2)
...     .add_meta("e0", e0_values)
...     .to_table()
... )
With custom variable types:
>>> table = (
...     Converter()
...     .add_features(x, spectra)
...     .add_meta("Location", locations, var_type=StringVariable)
...     .add_target("Quality", predictions, var_type=ContinuousVariable)
...     .to_table()
... )
Round-trip conversion:
>>> table = (
...     Converter()
...     .add_features(x, spectra)
...     .add_meta("Area", areas)
...     .to_table()
... )
>>> converter = Converter.from_table(table)
>>> feature_names, spectra = converter.features
>>> metas = converter.metas

Classes

Column(*, name, data, var_type[, values, ...])

A single named meta/target column together with its Orange variable type.

Converter()

Helper class to convert between spectroscopic data and Orange Tables.

Features(names, data[, attributes])

The spectral feature block: x-axis names and the 2D intensity matrix.

Role(*values)

Enum for table roles with permitted variable types as values.

VarType(*values)

Structuring variables as observed within the Orange Canvas.