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 experimental 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 |… | … | … | … | … | … |
Usage#
- Creating a simple table with the builder pattern:
>>> x = np.linspace(0, 10, 100) >>> spectra = np.array([...]) # shape: (n_samples, n_energies) >>> 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() ... )
- 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
Functions
|
Classes
Helper class to convert between spectroscopic data and Orange Tables. |