Skip to content
This repository was archived by the owner on Aug 30, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion oceanoptics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@

from oceanoptics.defines import OceanOpticsError

from oceanoptics.utils import get_a_random_spectrometer
from oceanoptics.utils import get_a_random_spectrometer, get_available_spectrometers
from oceanoptics.utils import get_spectrometer, list_available_spectrometers
57 changes: 36 additions & 21 deletions oceanoptics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class OceanOpticsSpectrometer(object):
All spectrometers should inherit from this!
(or from a class that inherits from this)
"""

def wavelengths(self, only_valid_pixels=True):
""" returns a np.array with wavelenghts in nm """
raise NotImplementedError
Expand All @@ -44,10 +45,10 @@ def integration_time(self, time_sec=None):

class OceanOpticsUSBComm(object):

def __init__(self, model):
self._usb_init_connection(model)
def __init__(self, model, device=None):
self._usb_init_connection(model, device)

def _usb_init_connection(self, model):
def _usb_init_connection(self, model, device):

if model not in _OOModelConfig.keys():
raise _OOError('Unkown OceanOptics spectrometer model: %s' % model)
Expand All @@ -63,20 +64,25 @@ def _usb_init_connection(self, model):
self._EPin1_size = _OOModelConfig[model]['EPin1_size']
self._min_integration_time, self._max_integration_time = _OOMinMaxIT[model]

devices = usb.core.find(find_all=True,
custom_match=lambda d: (d.idVendor==vendorId and
d.idProduct in productId))
# FIXME: generator fix
devices = list(devices)
if device is None:
#if no specific device is passed in, then search for all OO devices
#and open the first one.
devices = usb.core.find(find_all=True,
custom_match=lambda d: (d.idVendor==vendorId and
d.idProduct in productId))
# FIXME: generator fix
devices = list(devices)

try:
self._dev = devices.pop(0)
except (AttributeError, IndexError):
raise _OOError('No OceanOptics %s spectrometer found!' % model)
try:
self._dev = devices.pop(0)
except (AttributeError, IndexError):
raise _OOError('No OceanOptics %s spectrometer found!' % model)
else:
if devices:
warnings.warn('Currently the first device matching the '
'Vendor/Product id is used')
else:
if devices:
warnings.warn('Currently the first device matching the '
'Vendor/Product id is used')
self._dev = device

self._dev.set_configuration()
self._USBTIMEOUT = self._dev.default_timeout * 1e-3
Expand Down Expand Up @@ -117,8 +123,8 @@ class OceanOpticsBase(OceanOpticsSpectrometer, OceanOpticsUSBComm):

"""

def __init__(self, model):
super(OceanOpticsBase, self).__init__(model)
def __init__(self, model,**kwargs):
super(OceanOpticsBase, self).__init__(model, **kwargs)
self._initialize()

status = self._init_robust_status()
Expand All @@ -127,22 +133,31 @@ def __init__(self, model):
self._pixels = status['pixels']
self._EPspec = self._EPin1 if self._usb_speed == 0x80 else self._EPin0
self._packet_N, self._packet_size, self._packet_func = (
_OOSpecConfig[model][self._usb_speed] )
_OOSpecConfig[self.model][self._usb_speed] )
self._init_robust_spectrum()


self._serial_number = self._query_information(0)

# XXX: differs for some spectrometers...
#self._sat_factor = 65535.0/float(
# stuct.unpack('<h', self._query_information(17, raw=True)[6:8])[0])
self._wl_factors = [float(self._query_information(i)) for i in range(1,5)]
self._nl_factors = [float(self._query_information(i)) for i in range(6,14)]
self._wl = sum( self._wl_factors[i] *
np.arange(self._pixels, dtype=np.float64)**i for i in range(4) )
self._valid_pixels = _OOValidPixels[model]
self._valid_pixels = _OOValidPixels[self.model]

#---------------------
# High level functions
#---------------------


@property
def serial_number(self):
"""
The serial number of the spectrometer (string).
"""
return self._serial_number

def wavelengths(self, only_valid_pixels=True):
"""returns array of wavelengths

Expand Down
4 changes: 2 additions & 2 deletions oceanoptics/spectrometers/APEX.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class APEX(_OOBase):

def __init__(self):
super(APEX, self).__init__('Apex')
def __init__(self, **kwargs):
super(APEX, self).__init__('Apex', **kwargs)


4 changes: 2 additions & 2 deletions oceanoptics/spectrometers/MAYA.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class MAYA(_OOBase):

def __init__(self):
super(MAYA, self).__init__('Maya')
def __init__(self, **kwargs):
super(MAYA, self).__init__('Maya', **kwargs)


4 changes: 2 additions & 2 deletions oceanoptics/spectrometers/MAYA2000pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class MAYA2000pro(_OOBase):

def __init__(self):
super(MAYA2000pro, self).__init__('Maya2000pro')
def __init__(self, **kwargs):
super(MAYA2000pro, self).__init__('Maya2000pro', **kwargs)


9 changes: 5 additions & 4 deletions oceanoptics/spectrometers/QE65xxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from oceanoptics.base import OceanOpticsBase as _OOBase
from oceanoptics.base import OceanOpticsTEC as _OOTEC
import struct
import numpy as np
#----------------------------------------------------------


Expand Down Expand Up @@ -39,8 +40,8 @@ def _query_status(self):
#--------

class QE65000(_QE65xxx):
def __init__(self):
super(QE65000, self).__init__('QE65000')
def __init__(self, **kwargs):
super(QE65000, self).__init__('QE65000', **kwargs)
# The QE65000 needs a -10 offset for calculating the wavelengths
# due to some legacy issues...
self._wl = sum( self._wl_factors[i] *
Expand All @@ -53,8 +54,8 @@ def __init__(self):
#----------

class QE65pro(_QE65xxx):
def __init__(self):
super(QE65pro, self).__init__('QE65pro')
def __init__(self, **kwargs):
super(QE65pro, self).__init__('QE65pro', **kwargs)
self.initialize_TEC()


4 changes: 2 additions & 2 deletions oceanoptics/spectrometers/STS.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ class _STSCONSTANTS(object):
class STS(_OOSpec, _OOUSBComm):
"""Rewrite of STS class"""

def __init__(self, integration_time=0.001):
super(STS, self).__init__('STS')
def __init__(self, integration_time=0.001, **kwargs):
super(STS, self).__init__('STS', **kwargs)

self._const = _STSCONSTANTS

Expand Down
4 changes: 2 additions & 2 deletions oceanoptics/spectrometers/TORUS.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class TORUS(_OOBase):

def __init__(self):
super(TORUS, self).__init__('Torus')
def __init__(self, **kwargs):
super(TORUS, self).__init__('Torus', **kwargs)


12 changes: 6 additions & 6 deletions oceanoptics/spectrometers/XXX2000.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def _request_spectrum(self):

class USB2000(_XXX2000):

def __init__(self):
super(USB2000, self).__init__('USB2000')
def __init__(self, **kwargs):
super(USB2000, self).__init__('USB2000', **kwargs)

def _set_integration_time(self, time_us):
""" send command 0x02 """
Expand Down Expand Up @@ -76,8 +76,8 @@ def _query_status(self):

class HR2000(_XXX2000):

def __init__(self):
super(HR2000, self).__init__('HR2000')
def __init__(self, **kwargs):
super(HR2000, self).__init__('HR2000', **kwargs)

def _set_integration_time(self, time_us):
""" send command 0x02 """
Expand Down Expand Up @@ -118,8 +118,8 @@ def _query_status(self):

class USB650(_XXX2000):

def __init__(self):
super(USB650, self).__init__('USB650')
def __init__(self, **kwargs):
super(USB650, self).__init__('USB650', **kwargs)

def _set_integration_time(self, time_us):
""" send command 0x02 """
Expand Down
8 changes: 4 additions & 4 deletions oceanoptics/spectrometers/XXX2000plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

class USB2000plus(_OOBase):

def __init__(self):
super(USB2000plus, self).__init__('USB2000+')
def __init__(self, **kwargs):
super(USB2000plus, self).__init__('USB2000+', **kwargs)


class HR2000plus(_OOBase):

def __init__(self):
super(HR2000plus, self).__init__('HR2000+')
def __init__(self, **kwargs):
super(HR2000plus, self).__init__('HR2000+', **kwargs)


8 changes: 4 additions & 4 deletions oceanoptics/spectrometers/XXX4000.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ def _read_pcb_temperature(self):

class USB4000(_XXX4000):

def __init__(self):
def __init__(self, **kwargs):
self._EPin2 = _OOModelConfig['USB4000']['EPin2']
self._EPin6 = _OOModelConfig['USB4000']['EPin6']
self._EPin2_size = _OOModelConfig['USB4000']['EPin2_size']
self._EPin6_size = _OOModelConfig['USB4000']['EPin6_size']
super(USB4000, self).__init__('USB4000')
super(USB4000, self).__init__('USB4000', **kwargs)


#----------
Expand All @@ -69,10 +69,10 @@ def __init__(self):

class HR4000(_XXX4000):

def __init__(self):
def __init__(self, **kwargs):
self._EPin2 = _OOModelConfig['HR4000']['EPin2']
self._EPin6 = _OOModelConfig['HR4000']['EPin6']
self._EPin2_size = _OOModelConfig['HR4000']['EPin2_size']
self._EPin6_size = _OOModelConfig['HR4000']['EPin6_size']
super(HR4000, self).__init__('HR4000')
super(HR4000, self).__init__('HR4000', **kwargs)

Loading