Ejemplo n.º 1
0
def test_MultiCursor(horizOn, vertOn):
    fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True)

    # useblit=false to avoid having to draw the figure to cache the renderer
    multi = widgets.MultiCursor(fig.canvas, (ax1, ax2),
                                useblit=False,
                                horizOn=horizOn,
                                vertOn=vertOn)

    # Only two of the axes should have a line drawn on them.
    if vertOn:
        assert len(multi.vlines) == 2
    if horizOn:
        assert len(multi.hlines) == 2

    # mock a motion_notify_event
    # Can't use `do_event` as that helper requires the widget
    # to have a single .ax attribute.
    event = mock_event(ax1, xdata=.5, ydata=.25)
    multi.onmove(event)

    # the lines in the first two ax should both move
    for l in multi.vlines:
        assert l.get_xdata() == (.5, .5)
    for l in multi.hlines:
        assert l.get_ydata() == (.25, .25)

    # test a move event in an axes not part of the MultiCursor
    # the lines in ax1 and ax2 should not have moved.
    event = mock_event(ax3, xdata=.75, ydata=.75)
    multi.onmove(event)
    for l in multi.vlines:
        assert l.get_xdata() == (.5, .5)
    for l in multi.hlines:
        assert l.get_ydata() == (.25, .25)
Ejemplo n.º 2
0
    def add_multicursor(self,
                        ax_nrs=[],
                        horizontal=False,
                        vertical=False,
                        **kwargs):

        ax_list = []
        for ax_nr in ax_nrs:
            ax_list.append(self.ax[ax_nr][1])
        self.multi_cursors[str(ax_nrs)] = widgets.MultiCursor(
            self.fig.canvas,
            ax_list,
            horizOn=horizontal,
            vertOn=vertical,
            **kwargs)
        plt.show()
Ejemplo n.º 3
0
    def __init__(self,
                 input_unlabeled_elm_event_file=None,
                 output_labeled_elm_event_filename=None,
                 save_pdf=True,
                 manual_elm_list=None):
        self.manual_elm_list = manual_elm_list
        self.time_markers = [None, None, None, None]
        self.marker_label = [
            'Pre-ELM start', 'ELM start', 'ELM end', 'Post-ELM end'
        ]
        self.fig, self.axes = plt.subplots(nrows=3, figsize=[15, 8])
        # self.fig_num = self.fig.number
        self.fig.canvas.mpl_connect('close_event', self.on_close)
        for axes in self.axes:
            axes.set_xlabel('Time (ms)')
        self.axes[0].set_ylabel('Line avg dens (AU)')
        self.axes[1].set_ylabel('D alpha')
        self.axes[2].set_ylabel('BES')
        plt.suptitle('empty')
        plt.tight_layout(rect=(0, 0.08, 1, 1))

        self.fig.canvas.mpl_connect('button_press_event', self.axis_click)

        self.save_pdf = save_pdf

        self.skip_button = widgets.Button(plt.axes([0.01, 0.02, 0.07, 0.04]),
                                          'Skip ELM',
                                          color='lightsalmon',
                                          hovercolor='red')
        self.skip_button.on_clicked(self.skip)

        self.clear_button = widgets.Button(plt.axes([0.2, 0.02, 0.2, 0.04]),
                                           'Clear markers',
                                           color='lightgray',
                                           hovercolor='darkgray')
        self.clear_button.on_clicked(self.clear_markers)

        self.status_box = widgets.TextBox(plt.axes([0.5, 0.02, 0.2, 0.04]),
                                          'Status:',
                                          color='w',
                                          hovercolor='w')

        self.accept_button = widgets.Button(plt.axes([0.75, 0.02, 0.2, 0.04]),
                                            'Accept markers',
                                            color='whitesmoke',
                                            hovercolor='whitesmoke')
        self.accept_button.on_clicked(self.accept)

        self.multi = widgets.MultiCursor(self.fig.canvas,
                                         self.axes,
                                         color='r',
                                         lw=1)

        assert Path(input_unlabeled_elm_event_file).exists()
        self.unlabeled_elm_events_h5 = h5py.File(
            input_unlabeled_elm_event_file, 'r')
        self.n_elms = len(self.unlabeled_elm_events_h5)
        print(
            f'Unlabeled ELM event data file: {input_unlabeled_elm_event_file}')
        print(f'  Number of ELM events: {self.n_elms}')
        # shots = np.unique([elm_event.attrs['shot'] for elm_event in self.unlabeled_elm_events_h5.values()])
        # print(f'  Number of unique shots: {shots.size}')

        output_file = Path().resolve() / output_labeled_elm_event_filename
        print(f'Output labeled ELM event file: {output_file}')
        print(f'  File exists: {output_file.exists()}')
        self.labeled_elm_events_h5 = h5py.File(output_file.as_posix(), 'a')

        self.figures_dir = Path().resolve() / 'figures'
        self.figures_dir.mkdir(exist_ok=True)

        self.labeled_elms = self.labeled_elm_events_h5.attrs.setdefault(
            'labeled_elms', np.array([], dtype=int))
        self.skipped_elms = self.labeled_elm_events_h5.attrs.setdefault(
            'skipped_elms', np.array([], dtype=int))

        self.validate_data_file()

        self.rng = np.random.default_rng()
        self.elm_index = None
        self.shot = None
        self.start_time = None
        self.stop_time = None
        self.time = None
        self.signals = None
        self.connection = MDSplus.Connection('atlas.gat.com')

        self.vlines = []
        self.data_lines = []
        self.clear_and_get_new_elm()
        plt.show()
    def __init__(self, save_pdf=False, manual_elm_list=None):
        self.manual_elm_list = manual_elm_list
        self.time_markers = [None, None, None, None]
        self.marker_label = [
            'Pre-ELM start', 'ELM start', 'ELM end', 'Post-ELM end'
        ]
        self.fig, self.axes = plt.subplots(ncols=3, figsize=[11.5, 4])
        self.fig_num = self.fig.number
        self.fig.canvas.mpl_connect('close_event', self.on_close)
        for axes in self.axes:
            axes.set_xlabel('Time (ms)')
            axes.set_title('empty')
        self.axes[0].set_ylabel('Line avg dens (AU)')
        self.axes[1].set_ylabel('D alpha')
        self.axes[2].set_ylabel('BES')
        plt.tight_layout(rect=(0, 0.15, 1, 1))

        self.fig.canvas.mpl_connect('button_press_event', self.axis_click)

        self.save_pdf = save_pdf

        # self.quit_button = widgets.Button(plt.axes([0.01, 0.05, 0.07, 0.075]),
        #                                   'Quit',
        #                                   color='lightsalmon',
        #                                   hovercolor='red')
        # self.quit_button.on_clicked(self.on_close)

        self.skip_button = widgets.Button(plt.axes([0.01, 0.05, 0.07, 0.075]),
                                          'Skip ELM',
                                          color='lightsalmon',
                                          hovercolor='red')
        self.skip_button.on_clicked(self.skip)

        self.clear_button = widgets.Button(plt.axes([0.2, 0.05, 0.2, 0.075]),
                                           'Clear markers',
                                           color='lightgray',
                                           hovercolor='darkgray')
        self.clear_button.on_clicked(self.clear_markers)

        self.status_box = widgets.TextBox(plt.axes([0.5, 0.05, 0.2, 0.075]),
                                          'Status:',
                                          color='w',
                                          hovercolor='w')

        self.accept_button = widgets.Button(plt.axes([0.75, 0.05, 0.2, 0.075]),
                                            'Accept markers',
                                            color='whitesmoke',
                                            hovercolor='whitesmoke')
        self.accept_button.on_clicked(self.accept)

        self.multi = widgets.MultiCursor(self.fig.canvas,
                                         self.axes,
                                         color='r',
                                         lw=1)

        self.elm_data_file = h5py.File(elm_signals_file, 'r')
        self.nelms = len(self.elm_data_file)

        self.label_file = h5py.File(labeled_elms_file, 'a')
        self.labeled_elms = self.label_file.attrs.setdefault(
            'labeled_elms', np.array([], dtype=np.int))
        self.skipped_elms = self.label_file.attrs.setdefault(
            'skipped_elms', np.array([], dtype=np.int))

        self.validate_data_file()

        self.rng = np.random.default_rng()
        self.elm_index = None
        self.shot = None
        self.start_time = None
        self.stop_time = None
        self.time = None
        self.signals = None
        self.connection = MDSplus.Connection('atlas.gat.com')

        self.vlines = []
        self.data_lines = []
        self.clear_and_get_new_elm()
Ejemplo n.º 5
0
    fig = plt.figure()
    top = plt.subplot2grid((3, 3), (0, 0), colspan=2)
    bot = plt.subplot2grid((3, 3), (1, 0), colspan=2, sharex=top)
    mlrn = plt.subplot2grid((3, 3), (2, 0), colspan=2, sharex=top)
    sid = plt.subplot2grid((3, 3), (0, 2), rowspan=3)

    fig = plot_data(stklst[0], fig, top, bot, mlrn, sid)

    #Setup for radio bottoms
    axcolor = 'lightgoldenrodyellow'
    ylen = len(stklst) / 50.0
    prop_radio = plt.axes([0.95, 1 - ylen, 0.048, ylen], axisbg=axcolor)
    radio = wd.RadioButtons(prop_radio, stklst)

    return [fig, top, bot, sid, mlrn, radio]


if __name__ == "__main__":
    fig, top, bot, sid, mlrn, radio = setup()

    #Setup multicursor between top and bottom plot
    multi = wd.MultiCursor(fig.canvas, (top, bot, mlrn), color='r', lw=2)

    def stocksel(label):
        plot_data(label, fig, top, bot, mlrn, sid)

    radio.on_clicked(stocksel)

    #Show plot
    plt.show()