# -*- coding: utf-8 -*- """ GEPARD - Gepard-Enabled PARticle Detection Copyright (C) 2018 Lars Bittrich and Josef Brandt, Leibniz-Institut für Polymerforschung Dresden e. V. 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 . Simualted Raman interface module for testing without actual raman system connected """ import sys, os stdout = sys.stdout from time import sleep import numpy as np from shutil import copyfile from .ramanbase import RamanBase class SimulatedRaman(RamanBase): magn = 20 ramanParameters = {} def __init__(self, logger): super().__init__() self.name = 'SimulatedRaman' self.logger = logger self.currentpos = None, 0., 0. self.currentZ = 0. # some plausible data to simulate consecutively changing positions self.positionlist = np.array([[-1201, 1376, -1290], [-1195, -1200, -1279], [1097, -1254, -1297], [2704.1, 1288.2, -1381], [1884., -1500.8, -1381]]) 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): assert self.connected self.logger.info(f'moving to: x: {x}, y: {y}, z: {z}') 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 cwd = os.getcwd() fakeImgPath = os.path.join(cwd, "gepard", "fakeData/image.bmp") copyfile(fakeImgPath, 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 # IT IS NOT NEEDED, ISN'T IT?? # 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) if num==self.timeseries-1: self.timeseries = False def finishMeasurement(self, aborted=False): self.logger.info('measurement was aborted')