def update_axis(self):
     axis = utils.Axis()
     unit = self.settings.child('acq_settings', 'units').value()
     if unit == 'nm':
         axis['data'] = self.viewer_freq_axis['data']
     elif unit == 'cm-1':
         axis['data'] = Enm2cmrel(
             self.viewer_freq_axis['data'],
             self.settings.child('config_settings', 'laser_wl').value())
     elif unit == 'eV':
         axis['data'] = nm2eV(self.viewer_freq_axis['data'])
     axis['units'] = unit
     axis['label'] = 'Photon energy'
     self.viewer.x_axis = axis
    def update_center_frequency(self, spectro_wl):
        self._spectro_wl = spectro_wl
        if self.settings.child('acq_settings', 'units').value() == 'nm':
            self.settings.child('acq_settings',
                                'spectro_center_freq').setValue(spectro_wl)
        elif self.settings.child('acq_settings', 'units').value() == 'cm-1':
            self.settings.child('acq_settings',
                                'spectro_center_freq').setValue(
                                    Enm2cmrel(
                                        spectro_wl,
                                        self.settings.child(
                                            'config_settings',
                                            'laser_wl').value()))
        elif self.settings.child('acq_settings', 'units').value() == 'eV':
            self.settings.child('acq_settings',
                                'spectro_center_freq').setValue(
                                    nm2eV(spectro_wl))

        self.set_status_center(
            self.settings.child('acq_settings', 'spectro_center_freq').value(),
            self.settings.child('acq_settings', 'units').value())
Exemple #3
0
 def test_nm2eV(self):
     assert utils.nm2eV(800) == pytest.approx(1.54980259)
    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