simulatedraman.py 4.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# -*- 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
"""

JosefBrandt's avatar
JosefBrandt committed
24
import sys, os
25
stdout = sys.stdout
26 27 28
from time import sleep
import numpy as np
from shutil import copyfile
29
from .ramanbase import RamanBase
30

Josef Brandt's avatar
Josef Brandt committed
31

32 33 34
class SimulatedRaman(RamanBase):
    magn = 20
    ramanParameters = {}
Josef Brandt's avatar
Josef Brandt committed
35

36
    def __init__(self, logger):
37
        super().__init__()
38
        self.name = 'SimulatedRaman' 
39
        self.logger = logger
40 41 42
        self.currentpos = None, 0., 0.
        self.currentZ = 0.
        # some plausible data to simulate consecutively changing positions
Josef Brandt's avatar
Josef Brandt committed
43 44 45 46 47
        self.positionlist = np.array([[-1201,  1376,  -1290],
                                      [-1195,  -1200,  -1279],
                                      [1097,  -1254,  -1297],
                                      [2704.1, 1288.2,  -1381],
                                      [1884., -1500.8,  -1381]])
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
        self.znum = 4
        self.gridnum = 36
        self.positionindex = 0
        self.imageindex = 0
        
    def getRamanPositionShift(self):
        return 0., 0.
        
    def connect(self):
        self.connected = True
        self.imageindex = 0
        return True
    
    def disconnect(self):
        self.connected = False
    
    def getPosition(self):
        if self.currentpos[0] is None:
            pos = self.positionlist[self.positionindex]
            self.positionindex = (self.positionindex+1)%len(self.positionlist)
        else:
            pos = self.currentpos
        return pos
    
    def getSoftwareZ(self):
        return self.currentpos[2]
    
    def getUserZ(self):
        assert self.connected
        if self.currentpos[0] is None:
            index = (self.positionindex-1)%len(self.positionlist)
            return self.positionlist[index][2]
        else:
            return self.currentZ
        
83
    def moveToAbsolutePosition(self, x, y, z=None, epsxy=0.11, epsz=0.011):
84
        assert self.connected
85
        self.logger.info(f'moving to: x: {x}, y: {y}, z: {z}')
86 87 88 89 90 91 92 93 94 95 96 97
        if z is None:
            self.currentpos = x, y, self.currentpos[2]        
        else:
            self.currentpos = x, y, z
        sleep(0.1)
        
    def moveZto(self, z, epsz=0.011):
        assert self.connected
        self.currentpos = self.currentpos[0], self.currentpos[1], z
        
    def saveImage(self, fname):
        assert self.connected
JosefBrandt's avatar
JosefBrandt committed
98 99 100
        cwd = os.getcwd()
        fakeImgPath = os.path.join(cwd, "gepard", "fakeData/image.bmp")
        copyfile(fakeImgPath, fname)
101 102 103 104
        self.imageindex = (self.imageindex+1)%(self.znum*self.gridnum)
        sleep(.01)
        
    def getImageDimensions(self, mode = 'df'):
105 106
        """ 
        Get the image width and height in um and the orientation angle in degrees.
107 108 109 110
        """
        assert self.connected
        width, height, angle = 463.78607177734375, 296.0336608886719, -0.04330849274992943
        return width, height, angle
Josef Brandt's avatar
Josef Brandt committed
111 112 113 114 115 116

    # IT IS NOT NEEDED, ISN'T IT??
    # def startSinglePointScan(self):
    #     assert self.connected
    #     self.logger.info("Fake scan")
    #     sleep(.3)
117
        
JosefBrandt's avatar
JosefBrandt committed
118
    def initiateMeasurement(self, ramanSettings):
119
        assert self.connected
120
        self.logger.info(f"Scanning {ramanSettings['numPoints']} particle positions")
JosefBrandt's avatar
JosefBrandt committed
121
        self.timeseries = ramanSettings['numPoints']
122
        sleep(.1)
Josef Brandt's avatar
Josef Brandt committed
123

124 125
    def triggerMeasurement(self, num):
        assert self.timeseries
126
        self.logger.info(f"Scan number: {num}")
127 128
        sleep(.1)
        if num==self.timeseries-1:
129
            self.timeseries = False
130 131 132

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