Skip to content
Merged
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
12 changes: 6 additions & 6 deletions hardwarelibrary/cameras/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
from hardwarelibrary.physicaldevice import PhysicalDevice
from hardwarelibrary.notificationcenter import NotificationCenter, Notification
from threading import Thread, RLock
try:
import cv2
except Exception as err:
print("No support for OpenCVcameras")
pass

import re

class CameraDeviceNotification(Enum):
Expand Down Expand Up @@ -71,6 +65,8 @@ def stop(self):
raise RuntimeError("No monitoring loop running")

def captureLoopSynchronous(self):
import cv2

frame = None
NotificationCenter().postNotification(notificationName=CameraDeviceNotification.didStartCapture,
notifyingObject=self)
Expand Down Expand Up @@ -114,6 +110,8 @@ def __init__(self, serialNumber:str = None, idProduct:int = None, idVendor:int =
self.cvCameraIndex = int(serialNumber)

def openCVProperties(self):
import cv2

properties = {}
for property in dir(cv2):
if re.search('CAP_', property) is not None:
Expand All @@ -139,6 +137,8 @@ def isCompatibleWith(cls, serialNumber, idProduct, idVendor):
return wasAcquired

def doInitializeDevice(self):
import cv2

super().doInitializeDevice()
with self.lock:
# FIXME: Open the first camera we find
Expand Down
2 changes: 0 additions & 2 deletions hardwarelibrary/echodevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import time
from struct import *

from pyftdi.ftdi import Ftdi #FIXME: should not be here.


class EchoDevice(PhysicalDevice):
classIdProduct = 0x6001
Expand Down
2 changes: 0 additions & 2 deletions hardwarelibrary/motion/sutterdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import time
from struct import *

from pyftdi.ftdi import Ftdi #FIXME: should not be here.

class SutterDevice(LinearMotionDevice):
classIdVendor = 4930
classIdProduct = 1
Expand Down
3 changes: 2 additions & 1 deletion hardwarelibrary/oscilloscope/oscilloscopedevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from hardwarelibrary.communication.serialport import SerialPort
from hardwarelibrary.physicaldevice import *
from hardwarelibrary.notificationcenter import NotificationCenter, Notification
import matplotlib.pyplot as plt

class Channels(Enum):
CH1 = "CH1"
Expand Down Expand Up @@ -35,6 +34,8 @@ def __init__(self, serialNumber:str = None, idProduct = 0x6001, idVendor = 0x040
self.delay = None

def displayWaveforms(self, channels=None):
import matplotlib.pyplot as plt

if channels is None:
channels = [Channels.CH1, Channels.CH2]

Expand Down
2 changes: 1 addition & 1 deletion hardwarelibrary/spectrometers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def __init__(self):

from .base import Spectrometer, getAllSubclasses
from .oceaninsight import OISpectrometer, USB2000, USB4000, USB2000Plus, USB4000_2000Plus, USB650
from .viewer import SpectraViewer

def any() -> Spectrometer:
return Spectrometer.any()

def displayAny():
from .viewer import SpectraViewer
spectrometer = Spectrometer.any()
if spectrometer is not None:
spectrometer.initializeDevice()
Expand Down
7 changes: 5 additions & 2 deletions hardwarelibrary/spectrometers/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import time
import numpy as np
from abc import abstractmethod
from struct import *
import csv
Expand All @@ -17,7 +18,6 @@

from pathlib import *
from hardwarelibrary.physicaldevice import PhysicalDevice, DeviceState
from hardwarelibrary.spectrometers.viewer import *

class NoSpectrometerConnected(RuntimeError):
pass
Expand All @@ -32,6 +32,8 @@ class Spectrometer(PhysicalDevice):
idVendor = None
idProduct = None
def __init__(self, serialNumber=None, idProduct:int = None, idVendor:int = None):
import numpy as np

PhysicalDevice.__init__(self, serialNumber=serialNumber, idProduct=idProduct, idVendor=idVendor)
self.model = ""
self.wavelength = np.linspace(400,1000,1024)
Expand All @@ -57,6 +59,7 @@ def display(self):
"""
if self.state != DeviceState.Ready:
self.initializeDevice()
from hardwarelibrary.spectrometers.viewer import SpectraViewer
viewer = SpectraViewer(spectrometer=self)
viewer.display()

Expand Down
16 changes: 9 additions & 7 deletions hardwarelibrary/spectrometers/oceaninsight.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
try:
import time
import numpy as np
from struct import *
import csv
from typing import NamedTuple
Expand All @@ -17,18 +16,12 @@
import usb.util
import usb.backend.libusb1

import matplotlib.backends as backends
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.widgets import Button, TextBox


except Exception as err:
print('** Error importing modules. {0}'.format(err))
print('We will attempt to continue and hope for the best.')

from hardwarelibrary.spectrometers.base import *
from hardwarelibrary.spectrometers.viewer import *

"""
This is a simple script to use an Ocean Insight USB2000 spectrometer. You can
Expand Down Expand Up @@ -627,6 +620,8 @@ def getSpectrumData(self):
The spectrum, in 16-bit integers corresponding to each wavelength
available in self.wavelength.
"""
import numpy as np

spectrum = []

for packet in range(32):
Expand Down Expand Up @@ -726,6 +721,8 @@ def getSpectrumData(self):
The spectrum, in 16-bit integers corresponding to each wavelength
available in self.wavelength.
"""
import numpy as np

spectrum = []

if not self.lastStatus.isHighSpeed:
Expand Down Expand Up @@ -847,6 +844,8 @@ class Emitter(NamedTuple):
intensity:float = None

def __init__(self):
import numpy as np

self.model = "Debug - Nothing is connected"
self.wavelength = np.linspace(400,1000,1024)
self.integrationTime = 10
Expand All @@ -862,6 +861,8 @@ def getSerialNumber(self):
return "000-000-000"

def getSpectrum(self):
import numpy as np

spectrum = []
time = self.getIntegrationTime()
for wavelength in self.wavelength:
Expand All @@ -880,6 +881,7 @@ def getSpectrum(self):

def display(self):
""" Display the spectrum with the SpectraViewer class."""
from hardwarelibrary.spectrometers.viewer import SpectraViewer
viewer = SpectraViewer(spectrometer=self)
viewer.display()

Expand Down
Loading