Пример #1
0
def get_class(string):
    """
    Returns class by interpreting input string as module path and class name.
    Module path should be separated by dots as usual. Separate class name from module by '/'.
    Example: my_class = get_class('hyperion.controller.example_controller/ExampleController')

    :param string: string containing module path and class name separated by '/'
    :return: class
    """
    logger = logman.getLogger(__name__)
    if '/' not in string:
        logger.error("The string is not properly formatted. Use '/' to separate module path from classname. String is: {}".format(string))
        return
    module_name, class_name = string.split('/')
    try:
        logger.debug('Retrieving class {} from module {}'.format(class_name, module_name))
        temp_class = getattr(importlib.import_module(module_name), class_name)
    except ModuleNotFoundError:
        logger.error("Module not found: {}".format(module_name))
        raise
    except AttributeError:
        logger.error("Class not found: {}".format(class_name))
        raise
    except:
        logger.error("Unexpected error while loading {}".format(string))
        raise

    return temp_class
    def __init__(self, example_instr, output_gui=None, also_close_output=True):
        super().__init__()
        self.logger = logman.getLogger(__name__)
        self.also_close_output = also_close_output
        self.example_instr = example_instr

        # if output_gui is dict, just grab the first value
        if type(output_gui) is dict:
            self.imv = list(output_gui.values())[0]
        else:
            self.imv = output_gui

        colors = [
            (0, 0, 0),
            (45, 5, 61),
            (84, 42, 55),
            (150, 87, 60),
            (208, 171, 141),
            (255, 255, 255)
        ]
        cmap = pg.ColorMap(pos=np.linspace(0.0, 1.0, 6), color=colors)
        self.imv.setColorMap(cmap)

        self.title = 'Example Gui'
        self.left = 40
        self.top = 40
        self.width = 320
        self.height = 200
        self.initUI()

        self.cont_plot_timer = QTimer()
        self.cont_plot_timer.timeout.connect(self.show_one_plot)
Пример #3
0
 def __init__(self, actiondict, experiment = None, parent = None):
     self.logger = logman.getLogger(__name__)
     self.logger.debug('Creating Power Meter Gui')
     super().__init__(parent)
     self.actiondict = actiondict
     self.experiment = experiment
     self.initUI()
     self.setLayout(self.layout)
Пример #4
0
    def __init__(self, settings, sub_instruments):
        """ init of the class"""
        super().__init__(settings, sub_instruments)
        self.logger = logging.getLogger(__name__)
        self.logger.info('Class ExampleMetaInstrument created.')

        self.x = sub_instruments['x']
        self.y = sub_instruments['y']
        self.z = sub_instruments['z']
    def __init__(self, actiondict, experiment=None, parent=None):
        self.logger = logman.getLogger(__name__)
        self.logger.debug('Creating SpectrumWithFilters Gui')
        super().__init__(parent)
        self.actiondict = actiondict
        self.experiment = experiment
        self.last_row = 0

        self.initUI()
        self.setLayout(self.layout)
Пример #6
0
 def __init__(self, actiondict, experiment=None, parent=None):
     # Note that actiondict is of type ActionDict, which returns default values from the corresponding ActionType if
     # the value is not available in the Action itself and returns None if the key is not available at all.
     self.logger = logman.getLogger(__name__)
     self.logger.debug('Creating ImageWithFilters Gui')
     super().__init__(parent)
     self.actiondict = actiondict
     self.experiment = experiment
     self.initUI()
     self.setLayout(self.layout)
    def __init__(self, settings):
        """ Init of the class.

        :param settings: this includes all the settings needed to connect to the device in question.
        :type settings: dict

        """
        super().__init__(settings)  # mandatory line
        self.logger = logging.getLogger(__name__)
        self.logger.info('Class ExampleController created.')
        self.name = 'Example Controller'

        self._amplitude = []
Пример #8
0
    def __init__(self, actiondict, experiment = None, parent = None):
        self.logger = logman.getLogger(__name__)
        self.logger.debug('Creating ScanMicroPositioner gui')
        super().__init__(parent)
        self.actiondict = actiondict
        self.experiment = experiment

        # # To load a ui file:
        # uic.loadUi(path_to_file, self)

        # # or maybe like this:
        # gui = QWidget()
        # uic.loadUi(path_to_file, gui)

        self.initUI()
        self.setLayout(self.layout)
    def __init__(self, example_instr, output_gui=None, also_close_output=True):
        super().__init__()
        self.logger = logman.getLogger(__name__)
        self.also_close_output = also_close_output
        self.example_instr = example_instr
        self.output_gui = output_gui
        if self.output_gui is None:
            self.curve = lambda *args, **kwargs: None
        else:
            self.curve = self.output_gui.plot() # initialize plot
        # self.output_gui.show_dock = lambda *args, **kwargs: None  # this will be overwritten by ExpGui
        self.title = 'Example Gui'
        self.left = 40
        self.top = 40
        self.width = 320
        self.height = 200
        self.initUI()

        self.cont_plot_timer = QTimer()
        self.cont_plot_timer.timeout.connect(self.show_one_plot)
Пример #10
0
    def __init__(self, actiondict, experiment = None, parent = None):
        self.logger = logman.getLogger(__name__)
        self.logger.debug('Creating saver gui')
        super().__init__(parent)
        self.actiondict = actiondict
        self.experiment = experiment

        # Add incrementer method to experiment so that it can call the incrementer after a measurement finished.
        # This is not strictly necessary (the experiment class will increment by itself if auto_increment is set),
        # but it's nices for the user if the name updates.
        self.experiment._saver_gui_incremeter = self.apply_incrementer

        # # To load a ui file:
        # uic.loadUi(path_to_file, self)

        # # or maybe like this:
        # gui = QWidget()
        # uic.loadUi(path_to_file, gui)

        self.initUI()
        self.setLayout(self.layout)
    def __init__(self, example_ins, output_gui_dict, also_close_output=True):
        super().__init__()
        self.logger = logman.getLogger(__name__)
        self.also_close_output = also_close_output
        self.output_gui_dict = output_gui_dict
        if type(self.output_gui_dict) is not dict:
            self.logger.error('This example needs a dictionary of visualization guis')

        self.plot_a = self.output_gui_dict['Spectrum'].plot()
        self.plot_b = self.output_gui_dict['Power'].plot()

        self.title = 'Example Gui Multiple Plots'
        self.left = 40
        self.top = 40
        self.width = 320
        self.height = 200
        self.example_ins = example_ins
        self.initUI()

        self.cont_plot_timer = QTimer()
        self.cont_plot_timer.timeout.connect(self.show_plot_b)
Пример #12
0
    def __init__(self, instr, also_close_output=True):
        super().__init__()
        self.logger = logman.getLogger(__name__)
        self.also_close_output = also_close_output
        self.instr = instr

        self.instr.blanking(True)

        # load the UI file
        name = 'aotf_instrument.ui'
        gui_folder = os.path.dirname(os.path.abspath(__file__))
        gui_file = os.path.join(gui_folder, name)
        self.logger.debug('Loading the GUI file: {}'.format(gui_file))
        self.gui = uic.loadUi(gui_file, self)

        self.mode = 'internal'
        self.wavelength = 532 * ur('nm')
        self.delta_wavelength = 1 * ur('nm')
        self.power = 20
        self.enable = False

        self.initUI()
Пример #13
0
 def __init__(self, settings):
     """ init of the class"""
     super().__init__(settings)
     self.logger = logging.getLogger(__name__)
     self.logger.info('Class ExampleInstrument created.')
     self.initialize()  # An Instrument should initialize at instantiation
Пример #14
0
 def __init__(self):
     super().__init__()                      # Mandatory line
     self.logger = logman.getLogger(__name__)
     self.display_name = 'Hyperion Example Experiment'  # Title of the experimental setup
Пример #15
0
    def apply_wavelength(self):
        self.logger.debug(
            'Applying the wavelength calibration and doing stuff in instrument'
        )
        self.instr.set_wavelength(self.wavelength, self.power, self.enable,
                                  self.mode)


if __name__ == '__main__':
    from os import path
    from PyQt5.QtGui import QIcon
    from hyperion.instrument.polarization.aa_aotf import AaAotf
    from hyperion import package_path

    log = logman.getLogger(__name__)

    with AaAotf(
            settings={
                'port': 'COM8',
                'dummy': False,
                'controller':
                'hyperion.controller.aa.aa_modd18012/AaModd18012',
                'apply defaults': False
            }) as aotf:

        app = QApplication(sys.argv)
        app.setWindowIcon(
            QIcon(path.join(package_path, 'view', 'logo_hyperion.png')))
        ex = AotfInstrumentGui(aotf)
        sys.exit(app.exec_())