instrumentComBase.py 3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# -*- coding: utf-8 -*-
"""
GEPARD - Gepard-Enabled PARticle Detection
Copyright (C) 2018  Lars Bittrich and Josef Brandt, Leibniz-Institut für 
Polymerforschung Dresden e. V. <bittrich-lars@ipfdd.de>    

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program, see COPYING.  
If not, see <https://www.gnu.org/licenses/>.
"""
Josef Brandt's avatar
Josef Brandt committed
21 22
import cv2
from ..helperfunctions import cv2imread_fix, cv2imwrite_fix
23

Josef Brandt's avatar
Josef Brandt committed
24

25
class InstrumentComBase(object):
Josef Brandt's avatar
Josef Brandt committed
26 27 28 29 30 31
    videoScaleFactor: float = 1.0

    @classmethod
    def setVideoScaleFactor(cls, newFac) -> None:
        cls.videoScaleFactor = float(newFac)

32
    def __init__(self, logger=None):
33
        self.name = None
34 35
        self.connected = False
        self.timeseries = False
Josef Brandt's avatar
Josef Brandt committed
36
        self.logger = logger
Josef Brandt's avatar
Josef Brandt committed
37 38 39 40 41 42 43 44 45

    def _scaleVideoImage(self, imagePath: str) -> None:
        """
        For convenience.. Takes the image at the indicated path and scales it to the videoScaleFactor.
        """
        img = cv2imread_fix(imagePath)
        img = cv2.resize(img, None, fx=self.videoScaleFactor, fy=self.videoScaleFactor)
        cv2imwrite_fix(imagePath, img)

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    def getRamanPositionShift(self):
        """ Compute the shift between laser spot and image center"""
        raise NotImplementedError
        
    def connect(self):
        self.connected = True
        return True
    
    def disconnect(self):
        self.connected = False
    
    def getPosition(self):
        raise NotImplementedError
    
    def getSoftwareZ(self):
        raise NotImplementedError
    
    def getUserZ(self):
        raise NotImplementedError
        
66
    def moveToAbsolutePosition(self, x, y, z=None, epsxy=0.11, epsz=0.011):
67 68 69 70 71 72 73 74
        raise NotImplementedError
        
    def moveZto(self, z, epsz=0.011):
        raise NotImplementedError
        
    def saveImage(self, fname):
        raise NotImplementedError
        
Josef Brandt's avatar
Josef Brandt committed
75
    def getImageDimensions(self, mode: str = 'df'):
76 77 78 79
        """ Get the image width and height in um and the orientation angle in degrees.
        """
        raise NotImplementedError
        
80
    def initiateMeasurement(self, specScanSettings):
81 82
        raise NotImplementedError
        
83 84 85
    def triggerMeasurement(self, num):
        raise NotImplementedError
        
Josef Brandt's avatar
Josef Brandt committed
86
    def finishMeasurement(self, aborted=False):
Josef Brandt's avatar
Josef Brandt committed
87 88
        raise NotImplementedError

Josef Brandt's avatar
Josef Brandt committed
89
    def updateImageConfig(self, dsetpath: str) -> None:
Josef Brandt's avatar
Josef Brandt committed
90
        """
91
        Can be overloaded if the instrcontrol needs to update image config fro dataset folder
Josef Brandt's avatar
Josef Brandt committed
92
        :param dsetpath: filepath to the dataset
Josef Brandt's avatar
Josef Brandt committed
93 94
        :return:
        """
Josef Brandt's avatar
Josef Brandt committed
95
        pass