Python module for Ocean Optics spectrometers
Python-seabreeze is the easy way to access your Ocean Optics spectrometers from python. It wraps the SeaBreeze library provided by Ocean Optics to communicate with the spectrometer. If SeaBreeze is not available it can fallback to a pyUSB based reimplementation. This software is not associated with Ocean Optics. Use it at your own risk.
conda install -c poehlmann python-seabreeze
if windows ( force your spectrometer to use a driver from here )
if linux ( install udev rules from here )
>>> 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])
Consider supporting open source software and buying me a beer.
Starting with version 0.6.0, python-seabreeze is available as a pre-built package for Python versions 2.7.x, 3.5.x, 3.6.x on win-32, win-64, osx-64, linux-64 and linux-armv7l via anaconda. The module supports communicating with various Ocean Optics spectrometers via one of two backends. More information on the backends is available here. The recommended default is cseabreeze. Everything required ships with the conda package.
python-seabreeze now ships pre-built packages for Anaconda. If you're not using Anaconda yet, start using it now. As a scientist, who spent way to much time dealing with stupid computer problems, I urge you to switch all your python development to Anaconda environments. It'll save you a lot of time, believe me. (for RaspberryPIs I recommend using Berryconda)
To install the module run the following in your conda environment. This will install the module and the dependencies you need for the cseabreeze backend.
conda install -c poehlmann python-seabreeze
IF WINDOWS: you need to install driver-files for your spectrometer from here. These drivers tell windows to use the winusb driver for the spectrometer. It's possible that OceanView won't find the spectrometer anymore after this. Extract the drivers to a location you like. Goto Device Manager. Select your spectrometer, right click and update driver software. Then choose a suiting driver from the extracted folder.
IF LINUX:
you need to install the udev rules from here. These give all users access to connected usb spectrometers and are required, so that you can access the
spectrometers via libusb as a user without root privileges. Download (On Fedora, download the rules from here and replace "user" with your username) and copy the file to /etc/udev/rules.d/
and run sudo udevadm control --reload-rules
. Replug your spectrometer.
IF OSX: You're all set. It should already work.
Platform | OS | interpreter | backend | instructions |
---|---|---|---|---|
x86/x64 | Windows | Anaconda | pyseabreeze | recommended + pyusb |
x86/x64 | Windows | Python.org | cseabreeze | windows |
x86/x64 | Windows | Python.org | pyseabreeze | without-cseabreeze + pyusb |
x86/x64 | OSX | Anaconda | pyseabreeze | recommended + pyusb |
x86/x64 | OSX | Python.org | cseabreeze | osx |
x86/x64 | OSX | Python.org | pyseabreeze | without-cseabreeze + pyusb |
x86/x64 | Linux | Anaconda | pyseabreeze | recommended + pyusb |
x86/x64 | Linux | Python.org | cseabreeze | linux |
x86/x64 | Linux | Python.org | pyseabreeze | without-cseabreeze + pyusb |
ARM | Linux | Python.org | cseabreeze | linux |
ARM | Linux | Python.org | pyseabreeze | without-cseabreeze + pyusb |
If you think that you can't install this module because there is something wrong with it, read through the installation instructions again. Then try to look for a solution for your problem on the internet at least three times. If nothing helped, read the contributing guidelines, file an issue on github and be nice. Please note, that I am not an Ocean Optics employee and am maintaining this module in my free time.
The following example shows how simple it is to acquire a spectrum with python-seabreeze through the model independent Spectrometer class. For a more detailed description read the (currently incomplete) documentation.:
>>> import seabreeze.spectrometers as sb
>>> devices = sb.list_devices()
>>> print devices
[<SeaBreezeDevice USB2000PLUS:USB2+H02749>, <SeaBreezeDevice USB2000PLUS:USB2+H02751>]
>>> spec = sb.Spectrometer(devices[0])
>>> spec.integration_time_micros(12000)
>>> 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])
To use the pyseabreeze backend simply run this before importing seabreeze.spectrometers. The pyseabreeze backend requires pyUSB to be installed. (Look at the backends documentation for more info.)
>>> import seabreeze
>>> seabreeze.use('pyseabreeze')
>>> import seabreeze.spectrometers as sb
Some examples of implementation, including an example of a graphical front-end, are provided under /MyOpticsLab.
Spectrometer | cseabreeze | pyseabreeze |
---|---|---|
HR2000 | x | x |
HR2000PLUS | x | x |
HR4000 | x | x |
JAZ | x | x |
MAYA2000 | x | x |
MAYA2000PRO | x | x |
MAYALSL | x | x |
NIRQUEST256 | x | x |
NIRQUEST512 | x | x |
QE65000 | x | x |
QE-PRO | x | x |
STS | x | x |
TORUS | x | x |
USB2000 | x | x |
USB2000PLUS | x | x |
USB4000 | x | x |
USB650 | Issue #47 | |
SPARK | x |
- USB2000 spectrometers cause
Data transfer error
due to old firmware Issue #48 - USB650 not supported Issue #47
- No conda packages for armv6 (RPI version 1) Issue #46
If you run into any problems, file an issue and be sure to include the following in your report:
- Operating system (Linux distribution, Windows version, OSX version) and archictecture (32bit, 64bit, arm)
- Python version and arch (i.e. Python 2.7.10 64bit)
- python-seabreeze version
If you want a feature implemented, please file an issue, or create a pull request when you implement it yourself. And if you would like to support me via paypal, click on the paypal donate button on top of this README.
Files in this repository are released under the MIT license.
If you want me to add your project here, let me know. Happy to add it.
- SeaBreeze - Ocean Optics' SeaBreeze C library.
- libseabreeze - github clone of the C library. internal use only (has pre-built libraries if you know what you're doing)
- python-seabreeze-feedstock - anaconda feedstock for automated package deployment. internal use only