Exemple #1
0
    def new_window(self, name=None, title=None, is_image=False):
        """Creates a new window and returns the index into the **windows** list
        for the new window.
        """
        new_win = PlotWindow(
            is_image=is_image,
            size=(self.prefs.window_width, self.prefs.window_height),
            bgcolor=self.prefs.bgcolor,
            image_default_origin=self.prefs.image_default_origin,
        )
        new_win.data = self.data
        new_win.get_container().data = self.data
        new_win.session = self

        if title is not None:
            new_win.set_title(title)
        elif name != None:
            new_win.set_title(name)
        else:
            new_win.set_title(self.prefs.default_window_name)

        self.windows.append(new_win)
        if name != None:
            self.window_map[name] = new_win
        return len(self.windows)-1
Exemple #2
0
 def show_plot_window(self):
     """Creates the main window (EEG and FFT plots) from plot_window.py.
     """
     self.plot_window = QtWidgets.QMainWindow()
     self.ui = PlotWindow()
     self.ui.setup_ui(self.plot_window)
     self.plot_window.setWindowFlags(QtCore.Qt.Window)
     self.plot_window.show()
     app.aboutToQuit.connect(self.close_threads)
def create_plot_types(names):
    for name in names:
        fname = '{}_plot.png'.format(name)
        print("*** creating figure {!r} for type {!r} ***".format(fname, name))
        plot = all_examples[name]()

        window = PlotWindow(plot=plot)
        window.edit_traits()

        save_plot(window.container, fname)
def create_plot_types(names):
    for name in names:
        fname = '{}_plot.png'.format(name)
        print("*** creating figure {!r} for type {!r} ***".format(fname, name))
        plot = all_examples[name]()

        window = PlotWindow(plot=plot)
        window.edit_traits()

        save_plot(window.container, fname)
Exemple #5
0
 def show(self):
     """
     Creates and displays a plot window, or activates it
     (gives it focus) if it has already been created.
     """
     if self._window and not self._window.has_exit:
         self._window.activate()
     else:
         self._win_args['visible'] = True
         self.axes.reset_resources()
         self._window = PlotWindow(self, **self._win_args)
Exemple #6
0
    def __init__(self, config, out_file_name, parent=None):
        super(ViewPSD, self).__init__(parent)
        self.config = config
        self.out_file_name = out_file_name
        self.plot_window = PlotWindow()

        self.plot_window.closed.connect(self.stop_view_psd)

        self.plot_window.show()
        self.plot_flg = False

        self.plot_ready[list].connect(self.plot)
Exemple #7
0
    def __init__(self, labels, clusterProfiles, distanceMatrix, plot_stretching=None, show_toolbar=False, parent=None):

        PlotWindow.__init__(self, 2, plot_stretching, show_toolbar, parent)
        self.setWindowTitle('Cluster profiles')

        mask1 = numpy.isfinite(distanceMatrix)[0]
        mask2 = numpy.isfinite(distanceMatrix)[:,0]
        valid_mask = numpy.logical_and(mask1, mask2)
        valid_indices = numpy.arange(valid_mask.shape[0])[valid_mask]
        self.__labels = []
        for i in valid_indices:
            self.__labels.append(labels[i])
        self.__clusterProfiles = clusterProfiles[valid_mask]
        self.__distanceMatrix = distanceMatrix[valid_mask][:,valid_mask]

        self.__create_distance_heatmap_plot()
Exemple #8
0
class Controller:
    """Controller class for slave QMainWindows. Used for expandability in case
    the user wishes to create additional windows for the program (ex: home
    window).
    """
    def show_plot_window(self):
        """Creates the main window (EEG and FFT plots) from plot_window.py.
        """
        self.plot_window = QtWidgets.QMainWindow()
        self.ui = PlotWindow()
        self.ui.setup_ui(self.plot_window)
        self.plot_window.setWindowFlags(QtCore.Qt.Window)
        self.plot_window.show()
        app.aboutToQuit.connect(self.close_threads)

    def close_threads(self):
        """Helper function that closes all running threads when the application
        is about to quit.
        """
        self.ui.close_threads()
Exemple #9
0
 def show(self):
     """
     Creates and displays a plot window, or activates it
     (gives it focus) if it has already been created.
     """
     if self._window and not self._window.has_exit:
         self._window.activate()
     else:
         self._win_args['visible'] = True
         self.axes.reset_resources()
         self._window = PlotWindow(self, **self._win_args)
Exemple #10
0
def plotResults(directory):
    np.set_printoptions(linewidth=150)
    plt.rc('text', usetex=True)
    plt.rc('font', family='serif')

    global xtitles, vtitles, etitles, imu_titles, colors, data, pw, plotCov
    xtitles = ['$p_x$', '$p_y$', '$p_z$', '$q_w$', '$q_x$', '$q_y$', '$q_z$']
    vtitles = ['$v_x$', '$v_y$', '$v_z$']
    etitles = ['$\phi$', r'$\theta$', '$\psi$']
    imu_titles = [
        r"$acc_x$", r"$acc_y$", r"$acc_z$", r"$\omega_x$", r"$\omega_y$",
        r"$\omega_z$"
    ]
    colors = [
        '#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b',
        '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'
    ]

    plotCov = True

    data = Log(directory)
    pw = PlotWindow()

    plotPosition()
    plotPosition2d()
    plotVelocity()
    plotAttitude()
    plotEuler()
    plotLla()
    plotIMU()
    plotImuBias()

    plotZVRes()
    plotBaroRes()
    plotRangeRes()
    plotGnssRes()

    pw.show()
Exemple #11
0
    def show_spec_layer(self, title, data):
        plot = PlotWindow(title)

        plt.sca(plot.axis)
        plt.imshow(data, origin='lower')
        plt.subplots_adjust(top=0.975, bottom=0.025, left=0.025, right=0.975)
        plt.draw()
        plot.setWindowFlag(Qt.WindowStaysOnTopHint, False)
        plot.show()

        padding = 32

        display = QApplication.desktop()
        current_screen = display.screenNumber(self.view)
        geom = display.screenGeometry(current_screen)
        width = geom.width() - 2 * padding
        height = geom.height() - 2 * padding
        plot.setGeometry(geom.left() + padding, geom.top() + padding, width, height)
        plt.close()
Exemple #12
0
    def save(self, outfile=None, format='', size=(600, 500)):
        self.outfile = outfile
        self.format = format
        self.size = size
        self.screenshot_requested = True

        if not self._plot._window or self._plot._window.has_exit:
            self._plot._win_args['visible'] = False

            self._plot._win_args['width'] = size[0]
            self._plot._win_args['height'] = size[1]

            self._plot.axes.reset_resources()
            self._plot._window = PlotWindow(self._plot, **self._plot._win_args)
            self.invisibleMode = True

        if self.outfile is None:
            self.outfile = self._create_unique_path()
            print(self.outfile)
Exemple #13
0
    def plot_pixel_sums(self, axis, label):

        plot = PlotWindow(f'{self.spec.id} {label} Sum')

        plt.sca(plot.axis)
        science = self.spec.science.sum(axis=axis)
        contamination = self.spec.contamination.sum(axis=axis)
        plt.plot(contamination, alpha=0.6, label='Contamination')
        plt.plot(science + contamination, alpha=0.6, label='Original')
        plt.plot(science, label='Decontaminated')
        plt.title(f'Object ID: {self.spec.id}')
        plt.xlabel(f'Pixel {label}')
        plt.ylabel(f'{label} Sum')
        plt.legend()
        plt.draw()
        plot.show()
        plot.adjustSize()
        plt.close()
Exemple #14
0
    def _plot(self, dither, detector):
        if self._data_series == 0:
            return

        plot = PlotWindow(f"object {self._object_id} detector: {dither}.{detector}")

        spec = self._inspector.collection.get_spectrum(dither, detector, self._object_id)
        dispersion_axis = spec.solution.dispersion_orientation()

        plot_flux = self._y_type == PlotSelector.Y_FLUX
        plot_wavelength = self._x_type == PlotSelector.X_WAV

        if dispersion_axis == 0:
            pixels = spec.x_offset + np.arange(0, spec.science.shape[1])
            wavelengths = spec.solution.compute_wavelength(pixels)
        else:
            pixels = spec.y_offset + np.arange(0, spec.science.shape[0])
            wavelengths = spec.solution.compute_wavelength(pixels)

        min_wav, max_wav = 12400, 18600

        short_wav_end = np.argmin(np.fabs(wavelengths - min_wav))
        long_wav_end = np.argmin(np.fabs(wavelengths - max_wav))
        i_min = min(short_wav_end, long_wav_end)
        i_max = max(short_wav_end, long_wav_end)

        x_values = wavelengths[i_min: i_max] if plot_wavelength else pixels[i_min: i_max]

        # determine and set the limits of the x-axis

        if plot_wavelength and plot_flux:
            plot.axis.set_xlim((min_wav, max_wav))
        elif plot_flux and not plot_wavelength:
            short_wav_end = np.argmin(np.fabs(wavelengths - min_wav))
            long_wav_end = np.argmin(np.fabs(wavelengths - max_wav))
            x_min = min(pixels[short_wav_end], pixels[long_wav_end])
            x_max = max(pixels[short_wav_end], pixels[long_wav_end])
            plot.axis.set_xlim((x_min, x_max))

        zeroth_mask = np.sum(spec.mask & flag['ZERO'], axis=dispersion_axis)

        if self._data_series & PlotSelector.S_ORIG == PlotSelector.S_ORIG:
            if plot_flux:
                uncalibrated = np.sum(spec.science + spec.contamination, axis=dispersion_axis)
                y_values = self._calibrate_spectrum(dither, uncalibrated, wavelengths)
            else:
                y_values = np.sum(spec.science + spec.contamination, axis=dispersion_axis)

            y_values = np.ma.masked_where(zeroth_mask != 0, y_values)

            plot.axis.plot(x_values, y_values[i_min: i_max], label='original spectrum', color='k', linewidth=0.5,
                           alpha=0.7)

        if self._data_series & PlotSelector.S_CONTAM == PlotSelector.S_CONTAM:
            if plot_flux:
                y_values = self._calibrate_spectrum(dither, spec.contamination.sum(dispersion_axis), wavelengths)
            else:
                y_values = spec.contamination.sum(dispersion_axis)

            plot.axis.plot(x_values, y_values[i_min: i_max], label='contamination', color='g', linewidth=0.75,
                           alpha=0.8)

        if self._data_series & PlotSelector.S_DECON == PlotSelector.S_DECON:
            if plot_flux:
                y_values_unmasked = self._calibrate_spectrum(dither, spec.science.sum(dispersion_axis), wavelengths)
            else:
                y_values_unmasked = spec.science.sum(dispersion_axis)

            y_values = np.ma.masked_where(zeroth_mask != 0, y_values_unmasked)

            plot.axis.plot(x_values, y_values[i_min: i_max], label='decontaminated spectrum', color='b', linewidth=0.9)

        if self._data_series & PlotSelector.S_MODEL == PlotSelector.S_MODEL:
            model = self._inspector.collection.get_model(dither, detector, self._object_id, order=1)
            if model is not None:
                if plot_flux:
                    y_values = self._calibrate_spectrum(dither, model.pixels.sum(dispersion_axis), wavelengths)
                else:
                    y_values = model.pixels.sum(dispersion_axis)

                plot.axis.plot(x_values, y_values[i_min: i_max], label='model spectrum', color='r', linewidth=0.9,
                               alpha=0.9)

        # plot the J and H band fluxes if the plot shows flux vs wavelength

        if plot_wavelength and plot_flux:
            info = self._inspector.location_tables.get_info(self._object_id)
            j_microjansky = utils.mag_to_fnu(info.jmag, zero_point=22)
            h_microjansky = utils.mag_to_fnu(info.hmag, zero_point=22)
            j_fnu = utils.mjy_to_angstrom(j_microjansky, J_WAV)
            h_fnu = utils.mjy_to_angstrom(h_microjansky, H_WAV)
            plot.axis.scatter(J_WAV, j_fnu, color='r', label='J and H band fluxes')
            plot.axis.scatter(H_WAV, h_fnu, color='r')

        x_label = r'Wavelength $\rm (\AA)$' if self._x_type == PlotSelector.X_WAV else 'Pixel'
        y_label = r'Flux ($\rm erg/s/cm^2/\AA$)' if self._y_type == PlotSelector.Y_FLUX else 'Electrons / second'

        plot.axis.set_xlabel(x_label)
        plot.axis.set_ylabel(y_label)
        plot.axis.legend()

        # set the descriptor; a string in the format: id.dither.detector.data_series.y_type.x_type
        plot.descriptor = f'{self._object_id}.{dither}.{detector}.{self._data_series}.{self._y_type}.{self._x_type}'

        return plot
Exemple #15
0
 def addGraph(self):
     self.parent.readCfg(self.parent.config_path, last=False)
     self.layout.addWidget(PlotWindow(self))
     self.layout.addWidget(self.button_add_graph)
Exemple #16
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("USRP B210 信号采样")
        self.setWindowIcon(QIcon("signal_app_24.png"))
        self.resize(1280, 720)

        self.plot_win = PlotWindow()

        # qss = "QWidget#MainWindow{background-color:red;}"
        # qss = "QWidget#MainWindow{border-image:url(signal_app_24.png);}"
        # self.setStyleSheet(qss)

        self.home_dir = pjoin(os.path.expanduser("~"), ".uhd_ui")
        self.config_path = pjoin(self.home_dir, "config.json")

        self.CONFIG = {}

        self.config = Config()
        self.config_keys = [
            "gnu_radio_path", "save_path", "fc", "fs", "stop_fc",
            "sample_interval", "sample_nums", "sample_times"
        ]

        self.view_spec_config = Config()
        self.view_spec_config.save_path = self.home_dir
        self.view_spec_config.sample_times = 1
        self.view_spec_config.sample_nums = 1 * 1024 * 1024

        self.sample_thread = None  # SampleThread()

        self.initial()

        self.save_path_btn.clicked.connect(self.open_folder)
        self.gnu_radio_btn.clicked.connect(self.open_gnu_folder)

        self.ok_btn.clicked.connect(self.sample_thread_start)
        self.ok_btn.setToolTip("开始采集信号")

        self.plot_btn.clicked.connect(self.plot_psd_start)
        self.plot_win.closed.connect(self.plot_psd_stop)

        self.stop_btn.setEnabled(False)
        self.stop_btn.setToolTip("停止当前信号采样")
        self.stop_btn.clicked.connect(self.stop_current_sampling)

        self.advance_groupBox.hide()
        self.advance_mode = False
        self.advance_mode_btn.setText("打开高级模式")
        self.advance_mode_btn.clicked.connect(self.set_advance_mode)

        self.gnu_radio_path_edit.textChanged[str].connect(
            self.new_gnu_radio_path)
        self.save_path_edit.textChanged[str].connect(self.new_save_path)
        self.fc_spinBox.valueChanged[int].connect(self.new_fc_val)
        self.fc_comboBox.currentIndexChanged[int].connect(self.new_fc_cbox)
        self.stop_fc_spinBox.valueChanged[int].connect(self.new_stop_fc_val)
        self.stop_fc_comboBox.currentIndexChanged[int].connect(
            self.new_stop_fc_cbox)
        self.fs_spinBox.valueChanged[int].connect(self.new_fs_val)
        self.fs_comboBox.currentIndexChanged[int].connect(self.new_fs_cbox)
        self.sample_interval_spinBox.valueChanged[int].connect(
            self.new_sample_interval_val)
        self.sample_interval_comboBox.currentIndexChanged[int].connect(
            self.new_sample_interval_cbox)
        self.sample_nums_spinBox.valueChanged[int].connect(
            self.new_n_sample_val)
        self.sample_nums_comboBox.currentIndexChanged[int].connect(
            self.new_n_sample_cbox)
        self.sample_times_spinBox.valueChanged[int].connect(
            self.new_sample_times)

        self.config_changed.connect(self.update_config)
Exemple #17
0
class PygletPlot(object):
    """
    Plot Examples
    =============

    See examples/advaned/pyglet_plotting.py for many more examples.


    >>> from sympy.plotting.pygletplot import PygletPlot as Plot
    >>> from sympy.abc import x, y, z

    >>> Plot(x*y**3-y*x**3)
    [0]: -x**3*y + x*y**3, 'mode=cartesian'

    >>> p = Plot()
    >>> p[1] = x*y
    >>> p[1].color = z, (0.4,0.4,0.9), (0.9,0.4,0.4)

    >>> p = Plot()
    >>> p[1] =  x**2+y**2
    >>> p[2] = -x**2-y**2


    Variable Intervals
    ==================

    The basic format is [var, min, max, steps], but the
    syntax is flexible and arguments left out are taken
    from the defaults for the current coordinate mode:

    >>> Plot(x**2) # implies [x,-5,5,100]
    [0]: x**2, 'mode=cartesian'
    >>> Plot(x**2, [], []) # [x,-1,1,40], [y,-1,1,40]
    [0]: x**2, 'mode=cartesian'
    >>> Plot(x**2-y**2, [100], [100]) # [x,-1,1,100], [y,-1,1,100]
    [0]: x**2 - y**2, 'mode=cartesian'
    >>> Plot(x**2, [x,-13,13,100])
    [0]: x**2, 'mode=cartesian'
    >>> Plot(x**2, [-13,13]) # [x,-13,13,100]
    [0]: x**2, 'mode=cartesian'
    >>> Plot(x**2, [x,-13,13]) # [x,-13,13,10]
    [0]: x**2, 'mode=cartesian'
    >>> Plot(1*x, [], [x], mode='cylindrical')
    ... # [unbound_theta,0,2*Pi,40], [x,-1,1,20]
    [0]: x, 'mode=cartesian'


    Coordinate Modes
    ================

    Plot supports several curvilinear coordinate modes, and
    they independent for each plotted function. You can specify
    a coordinate mode explicitly with the 'mode' named argument,
    but it can be automatically determined for Cartesian or
    parametric plots, and therefore must only be specified for
    polar, cylindrical, and spherical modes.

    Specifically, Plot(function arguments) and Plot[n] =
    (function arguments) will interpret your arguments as a
    Cartesian plot if you provide one function and a parametric
    plot if you provide two or three functions. Similarly, the
    arguments will be interpreted as a curve if one variable is
    used, and a surface if two are used.

    Supported mode names by number of variables:

    1: parametric, cartesian, polar
    2: parametric, cartesian, cylindrical = polar, spherical

    >>> Plot(1, mode='spherical') # doctest: +SKIP


    Calculator-like Interface
    =========================

    >>> p = Plot(visible=False)
    >>> f = x**2
    >>> p[1] = f
    >>> p[2] = f.diff(x)
    >>> p[3] = f.diff(x).diff(x) # doctest: +SKIP
    >>> p # doctest: +SKIP
    [1]: x**2, 'mode=cartesian'
    [2]: 2*x, 'mode=cartesian'
    [3]: 2, 'mode=cartesian'
    >>> p.show()
    >>> p.clear()
    >>> p
    <blank plot>
    >>> p[1] =  x**2+y**2
    >>> p[1].style = 'solid'
    >>> p[2] = -x**2-y**2
    >>> p[2].style = 'wireframe'
    >>> p[1].color = z, (0.4,0.4,0.9), (0.9,0.4,0.4)
    >>> p[1].style = 'both'
    >>> p[2].style = 'both'
    >>> p.close()


    Plot Window Keyboard Controls
    =============================

    Screen Rotation:
        X,Y axis      Arrow Keys, A,S,D,W, Numpad 4,6,8,2
        Z axis        Q,E, Numpad 7,9

    Model Rotation:
        Z axis        Z,C, Numpad 1,3

    Zoom:             R,F, PgUp,PgDn, Numpad +,-

    Reset Camera:     X, Numpad 5

    Camera Presets:
        XY            F1
        XZ            F2
        YZ            F3
        Perspective   F4

    Sensitivity Modifier: SHIFT

    Axes Toggle:
        Visible       F5
        Colors        F6

    Close Window:     ESCAPE

    =============================

    """
    #python 2.5 does not support class decorators so use this workaround
    _doctest_depends_on = {'modules': ('pyglet',)}

    @doctest_depends_on(modules=('pyglet',))
    def __init__(self, *fargs, **win_args):
        """
        Positional Arguments
        ====================

        Any given positional arguments are used to
        initialize a plot function at index 1. In
        other words...

        >>> from sympy.plotting.pygletplot import PygletPlot as Plot
        >>> from sympy.core import Symbol
        >>> from sympy.abc import x
        >>> p = Plot(x**2, visible=False)

        ...is equivalent to...

        >>> p = Plot(visible=False)
        >>> p[1] = x**2

        Note that in earlier versions of the plotting
        module, you were able to specify multiple
        functions in the initializer. This functionality
        has been dropped in favor of better automatic
        plot plot_mode detection.


        Named Arguments
        ===============

        axes
            An option string of the form
            "key1=value1; key2 = value2" which
            can use the following options:

            style = ordinate
                none OR frame OR box OR ordinate

            stride = 0.25
                val OR (val_x, val_y, val_z)

            overlay = True (draw on top of plot)
                True OR False

            colored = False (False uses Black,
                             True uses colors
                             R,G,B = X,Y,Z)
                True OR False

            label_axes = False (display axis names
                                at endpoints)
                True OR False

        visible = True (show immediately
            True OR False


        The following named arguments are passed as
        arguments to window initialization:

        antialiasing = True
            True OR False

        ortho = False
            True OR False

        invert_mouse_zoom = False
            True OR False

        """
        self._win_args = win_args
        self._window = None

        self._render_lock = RLock()

        self._functions = {}
        self._pobjects = []
        self._screenshot = ScreenShot(self)

        axe_options = parse_option_string(win_args.pop('axes', ''))
        self.axes = PlotAxes(**axe_options)
        self._pobjects.append(self.axes)

        self[0] = fargs
        if win_args.get('visible', True):
            self.show()

    ## Window Interfaces

    def show(self):
        """
        Creates and displays a plot window, or activates it
        (gives it focus) if it has already been created.
        """
        if self._window and not self._window.has_exit:
            self._window.activate()
        else:
            self._win_args['visible'] = True
            self.axes.reset_resources()

            if hasattr(self, '_doctest_depends_on'):
                self._win_args['runfromdoctester'] = True

            self._window = PlotWindow(self, **self._win_args)

    def close(self):
        """
        Closes the plot window.
        """
        if self._window:
            self._window.close()

    def saveimage(self, outfile=None, format='', size=(600, 500)):
        """
        Saves a screen capture of the plot window to an
        image file.

        If outfile is given, it can either be a path
        or a file object. Otherwise a png image will
        be saved to the current working directory.
        If the format is omitted, it is determined from
        the filename extension.
        """
        self._screenshot.save(outfile, format, size)

    ## Function List Interfaces

    def clear(self):
        """
        Clears the function list of this plot.
        """
        self._render_lock.acquire()
        self._functions = {}
        self.adjust_all_bounds()
        self._render_lock.release()

    def __getitem__(self, i):
        """
        Returns the function at position i in the
        function list.
        """
        return self._functions[i]

    def __setitem__(self, i, args):
        """
        Parses and adds a PlotMode to the function
        list.
        """
        if not (isinstance(i, (int, Integer)) and i >= 0):
            raise ValueError("Function index must "
                             "be an integer >= 0.")

        if isinstance(args, PlotObject):
            f = args
        else:
            if (not is_sequence(args)) or isinstance(args, GeometryEntity):
                args = [args]
            if len(args) == 0:
                return  # no arguments given
            kwargs = dict(bounds_callback=self.adjust_all_bounds)
            f = PlotMode(*args, **kwargs)

        if f:
            self._render_lock.acquire()
            self._functions[i] = f
            self._render_lock.release()
        else:
            raise ValueError("Failed to parse '%s'."
                    % ', '.join(str(a) for a in args))

    def __delitem__(self, i):
        """
        Removes the function in the function list at
        position i.
        """
        self._render_lock.acquire()
        del self._functions[i]
        self.adjust_all_bounds()
        self._render_lock.release()

    def firstavailableindex(self):
        """
        Returns the first unused index in the function list.
        """
        i = 0
        self._render_lock.acquire()
        while i in self._functions:
            i += 1
        self._render_lock.release()
        return i

    def append(self, *args):
        """
        Parses and adds a PlotMode to the function
        list at the first available index.
        """
        self.__setitem__(self.firstavailableindex(), args)

    def __len__(self):
        """
        Returns the number of functions in the function list.
        """
        return len(self._functions)

    def __iter__(self):
        """
        Allows iteration of the function list.
        """
        return self._functions.itervalues()

    def __repr__(self):
        return str(self)

    def __str__(self):
        """
        Returns a string containing a new-line separated
        list of the functions in the function list.
        """
        s = ""
        if len(self._functions) == 0:
            s += "<blank plot>"
        else:
            self._render_lock.acquire()
            s += "\n".join(["%s[%i]: %s" % ("", i, str(self._functions[i]))
                            for i in self._functions])
            self._render_lock.release()
        return s

    def adjust_all_bounds(self):
        self._render_lock.acquire()
        self.axes.reset_bounding_box()
        for f in self._functions:
            self.axes.adjust_bounds(self._functions[f].bounds)
        self._render_lock.release()

    def wait_for_calculations(self):
        sleep(0)
        self._render_lock.acquire()
        for f in self._functions:
            a = self._functions[f]._get_calculating_verts
            b = self._functions[f]._get_calculating_cverts
            while a() or b():
                sleep(0)
        self._render_lock.release()
Exemple #18
0
    def new_window(self, name=None, title=None, is_image=False):
        """Creates a new window and returns the index into the **windows** list
        for the new window.
        """
        new_win = PlotWindow(
            is_image=is_image,
            size=(self.prefs.window_width, self.prefs.window_height),
            bgcolor=self.prefs.bgcolor,
            image_default_origin=self.prefs.image_default_origin,
        )
        new_win.data = self.data
        new_win.get_container().data = self.data
        new_win.session = self

        if title is not None:
            new_win.set_title(title)
        elif name != None:
            new_win.set_title(name)
        else:
            new_win.set_title(self.prefs.default_window_name)

        self.windows.append(new_win)
        if name != None:
            self.window_map[name] = new_win
        return len(self.windows) - 1
Exemple #19
0
class ViewPSD(QObject):  #
    view_finished = pyqtSignal()
    plot_ready = pyqtSignal(list)

    def __init__(self, config, out_file_name, parent=None):
        super(ViewPSD, self).__init__(parent)
        self.config = config
        self.out_file_name = out_file_name
        self.plot_window = PlotWindow()

        self.plot_window.closed.connect(self.stop_view_psd)

        self.plot_window.show()
        self.plot_flg = False

        self.plot_ready[list].connect(self.plot)

    def __del__(self):
        self.plot_window.close()

    def update_config(self, config):
        self.config = config

    def plot(self, data):
        print("-- plot --")
        self.plot_window.fc = self.config.fc
        self.plot_window.fs = self.config.fs
        self.plot_window.sig = data
        #        if not self.plot_window.t.isActive():
        if self.plot_flg:
            self.plot_window.t.start(50)

    def plot_psd_process(self):
        self.plot_flg = True

        bat = pjoin(self.config.gnu_radio_path, "run_gr.bat")
        rx_py = pjoin(self.config.gnu_radio_path, "uhd_rx_cfile.py")
        output_path = pjoin(self.config.save_path, self.out_file_name)

        print(
            f"{bat} {rx_py} {output_path} -s -f {self.config.fc} -r {self.config.fs} -N {self.config.sample_nums}"
        )

        print("查看频谱模式")
        while self.plot_flg:
            print("=========================")
            os.spawnl(
                os.P_WAIT, bat,
                f"{bat} {rx_py} {output_path} -s -f {self.config.fc} -r {self.config.fs} -N {self.config.sample_nums}"
            )
            with open(output_path, "rb") as f:
                buff = f.read()
                tmp = np.frombuffer(buff, np.int16) / 32768

            d_i, d_q = np.reshape(tmp, (-1, 2)).T
            data = d_i + 1j * d_q

            #            if not self.plot_flg:
            #                break
            self.plot_ready.emit(list(data))

    def stop_view_psd(self):
        print("-- stop_view_psd --")
        self.plot_flg = False
        self.view_finished.emit()
    'scatter': get_scatter_plot,
    'cmap_scatter': get_cmap_scatter_plot,
    'vsize_scatter': get_variable_size_scatter_plot,
    'jitter': get_jitter_plot,
    'candle': get_candle_plot,
    'errorbar': get_errorbar_plot,
    'filled_line': get_filled_line_plot,
    'image': get_image_plot,
    'image_from_file': get_image_from_file,
    'cmap_image': get_cmap_image_plot,
    'contour_line': get_contour_line_plot,
    'contour_poly': get_contour_poly_plot,
    'polygon': get_polygon_plot,
    'bar': get_bar_plot,
    'quiver': get_quiver_plot,
    'polar': get_polar_plot,
    'multiline': get_multiline_plot,
}

if __name__ == '__main__':
    name = 'line'

    factory_func = all_examples[name]
    plot = factory_func()

    window = PlotWindow(plot=plot)
    ui = window.edit_traits()

    filename = '{}_plot.png'.format(name)
    save_plot(window.container, filename)
Exemple #21
0
class Plot(object):
    """
    Plot Examples
    =============

    See examples/plotting.py for many more examples.


    >>> from sympy import symbols, Plot
    >>> x,y,z = symbols('xyz')

    >>> Plot(x*y**3-y*x**3)

    >>> p = Plot()
    >>> p[1] = x*y
    >>> p[1].color = z, (0.4,0.4,0.9), (0.9,0.4,0.4)

    >>> p = Plot()
    >>> p[1] =  x**2+y**2
    >>> p[2] = -x**2-y**2


    Variable Intervals
    ==================

    The basic format is [var, min, max, steps], but the
    syntax is flexible and arguments left out are taken
    from the defaults for the current coordinate mode:

    >>> Plot(x**2) # implies [x,-5,5,100]
    >>> Plot(x**2, [], []) # [x,-1,1,40], [y,-1,1,40]
    >>> Plot(x**2-y**2, [100], [100]) # [x,-1,1,100], [y,-1,1,100]
    >>> Plot(x**2, [x,-13,13,100])
    >>> Plot(x**2, [-13,13]) # [x,-13,13,100]
    >>> Plot(x**2, [x,-13,13]) # [x,-13,13,100]
    >>> Plot(1*x, [], [x], mode='cylindrical')
    ... # [unbound_theta,0,2*Pi,40], [x,-1,1,20]


    Coordinate Modes
    ================

    Plot supports several curvilinear coordinate modes, and
    they independent for each plotted function. You can specify
    a coordinate mode explicitly with the 'mode' named argument,
    but it can be automatically determined for cartesian or
    parametric plots, and therefore must only be specified for
    polar, cylindrical, and spherical modes.

    Specifically, Plot(function arguments) and Plot[n] =
    (function arguments) will interpret your arguments as a
    cartesian plot if you provide one function and a parametric
    plot if you provide two or three functions. Similarly, the
    arguments will be interpreted as a curve is one variable is
    used, and a surface if two are used.

    Supported mode names by number of variables:

    1: parametric, cartesian, polar
    2: parametric, cartesian, cylindrical = polar, spherical

    >>> Plot(1, mode='spherical')


    Calculator-like Interface
    =========================

    >>> p = Plot(visible=False)
    >>> f = x**2
    >>> p[1] = f
    >>> p[2] = f.diff(x)
    >>> p[3] = f.diff(x).diff(x)
    >>> p
    [1]: x**2, 'mode=cartesian'
    [2]: 2*x, 'mode=cartesian'
    [3]: 2, 'mode=cartesian'
    >>> p.show()
    >>> p.clear()
    >>> p
    <blank plot>
    >>> p[1] =  x**2+y**2
    >>> p[1].style = 'solid'
    >>> p[2] = -x**2-y**2
    >>> p[2].style = 'wireframe'
    >>> p[1].color = z, (0.4,0.4,0.9), (0.9,0.4,0.4)
    >>> p[1].style = 'both'
    >>> p[2].style = 'both'
    >>> p.close()


    Plot Window Keyboard Controls
    =============================

    Screen Rotation:
        X,Y axis      Arrow Keys, A,S,D,W, Numpad 4,6,8,2
        Z axis        Q,E, Numpad 7,9

    Model Rotation:
        Z axis        Z,C, Numpad 1,3

    Zoom:             R,F, PgUp,PgDn, Numpad +,-

    Reset Camera:     X, Numpad 5

    Camera Presets:
        XY            F1
        XZ            F2
        YZ            F3
        Perspective   F4

    Sensitivity Modifier: SHIFT

    Axes Toggle:
        Visible       F5
        Colors        F6

    Close Window:     ESCAPE

    =============================
    """
    def __init__(self, *fargs, **win_args):
        """
        Positional Arguments
        ====================

        Any given positional arguments are used to
        initialize a plot function at index 1. In
        other words...

        >>> from sympy.core import Symbol
        >>> x = Symbol('x')
        >>> p = Plot(x**2, visible=False)

        ...is equivalent to...

        >>> p = Plot(visible=False)
        >>> p[1] = x**2

        Note that in earlier versions of the plotting
        module, you were able to specify multiple
        functions in the initializer. This functionality
        has been dropped in favor of better automatic
        plot plot_mode detection.


        Named Arguments
        ===============

        axes
            An option string of the form
            "key1=value1; key2 = value2" which
            can use the following options:

            style = ordinate
                none OR frame OR box OR ordinate

            stride = 0.25
                val OR (val_x, val_y, val_z)

            overlay = True (draw on top of plot)
                True OR False

            colored = False (False uses Black,
                             True uses colors
                             R,G,B = X,Y,Z)
                True OR False

            label_axes = False (display axis names
                                at endpoints)
                True OR False

        visible = True (show immediately
            True OR False


        The following named arguments are passed as
        arguments to window initialization:

        antialiasing = True
            True OR False

        ortho = False
            True OR False

        invert_mouse_zoom = False
            True OR False

        """
        self._win_args = win_args
        self._window = None

        self._render_lock = RLock()

        self._functions = {}
        self._pobjects = []
        self._screenshot = ScreenShot(self)

        axe_options = parse_option_string(win_args.pop('axes', ''))
        self.axes = PlotAxes(**axe_options)
        self._pobjects.append(self.axes)

        self[0] = fargs
        if win_args.get('visible', True):
            self.show()

    ## Window Interfaces

    def show(self):
        """
        Creates and displays a plot window, or activates it
        (gives it focus) if it has already been created.
        """
        if self._window and not self._window.has_exit:
            self._window.activate()
        else:
            self._win_args['visible'] = True
            self.axes.reset_resources()
            self._window = PlotWindow(self, **self._win_args)

    def close(self):
        """
        Closes the plot window.
        """
        if self._window:
            self._window.close()

    def saveimage(self, outfile=None, format='', size=(600, 500)):
        """
        Saves a screen capture of the plot window to an
        image file.

        If outfile is given, it can either be a path
        or a file object. Otherwise a png image will
        be saved to the current working directory.
        If the format is omitted, it is determined from
        the filename extension.
        """
        self._screenshot.save(outfile, format, size)

    ## Function List Interfaces

    def clear(self):
        """
        Clears the function list of this plot.
        """
        self._render_lock.acquire()
        self._functions = {}
        self.adjust_all_bounds()
        self._render_lock.release()

    def __getitem__(self, i):
        """
        Returns the function at position i in the
        function list.
        """
        return self._functions[i]

    def __setitem__(self, i, args):
        """
        Parses and adds a PlotMode to the function
        list.
        """
        if not (isinstance(i, (int, Integer)) and i >= 0):
            raise ValueError("Function index must " "be an integer >= 0.")

        if isinstance(args, PlotObject):
            f = args
        else:
            if (not isinstance(args, (list, tuple))) or isinstance(
                    args, GeometryEntity):
                args = [args]
            if len(args) == 0:
                return  # no arguments given
            kwargs = dict(bounds_callback=self.adjust_all_bounds)
            f = PlotMode(*args, **kwargs)

        if f:
            self._render_lock.acquire()
            self._functions[i] = f
            self._render_lock.release()
        else:
            raise ValueError("Failed to parse '%s'." %
                             ', '.join(str(a) for a in args))

    def __delitem__(self, i):
        """
        Removes the function in the function list at
        position i.
        """
        self._render_lock.acquire()
        del self._functions[i]
        self.adjust_all_bounds()
        self._render_lock.release()

    def firstavailableindex(self):
        """
        Returns the first unused index in the function list.
        """
        i = 0
        self._render_lock.acquire()
        while i in self._functions:
            i += 1
        self._render_lock.release()
        return i

    def append(self, *args):
        """
        Parses and adds a PlotMode to the function
        list at the first available index.
        """
        self.__setitem__(self.firstavailableindex(), args)

    def __len__(self):
        """
        Returns the number of functions in the function list.
        """
        return len(self._functions)

    def __iter__(self):
        """
        Allows iteration of the function list.
        """
        return self._functions.itervalues()

    def __repr__(self):
        return str(self)

    def __str__(self):
        """
        Returns a string containing a new-line separated
        list of the functions in the function list.
        """
        s = ""
        if len(self._functions) == 0:
            s += "<blank plot>"
        else:
            self._render_lock.acquire()
            s += "\n".join([
                "%s[%i]: %s" % ("", i, str(self._functions[i]))
                for i in self._functions
            ])
            self._render_lock.release()
        return s

    def adjust_all_bounds(self):
        self._render_lock.acquire()
        self.axes.reset_bounding_box()
        for f in self._functions:
            self.axes.adjust_bounds(self._functions[f].bounds)
        self._render_lock.release()

    def wait_for_calculations(self):
        sleep(0)
        self._render_lock.acquire()
        for f in self._functions:
            a = self._functions[f]._get_calculating_verts
            b = self._functions[f]._get_calculating_cverts
            while a() or b():
                sleep(0)
        self._render_lock.release()
Exemple #22
0
class MainWindow(QMainWindow, Ui_MainWindow):
    config_changed = pyqtSignal()

    def __init__(self):
        super(MainWindow, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("USRP B210 信号采样")
        self.setWindowIcon(QIcon("signal_app_24.png"))
        self.resize(1280, 720)

        self.plot_win = PlotWindow()

        # qss = "QWidget#MainWindow{background-color:red;}"
        # qss = "QWidget#MainWindow{border-image:url(signal_app_24.png);}"
        # self.setStyleSheet(qss)

        self.home_dir = pjoin(os.path.expanduser("~"), ".uhd_ui")
        self.config_path = pjoin(self.home_dir, "config.json")

        self.CONFIG = {}

        self.config = Config()
        self.config_keys = [
            "gnu_radio_path", "save_path", "fc", "fs", "stop_fc",
            "sample_interval", "sample_nums", "sample_times"
        ]

        self.view_spec_config = Config()
        self.view_spec_config.save_path = self.home_dir
        self.view_spec_config.sample_times = 1
        self.view_spec_config.sample_nums = 1 * 1024 * 1024

        self.sample_thread = None  # SampleThread()

        self.initial()

        self.save_path_btn.clicked.connect(self.open_folder)
        self.gnu_radio_btn.clicked.connect(self.open_gnu_folder)

        self.ok_btn.clicked.connect(self.sample_thread_start)
        self.ok_btn.setToolTip("开始采集信号")

        self.plot_btn.clicked.connect(self.plot_psd_start)
        self.plot_win.closed.connect(self.plot_psd_stop)

        self.stop_btn.setEnabled(False)
        self.stop_btn.setToolTip("停止当前信号采样")
        self.stop_btn.clicked.connect(self.stop_current_sampling)

        self.advance_groupBox.hide()
        self.advance_mode = False
        self.advance_mode_btn.setText("打开高级模式")
        self.advance_mode_btn.clicked.connect(self.set_advance_mode)

        self.gnu_radio_path_edit.textChanged[str].connect(
            self.new_gnu_radio_path)
        self.save_path_edit.textChanged[str].connect(self.new_save_path)
        self.fc_spinBox.valueChanged[int].connect(self.new_fc_val)
        self.fc_comboBox.currentIndexChanged[int].connect(self.new_fc_cbox)
        self.stop_fc_spinBox.valueChanged[int].connect(self.new_stop_fc_val)
        self.stop_fc_comboBox.currentIndexChanged[int].connect(
            self.new_stop_fc_cbox)
        self.fs_spinBox.valueChanged[int].connect(self.new_fs_val)
        self.fs_comboBox.currentIndexChanged[int].connect(self.new_fs_cbox)
        self.sample_interval_spinBox.valueChanged[int].connect(
            self.new_sample_interval_val)
        self.sample_interval_comboBox.currentIndexChanged[int].connect(
            self.new_sample_interval_cbox)
        self.sample_nums_spinBox.valueChanged[int].connect(
            self.new_n_sample_val)
        self.sample_nums_comboBox.currentIndexChanged[int].connect(
            self.new_n_sample_cbox)
        self.sample_times_spinBox.valueChanged[int].connect(
            self.new_sample_times)

        self.config_changed.connect(self.update_config)

    def resizeEvent(self, event):
        print(f"new_window_size: [{self.width()}, {self.height()}]")

    def closeEvent(self, event):
        self.plot_win.close()
        self.sample_thread.stop()
        self.sample_thread.quit()
        self.sample_thread.wait()

    def initial(self):
        def _get(s_cfg, index=0):
            s_cfg = s_cfg.split()
            if len(s_cfg) == 2:
                try:
                    index = self.config.u2ix_dict[s_cfg[1]]
                    return s_cfg[0], index
                except:
                    raise ValueError("配置出错!")
            elif len(s_cfg) == 1:
                return s_cfg[0], index
            else:
                raise ValueError("配置出错!")

        initial_config = _config()
        if not os.path.exists(self.home_dir):
            os.makedirs(self.home_dir)
        if not os.path.exists(self.config_path):
            # self.CONFIG["gnu_radio_path"] = initial_config.gnu_radio_path
            # self.CONFIG["save_path"] = initial_config.save_path
            # self.CONFIG["FC"] = initial_config.fc
            # self.CONFIG["FS"] = initial_config.fs
            # self.CONFIG["stop_FC"] = initial_config.stop_fc
            # self.CONFIG["sample_interval"] = initial_config.sample_interval
            # self.CONFIG["sample_nums"] = initial_config.sample_nums
            # self.CONFIG["sample_times"] = initial_config.sample_times
            for key in self.config_keys:
                self.CONFIG[key] = initial_config.__getattribute__(key)

            self.save_config()

            self.gnu_radio_path_edit.setText(self.CONFIG["gnu_radio_path"])
            self.save_path_edit.setText(self.CONFIG["save_path"])

            _fc, _fc_index = _get(self.CONFIG["fc"])
            self.fc_spinBox.setValue(int(_fc))
            self.fc_comboBox.setCurrentIndex(_fc_index)

            _fs, _fs_index = _get(self.CONFIG["fs"])
            self.fs_spinBox.setValue(int(_fs))
            self.fs_comboBox.setCurrentIndex(_fs_index)

            _stop_fc, _stop_fc_index = _get(self.CONFIG["stop_fc"])
            self.stop_fc_spinBox.setValue(int(_stop_fc))
            self.stop_fc_comboBox.setCurrentIndex(_stop_fc_index)

            _interval, _interval_index = _get(self.CONFIG["sample_interval"])
            self.sample_interval_spinBox.setValue(int(_interval))
            self.sample_interval_comboBox.setCurrentIndex(_interval_index)

            _n_sample, _n_index = _get(self.CONFIG["sample_nums"])
            self.sample_nums_spinBox.setValue(int(_n_sample))
            self.sample_nums_comboBox.setCurrentIndex(_n_index)

            self.sample_times_spinBox.setValue(int(
                self.CONFIG["sample_times"]))
        else:
            with open(self.config_path, "r") as f:
                self.CONFIG = json.load(f)
                self.config_changed.emit()
                for key in self.config_keys:
                    if key not in self.CONFIG:
                        self.CONFIG[key] = initial_config.__getattribute__(key)

                self.gnu_radio_path_edit.setText(self.CONFIG["gnu_radio_path"])
                self.save_path_edit.setText(self.CONFIG["save_path"])

                _fc, _fc_index = _get(self.CONFIG["fc"])
                self.fc_spinBox.setValue(int(_fc))
                self.fc_comboBox.setCurrentIndex(_fc_index)

                _fs, _fs_index = _get(self.CONFIG["fs"])
                self.fs_spinBox.setValue(int(_fs))
                self.fs_comboBox.setCurrentIndex(_fs_index)

                _stop_fc, _stop_fc_index = _get(self.CONFIG["stop_fc"])
                self.stop_fc_spinBox.setValue(int(_stop_fc))
                self.stop_fc_comboBox.setCurrentIndex(_stop_fc_index)

                _interval, _interval_index = _get(
                    self.CONFIG["sample_interval"])
                self.sample_interval_spinBox.setValue(int(_interval))
                self.sample_interval_comboBox.setCurrentIndex(_interval_index)

                _n_sample, _n_index = _get(self.CONFIG["sample_nums"])
                self.sample_nums_spinBox.setValue(int(_n_sample))
                self.sample_nums_comboBox.setCurrentIndex(_n_index)

                self.sample_times_spinBox.setValue(
                    int(self.CONFIG["sample_times"]))

        self.update_config()

    def save_config(self):
        with open(self.config_path, "w") as f:
            json.dump(self.CONFIG, f)
        self.config_changed.emit()

    def update_config(self):
        def get_value(cfg, u=1000):
            val, unit = cfg.split() if len(cfg.split()) > 1 else [
                cfg.split()[0], ""
            ]
            val = int(int(val) * u**self.config.u2ix_dict[unit])
            return val

        self.config.gnu_radio_path = self.CONFIG["gnu_radio_path"]
        self.config.save_path = self.CONFIG["save_path"]

        self.config.fc = get_value(self.CONFIG["fc"])
        self.config.fs = get_value(self.CONFIG["fs"])
        self.config.stop_fc = get_value(self.CONFIG["stop_fc"])
        self.config.sample_interval = get_value(self.CONFIG["sample_interval"])
        self.config.sample_nums = get_value(self.CONFIG["sample_nums"], 1024)
        self.config.sample_times = int(self.CONFIG["sample_times"])

        self.view_spec_config.gnu_radio_path = self.config.gnu_radio_path
        self.view_spec_config.fc = self.config.fc
        self.view_spec_config.fs = self.config.fs

        print(f"---- config changed ----\n\
    GNU Radio 安装目录:\t{self.config.gnu_radio_path} \n\
    文件保存路径:\t{self.config.save_path} \n\
    中心频率:\t\t{self.config.fc} \n\
    采样带宽:\t\t{self.config.fs} \n\
    结束频率:\t\t{self.config.stop_fc} \n\
    采样间隔:\t\t{self.config.sample_interval} \n\
    采样点数:\t\t{self.config.sample_nums} \n\
    采样次数:\t\t{self.config.sample_times} \n")

    def sample_thread_start(self):
        self.textEdit.append("---- 开始采样 ----\n")

        self.sample_thread = SampleThread()
        self.sample_thread.one_sample_end[int,
                                          str].connect(self.one_sample_end)
        self.sample_thread.all_sample_end.connect(self.sample_thread_end)

        self.sample_thread.config = self.config
        # self.sample_thread.mode = 2  # test_mode
        self.sample_thread.mode = 1  # test_mode
        self.sample_thread.start_sample = True
        self.sample_thread.start()

        self.plot_btn.setEnabled(False)
        self.plot_btn.setToolTip("正在采集信号, 无法查看当前频谱")
        self.stop_btn.setEnabled(True)

        self.ok_btn.setEnabled(False)

    def one_sample_end(self, ix, output_path):
        self.textEdit.append(
            f"第 {ix} 次采样完成,共 {self.config.sample_times} 次,文件保存路径:{output_path}"
        )

    def sample_thread_end(self):
        self.textEdit.append("---- 采样结束 ----\n")

        # self.sample_thread.terminate()
        self.sample_thread.stop()
        self.sample_thread.wait()
        self.sample_thread = None

        self.ok_btn.setEnabled(True)
        self.plot_btn.setEnabled(True)
        self.plot_btn.setToolTip("查看当前频谱")
        self.stop_btn.setEnabled(False)

    def stop_current_sampling(self):
        self.textEdit.append("---- 停止采样 ----\n")
        self.stop_btn.setEnabled(False)

        # self.sample_thread.terminate()
        self.sample_thread.stop()
        self.sample_thread.wait()
        self.sample_thread = None

        self.plot_btn.setEnabled(True)
        self.plot_btn.setToolTip("查看当前频谱")

    def plot_psd_start(self):
        self.textEdit.append("---- 查看频谱 ----\n")
        self.sample_thread = SampleThread()
        self.sample_thread.spec_data_get[list].connect(self.plot_psd)

        self.sample_thread.out_file_name = "usrp_tmp.bin"
        self.sample_thread.config = self.view_spec_config

        self.sample_thread.mode = 0
        self.sample_thread.start_sample = True

        self.sample_thread.start()

        self.ok_btn.setEnabled(False)

    @pyqtSlot(list)
    def plot_psd(self, data):
        print("-- plot spec --")
        self.plot_win.show()
        self.plot_win.fc = self.config.fc
        self.plot_win.fs = self.config.fs
        self.plot_win.sig = data
        self.plot_win.t.start(50)

    @pyqtSlot()
    def plot_psd_stop(self):
        self.textEdit.append("---- 查看频谱 ----\n")
        self.sample_thread.start_plot = False
        # self.sample_thread.terminate()
        self.sample_thread.stop()
        self.sample_thread.wait()
        self.sample_thread = None

        self.ok_btn.setEnabled(True)

    def set_advance_mode(self):
        self.advance_mode = not self.advance_mode
        if self.advance_mode:
            self.advance_groupBox.show()
            self.advance_mode_btn.setText("退出高级模式")
            self.textEdit.setText("-- 退出高级模式 --")
        else:
            self.advance_groupBox.hide()
            self.advance_mode_btn.setText("打开高级模式")
            self.textEdit.setText("-- 打开高级模式 --")

    def open_folder(self):
        dataPath = QtWidgets.QFileDialog.getExistingDirectory(
            self, "选择文件保存路径", self.CONFIG["save_path"],
            QtWidgets.QFileDialog.ShowDirsOnly)
        if dataPath == "":
            return
        else:
            self.save_path_edit.setText(dataPath)

    def open_gnu_folder(self):
        dataPath = QtWidgets.QFileDialog.getExistingDirectory(
            self, "打开GNU Radio/bin目录", self.CONFIG["gnu_radio_path"],
            QtWidgets.QFileDialog.ShowDirsOnly)
        if dataPath == "":
            return
        else:
            self.gnu_radio_path_edit.setText(dataPath)

    @pyqtSlot(str)
    def new_gnu_radio_path(self, path):
        self.textEdit.append("gnu_path_changed: " + path)
        self.CONFIG["gnu_radio_path"] = path
        self.save_config()

    @pyqtSlot(str)
    def new_save_path(self, path):
        self.textEdit.append("save_path_changed: " + path)
        self.CONFIG["save_path"] = path
        self.save_config()

    @pyqtSlot(int)
    def new_fc_val(self, val):
        unit = self.config.ix2u_dict[self.fc_comboBox.currentIndex()]
        new_fc = f"{int(val)} {unit}"
        self.textEdit.append("FC: " + new_fc + "Hz")
        self.CONFIG["fc"] = new_fc
        self.save_config()

    @pyqtSlot(int)
    def new_fc_cbox(self, ix):
        try:
            unit = self.config.ix2u_dict[ix]
        except KeyError:
            raise ValueError("设置出错")
        new_fc = f"{self.fc_spinBox.value()} {unit}"
        self.textEdit.append("FC: " + new_fc + "Hz")
        self.CONFIG["fc"] = new_fc
        self.save_config()

    @pyqtSlot(int)
    def new_stop_fc_val(self, val):
        unit = self.config.ix2u_dict[self.stop_fc_comboBox.currentIndex()]
        new_stop_fc = f"{int(val)} {unit}"
        self.textEdit.append("stop_FC: " + new_stop_fc + "Hz")
        self.CONFIG["stop_fc"] = new_stop_fc
        self.save_config()

    @pyqtSlot(int)
    def new_stop_fc_cbox(self, ix):
        try:
            unit = self.config.ix2u_dict[ix]
        except KeyError:
            raise ValueError("设置出错")
        new_stop_fc = f"{self.stop_fc_spinBox.value()} {unit}"
        self.textEdit.append("stop_FC: " + new_stop_fc + "Hz")
        self.CONFIG["stop_fc"] = new_stop_fc
        self.save_config()

    @pyqtSlot(int)
    def new_fs_val(self, val):
        unit = self.config.ix2u_dict[self.fs_comboBox.currentIndex()]
        new_fs = f"{int(val)} {unit}"
        self.textEdit.append("FS: " + new_fs + "Hz")
        self.CONFIG["fs"] = new_fs
        self.save_config()

    @pyqtSlot(int)
    def new_fs_cbox(self, ix):
        try:
            unit = self.config.ix2u_dict[ix]
        except KeyError:
            raise ValueError("设置出错")
        new_fs = f"{self.fs_spinBox.value()} {unit}"
        self.textEdit.append("FS: " + new_fs + "Hz")
        self.CONFIG["fs"] = new_fs
        self.save_config()

    @pyqtSlot(int)
    def new_sample_interval_val(self, val):
        unit = self.config.ix2u_dict[
            self.sample_interval_comboBox.currentIndex()]
        new_sample_interval = f"{int(val)} {unit}"
        self.textEdit.append("sample_interval: " + new_sample_interval + "Hz")
        self.CONFIG["sample_interval"] = new_sample_interval
        self.save_config()

    @pyqtSlot(int)
    def new_sample_interval_cbox(self, ix):
        try:
            unit = self.config.ix2u_dict[ix]
        except KeyError:
            raise ValueError("设置出错")
        new_sample_interval = f"{self.sample_interval_spinBox.value()} {unit}"
        self.textEdit.append("sample_interval: " + new_sample_interval + "Hz")
        self.CONFIG["sample_interval"] = new_sample_interval
        self.save_config()

    @pyqtSlot(int)
    def new_n_sample_val(self, val):
        unit = self.config.ix2u_dict[self.sample_nums_comboBox.currentIndex()]
        new_n_sample = f"{int(val)} {unit}"
        # new_n_sample = f"{int(val)} {_d[self.sample_nums_comboBox.currentIndex()]}"
        self.textEdit.append("sample_num: " + new_n_sample)
        self.CONFIG["sample_nums"] = new_n_sample
        self.save_config()

    @pyqtSlot(int)
    def new_n_sample_cbox(self, ix):
        try:
            unit = self.config.ix2u_dict[ix]
        except KeyError:
            raise ValueError("设置出错")
        new_n_sample = f"{self.sample_nums_spinBox.value()} {unit}"
        self.textEdit.append("sample_num: " + new_n_sample)
        self.CONFIG["sample_nums"] = new_n_sample
        self.save_config()

    @pyqtSlot(int)
    def new_sample_times(self, val):
        new_times = str(val)
        self.textEdit.append("sample_times: " + new_times)
        self.CONFIG["sample_times"] = new_times
        self.save_config()
Exemple #23
0
    def show_all_layers(self):
        title = f'All Layers of {self.spec.id}'
        horizontal = self.rect().width() > self.rect().height()
        subplot_grid_shape = (7, 1) if horizontal else (1, 7)

        plot = PlotWindow(title, shape=subplot_grid_shape)

        plt.sca(plot.axis[0])
        plt.imshow(self.spec.contamination + self.spec.science, origin='lower')
        plt.title('Original')
        plt.draw()

        plt.sca(plot.axis[1])
        plt.imshow(self.spec.contamination, origin='lower')
        plt.title('Contamination')
        plt.draw()

        plt.sca(plot.axis[2])
        plt.imshow(self.spec.science, origin='lower')
        plt.title('Decontaminated')
        plt.draw()

        plt.sca(plot.axis[3])
        if self.model is not None:
            plt.imshow(self.model, origin='lower')
            plt.title('Model')
        else:
            plt.title('N/A')
        plt.draw()

        plt.sca(plot.axis[4])
        if self.model is not None:
            plt.imshow(self.spec.science - self.model, origin='lower')
            plt.title('Residual')
        else:
            plt.title('N/A')
        plt.draw()

        plt.sca(plot.axis[5])
        plt.imshow(self.spec.variance, origin='lower')
        plt.title('Variance')
        plt.draw()

        plt.sca(plot.axis[6])
        data = (flag['ZERO'] & self.spec.mask) == flag['ZERO']
        plt.imshow(data, origin='lower')
        plt.title('Zeroth Orders')
        plt.draw()

        if horizontal:
            plt.subplots_adjust(top=0.97, bottom=0.025, left=0.025, right=0.975, hspace=0, wspace=0)
        else:
            plt.subplots_adjust(top=0.9, bottom=0.03, left=0.025, right=0.975, hspace=0, wspace=0)

        plt.draw()
        plot.setWindowFlag(Qt.WindowStaysOnTopHint, False)
        plot.show()

        padding = 50

        display = QApplication.desktop()
        current_screen = display.screenNumber(self.view)
        geom = display.screenGeometry(current_screen)
        width = geom.width() - 2 * padding
        height = geom.height() - 2 * padding
        plot.setGeometry(geom.left() + padding, geom.top() + padding, width, height)
        plt.close()
Exemple #24
0
    'jitter': get_jitter_plot,
    'candle': get_candle_plot,
    'errorbar': get_errorbar_plot,
    'filled_line': get_filled_line_plot,
    'image': get_image_plot,
    'image_from_file': get_image_from_file,
    'cmap_image': get_cmap_image_plot,
    'contour_line': get_contour_line_plot,
    'contour_poly': get_contour_poly_plot,
    'polygon': get_polygon_plot,
    'bar': get_bar_plot,
    'quiver': get_quiver_plot,
    'polar': get_polar_plot,
    'multiline': get_multiline_plot,
}


if __name__ == '__main__':
    name = 'vsize_scatter'

    factory_func = all_examples[name]
    plot = factory_func()

    window = PlotWindow(plot=plot)
    ui = window.edit_traits()

    filename = '{}_plot.png'.format(name)
    save_plot(window.container, filename)