Esempio n. 1
0
    def process_roi_lineouts(self, roi_dict):
        roi_dict = self.scale_lineout_dicts(roi_dict)
        self.view.display_roi_lineouts(roi_dict)

        self.measure_data_dict = dict([])
        for roi_key, lineout_data in roi_dict.items():
            if not self._display_temporary:
                self.data_to_export['data1D'][f'{self.title}_Hlineout_{roi_key}'] = \
                    utils.DataToExport(name=self.title, data=lineout_data.hor_data, source='roi',
                                       x_axis=utils.Axis(data=lineout_data.hor_axis,
                                                         units=self.x_axis.axis_units,
                                                         label=self.x_axis.axis_label))

                self.data_to_export['data1D'][f'{self.title}_Vlineout_{roi_key}'] = \
                    utils.DataToExport(name=self.title, data=lineout_data.ver_data, source='roi',
                                       x_axis=utils.Axis(data=lineout_data.ver_axis,
                                                         units=self.y_axis.axis_units,
                                                         label=self.y_axis.axis_units))

                self.data_to_export['data0D'][f'{self.title}_Integrated_{roi_key}'] = \
                    utils.DataToExport(name=self.title, data=lineout_data.int_data, source='roi', )

            self.measure_data_dict[f'{roi_key}:'] = lineout_data.int_data

            QtWidgets.QApplication.processEvents()

        self.view.roi_manager.settings.child('measurements').setValue(
            self.measure_data_dict)
        if not self._display_temporary:
            self.data_to_export_signal.emit(self.data_to_export)
        self.ROI_changed.emit()
Esempio n. 2
0
    def show_data(self, datas, labels=None, x_axis=None):
        try:
            self.datas = datas
            self.update_labels(self.labels)

            self.data_to_export = OrderedDict(name=self.title,
                                              data0D=OrderedDict(),
                                              data1D=OrderedDict(),
                                              data2D=None)
            for ind, data in enumerate(datas):
                self.data_to_export['data1D']['CH{:03d}'.format(
                    ind)] = utils.DataToExport()

            if self.plot_channels == [] or self.plot_channels is None:  #initialize data and plots
                self.ini_data_plots(len(datas))

            elif len(self.plot_channels) != len(datas):
                self.remove_plots()
                self.ini_data_plots(len(datas))

            self.update_graph1D(datas)

            if x_axis is not None:
                self.x_axis = x_axis

            if labels is not None:
                self.update_labels(labels)

            if self.ui.do_measurements_pb.isChecked():
                self.update_measurement_module()

        except Exception as e:
            self.update_status(str(e), wait_time=self.wait_time)
Esempio n. 3
0
    def update_Graph1D(self, datas):
        try:
            data_tot = []
            L = len(self.datas[0]) + 1
            if L > self.Nsamples:
                self.x_axis += 1
            else:
                self.x_axis = np.linspace(0, L - 1, L)
            for ind_plot, data in enumerate(datas):
                data_tmp = self.datas[ind_plot]
                data_tmp = np.append(data_tmp, data)

                if len(data_tmp) > self.Nsamples:
                    data_tmp = data_tmp[L - self.Nsamples:]

                data_tot.append(data_tmp)

                self.plot_channels[ind_plot].setData(x=self.x_axis, y=data_tmp)
                self.data_to_export['data0D']['CH{:03d}'.format(ind_plot)] = utils.DataToExport(name=self.title,
                                                                                                data=data[0],
                                                                                                source='raw')
            self.datas = data_tot

            self.data_to_export['acq_time_s'] = datetime.datetime.now().timestamp()
            self.data_to_export_signal.emit(self.data_to_export)

        except Exception as e:
            self.update_status(str(e), self.wait_time)
Esempio n. 4
0
    def test_update_graph1D(self, init_prog):
        prog = init_prog

        datas = np.linspace(np.linspace(1, 10, 10), np.linspace(11, 20, 10), 2)

        prog.datas = datas
        prog.update_labels(prog.labels)
        prog.data_to_export = OrderedDict(name=prog.title, data0D=OrderedDict(), data1D=OrderedDict(), data2D=None)
        for ind, data in enumerate(datas):
            prog.data_to_export['data1D']['CH{:03d}'.format(ind)] = utils.DataToExport()

        prog.ini_data_plots(len(datas))

        prog.zoom_plot = []
        for ind, data in enumerate(datas):
            channel = prog.ui.Graph_zoom.plot()
            channel.setPen(prog.plot_colors[ind])
            prog.zoom_plot.append(channel)

        prog.ui.zoom_pb.setChecked(True)
        prog.ui.Do_math_pb.setChecked(True)
        prog.ui.scatter.setChecked(True)

        prog.update_graph1D(datas)

        x_axis = np.linspace(0, len(datas[0]), len(datas[0]), endpoint=False)

        assert np.array_equal(prog.x_axis, x_axis)

        for ind, data in enumerate(datas):
            data1D = prog.data_to_export['data1D']['CH{:03d}'.format(ind)]
            dx_axis = data1D['x_axis']

            assert np.array_equal(prog.plot_channels[ind].getData()[0], prog.x_axis)
            assert np.array_equal(prog.plot_channels[ind].getData()[1], data)
            assert np.array_equal(prog.zoom_plot[ind].getData()[0], prog.x_axis)
            assert np.array_equal(prog.zoom_plot[ind].getData()[1], data)
            assert data1D['name'] == prog.title
            assert np.array_equal(data1D['name'], prog.title)
            assert np.array_equal(dx_axis['data'], prog.x_axis)
            assert np.array_equal(dx_axis['units'], prog.axis_settings['units'])
            assert np.array_equal(dx_axis['label'], prog.axis_settings['label'])

        assert np.array_equal(prog.measurement_dict['datas'], datas)
        assert np.array_equal(prog.measurement_dict['x_axis'], prog.x_axis)

        datas = np.linspace(np.linspace(1, 10, 5), np.linspace(11, 20, 5), 2)
        prog.datas = datas

        prog.ui.xyplot_action.setChecked(True)

        prog.update_graph1D(datas)

        x_axis = np.linspace(0, len(datas[0]), len(datas[0]), endpoint=False)

        assert np.array_equal(prog.x_axis, x_axis)
        assert not prog.plot_channels[1].getData()[0]
        assert not prog.plot_channels[1].getData()[1]
        assert np.array_equal(prog.plot_channels[0].getData()[0], datas[0])
        assert np.array_equal(prog.plot_channels[0].getData()[1], datas[1])
Esempio n. 5
0
 def show_measurement(self, data_meas):
     ind_offset = len(self.data_to_export['data0D'])
     for ind, res in enumerate(data_meas):
         self.measure_data_dict["Meas.{}:".format(ind)] = res
         self.data_to_export['data0D']['Measure_{:03d}'.format(ind + ind_offset)] =\
             utils.DataToExport(name=self.title, data=res, source='roi')
     self.roi_manager.settings.child('measurements').setValue(
         self.measure_data_dict)
     self.data_to_export['acq_time_s'] = datetime.datetime.now().timestamp()
     self.data_to_export_signal.emit(self.data_to_export)
Esempio n. 6
0
    def show_math(self, data_lo):
        # self.data_to_export=OrderedDict(x_axis=None,y_axis=None,z_axis=None,data0D=None,data1D=None,data2D=None)
        if len(data_lo) != 0:
            for ind, key in enumerate(self.lo_items):
                self.measure_data_dict["Lineout_{:s}:".format(
                    key)] = data_lo[ind]
                self.data_to_export['data0D']['Measure_{:03d}'.format(
                    ind)] = utils.DataToExport(name=self.title,
                                               data=data_lo[ind],
                                               source='roi')
            self.roi_manager.settings.child(
                ('measurements')).setValue(self.measure_data_dict)

            for ind, key in enumerate(self.lo_items):
                self.lo_data[key] = np.append(self.lo_data[key], data_lo[ind])
                self.lo_items[key].setData(y=self.lo_data[key])

        if not (self.ui.do_measurements_pb.isChecked()
                ):  # otherwise you export data from measurement
            self.data_to_export['acq_time_s'] = datetime.datetime.now(
            ).timestamp()
            self.data_to_export_signal.emit(self.data_to_export)
Esempio n. 7
0
    def test_DataToExport(self):
        data = np.array([1])
        data_test = utils.DataToExport(data=data)
        assert isinstance(data_test, utils.DataToExport)
        assert data_test['data'] == data
        assert data_test['dim'] == 'Data0D'
        data_test = utils.DataToExport()
        assert data_test['dim'] == 'Data0D'
        data = np.array([1, 1])
        data_test = utils.DataToExport(data=data)
        assert data_test['dim'] == 'Data1D'
        data = np.array([[1, 1], [1, 2]])
        data_test = utils.DataToExport(data=data)
        assert data_test['dim'] == 'Data2D'
        data = np.array([[[1, 1], [1, 2]], [[2, 1], [2, 2]]])
        data_test = utils.DataToExport(data=data)
        assert data_test['dim'] == 'DataND'

        with pytest.raises(TypeError):
            utils.DataToExport(data="data")