Ejemplo n.º 1
0
    def show_remote(self):
        """

        """
        dialog = QtWidgets.QDialog()
        vlayout = QtWidgets.QVBoxLayout()
        tree = ParameterTree()
        # tree.setMinimumWidth(400)
        tree.setMinimumHeight(500)
        tree.setParameters(self.remote_params, showTop=False)

        vlayout.addWidget(tree)
        dialog.setLayout(vlayout)
        buttonBox = QtWidgets.QDialogButtonBox(parent=dialog)

        buttonBox.addButton('Save', buttonBox.AcceptRole)
        buttonBox.accepted.connect(dialog.accept)
        buttonBox.addButton('Cancel', buttonBox.RejectRole)
        buttonBox.rejected.connect(dialog.reject)

        vlayout.addWidget(buttonBox)
        dialog.setWindowTitle(
            'Fill in information about the actions and their shortcuts')
        res = dialog.exec()

        if res == dialog.Accepted:
            # save preset parameters in a xml file
            custom_tree.parameter_to_xml_file(
                self.remote_params,
                os.path.join(remote_path,
                             self.remote_params.child(('filename')).value()))
Ejemplo n.º 2
0
    def show_overshoot(self):
        """

        """
        dialog = QtWidgets.QDialog()
        vlayout = QtWidgets.QVBoxLayout()
        tree = ParameterTree()
        tree.setMinimumWidth(400)
        tree.setMinimumHeight(500)
        tree.setParameters(self.overshoot_params, showTop=False)

        vlayout.addWidget(tree)
        dialog.setLayout(vlayout)
        buttonBox = QtWidgets.QDialogButtonBox(parent=dialog)

        buttonBox.addButton('Save', buttonBox.AcceptRole)
        buttonBox.accepted.connect(dialog.accept)
        buttonBox.addButton('Cancel', buttonBox.RejectRole)
        buttonBox.rejected.connect(dialog.reject)

        vlayout.addWidget(buttonBox)
        dialog.setWindowTitle('Fill in information about this managers')
        res = dialog.exec()

        if res == dialog.Accepted:
            # save managers parameters in a xml file
            #start = os.path.split(os.path.split(os.path.realpath(__file__))[0])[0]
            #start = os.path.join("..",'daq_scan')
            custom_tree.parameter_to_xml_file(
                self.overshoot_params,
                os.path.join(overshoot_path,
                             self.overshoot_params.child(
                                 ('filename')).value()))
Ejemplo n.º 3
0
    def set_new_roi(self, file=None):
        if file is None:
            file = 'roi_default'

        self.roi_presets = Parameter.create(name='roi_settings',
                                            type='group',
                                            children=[
                                                {
                                                    'title': 'Filename:',
                                                    'name': 'filename',
                                                    'type': 'str',
                                                    'value': file
                                                },
                                            ])

        for ind_det, det in enumerate(self.detector_modules):
            det_param = Parameter.create(name=f'det_{ind_det:03d}',
                                         type='group',
                                         children=[
                                             {
                                                 'title': 'Det Name:',
                                                 'name': 'detname',
                                                 'type': 'str',
                                                 'value': det.title
                                             },
                                         ])

            for ind_viewer, viewer in enumerate(det.ui.viewers):
                viewer_param = Parameter.create(
                    name=f'viewer_{ind_viewer:03d}',
                    type='group',
                    children=[
                        {
                            'title': 'Viewer:',
                            'name': 'viewername',
                            'type': 'str',
                            'value': det.ui.viewer_docks[ind_viewer].name()
                        },
                    ])

                if hasattr(viewer, 'roi_manager'):
                    viewer_param.addChild({
                        'title':
                        'ROI type:',
                        'name':
                        'roi_type',
                        'type':
                        'str',
                        'value':
                        viewer.roi_manager.settings.child(('ROIs')).roi_type
                    })
                    viewer_param.addChildren(
                        viewer.roi_manager.settings.child(('ROIs')).children())
                det_param.addChild(viewer_param)
            self.roi_presets.addChild(det_param)

        custom_tree.parameter_to_xml_file(self.roi_presets,
                                          os.path.join(roi_path, file))
        self.show_rois()
Ejemplo n.º 4
0
    def show_preset(self):
        """

        """
        dialog = QtWidgets.QDialog()
        vlayout = QtWidgets.QVBoxLayout()
        tree = ParameterTree()
        tree.setMinimumWidth(400)
        tree.setMinimumHeight(500)
        tree.setParameters(self.preset_params, showTop=False)

        vlayout.addWidget(tree)
        dialog.setLayout(vlayout)
        buttonBox = QtWidgets.QDialogButtonBox(parent=dialog)

        buttonBox.addButton('Save', buttonBox.AcceptRole)
        buttonBox.accepted.connect(dialog.accept)
        buttonBox.addButton('Cancel', buttonBox.RejectRole)
        buttonBox.rejected.connect(dialog.reject)

        vlayout.addWidget(buttonBox)
        dialog.setWindowTitle('Fill in information about this preset')
        res = dialog.exec()

        if self.pid_type:
            path = pid_path
        else:
            path = preset_path

        if res == dialog.Accepted:
            # save preset parameters in a xml file
            #start = os.path.split(os.path.split(os.path.realpath(__file__))[0])[0]
            #start = os.path.join("..",'daq_scan')
            custom_tree.parameter_to_xml_file(
                self.preset_params,
                os.path.join(path,
                             self.preset_params.child(('filename')).value()))

            if not self.pid_type:
                #check if overshoot configuration and layout configuration with same name exists => delete them if yes
                overshoot_path = os.path.join(local_path,
                                              'overshoot_configurations')
                file = os.path.splitext(
                    self.preset_params.child(('filename')).value())[0]
                file = os.path.join(overshoot_path, file + '.xml')
                if os.path.isfile(file):
                    os.remove(file)

                layout_path = os.path.join(local_path, 'layout')
                file = os.path.splitext(
                    self.preset_params.child(('filename')).value())[0]
                file = os.path.join(layout_path, file + '.dock')
                if os.path.isfile(file):
                    os.remove(file)
Ejemplo n.º 5
0
 def save_data(self):
     params = [
         {
             'title':
             'Axis options:',
             'name':
             'axes',
             'type':
             'group',
             'visible':
             False,
             'expanded':
             False,
             'children': [
                 {
                     'title':
                     'X axis:',
                     'name':
                     'xaxis',
                     'type':
                     'group',
                     'children': [
                         {
                             'title': 'Label:',
                             'name': 'xlabel',
                             'type': 'str',
                             'value': "x axis"
                         },
                         {
                             'title':
                             'Units:',
                             'name':
                             'xunits',
                             'type':
                             'str',
                             'value':
                             self.settings.child('xaxis', 'xunits').value()
                         },
                         {
                             'title':
                             'Offset:',
                             'name':
                             'xoffset',
                             'type':
                             'float',
                             'default':
                             0.,
                             'value':
                             self.settings.child('xaxis',
                                                 'xoffset').value()
                         },
                         {
                             'title':
                             'Scaling',
                             'name':
                             'xscaling',
                             'type':
                             'float',
                             'default':
                             1.,
                             'value':
                             self.settings.child('xaxis',
                                                 'dx_units').value() /
                             self.settings.child('xaxis', 'dx_fit').value()
                         },
                     ]
                 },
                 {
                     'title':
                     'Y axis:',
                     'name':
                     'yaxis',
                     'type':
                     'group',
                     'children': [
                         {
                             'title': 'Label:',
                             'name': 'ylabel',
                             'type': 'str',
                             'value': "x axis"
                         },
                         {
                             'title':
                             'Units:',
                             'name':
                             'yunits',
                             'type':
                             'str',
                             'value':
                             self.settings.child('yaxis', 'yunits').value()
                         },
                         {
                             'title':
                             'Offset:',
                             'name':
                             'yoffset',
                             'type':
                             'float',
                             'default':
                             0.,
                             'value':
                             self.settings.child('yaxis',
                                                 'yoffset').value()
                         },
                         {
                             'title':
                             'Scaling',
                             'name':
                             'yscaling',
                             'type':
                             'float',
                             'default':
                             1.,
                             'value':
                             self.settings.child('yaxis',
                                                 'dy_units').value() /
                             self.settings.child('yaxis', 'dy_fit').value()
                         },
                     ]
                 },
             ]
         },
     ]
     param_obj = Parameter.create(name='Axes_Settings',
                                  type='group',
                                  children=params)
     custom_tree.parameter_to_xml_file(
         param_obj, os.path.join(calib_path,
                                 os.path.split(self.fname)[1]))
     self.settings.child(('data_saved')).setValue(True)
     self.settings.child(('filepath')).setValue(
         os.path.join(calib_path,
                      os.path.split(self.fname)[1]))
Ejemplo n.º 6
0
    def parameter_tree_changed(self, param, changes):
        for param, change, data in changes:
            path = self.settings.childPath(param)
            if path is not None:
                childName = '.'.join(path)
            else:
                childName = param.name()
            if change == 'childAdded':
                pass

            elif change == 'value':
                if param.name() == 'show_det':
                    self.show_detector(data)

                elif param.name() == 'spectro_center_freq':
                    unit = self.settings.child('acq_settings', 'units').value()
                    if unit == 'nm':
                        center_wavelength = data
                    elif unit == 'cm-1':
                        center_wavelength = Ecmrel2Enm(
                            data,
                            self.settings.child('config_settings',
                                                'laser_wl').value())
                    elif unit == 'eV':
                        center_wavelength = eV2nm(data)

                    if int(self.spectro_wl * 100) != int(
                            100 * center_wavelength):  #comprison at 1e-2
                        self.spectro_wl = center_wavelength

                    self.update_axis()

                elif param.name() == 'units':
                    if self.settings.child(
                            'acq_settings',
                            'spectro_center_freq').value() > 0.000000001:
                        if data == 'nm':
                            self.settings.child(
                                'acq_settings',
                                'spectro_center_freq').setValue(
                                    self._spectro_wl)
                        elif data == 'cm-1':
                            self.settings.child(
                                'acq_settings',
                                'spectro_center_freq').setValue(
                                    Enm2cmrel(
                                        self._spectro_wl,
                                        self.settings.child(
                                            'config_settings',
                                            'laser_wl').value()))
                        elif data == 'eV':
                            self.settings.child(
                                'acq_settings',
                                'spectro_center_freq').setValue(
                                    nm2eV(self._spectro_wl))

                        self.set_status_center(
                            self.settings.child('acq_settings',
                                                'spectro_center_freq').value(),
                            self.settings.child('acq_settings',
                                                'units').value())

                elif param.name() == 'laser_wl_list':
                    if data is not None:
                        self.move_laser_wavelength(data)

                elif param.name() == 'laser_wl':
                    if data is not None:
                        self.move_laser_wavelength(data)
                        if int(data) == 0:
                            self.settings.child('acq_settings',
                                                'units').setValue('nm')
                            self.settings.child('acq_settings',
                                                'units').setOpts(readonly=True)
                        else:
                            self.settings.child(
                                'acq_settings',
                                'units').setOpts(readonly=False)
                        if data != 0:
                            self.set_manual_laser_wl(data)

                elif param.name() == 'exposure_ms':
                    self.set_exposure_ms(data)

                elif param.name() == 'do_calib':
                    if len(self.raw_data) != 0:
                        if data:
                            self.calib_dock = Dock('Calibration module')
                            self.dockarea.addDock(self.calib_dock)
                            self.calibration = Calibration(self.dockarea)
                            self.calib_dock.addWidget(self.calibration)

                            self.calibration.coeffs_calib.connect(
                                self.update_calibration)
                        else:
                            self.calib_dock.close()

                elif param.name() == 'save_calib':
                    filename = select_file(start_path=self.save_file_pathname,
                                           save=True,
                                           ext='xml')
                    if filename != '':
                        custom_tree.parameter_to_xml_file(
                            self.settings.child('calib_settings',
                                                'calib_coeffs'), filename)

                elif param.name() == 'load_calib':
                    filename = select_file(start_path=self.save_file_pathname,
                                           save=False,
                                           ext='xml')
                    if filename != '':
                        children = custom_tree.XML_file_to_parameter(filename)
                        self.settings.child(
                            'calib_settings', 'calib_coeffs').restoreState(
                                Parameter.create(
                                    title='Calibration coeffs:',
                                    name='calib_coeffs',
                                    type='group',
                                    children=children).saveState())



                elif param.name() in custom_tree.iter_children(self.settings.child('calib_settings', 'calib_coeffs')) \
                        or param.name() == 'use_calib':
                    if self.settings.child('calib_settings',
                                           'use_calib').value():
                        calib_coeffs = [
                            self.settings.child('calib_settings',
                                                'calib_coeffs',
                                                'third_calib').value(),
                            self.settings.child('calib_settings',
                                                'calib_coeffs',
                                                'second_calib').value(),
                            self.settings.child('calib_settings',
                                                'calib_coeffs',
                                                'slope_calib').value(),
                            self.settings.child('calib_settings',
                                                'calib_coeffs',
                                                'center_calib').value()
                        ]

                        self.update_center_frequency(
                            self.settings.child('calib_settings',
                                                'calib_coeffs',
                                                'center_calib').value())
                        self.settings.child('acq_settings',
                                            'spectro_center_freq').show()
                        self.settings.child(
                            'acq_settings',
                            'spectro_center_freq').setOpts(readonly=True)
                        self.status_center.setStyleSheet(
                            "background-color: green")
                        self.settings.child('acq_settings',
                                            'spectro_center_freq_txt').hide()
                        x_axis_pxls = np.linspace(0, self.raw_data[0].size - 1,
                                                  self.raw_data[0].size)
                        self.viewer_freq_axis['data'] = np.polyval(
                            calib_coeffs,
                            x_axis_pxls - np.max(x_axis_pxls) / 2)
                        self.update_axis()
                    else:
                        self.settings.child('acq_settings',
                                            'spectro_center_freq').hide()
                        self.settings.child('acq_settings',
                                            'spectro_center_freq_txt').show()
                        self.status_center.setStyleSheet(
                            "background-color: red")

            elif change == 'parent':
                pass