Skip to content

Python SDK

The Python SDK is designed for notebook users, labs, and module developers.

Capture From Serial

from luxspec import SerialLuxNode, analyze_frame

with SerialLuxNode("/dev/tty.usbmodem1101") as node:
    dark = node.capture("dark")
    white = node.capture("white")
    sample = node.capture("raw")

analysis = analyze_frame(sample, dark=dark, reference=white, mode="reflectance", module="plants")
print(analysis.metrics)

Parse a Saved Frame

from luxspec import LuxFrame

frame = LuxFrame.from_json(open("scan.json").read())
spectrum = frame.to_spectrum()

Analyze Minerals

from luxspec.processing import module_metrics

result = module_metrics(reflectance_spectrum, "minerals")
for match in result.matches:
    print(match.name, match.score)

CLI

luxspec inspect-frame scan.json
luxspec match-mineral reflectance-frame.json