simulatedraman.py 3.74 KB
Newer Older
Josef Brandt's avatar
Josef Brandt committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
# -*- 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/>.

Simualted Raman interface module for testing without actual raman system connected
"""

import sys
stdout = sys.stdout
from time import sleep
from ..ramanbase import RamanBase
from ...helperfunctions import cv2imwrite_fix
from .simulatedStage import SimulatedStage


class SimulatedRaman(RamanBase):
    magn = 20
    ramanParameters = {}
    simulatedInterface = True

37
    def __init__(self, logger, ui: bool = False):
Josef Brandt's avatar
Josef Brandt committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
        super().__init__()
        self.name = 'SimulatedRaman' 
        self.logger = logger
        self.userZ = 0.0
        self.stage: SimulatedStage = SimulatedStage(ui=ui)
        self.znum = 4
        self.gridnum = 36
        self.positionindex = 0
        self.imageindex = 0
        
    def getRamanPositionShift(self):
        return 0., 0.
        
    def connect(self):
        self.stage.connect()
        self.connected = True
        self.imageindex = 0
        return True
    
    def disconnect(self):
        self.stage.disconnect()
        self.connected = False
    
    def getPosition(self):
        return self.stage.currentpos
    
    def getSoftwareZ(self):
        return self.stage.currentpos[2]
    
    def getUserZ(self):
        assert self.connected
        return self.userZ
        
    def moveToAbsolutePosition(self, x, y, z=None, epsxy=0.11, epsz=0.011):
        assert self.connected
        self.logger.info(f'moving to: x: {x}, y: {y}, z: {z}')
        if z is None:
            self.stage.moveToPosition(x, y, self.stage.currentpos[2])
        else:
            self.stage.moveToPosition(x, y, z)
        sleep(0.1)
        
    def moveZto(self, z, epsz=0.011):
        assert self.connected
        self.stage.moveToPosition(self.stage.currentpos[0], self.stage.currentpos[1], z)
        
    def saveImage(self, fname):
        assert self.connected
        cv2imwrite_fix(fname, self.stage.getCurrentCameraImage())
        self.imageindex = (self.imageindex+1) % (self.znum*self.gridnum)
        
    def getImageDimensions(self, mode='df'):
        """ 
        Get the image width and height in um and the orientation angle in degrees.
        """
        assert self.connected
        camDims: tuple = self.stage.camera.imgDims
        return camDims[0], camDims[1], 0  # TODO: RE-Implement a small angle to simulate a tilted camera!
    
    def startSinglePointScan(self):
        assert self.connected
        self.logger.info("Fake scan")
        sleep(.3)
        
    def initiateMeasurement(self, ramanSettings):
        assert self.connected
        self.logger.info(f"Scanning {ramanSettings['numPoints']} particle positions")
        self.timeseries = ramanSettings['numPoints']
        sleep(.1)

    def triggerMeasurement(self, num):
        assert self.timeseries
        self.logger.info(f"Scan number: {num}")
        sleep(1.0)
        if num == self.timeseries-1:
            self.timeseries = False

    def finishMeasurement(self, aborted=False):
        self.logger.info('measurement was aborted')