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

24
__all__ = ["InstrumentControl", "defaultPath", "simulatedRaman", "SpecScanParameter"]
25

26
defaultPath = os.path.dirname(os.path.split(__file__)[0])
27

28
config = configparser.ConfigParser()
29
config.read(os.path.join(defaultPath, 'gepard.cfg'))
30

31
interface = "SIMULATED_RAMAN_CONTROL"
32

33

Josef Brandt's avatar
Josef Brandt committed
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
class SpecScanParameter(object):
    def __init__(self, name, dtype, default=None, minVal=None, maxVal=None, valList=None, openFileType=None):
        self.name = name
        self.dtype = dtype
        self.value = default
        self.minVal = minVal
        self.maxVal = maxVal
        self.valList = valList
        self.openFileType = openFileType

        if not self.hasValidType():
            print('erroreneous type in setting parameter:', self.dtype)

    def hasValidType(self):
        if self.dtype in ['int', 'double', 'checkBox', 'combobox', 'selectBtn']:
            return True
        else:
            return False

    def value_of(self, obj):
        if self.dtype in ['int', 'double']:
            return obj.value()
        elif self.dtype == 'checkBox':
            return obj.isChecked()
        elif self.dtype == 'combobox':
            return obj.currentText()
        elif self.dtype == 'selectBtn':
            return obj.text()


64 65
try: 
    defaultPath = config["Defaults"]["file_path"]
66
    print('default Path is now:', defaultPath)
67 68 69 70 71 72 73 74 75
except KeyError:
    pass

try:
    interface = config["Interface"]["raman_interface"]
except KeyError:
    pass

if interface == "SIMULATED_RAMAN_CONTROL":
Josef Brandt's avatar
Josef Brandt committed
76
    from .simulated.simulatedraman import SimulatedRaman
77
    InstrumentControl = SimulatedRaman
78 79
    print("WARNING: using only simulated raman control!")
    simulatedRaman = True
80
    
Raman's avatar
Raman committed
81
elif interface == "WITEC_CONTROL":
82
    from .WITecCOM import WITecCOM
83 84
    InstrumentControl = WITecCOM
    InstrumentControl.magn = int(config["General Microscope Setup"]["magnification"])    # not yet implemented in WITecCOM, but would probably be a good idea...
85
    simulatedRaman = False
86
    
87
elif interface == "RENISHAW_CONTROL":
88
    from .renishawcom import RenishawCOM
89 90
    InstrumentControl = RenishawCOM
    InstrumentControl.magn = int(config["General Microscope Setup"]["magnification"])
91 92 93
    try:
        bf_dims = config["Renishaw"]["img_size_BF"].split('*')
        df_dims = config["Renishaw"]["img_size_DF"].split('*')
94 95
        InstrumentControl.cam_bf_dims = [float(bf_dims[0]), float(bf_dims[1])]
        InstrumentControl.cam_df_dims = [float(df_dims[0]), float(df_dims[1])]
96 97
    except:
        print('Invalid image dimensions in config file!')
98 99 100 101
#    InstrumentControl.defaultMeasTemplate = config["Renishaw"]["defaultMeasTemplate"]
    InstrumentControl.measTemplatePath = config["Renishaw"]["measTemplatePath"]
    print(InstrumentControl.measTemplatePath)
    InstrumentControl.specScanParameters = InstrumentControl.updateSpecScanParameters(InstrumentControl, InstrumentControl.measTemplatePath)
102
            
103
    simulatedRaman = False
104

Josef Brandt's avatar
Josef Brandt committed
105 106
elif interface == "THERMO_FTIR":
    from .thermoFTIRCom import ThermoFTIRCom
107
    InstrumentControl = ThermoFTIRCom
Josef Brandt's avatar
Josef Brandt committed
108
    simulatedRaman = False