simulatedraman.py 3.98 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 24
# -*- 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
"""

from time import sleep
25
import numpy as np
26
from shutil import copyfile
27
from ramancom.ramanbase import RamanBase
28 29 30


class SimulatedRaman(RamanBase):
31 32
    magn = 20
    ramanParameters = {}
33 34 35 36
    def __init__(self):
        super().__init__()
        self.currentpos = None, 0., 0.
        self.currentZ = 0.
37 38 39 40 41 42 43 44
        # some plausible data to simulate consecutively changing positions
        self.positionlist = np.array([[ 1526. , -1379.9,  -131. ],
                                      [ 3762.5, -1197.7,  -138.1],
                                      [ 2313.7, -2627.2,  -138.1],
                                      [ 2704.1, -1788.2,  -138.1],
                                      [ 3884. , -2650.8,  -138.1]])
        self.znum = 4
        self.gridnum = 36
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
        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:
            return self.positionlist[self.positionindex][2]
        else:
            return self.currentZ
        
77
    def moveToAbsolutePosition(self, x, y, z=None, epsxy=0.11, epsz=0.011, debugReturn=False, measurementRunning=False):
78 79 80 81 82
        assert self.connected
        if z is None:
            self.currentpos = x, y, self.currentpos[2]        
        else:
            self.currentpos = x, y, z
83
        sleep(0.1)
84 85 86 87 88 89 90
        
    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
91
        copyfile(f"fakeData/image.bmp", fname)
92 93 94
        self.imageindex = (self.imageindex+1)%(self.znum*self.gridnum)
        sleep(.01)
        
95
    def getImageDimensions(self, mode = 'df'):
96 97 98 99 100 101 102 103 104 105 106
        """ Get the image width and height in um and the orientation angle in degrees.
        """
        assert self.connected
        width, height, angle = 463.78607177734375, 296.0336608886719, -0.04330849274992943
        return width, height, angle
    
    def startSinglePointScan(self):
        assert self.connected
        print("Fake scan")
        sleep(.3)
        
107
    def initiateMeasurement(self, label, numberofscans, accumulations, integrtime):
108 109 110
        assert self.connected
        print("Scanning ",numberofscans, "particle positions")
        self.timeseries = numberofscans
111
        sleep(.1)
112 113
        
        
114
    def triggerMeasurement(self, num):
115
        assert self.timeseries
116
        print("Scan number:", num)
117
        sleep(.1)
118 119
        if num==self.timeseries-1:
            self.timeseries = False