Exemplo n.º 1
0
    def commit_settings(self, param):
        """
            Activate parameters changes on the hardware.

            =============== ================================ ===========================
            **Parameters**   **Type**                          **Description**
            *param*          instance of pyqtgraph Parameter   the parameter to activate
            =============== ================================ ===========================

            See Also
            --------
            set_Mock_data
        """
        try:
            if param.name() in putils.iter_children(
                    self.settings.child(('cam_settings')), []):

                self.stop()
                while self.controller.is_acquiring_images:
                    self.stop()
                    QtWidgets.QApplication.processEvents()

                feature = self.controller.device.node_map.get_node(
                    param.name())
                interface_type = feature.node.principal_interface_type
                if interface_type == EInterfaceType.intfIInteger:
                    val = int((param.value() // param.opts['step']) *
                              param.opts['step'])
                else:
                    val = param.value()
                feature.value = val  #set the desired value
                param.setValue(feature.value)  # retrieve the actually set one

                #self.update_features()

                if param.name() in ['Height', 'Width', 'OffsetX', 'OffsetY']:
                    if param.name() in ['Height', 'Width'
                                        ] and not self.settings.child(
                                            'ROIselect', 'use_ROI').value():
                        self.width = self.controller.device.node_map.get_node(
                            'Width').value
                        self.height = self.controller.device.node_map.get_node(
                            'Height').value

                        self.data = np.zeros((self.height, self.width))

            if param.name() in putils.iter_children(
                    self.settings.child(('ROIselect')), []):

                while self.controller.is_acquiring_images:
                    QThread.msleep(50)
                    self.stop()
                    QtWidgets.QApplication.processEvents()

                self.set_ROI()

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
    def commit_settings(self, param):

        if param.name() not in putils.iter_children(
                self.settings.child(('stage_settings')), []):
            super().commit_settings(param)

        else:
            if param.name() == 'time_interval':
                self.stage._get_read()
                self.stage.set_time_interval(
                    Time(param.value(),
                         unit='m'))  # set time interval between pixels

            elif param.name() == 'show_navigator':
                self.emit_status(ThreadCommand('show_navigator'))
                self.emit_status(ThreadCommand('show_scanner'))
                param.setValue(False)

            elif param.name() in putils.iter_children(
                    self.settings.child('stage_settings', 'move_at'), []):
                pos_x = self.settings.child('stage_settings', 'move_at',
                                            'move_at_x').value()
                pos_y = self.settings.child('stage_settings', 'move_at',
                                            'move_at_y').value()
                self.move_at_navigator(pos_x, pos_y)
Exemplo n.º 3
0
    def commit_settings(self, param):

        if param.name() in iter_children(self.settings.child(('settings_client')), []):
            grabber_socket = \
                [client['socket'] for client in self.connected_clients if client['type'] == self.client_type][0]
            grabber_socket.send_string('set_info')

            path = get_param_path(param)[2:]  # get the path of this param as a list starting at parent 'infos'
            grabber_socket.send_list(path)

            # send value
            data = ioxml.parameter_to_xml_string(param)
            grabber_socket.send_string(data)
Exemplo n.º 4
0
def test_iter_children():
    child = mock.Mock()
    child.name.side_effect = [
        'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh'
    ]
    child.type.side_effect = [[], [], [], ['group'], [], [], []]
    child.children.side_effect = [[child, child, child]]
    param = mock.Mock()
    param.children.return_value = [child, child, child, child]

    childlist = utils.iter_children(param)

    assert childlist == [
        'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh'
    ]
Exemplo n.º 5
0
    def commit_settings(self, param):

        if param.name() in putils.iter_children(
                self.settings.child(('settings_client')), []):
            actuator_socket = [
                client['socket'] for client in self.connected_clients
                if client['type'] == 'ACTUATOR'
            ][0]
            actuator_socket.send_string('set_info')
            path = putils.get_param_path(param)[2:]
            # get the path of this param as a list starting at parent 'infos'

            actuator_socket.send_list(path)

            # send value
            data = ioxml.parameter_to_xml_string(param)
            actuator_socket.send_string(data)
Exemplo n.º 6
0
    def commit_settings(self,param):
        """
        Activate parameters changes on the hardware.
        """

        #here we update the hardware if parameters have been changed by the user

        #for instance:

        if param.name()=='conex_lib':
            #then init the dll on the new path defined by the parameter value
            #for instance call the update_dll method of the controller object, fake here:
            self.controller.update_dll(param.value())

        #here check if the name of the parameter is a child of the group_parameter parameter
        # the group_parameter is obtained from self.settings using the child method
        #iter_children returns a list of all parameter names that are children or subchildren of 'group_parameter'
        elif param.name() in iter_children(self.settings.child('group_parameter'),childlist=[]):
            #then do something on self.controller or something else!
            pass
Exemplo n.º 7
0
    def commit_settings(self, param):
        """
            Setting the mock data

            ============== ========= =================
            **Parameters**  **Type**  **Description**
            *param*         none      not used
            ============== ========= =================

            See Also
            --------
            set_Mock_data
        """
        if param.name() in iter_children(self.settings.child(('x_axis')), []):
            if param.name() == 'x0':
                self.get_spectro_wl()

            self.set_x_axis()
            self.emit_x_axis()

        else:
            self.set_Mock_data()
Exemplo n.º 8
0
    def load_ROI(self, path=None, params=None):
        try:
            if params is None:
                if path is None:
                    path = select_file(start_path=Path.home(),
                                       save=False,
                                       ext='xml')
                    if path != '':
                        params = Parameter.create(
                            title='Settings',
                            name='settings',
                            type='group',
                            children=ioxml.XML_file_to_parameter(path))

            if params is not None:
                self.clear_ROI()
                QtWidgets.QApplication.processEvents()

                for param in params:
                    if 'roi_type' in putils.iter_children(param, []):
                        self.settings.child(('ROIs')).addNew(
                            param.child(('roi_type')).value())
                    else:
                        self.settings.child(('ROIs')).addNew()
                # self.settings.child(('ROIs')).addChildren(params)
                QtWidgets.QApplication.processEvents()

                # settings = Parameter.create(title='Settings', name='settings', type='group')
                #
                # for param in params:
                #     settings.addChildren(custom_tree.XML_string_to_parameter(custom_tree.parameter_to_xml_string(param)))

                self.set_roi(self.settings.child(('ROIs')).children(), params)

        except Exception as e:
            pass
Exemplo n.º 9
0
    def roi_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':  # new roi to create
                par = data[0]
                newindex = int(par.name()[-2:])

                if par.child(('type')).value() == '1D':
                    roi_type = ''

                    pos = self.viewer_widget.plotItem.vb.viewRange()[0]
                    newroi = LinearROI(index=newindex, pos=pos)
                    newroi.setZValue(-10)
                    newroi.setBrush(par.child(('Color')).value())
                    newroi.setOpacity(0.2)

                elif par.child(('type')).value() == '2D':
                    roi_type = par.child(('roi_type')).value()
                    xrange = self.viewer_widget.plotItem.vb.viewRange()[0]
                    yrange = self.viewer_widget.plotItem.vb.viewRange()[1]
                    width = np.max(((xrange[1] - xrange[0]) / 10, 2))
                    height = np.max(((yrange[1] - yrange[0]) / 10, 2))
                    pos = [
                        int(np.mean(xrange) - width / 2),
                        int(np.mean(yrange) - width / 2)
                    ]

                    if roi_type == 'RectROI':
                        newroi = RectROI(index=newindex,
                                         pos=pos,
                                         size=[width, height])
                    else:
                        newroi = EllipseROI(index=newindex,
                                            pos=pos,
                                            size=[width, height])
                    newroi.setPen(par.child(('Color')).value())

                newroi.sigRegionChanged.connect(self.ROI_changed.emit)
                newroi.sigRegionChangeFinished.connect(
                    self.ROI_changed_finished.emit)
                newroi.index_signal[int].connect(self.update_roi_tree)
                try:
                    self.settings.sigTreeStateChanged.disconnect()
                except Exception:
                    pass
                self.settings.sigTreeStateChanged.connect(
                    self.roi_tree_changed)
                self.viewer_widget.plotItem.addItem(newroi)

                self.ROIs["ROI_%02.0d" % newindex] = newroi

                self.new_ROI_signal.emit(newindex, roi_type)
                self.update_roi_tree(newindex)

            elif change == 'value':
                if param.name() in putils.iter_children(
                        self.settings.child(('ROIs')), []):
                    if param.name() == 'Color' or param.name() == 'angle':
                        parent = param.parent().name()
                    else:
                        parent = param.parent().parent().name()
                    self.update_roi(parent, param)

            elif change == 'parent':
                if 'ROI' in param.name():
                    roi = self.ROIs.pop(param.name())
                    self.viewer_widget.plotItem.removeItem(roi)
                    self.remove_ROI_signal.emit(param.name())

            if param.name() != 'measurements':
                self.roi_settings_changed.emit([(param, 'value', param.value())
                                                ])
        self.ROI_changed_finished.emit()
Exemplo n.º 10
0
    def parameter_tree_changed(self, param, changes):
        """
            | Check eventual changes in the changes list parameter.
            |
            | In case of changed values, emit the signal containing the current path and parameter via update_settings_signal to the connected hardware.

            =============== ====================================    ==================================================
            **Parameters**   **Type**                                **Description**

             *param*         instance of pyqtgraph parameter         The parameter to be checked

             *changes*       (parameter,change,infos) tuple list     The (parameter,change,infos) list to be treated
            =============== ====================================    ==================================================
        """

        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':
                if 'main_settings' not in path:
                    self.update_settings_signal.emit(
                        edict(path=path,
                              param=data[0].saveState(),
                              change=change))

            elif change == 'value':

                if param.name() == 'connect_server':
                    if param.value():
                        self.connect_tcp_ip()
                    else:
                        self.command_tcpip.emit(ThreadCommand('quit'))

                elif param.name() == 'ip_address' or param.name == 'port':
                    self.command_tcpip.emit(
                        ThreadCommand(
                            'update_connection',
                            dict(ipaddress=self.settings.child(
                                'main_settings', 'tcpip',
                                'ip_address').value(),
                                 port=self.settings.child(
                                     'main_settings', 'tcpip',
                                     'port').value())))

                if path is not None:
                    if 'main_settings' not in path:
                        self.update_settings_signal.emit(
                            edict(path=path, param=param, change=change))
                        if self.settings.child('main_settings', 'tcpip',
                                               'tcp_connected').value():
                            self.command_tcpip.emit(
                                ThreadCommand('send_info',
                                              dict(path=path, param=param)))

            elif change == 'parent':
                if param.name() not in putils.iter_children(
                        self.settings.child('main_settings'), []):
                    self.update_settings_signal.emit(
                        edict(path=['move_settings'],
                              param=param,
                              change=change))
Exemplo n.º 11
0
    def parameter_tree_changed(self, param, changes):
        """
            Foreach value changed, update :
                * Viewer in case of **DAQ_type** parameter name
                * visibility of button in case of **show_averaging** parameter name
                * visibility of naverage in case of **live_averaging** parameter name
                * scale of axis **else** (in 2D pymodaq type)

            Once done emit the update settings signal to link the commit.

            =============== =================================== ================================================================
            **Parameters**    **Type**                           **Description**
            *param*           instance of ppyqtgraph parameter   the parameter to be checked
            *changes*         tuple list                         Contain the (param,changes,info) list listing the changes made
            =============== =================================== ================================================================
        """

        for param, change, data in changes:
            path = self.settings.childPath(param)
            if change == 'childAdded':
                pass

            elif change == 'value':
                if param.name() == 'model_class':
                    self.get_set_model_params(param.value())

                elif param.name() == 'refresh_plot_time' or param.name() == 'timeout':
                    self.command_pid.emit(ThreadCommand('update_timer', [param.name(), param.value()]))

                elif param.name() == 'sample_time':
                    self.command_pid.emit(ThreadCommand('update_options', dict(sample_time=param.value())))

                elif param.name() in putils.iter_children(
                        self.settings.child('main_settings', 'pid_controls', 'output_limits'), []):


                    output_limits = convert_output_limits(
                        self.settings.child('main_settings', 'pid_controls', 'output_limits',
                                            'output_limit_min').value(),
                        self.settings.child('main_settings', 'pid_controls', 'output_limits',
                                           'output_limit_min_enabled').value(),
                        self.settings.child('main_settings', 'pid_controls', 'output_limits',
                                                               'output_limit_max').value(),
                        self.settings.child('main_settings', 'pid_controls', 'output_limits',
                                           'output_limit_max_enabled').value())

                    self.command_pid.emit(ThreadCommand('update_options', dict(output_limits=output_limits)))

                elif param.name() in putils.iter_children(
                        self.settings.child('main_settings', 'pid_controls', 'pid_constants'), []):
                    Kp = self.settings.child('main_settings', 'pid_controls', 'pid_constants', 'kp').value()
                    Ki = self.settings.child('main_settings', 'pid_controls', 'pid_constants', 'ki').value()
                    Kd = self.settings.child('main_settings', 'pid_controls', 'pid_constants', 'kd').value()
                    self.command_pid.emit(ThreadCommand('update_options', dict(tunings=(Kp, Ki, Kd))))

                elif param.name() in putils.iter_children(self.settings.child('models', 'model_params'), []):
                    if self.model_class is not None:
                        self.model_class.update_settings(param)

                elif param.name() == 'detector_modules':
                    self.model_class.update_detector_names()

            elif change == 'parent':
                pass
    def commit_settings(self, param):
        """
            | Activate parameters changes on the hardware from parameter's name.
            |

            =============== ================================    =========================
            **Parameters**   **Type**                           **Description**
            *param*          instance of pyqtgraph parameter    The parameter to activate
            =============== ================================    =========================

            Three profile of parameter :
                * **bin_x** : set binning camera from bin_x parameter's value
                * **bin_y** : set binning camera from bin_y parameter's value
                * **set_point** : Set the camera's temperature from parameter's value.

        """
        try:
            if param.name() == 'mult2':
                if param.value():
                    self.mult_image()
                    param.setValue(False)
                Nx = self.settings.child('stem_settings', 'pixels_settings',
                                         'Nx').value()
                Ny = self.settings.child('stem_settings', 'pixels_settings',
                                         'Ny').value()
                self.settings.child('stem_settings', 'spot_settings',
                                    'spot_x').setOpts(bounds=(0, Nx - 1))
                self.settings.child('stem_settings', 'spot_settings',
                                    'spot_y').setOpts(bounds=(0, Ny - 1))

            if param.name() == 'div2':
                if param.value():
                    self.divide_image()
                    param.setValue(False)
                Nx = self.settings.child('stem_settings', 'pixels_settings',
                                         'Nx').value()
                Ny = self.settings.child('stem_settings', 'pixels_settings',
                                         'Ny').value()
                self.settings.child('stem_settings', 'spot_settings',
                                    'spot_x').setOpts(bounds=(0, Nx - 1))
                self.settings.child('stem_settings', 'spot_settings',
                                    'spot_y').setOpts(bounds=(0, Ny - 1))

            elif param.name() == 'input1' or param.name() == 'input2':
                input1 = self.settings.child('stem_settings', 'inputs',
                                             'input1').value()
                input2 = self.settings.child('stem_settings', 'inputs',
                                             'input2').value()
                self.stem_scan.SetInputs(
                    [self.inputs.index(input1),
                     self.inputs.index(input2)])
                self.spim_scan.SetInputs(
                    [self.inputs.index(input1),
                     self.inputs.index(input2)])

            elif param.name() == 'Nx' or param.name() == 'Ny':
                self.init_data(
                    self.settings.child('stem_settings', 'pixels_settings',
                                        'Nx').value(),
                    self.settings.child('stem_settings', 'pixels_settings',
                                        'Ny').value())
                Nx = self.settings.child('stem_settings', 'pixels_settings',
                                         'Nx').value()
                Ny = self.settings.child('stem_settings', 'pixels_settings',
                                         'Ny').value()
                self.settings.child('stem_settings', 'spot_settings',
                                    'spot_x').setOpts(bounds=(0, Nx - 1))
                self.settings.child('stem_settings', 'spot_settings',
                                    'spot_y').setOpts(bounds=(0, Ny - 1))

            elif param.name() in putils.iter_children(
                    self.settings.child('stem_settings', 'times'), []):
                self.stem_scan.pixelTime = param.value() / 1e6

            elif param.name() == 'angle':
                self.stem_scan.setScanRotation(
                    self.settings.child('stem_settings', 'mag_rot',
                                        'angle').value())
                self.get_set_field()
            elif param.name() == 'field':
                self.get_set_field()

            elif param.name() == 'do_hyperspectroscopy':
                if param.value():
                    data_stem_STEM_as_reference = self.data_stem.reshape(
                        (2, self.SIZEX, self.SIZEY)).astype(np.float64)
                    self.data_stem_STEM_as_reference = [
                        DataFromPlugins(name=self.settings.child(
                            'stem_settings', 'inputs', 'input1').value(),
                                        data=[data_stem_STEM_as_reference[0]],
                                        dim='Data2D'),
                        DataFromPlugins(name=self.settings.child(
                            'stem_settings', 'inputs', 'input2').value(),
                                        data=[data_stem_STEM_as_reference[1]],
                                        dim='Data2D'),
                    ]

                # init the viewers
                self.emit_data_init()

                if self.is_Orsay_camera:
                    self.settings.child(
                        ('hyperspectroscopy')).show(param.value())
                    if param.value():
                        self.settings.child(('ROIselect')).show(True)
                        self.settings.child('ROIselect',
                                            'use_ROI').setValue(True)
                        self.settings.child('ROIselect',
                                            'use_ROI').setOpts(readonly=True)

                        QtWidgets.QApplication.processEvents()
                        self.init_data()

                        # init the viewers type
                        self.emit_data_temp([
                            DataFromPlugins(name='SPIM ',
                                            data=[np.zeros((1024, 10, 10))],
                                            dim='DataND'),
                            # data from SPIM camera
                            DataFromPlugins(name='Spectrum',
                                            data=[np.zeros((1024, ))],
                                            dim='Data1D')
                        ])
                    else:
                        self.settings.child('ROIselect',
                                            'use_ROI').setOpts(readonly=False)
                        if self.camera is None:
                            # remove viewers related to camera
                            self.emit_data_temp()

            elif param.name() in putils.iter_children(
                    self.settings.child(('hyperspectroscopy')),
                []):  # parameters related to camera
                if self.camera is not None:
                    self.camera.commit_settings(param)

        except Exception as e:
            self.emit_status(
                ThreadCommand('Update_Status',
                              [getLineInfo() + str(e), 'log']))
Exemplo n.º 13
0
    def parameter_tree_changed(self, param, changes):
        """
            Foreach value changed, update :
                * Viewer in case of **DAQ_type** parameter name
                * visibility of button in case of **show_averaging** parameter name
                * visibility of naverage in case of **live_averaging** parameter name
                * scale of axis **else** (in 2D pymodaq type)

            Once done emit the update settings signal to link the commit.

            =============== =================================== ================================================================
            **Parameters**    **Type**                           **Description**
            *param*           instance of ppyqtgraph parameter   the parameter to be checked
            *changes*         tuple list                         Contain the (param,changes,info) list listing the changes made
            =============== =================================== ================================================================
        """

        for param, change, data in changes:
            path = self.settings.childPath(param)
            if change == 'childAdded':
                pass

            elif change == 'value':
                if param.name() == 'model_class':
                    self.get_set_model_params(param.value())

                elif param.name() == 'module_settings':
                    if param.value():
                        self.settings.sigTreeStateChanged.disconnect(self.parameter_tree_changed)
                        param.setValue(False)
                        self.settings.sigTreeStateChanged.connect(self.parameter_tree_changed)
                        self.preset_manager.set_PID_preset(self.settings.child('models', 'model_class').value())

                elif param.name() == 'refresh_plot_time' or param.name() == 'timeout':
                    self.command_pid.emit(ThreadCommand('update_timer', [param.name(), param.value()]))

                elif param.name() == 'set_point':
                    if self.pid_led.state:
                        self.command_pid.emit(ThreadCommand('update_options', dict(setpoint=param.value())))
                    else:
                        output = self.model_class.convert_output(param.value(), 0, stab=False)
                        for ind_act, act in enumerate(self.actuator_modules):
                            act.move_Abs(output[ind_act])

                elif param.name() == 'sample_time':
                    self.command_pid.emit(ThreadCommand('update_options', dict(sample_time=param.value())))

                elif param.name() in putils.iter_children(
                        self.settings.child('main_settings', 'pid_controls', 'output_limits'), []):
                    output_limits = [None, None]
                    if self.settings.child('main_settings', 'pid_controls', 'output_limits',
                                           'output_limit_min_enabled').value():
                        output_limits[0] = self.settings.child('main_settings', 'pid_controls', 'output_limits',
                                                               'output_limit_min').value()
                    if self.settings.child('main_settings', 'pid_controls', 'output_limits',
                                           'output_limit_max_enabled').value():
                        output_limits[1] = self.settings.child('main_settings', 'pid_controls', 'output_limits',
                                                               'output_limit_max').value()

                    self.command_pid.emit(ThreadCommand('update_options', dict(output_limits=output_limits)))

                elif param.name() in putils.iter_children(
                        self.settings.child('main_settings', 'pid_controls', 'filter'), []):
                    self.command_pid.emit(ThreadCommand('update_filter',
                                                        [dict(
                                                            enable=self.settings.child('main_settings', 'pid_controls',
                                                                                       'filter',
                                                                                       'filter_enable').value(),
                                                            value=self.settings.child('main_settings', 'pid_controls',
                                                                                      'filter',
                                                                                      'filter_step').value())]))

                elif param.name() in putils.iter_children(
                        self.settings.child('main_settings', 'pid_controls', 'pid_constants'), []):
                    Kp = self.settings.child('main_settings', 'pid_controls', 'pid_constants', 'kp').value()
                    Ki = self.settings.child('main_settings', 'pid_controls', 'pid_constants', 'ki').value()
                    Kd = self.settings.child('main_settings', 'pid_controls', 'pid_constants', 'kd').value()
                    self.command_pid.emit(ThreadCommand('update_options', dict(tunings=(Kp, Ki, Kd))))

                elif param.name() in putils.iter_children(self.settings.child('models', 'model_params'), []):
                    self.model_class.update_settings(param)

                elif param.name() == 'detector_modules':
                    self.model_class.update_detector_names()

            elif change == 'parent':
                pass