Skip to content

Optimize a spectrum#

Spectral optimization starts from measured emitter data. Use the Rust CLI to capture a reproducible JSON snapshot, or read live emitter spectra through the Rust SDK and apply the resulting weights with manual mode.

Export spectral data#

enody download-spectral-data -o spectral-data.json

The export contains the host, fixture, source, emitter, and spectral sample data needed by offline Rust tools and tests.

Apply optimized weights#

This example shows the device-control side of an optimizer: read one source, set each emitter to a computed relative flux value, then display manual mode.

use enody::environment::Environment;
use enody::message::{Configuration, Flux};
use enody::usb::UsbEnvironment;

#[tokio::main]
async fn main() -> Result<(), enody::Error> {
    let env = UsbEnvironment::new();
    let runtime = env
        .runtimes()
        .into_iter()
        .next()
        .ok_or(enody::Error::InsufficientData)?;
    let host = runtime.host().await?;
    let fixture = host
        .fixtures()
        .await?
        .into_iter()
        .next()
        .ok_or(enody::Error::InsufficientData)?;
    let source = fixture
        .sources()
        .await?
        .into_iter()
        .next()
        .ok_or(enody::Error::InsufficientData)?;

    let emitters = source.emitters().await?;

    // Replace these with weights from your Rust optimizer.
    let weights = vec![0.35; emitters.len()];

    for (emitter, value) in emitters.iter().zip(weights) {
        emitter.set_flux(Flux::Relative(value)).await?;
    }

    fixture
        .display(Configuration::Manual, Flux::Relative(1.0))
        .await?;

    Ok(())
}

For target design and loss tuning, prefer working against spectral-data.json first. Once the optimizer produces stable emitter weights, apply those weights to EP01 with the same manual-mode flow.