simulatedraman.py 4.15 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 25 26
# -*- 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
import numpy as np
from shutil import copyfile
27
from .ramanbase import RamanBase
28 29 30 31 32 33 34 35 36 37 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 117 118 119


class SimulatedRaman(RamanBase):
    magn = 20
    ramanParameters = {}
    def __init__(self):
        super().__init__()
        self.currentpos = None, 0., 0.
        self.currentZ = 0.
        # 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
        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
        
    def moveToAbsolutePosition(self, x, y, z=None, epsxy=0.11, epsz=0.011, debugReturn=False, measurementRunning=False):
        assert self.connected
        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
        copyfile(f"fakeData/image.bmp", fname)
        self.imageindex = (self.imageindex+1)%(self.znum*self.gridnum)
        sleep(.01)
        
    def getImageDimensions(self, mode = 'df'):
        """ 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)
        
    def initiateMeasurement(self, label, numberofscans, accumulations, integrtime):
        assert self.connected
        print("Scanning ",numberofscans, "particle positions")
        self.timeseries = numberofscans
        sleep(.1)
        
        
    def triggerMeasurement(self, num):
        assert self.timeseries
        print("Scan number:", num)
        sleep(.1)
        if num==self.timeseries-1:
120
            self.timeseries = False