### seabreeze_os_setup - OS-Level Driver and udev Setup Source: https://context7.com/ap--/python-seabreeze/llms.txt A command-line tool to install necessary OS-level drivers and udev rules for Ocean Optics spectrometers. ```APIDOC ## seabreeze_os_setup - OS-Level Driver and udev Setup ### Description Command-line tool that installs udev rules on Linux or downloads/installs USB drivers on Windows so that Ocean Optics spectrometers are accessible from user space. ### Usage ```bash # Run after installation on any platform seabreeze_os_setup # On Linux this installs /etc/udev/rules.d/10-oceanoptics.rules # On Windows this downloads and installs the WinUSB/libusb drivers # On macOS no extra steps are required ``` ``` -------------------------------- ### Run OS-Level Driver Setup Source: https://context7.com/ap--/python-seabreeze/llms.txt This command-line tool is used to install necessary udev rules on Linux or download and install USB drivers on Windows, enabling Ocean Optics spectrometers to be accessed from user space. No extra steps are required on macOS. ```bash # Run after installation on any platform seabreeze_os_setup # On Linux this installs /etc/udev/rules.d/10-oceanoptics.rules # On Windows this downloads and installs the WinUSB/libusb drivers # On macOS no extra steps are required ``` -------------------------------- ### Install python-seabreeze Source: https://context7.com/ap--/python-seabreeze/llms.txt Install the library using pip or conda. Run the OS setup tool to configure necessary drivers or rules. The `pyseabreeze` extra ensures `pyusb` is installed. ```bash pip install seabreeze seabreeze_os_setup ``` ```bash conda install -c conda-forge seabreeze seabreeze_os_setup ``` ```bash pip install seabreeze[pyseabreeze] ``` -------------------------------- ### Install Seabreeze via Pip Source: https://github.com/ap--/python-seabreeze/blob/main/README.md Install the seabreeze library using pip. Run `seabreeze_os_setup` after installation to configure operating system specific settings. ```bash pip install seabreeze seabreeze_os_setup ``` -------------------------------- ### Run OS-Specific Setup for Python-Seabreeze Source: https://github.com/ap--/python-seabreeze/blob/main/os_support/readme.md Execute this command after installing python-seabreeze to automatically download and install necessary OS-specific files and configurations. You may need to unplug and replug your USB spectrometer after running this command. ```bash seabreeze_os_setup ``` -------------------------------- ### Install Seabreeze Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/tldr.md Install the seabreeze library using pip. Ensure you have the necessary build tools for binary extensions. ```bash pip install seabreeze ``` -------------------------------- ### Run Seabreeze OS Setup Script Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/troubleshoot.md Ensure the necessary operating system configurations are in place by running the seabreeze_os_setup script. ```bash # please run the script seabreeze_os_setup ``` -------------------------------- ### Install build tools on Windows Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/install.md Install Visual C++ build tools, Windows SDK, and Windows Driver Kit using Chocolatey for building seabreeze on Windows. ```bat REM assuming you already have chocolatey installed choco install visualcpp-build-tools choco install windows-sdk-10.1 choco install windowsdriverkit10 ``` -------------------------------- ### Install Seabreeze with Pyseabreeze Backend Source: https://github.com/ap--/python-seabreeze/blob/main/README.md Install the seabreeze library with the pyseabreeze backend, which ensures pyusb is installed. Manual installation of libusb1 may be required on Windows. ```bash pip install seabreeze[pyseabreeze] # this ensures installation of pyusb ``` -------------------------------- ### Clone and install seabreeze from source Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/install.md Clone the seabreeze repository and install it using pip. This method is used after preparing the environment and dependencies. ```bash git clone https://github.com/ap--/python-seabreeze.git python-seabreeze cd python-seabreeze python -m pip install . ``` -------------------------------- ### Install build dependencies on RPM-based systems Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/install.md Install git, compiler, make, and libusb development headers required for building seabreeze on RPM-based systems. ```bash # if your distro is a rpm flavor sudo yum install git-all gcc gcc-c++ make libusb-devel ``` -------------------------------- ### Install Dependencies and Run Tests Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/contributing.md Installs necessary testing packages and executes the project's tests using pytest. This is a common first step for contributors to verify compatibility and identify issues. ```bash pip install 'pytest-runner' 'pytest<5' python setup.py pytest ``` -------------------------------- ### Install build dependencies on Debian/Ubuntu Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/install.md Install git, build tools, and libusb development headers required for building seabreeze on Debian-based systems. ```bash # run the appropriate command for your distribution flavor # if your distro is a deb flavor (ubuntu, etc...) sudo apt-get install git-all build-essential libusb-dev ``` -------------------------------- ### Install seabreeze with pip Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/install.md Install seabreeze with pip, optionally including the pyseabreeze backend. Use the --no-use-pep517 and --no-build-isolation flags for specific pyseabreeze installations. ```bash # install only cseabreeze backend pip install seabreeze ``` ```bash # install both cseabreeze and pyseabreeze backend pip install seabreeze[pyseabreeze] ``` ```bash # install only pyseabreeze backend pip install seabreeze[pyseabreeze] --no-use-pep517 --no-build-isolation --install-option="--without-cseabreeze" ``` -------------------------------- ### Install build dependencies on Arch Linux Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/install.md Install base development tools, libusb, and make required for building seabreeze on Arch Linux. ```bash # if your distro is an arch flavor sudo pacman -S base-devel libusb libusb-compat libusb-devel make gcc ``` -------------------------------- ### Install seabreeze with conda Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/install.md Install seabreeze from the conda-forge channel. This is the recommended method for conda environments. ```bash # install via conda conda install -c conda-forge seabreeze ``` -------------------------------- ### Acquire Spectrum with Spectrometer Class Source: https://github.com/ap--/python-seabreeze/blob/main/README.md Example of acquiring a spectrum using the model-independent Spectrometer class. This involves initializing the spectrometer, setting integration time, and retrieving wavelengths and intensities. ```python >>> from seabreeze.spectrometers import Spectrometer >>> spec = Spectrometer.from_first_available() >>> spec.integration_time_micros(20000) >>> spec.wavelengths() array([ 340.32581 , 340.70321186, 341.08058305, ..., 1024.84940994, 1025.1300678 , 1025.4106617 ]) >>> spec.intensities() array([ 1.58187931e+01, 2.66704852e+04, 6.80208103e+02, ..., 6.53090172e+02, 6.35011552e+02, 6.71168793e+02]) ``` -------------------------------- ### Upgrade pip Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/install.md Ensure the latest version of pip is installed before proceeding with the installation of seabreeze. ```bash python -m pip install --upgrade pip ``` -------------------------------- ### Access and Read Spectrometer Data Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/tldr.md Import the seabreeze spectrometer module, initialize a spectrometer instance, set integration time, and retrieve wavelengths and intensities. This example assumes a spectrometer is available and can be accessed by default. ```python import seabreeze.spectrometers as sb spec = sb.Spectrometer.from_serial_number() spec.integration_time_micros(20000) spec.wavelengths() array([ 340.32581 , 340.70321186, 341.08058305, ..., 1024.84940994, 1025.1300678 , 1025.4106617 ]) spec.intensities() array([ 1.58187931e+01, 2.66704852e+04, 6.80208103e+02, ..., 6.53090172e+02, 6.35011552e+02, 6.71168793e+02]) ``` -------------------------------- ### Install seabreeze on Raspberry Pi Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/install.md Install seabreeze on a Raspberry Pi using the piwheels package repository. Ensure piwheels is added as an extra index to pip. ```bash pip3 install seabreeze ``` -------------------------------- ### Spectrometer.open() / Spectrometer.close() Source: https://context7.com/ap--/python-seabreeze/llms.txt Manually open or close the USB connection to the spectrometer. Under normal use these are called automatically; they are exposed for advanced scenarios such as multi-process setups. ```APIDOC ## `Spectrometer.open()` / `Spectrometer.close()` — Manage Device Connection Manually open or close the USB connection to the spectrometer. Under normal use these are called automatically; they are exposed for advanced scenarios such as multi-process setups. ### Methods `open(self)` `close(self)` ``` -------------------------------- ### Get Spectrometer Wavelengths and Intensities Together Source: https://context7.com/ap--/python-seabreeze/llms.txt Convenience method that returns a 2×N NumPy array stacking wavelengths and intensities. Accepts the same correction flags as `intensities()`. ```python from seabreeze.spectrometers import Spectrometer import numpy as np spec = Spectrometer.from_first_available() spec.integration_time_micros(50_000) wl, intensity = spec.spectrum() print(f"Shape: {spec.spectrum().shape}") # Shape: (2, 2048) # Unpack directly wavelengths, intensities = spec.spectrum(correct_dark_counts=True) peak_idx = np.argmax(intensities) print(f"Peak at {wavelengths[peak_idx]:.2f} nm with intensity {intensities[peak_idx]:.1f}") ``` -------------------------------- ### Pytest Test Session Output Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/contributing.md Example output from a pytest session, showing collected tests, their status (PASSED/FAILED), and platform information. Useful for understanding test execution and identifying failures. ```text ========================================== test session starts ========================================== platform linux2 -- Python 2.7.15+, pytest-4.6.5, py-1.8.0, pluggy-0.12.0 -- /python cachedir: .pytest_cache rootdir: /home/poehlmann/Development/python-seabreeze, inifile: pytest.ini collected 23 items tests/test_backends.py::test_backend_features_interface PASSED [ 4%] tests/test_backends.py::test_cseabreeze_seabreezeapi PASSED [ 8%] tests/test_backends.py::test_pyseabreeze_seabreezeapi PASSED [ 13%] tests/test_spectrometers.py::test_read_model[cseabreeze:SPARK:00061] PASSED [ 17%] tests/test_spectrometers.py::test_read_model[pyseabreeze:SPARK:00061] PASSED [ 21%] tests/test_spectrometers.py::test_read_serial_number[cseabreeze:SPARK:00061] PASSED [ 26%] tests/test_spectrometers.py::test_read_serial_number[pyseabreeze:SPARK:00061] PASSED [ 30%] tests/test_spectrometers.py::test_read_intensities[cseabreeze:SPARK:00061] PASSED [ 34%] tests/test_spectrometers.py::test_read_intensities[pyseabreeze:SPARK:00061] PASSED [ 39%] tests/test_spectrometers.py::test_read_wavelengths[cseabreeze:SPARK:00061] PASSED [ 43%] tests/test_spectrometers.py::test_read_wavelengths[pyseabreeze:SPARK:00061] PASSED [ 47%] tests/test_spectrometers.py::test_read_spectrum[cseabreeze:SPARK:00061] PASSED [ 52%] tests/test_spectrometers.py::test_read_spectrum[pyseabreeze:SPARK:00061] PASSED [ 56%] tests/test_spectrometers.py::test_max_intensity[cseabreeze:SPARK:00061] PASSED [ 60%] tests/test_spectrometers.py::test_max_intensity[pyseabreeze:SPARK:00061] PASSED [ 65%] tests/test_spectrometers.py::test_integration_time_limits[cseabreeze:SPARK:00061] PASSED [ 69%] tests/test_spectrometers.py::test_integration_time_limits[pyseabreeze:SPARK:00061] PASSED [ 73%] tests/test_spectrometers.py::test_integration_time[cseabreeze:SPARK:00061] PASSED [ 78%] tests/test_spectrometers.py::test_integration_time[pyseabreeze:SPARK:00061] PASSED [ 82%] tests/test_spectrometers.py::test_trigger_mode[cseabreeze:SPARK:00061] PASSED [ 86%] tests/test_spectrometers.py::test_trigger_mode[pyseabreeze:SPARK:00061] FAILED [ 91%] tests/test_spectrometers.py::test_cant_find_serial[cseabreeze] PASSED [ 95%] tests/test_spectrometers.py::test_cant_find_serial[pyseabreeze] PASSED [100%] =============================================== FAILURES ================================================ ______________________________ test_trigger_mode[pyseabreeze:SPARK:00061] _______________________________ backendlified_serial = '00061' def test_trigger_mode(backendlified_serial): devices = list(list_devices()) if len(devices) == 0: pytest.skip("no supported device connected") exc = Spectrometer._backend.SeaBreezeError spec = Spectrometer.from_serial_number(backendlified_serial) with pytest.raises(exc): spec.trigger_mode(0xF0) # <- should be unsupported for all specs > spec.trigger_mode(0x00) # <- normal mode tests/test_spectrometers.py:177: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ src/seabreeze/spectrometers.py:269: in trigger_mode self._dev.f.spectrometer.set_trigger_mode(mode) src/seabreeze/pyseabreeze/features/spectrometer.py:298: in set_trigger_mode self.protocol.send(0x00110110, mode) src/seabreeze/pyseabreeze/protocol.py:256: in send remaining_bytes, checksum_type = self._check_incoming_message_header(response[:44]) ``` -------------------------------- ### Get Spectrometer Wavelength Array Source: https://context7.com/ap--/python-seabreeze/llms.txt Returns a cached NumPy array of wavelengths in nanometers. Wavelengths are read once on device open. ```python from seabreeze.spectrometers import Spectrometer spec = Spectrometer.from_first_available() wl = spec.wavelengths() print(wl) # array([356.70501709, 357.06904128, 357.43303326, ..., 711.60684758, # 711.93799556, 712.26911135]) print(f"Pixels: {len(wl)}, Range: {wl[0]:.1f} – {wl[-1]:.1f} nm") # Pixels: 2048, Range: 356.7 – 712.3 nm ``` -------------------------------- ### Check Incoming Message Header Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/contributing.md Validates the header of an incoming OBP message. Raises SeaBreezeError for incorrect length, start bytes, protocol version, or specific flags indicating errors. ```python def _check_incoming_message_header(self, header): """check the incoming message header Parameters ---------- header : `str` a obp header of length 44 Returns ------- bytes_and_checksum_type : tuple[`int`, `int`] bytes_remaining after the header (returns 20 for a 64 byte message) checksum_type only supports self.OBP.CHECKSUM_TYPE_MD5 for now """ if len(header) != 44: raise SeaBreezeError("header has wrong length! len(header): %d" % len(header)) data = struct.unpack(self.OBP.HEADER_FMT, header) if data[0] != self.OBP.HEADER_START_BYTES: raise SeaBreezeError('Header start_bytes wrong: "%d"' % data[0]) if data[1] != self.OBP.HEADER_PROTOCOL_VERSION: raise SeaBreezeError('Header protocol version wrong: %d' % data[1]) flags = data[2] if flags == 0: pass if flags & self.OBP.FLAG_RESPONSE_TO_REQUEST: pass # TODO: propagate? if flags & self.OBP.FLAG_ACK: pass # TODO: propagate? if flags & self.OBP.FLAG_REQUEST_ACK: pass # TODO: only the host should be able to set this? if (flags & self.OBP.FLAG_NACK) or (flags & self.OBP.FLAG_HW_EXCEPTION): error = data[3] if error != 0: # != SUCCESS raise SeaBreezeError(self.OBP.ERROR_CODES[error]) ``` -------------------------------- ### Initialize and Use SeaBreezeAPI Source: https://context7.com/ap--/python-seabreeze/llms.txt This snippet shows how to initialize the SeaBreezeAPI, list connected devices, and access supported models. It also demonstrates how to manually register an Ethernet-connected device and shut down the API to release resources. ```python import seabreeze seabreeze.use("pyseabreeze") from seabreeze.pyseabreeze.api import SeaBreezeAPI api = SeaBreezeAPI() # List all connected devices devices = api.list_devices() print(devices) # [] # List models supported by this backend models = SeaBreezeAPI.supported_models() print(models[:5]) # ['ADC1000USB', 'FLAME-NIR', 'FLAME-S', 'FLAMEX', 'HDX'] # Register an Ethernet-connected device manually api.add_ipv4_device_location("HDX", ip_address="192.168.1.50", port=57357) eth_devices = api.list_devices() # Shutdown (release USB resources) api.shutdown() ``` -------------------------------- ### Open First Available Spectrometer with Spectrometer.from_first_available() Source: https://context7.com/ap--/python-seabreeze/llms.txt Opens the first connected spectrometer that is not already in use. Raises `SeaBreezeError` if no unopened device is found. Provides access to device model, serial number, and pixel count. ```python from seabreeze.spectrometers import Spectrometer try: spec = Spectrometer.from_first_available() print(spec) # print(f"Model: {spec.model}, Serial: {spec.serial_number}, Pixels: {spec.pixels}") # Model: USB2000PLUS, Serial: USB2+F01234, Pixels: 2048 except Exception as e: print(f"No spectrometer found: {e}") ``` -------------------------------- ### Select Backend with seabreeze.use() Source: https://context7.com/ap--/python-seabreeze/llms.txt Choose the backend (`cseabreeze` or `pyseabreeze`) before importing `seabreeze.spectrometers`. Supports additional kwargs for `pyseabreeze` like `pyusb_backend` and `network_adapter`. ```python import seabreeze # Use the default C-library backend (cseabreeze) seabreeze.use("cseabreeze") ``` ```python # Use the pure-Python backend seabreeze.use("pyseabreeze") ``` ```python # Use pyseabreeze with a specific pyusb backend seabreeze.use("pyseabreeze", pyusb_backend="libusb1") ``` ```python # Use pyseabreeze for Ethernet-connected spectrometers seabreeze.use("pyseabreeze", network_adapter="192.168.254.200") from seabreeze.spectrometers import list_devices, Spectrometer ``` -------------------------------- ### Test Spectrometer with Original Software Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/troubleshoot.md Confirm the spectrometer is functioning correctly by testing it with the original software provided by OceanOptics. ```bash # Test your spectrometer with the original software provided by OceanOptics ``` -------------------------------- ### Select Backend Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/quickstart.md Choose a backend for seabreeze. Defaults to cseabreeze if not specified. ```python >>> import seabreeze >>> seabreeze.use('cseabreeze') >>> from seabreeze.spectrometers import list_devices, Spectrometer ``` ```python >>> import seabreeze >>> seabreeze.use('pyseabreeze') >>> from seabreeze.spectrometers import list_devices, Spectrometer ``` -------------------------------- ### Enumerate Connected Spectrometers with list_devices() Source: https://context7.com/ap--/python-seabreeze/llms.txt Returns a list of all connected and supported `SeaBreezeDevice` instances. Each device object provides attributes like `serial_number`, `model`, `is_open`, `features`, and `f`. ```python from seabreeze.spectrometers import list_devices devices = list_devices() print(devices) # [, ] for dev in devices: print(f"Model: {dev.model}, Serial: {dev.serial_number}, Open: {dev.is_open}") # Model: USB2000PLUS, Serial: USB2+F01234, Open: False # Model: SPARK, Serial: 00001, Open: False ``` -------------------------------- ### Select Pyseabreeze Backend Source: https://github.com/ap--/python-seabreeze/blob/main/README.md To use the pyseabreeze backend, import the seabreeze library and explicitly call `seabreeze.use('pyseabreeze')` before importing `seabreeze.spectrometers`. ```python >>> import seabreeze >>> seabreeze.use('pyseabreeze') >>> import seabreeze.spectrometers as sb ``` -------------------------------- ### Open Spectrometer from SeaBreezeDevice instance Source: https://context7.com/ap--/python-seabreeze/llms.txt Constructs a `Spectrometer` object by wrapping a `SeaBreezeDevice` instance obtained from `list_devices()`. This process automatically opens the device, caches wavelengths, and detects correction support. ```python from seabreeze.spectrometers import list_devices, Spectrometer devices = list_devices() # Pick a specific device from the list spec = Spectrometer(devices[1]) print(spec) # ``` -------------------------------- ### Spectrometer.from_first_available() — Open First Available Spectrometer Source: https://context7.com/ap--/python-seabreeze/llms.txt A class method that opens the first connected spectrometer that is not currently in use. If no unopened devices are found, it raises a `SeaBreezeError`. ```APIDOC ## Spectrometer.from_first_available() ### Description Class method that opens the first available (not yet opened) connected spectrometer. Raises `SeaBreezeError` if no unopened device is found. ### Usage ```python from seabreeze.spectrometers import Spectrometer try: spec = Spectrometer.from_first_available() print(spec) # print(f"Model: {spec.model}, Serial: {spec.serial_number}, Pixels: {spec.pixels}") # Model: USB2000PLUS, Serial: USB2+F01234, Pixels: 2048 except Exception as e: print(f"No spectrometer found: {e}") ``` ``` -------------------------------- ### Open Spectrometer Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/quickstart.md Open a spectrometer using one of the provided methods. Ensure the device is connected. ```python # option 1 >>> from seabreeze.spectrometers import Spectrometer >>> spec = Spectrometer.from_first_available() >>> spec ``` ```python # option 2 >>> from seabreeze.spectrometers import Spectrometer, list_devices >>> devices = list_devices() >>> devices [, ] >>> spec = Spectrometer(devices[1]) >>> spec ``` ```python # option 3 >>> from seabreeze.spectrometers import Spectrometer >>> spec = Spectrometer.from_serial_number("F01234") >>> spec ``` -------------------------------- ### Spectrometer(device) — Open Spectrometer from SeaBreezeDevice Source: https://context7.com/ap--/python-seabreeze/llms.txt The constructor for the `Spectrometer` class, which takes a `SeaBreezeDevice` instance as an argument. Upon instantiation, the device is opened, its wavelengths are cached, and support for nonlinearity and dark-pixel correction is determined. ```APIDOC ## Spectrometer(device) ### Description Constructor that wraps a `SeaBreezeDevice` instance returned by `list_devices()`. On construction, the device is opened, wavelengths are cached, and nonlinearity/dark-pixel correction support is detected. ### Usage ```python from seabreeze.spectrometers import list_devices, Spectrometer devices = list_devices() # Pick a specific device from the list spec = Spectrometer(devices[1]) print(spec) # ``` ``` -------------------------------- ### list_devices() — Enumerate Connected Spectrometers Source: https://context7.com/ap--/python-seabreeze/llms.txt Retrieves a list of all connected and supported `SeaBreezeDevice` instances. Each device object in the returned list contains attributes such as `serial_number`, `model`, `is_open`, `features`, and `f`. ```APIDOC ## list_devices() ### Description Returns a list of all connected and supported `SeaBreezeDevice` instances. Each device exposes `serial_number`, `model`, `is_open`, `features`, and `f` attributes. ### Usage ```python from seabreeze.spectrometers import list_devices devices = list_devices() print(devices) # [, ] for dev in devices: print(f"Model: {dev.model}, Serial: {dev.serial_number}, Open: {dev.is_open}") # Model: USB2000PLUS, Serial: USB2+F01234, Open: False # Model: SPARK, Serial: 00001, Open: False ``` ``` -------------------------------- ### list_devices Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/api.md Provides a list of available instances of SeaBreezeDevice. ```APIDOC ## list_devices ### Description Provides a list of available instances of SeaBreezeDevice. ### Method Not specified (assumed to be a function call within the SDK) ### Endpoint Not applicable (SDK function) ### Parameters None specified ### Request Example ```python import seabreeze.spectrometers as [] spectrometers = seabreeze.spectrometers.list_devices() ``` ### Response #### Success Response - **spectrometers** (list) - A list of available spectrometer devices. ``` -------------------------------- ### Accessing Spectrometer Features Source: https://context7.com/ap--/python-seabreeze/llms.txt This code demonstrates how to access various hardware features of a spectrometer if they are supported. It includes reading temperature, controlling the thermo-electric cooler, accessing irradiance calibration, configuring spectrum processing, and performing raw USB communication. ```python if spec.features["temperature"]: temps = spec.f.temperature.temperature_get_all() print(f"Temperatures: {temps}") ``` ```python if spec.features["thermo_electric"]: spec.f.thermo_electric.set_temperature_setpoint_degrees_celsius(-10.0) spec.f.thermo_electric.enable_tec(True) current_temp = spec.f.thermo_electric.read_temperature_degrees_celsius() print(f"TEC temperature: {current_temp:.2f} °C") ``` ```python if spec.features["irrad_cal"]: cal = spec.f.irrad_cal.read_calibration() print(f"Calibration array shape: {cal.shape}") ``` ```python if spec.features["spectrum_processing"]: spec.f.spectrum_processing.set_boxcar_width(3) spec.f.spectrum_processing.set_scans_to_average(5) ``` ```python if spec.features["raw_usb_bus_access"]: spec.f.raw_usb_bus_access.raw_usb_write(b"\x00", endpoint="primary_out") raw_bytes = spec.f.raw_usb_bus_access.raw_usb_read(endpoint="primary_in", buffer_length=64) print(f"Raw USB response: {raw_bytes.hex()}") ``` -------------------------------- ### Check Spectrometer Model Support Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/troubleshoot.md Verify if your spectrometer model is supported by the chosen seabreeze backend (cseabreeze or pyseabreeze). ```python # check that it's supported >>> import seabreeze.cseabreeze as csb >>> api = csb.SeaBreezeAPI() >>> api.supported_models() [u'FlameNIR', ..., u'Ventana'] >>> import seabreeze.pyseabreeze as psb >>> api = psb.SeaBreezeAPI() >>> api.supported_models() [u'Apex', ..., u'Ventana'] ``` -------------------------------- ### seabreeze.use() — Select Backend Source: https://context7.com/ap--/python-seabreeze/llms.txt Selects the backend (`cseabreeze` or `pyseabreeze`) to be used for spectrometer communication. This function must be called before any spectrometer is instantiated. It also supports additional keyword arguments for the `pyseabreeze` backend, such as `pyusb_backend` and `network_adapter`. ```APIDOC ## seabreeze.use() ### Description Select which backend (`cseabreeze` or `pyseabreeze`) to use before importing `seabreeze.spectrometers`. Must be called before any spectrometer is instantiated. Supports additional kwargs for pyseabreeze: `pyusb_backend` and `network_adapter`. ### Usage ```python import seabreeze # Use the default C-library backend (cseabreeze) seabreeze.use("cseabreeze") # Use the pure-Python backend seabreeze.use("pyseabreeze") # Use pyseabreeze with a specific pyusb backend seabreeze.use("pyseabreeze", pyusb_backend="libusb1") # Use pyseabreeze for Ethernet-connected spectrometers seabreeze.use("pyseabreeze", network_adapter="192.168.254.200") from seabreeze.spectrometers import list_devices, Spectrometer ``` ``` -------------------------------- ### Acquire Spectrum Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/quickstart.md Acquire wavelengths and intensities from an opened spectrometer after setting the integration time. ```python >>> spec = Spectrometer.from_serial_number("F01234") # set integration time >>> spec.integration_time_micros(100000) # 0.1 seconds # get wavelengths >>> wavelengths = spec.wavelengths() >>> wavelengths array([356.70501709, 357.06904128, 357.43303326, ..., 711.60684758, 711.93799556, 712.26911135]) # get intensities >>> intensities = spec.intensities() >>> intensities array([1485., 1493., 1487., ..., 1496., 1497., 1493.]) ``` -------------------------------- ### Open Spectrometer by Serial Number with Spectrometer.from_serial_number() Source: https://context7.com/ap--/python-seabreeze/llms.txt Opens a specific spectrometer using its serial number. If `serial=None`, it defaults to opening the first available device. This method also supports opening Ethernet spectrometers when `pyseabreeze` is configured with a `network_adapter`. ```python from seabreeze.spectrometers import Spectrometer # Open by serial number spec = Spectrometer.from_serial_number("USB2+F01234") print(spec) # ``` ```python # Pass None to open first available spec2 = Spectrometer.from_serial_number(serial=None) ``` ```python # Ethernet spectrometer (requires pyseabreeze + network_adapter set) import seabreeze seabreeze.use("pyseabreeze", network_adapter="192.168.254.200") from seabreeze.spectrometers import Spectrometer spec3 = Spectrometer.from_serial_number("HDX12345") ``` -------------------------------- ### SeaBreezeAPI - Low-Level Backend API Source: https://context7.com/ap--/python-seabreeze/llms.txt The SeaBreezeAPI class provides direct access to device enumeration and location registration. It is available in both cseabreeze and pyseabreeze backends. ```APIDOC ## SeaBreezeAPI - Low-Level Backend API ### Description The `SeaBreezeAPI` class (available in both `cseabreeze` and `pyseabreeze` backends) provides direct access to device enumeration and location registration. Access it through the backend module directly for advanced use. ### Usage ```python import seabreeze seabreeze.use("pyseabreeze") from seabreeze.pyseabreeze.api import SeaBreezeAPI api = SeaBreezeAPI() # List all connected devices devices = api.list_devices() print(devices) # List models supported by this backend models = SeaBreezeAPI.supported_models() print(models[:5]) # Register an Ethernet-connected device manually api.add_ipv4_device_location("HDX", ip_address="192.168.1.50", port=57357) eth_devices = api.list_devices() # Shutdown (release USB resources) api.shutdown() ``` ### Methods #### `list_devices()` Lists all connected spectrometer devices. #### `supported_models()` Returns a list of spectrometer models supported by the current backend. #### `add_ipv4_device_location(model_name, ip_address, port)` Manually registers an Ethernet-connected device. - **model_name** (str) - The model name of the spectrometer. - **ip_address** (str) - The IP address of the spectrometer. - **port** (int) - The network port of the spectrometer. #### `shutdown()` Releases all USB resources and shuts down the API. ``` -------------------------------- ### Add New Spectrometer Device Class Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/contributing.md Define a new device class in `seabreeze/pyseabreeze/devices.py` to add basic spectrometer functionality. This includes communication configuration and spectrometer-specific parameters. ```python class SPARK(SeaBreezeDevice): model_name = 'SPARK' # communication config transport = (USBTransport, ) usb_product_id = 0x4200 usb_endpoint_map = EndPointMap(ep_out=0x01, lowspeed_in=0x81) # XXX: we'll ignore the alternative EPs usb_protocol = OBPProtocol # spectrometer config dark_pixel_indices = DarkPixelIndices.from_ranges() integration_time_min = 10 integration_time_max = 85000000 integration_time_base = 1 spectrum_num_pixel = 1024 spectrum_raw_length = (1024 * 2) + 64 # XXX: Metadata spectrum_max_value = 16383 trigger_modes = TriggerMode.supported('OBP_NORMAL', 'OBP_EXTERNAL', 'OBP_INTERNAL') # features feature_classes = ( sbf.spectrometer.SeaBreezeSpectrometerFeatureSPARK, # need to implement this sbf.rawusb.SeaBreezeRawUSBBusAccessFeature, ) ``` -------------------------------- ### Implement Spectrometer Feature Class Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/contributing.md Implement the specialized spectrometer feature class in `seabreeze/pyseabreeze/features/spectrometer.py`. For spectrometers that follow the default OBP Protocol, this may involve a simple class definition inheriting from the default. ```python # we're lucky here, and the Spark just uses the default implementation # of the OBP Protocol. It's possible that for other spectrometers you # need to override the `get_intensities` method or others dependent on how # much they deviate from the default implementation # (refer to the spectrometer's datasheet for this) # class SeaBreezeSpectrometerFeatureSPARK(SeaBreezeSpectrometerFeatureOBP): pass ``` -------------------------------- ### Exception Handling for Device Cleanup Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/contributing.md An AttributeError may occur during device cleanup if the device's context is None. ```python Exception AttributeError: "'NoneType' object has no attribute '_ctx'" in > ignored ``` -------------------------------- ### Spectrometer.from_serial_number() — Open Spectrometer by Serial Number Source: https://context7.com/ap--/python-seabreeze/llms.txt A class method to open a spectrometer identified by its serial number. If `serial` is set to `None`, it functions identically to `from_first_available()`. Raises `SeaBreezeError` if the specified device is not found or is already open. ```APIDOC ## Spectrometer.from_serial_number() ### Description Class method that opens the spectrometer matching the given serial number string. If `serial=None`, behaves like `from_first_available()`. Raises `SeaBreezeError` if the device is not found or already open. ### Usage ```python from seabreeze.spectrometers import Spectrometer # Open by serial number spec = Spectrometer.from_serial_number("USB2+F01234") print(spec) # # Pass None to open first available spec2 = Spectrometer.from_serial_number(serial=None) # Ethernet spectrometer (requires pyseabreeze + network_adapter set) import seabreeze seabreeze.use("pyseabreeze", network_adapter="192.168.254.200") from seabreeze.spectrometers import Spectrometer spec3 = Spectrometer.from_serial_number("HDX12345") ``` ``` -------------------------------- ### Spectrometer.intensities() Source: https://context7.com/ap--/python-seabreeze/llms.txt Acquires a single spectrum and returns it as a NumPy array of intensities in arbitrary units (ADC counts). Supports optional dark count subtraction and nonlinearity correction; raises `SeaBreezeError` if a requested correction is not supported by the device. ```APIDOC ## `Spectrometer.intensities()` — Acquire Intensity Spectrum Acquires a single spectrum and returns it as a NumPy array of intensities in arbitrary units (ADC counts). Supports optional dark count subtraction and nonlinearity correction; raises `SeaBreezeError` if a requested correction is not supported by the device. ### Method `intensities(self, correct_dark_counts: bool = False, correct_nonlinearity: bool = False) -> np.ndarray` ### Parameters - **correct_dark_counts** (bool) - Optional - Whether to subtract dark counts. - **correct_nonlinearity** (bool) - Optional - Whether to apply nonlinearity correction. ``` -------------------------------- ### Acquire Spectrometer Intensity Spectrum Source: https://context7.com/ap--/python-seabreeze/llms.txt Acquires a single spectrum and returns it as a NumPy array of intensities. Supports optional dark count subtraction and nonlinearity correction. ```python from seabreeze.spectrometers import Spectrometer spec = Spectrometer.from_first_available() spec.integration_time_micros(20_000) # 20 ms # Raw intensities raw = spec.intensities() print(raw) # array([1485., 1493., 1487., ..., 1496., 1497., 1493.]) # With dark count and nonlinearity corrections (if device supports them) corrected = spec.intensities(correct_dark_counts=True, correct_nonlinearity=True) print(f"Max intensity: {spec.max_intensity}") # Max intensity: 65535.0 ``` -------------------------------- ### Spectrometer.features / Spectrometer.f Source: https://context7.com/ap--/python-seabreeze/llms.txt `features` returns a `TypedDict` mapping feature names to lists of feature instances. `f` is a shorthand attribute accessor. Available features include: `eeprom`, `spectrometer`, `nonlinearity_coefficients`, `temperature`, `thermo_electric`, `light_source`, `shutter`, `gpio`, `irrad_cal`, `spectrum_processing`, `data_buffer`, `fast_buffer`, `pixel_binning`, `raw_usb_bus_access`, `revision`, `optical_bench`, `continuous_strobe`, `strobe_lamp`, `acquisition_delay`, `network_configuration`, `ipv4`, `ethernet_configuration`, `wifi_configuration`, `dhcp_server`, `multicast`, `i2c_master`, `introspection`, `stray_light_coefficients`. ```APIDOC ## `Spectrometer.features` / `Spectrometer.f` — Access Advanced Device Features `features` returns a `TypedDict` mapping feature names to lists of feature instances. `f` is a shorthand attribute accessor. Available features include: `eeprom`, `spectrometer`, `nonlinearity_coefficients`, `temperature`, `thermo_electric`, `light_source`, `shutter`, `gpio`, `irrad_cal`, `spectrum_processing`, `data_buffer`, `fast_buffer`, `pixel_binning`, `raw_usb_bus_access`, `revision`, `optical_bench`, `continuous_strobe`, `strobe_lamp`, `acquisition_delay`, `network_configuration`, `ipv4`, `ethernet_configuration`, `wifi_configuration`, `dhcp_server`, `multicast`, `i2c_master`, `introspection`, `stray_light_coefficients`. ### Attributes - **features** (TypedDict) - A dictionary mapping feature names to lists of feature instances. - **f** (object) - A shorthand attribute accessor for features. ``` -------------------------------- ### Read Spectrum via Ethernet Source: https://github.com/ap--/python-seabreeze/blob/main/README.md Use this snippet to read spectral data from an HDX spectrometer over an ethernet connection. Ensure the pyseabreeze backend is selected and the correct network adapter IP is provided. ```pycon >>> import seabreeze ... from seabreeze.spectrometers import Spectrometer ... ... seabreeze.use("pyseabreeze", network_adapter="192.168.254.200") >>> >>> spec = Spectrometer.from_serial_number("HDX12345") >>> spec.intensities() array([1967.07287765, 1325.69702018, 1418.40732539, ..., 1398.4680335 , 1406.44364585, 1397.47109175]) ``` -------------------------------- ### Spectrometer.integration_time_micros() Source: https://context7.com/ap--/python-seabreeze/llms.txt Sets the CCD integration time in microseconds. The valid range can be queried via `integration_time_micros_limits`. Out-of-range values raise `SeaBreezeError`. ```APIDOC ## `Spectrometer.integration_time_micros()` — Set Integration Time Sets the CCD integration time in microseconds. The valid range can be queried via `integration_time_micros_limits`. Out-of-range values raise `SeaBreezeError`. ### Method `integration_time_micros(self, integration_time_micros: int)` ### Parameters - **integration_time_micros** (int) - Required - The integration time in microseconds. ``` -------------------------------- ### Manage Spectrometer Device Connection Source: https://context7.com/ap--/python-seabreeze/llms.txt Manually open or close the USB connection to the spectrometer. These are called automatically under normal use but are exposed for advanced scenarios. ```python from seabreeze.spectrometers import Spectrometer spec = Spectrometer.from_first_available() # Acquire a spectrum spec.integration_time_micros(10_000) data = spec.intensities() # Explicitly release the device spec.close() # Re-open when needed spec.open() ``` -------------------------------- ### Set Spectrometer Integration Time Source: https://context7.com/ap--/python-seabreeze/llms.txt Sets the CCD integration time in microseconds. Query limits using `integration_time_micros_limits`. Out-of-range values raise `SeaBreezeError`. ```python from seabreeze.spectrometers import Spectrometer spec = Spectrometer.from_first_available() # Query hardware limits min_us, max_us = spec.integration_time_micros_limits print(f"Integration time range: {min_us} – {max_us} µs") # Integration time range: 1000 – 65535000 µs # Set to 100 ms spec.integration_time_micros(100_000) ``` -------------------------------- ### Spectrometer.spectrum() Source: https://context7.com/ap--/python-seabreeze/llms.txt Convenience method that returns a 2×N NumPy array stacking wavelengths and intensities. Accepts the same correction flags as `intensities()`. ```APIDOC ## `Spectrometer.spectrum()` — Get Wavelengths and Intensities Together Convenience method that returns a 2×N NumPy array stacking wavelengths and intensities. Accepts the same correction flags as `intensities()`. ### Method `spectrum(self, correct_dark_counts: bool = False, correct_nonlinearity: bool = False) -> np.ndarray` ### Parameters - **correct_dark_counts** (bool) - Optional - Whether to subtract dark counts. - **correct_nonlinearity** (bool) - Optional - Whether to apply nonlinearity correction. ### Returns - **np.ndarray** - A 2xN NumPy array where the first row contains wavelengths and the second row contains intensities. ``` -------------------------------- ### Access Advanced Spectrometer Features Source: https://context7.com/ap--/python-seabreeze/llms.txt Accesses advanced device features via `features` (a TypedDict) or the shorthand `f` attribute. Lists available features and demonstrates reading an EEPROM slot. ```python from seabreeze.spectrometers import Spectrometer spec = Spectrometer.from_first_available() # List all features and check availability for name, instances in spec.features.items(): if instances: print(f"{name}: available") # Read EEPROM slot via features dict eeprom_val = spec.features["eeprom"][0].eeprom_read_slot(4) print(f"EEPROM slot 4: {eeprom_val}") # Shorthand via .f accessor (identical result) eeprom_val2 = spec.f.eeprom.eeprom_read_slot(4) ``` -------------------------------- ### Spectrometer.trigger_mode() Source: https://context7.com/ap--/python-seabreeze/llms.txt Sets the spectrometer's trigger mode. Mode values are hardware-specific; refer to the spectrometer's datasheet (typically 0 = normal/free-running, 1 = software trigger, 2 = external hardware trigger, etc.). ```APIDOC ## `Spectrometer.trigger_mode()` — Set Hardware Trigger Mode Sets the spectrometer's trigger mode. Mode values are hardware-specific; refer to the spectrometer's datasheet (typically 0 = normal/free-running, 1 = software trigger, 2 = external hardware trigger, etc.). ### Method `trigger_mode(self, mode: int)` ### Parameters - **mode** (int) - Required - The trigger mode value (hardware-specific). ``` -------------------------------- ### Spectrometer.wavelengths() Source: https://context7.com/ap--/python-seabreeze/llms.txt Returns a cached NumPy array of wavelengths in nanometers, one value per detector pixel. Wavelengths are read once on device open. ```APIDOC ## `Spectrometer.wavelengths()` — Get Wavelength Array Returns a cached NumPy array of wavelengths in nanometers, one value per detector pixel. Wavelengths are read once on device open. ### Method `wavelengths(self) -> np.ndarray` ### Returns - **np.ndarray** - A NumPy array containing the wavelengths in nanometers. ``` -------------------------------- ### Deprecation Warning for fromstring Source: https://github.com/ap--/python-seabreeze/blob/main/docs/source/contributing.md A DeprecationWarning is issued when using the binary mode of numpy.fromstring, recommending the use of frombuffer instead. ```python return numpy.fromstring(datastring, dtype=numpy.uint8) ```