예제 #1
0
def test_Multi(qtbot):
    mpp = uspp.Multi()

    glw1 = pg.GraphicsLayoutWidget(window_title='Multi 1')
    gl = glw1.ci
    mpp.add_plot(
        'temp',
        uspp.OverlaidTemporal(gl=gl,
                              pens={
                                  'intensity': 'b',
                                  'phase': 'r'
                              },
                              bottom_label='t (cows)',
                              intensity_label='intensity (fish)'))
    mpp.add_plot('freq',
                 uspp.OverlaidFrequency(gl=gl, phase_label='phase (pi rad)'))
    glw1.show()

    glw2 = pg.GraphicsLayoutWidget(window_title='Multi 2')
    gl = glw2.ci
    mpp.add_plot('temp2', uspp.StackedTemporal(gl=gl, bottom_label='bottom'))
    # gl.currentCol=3
    # gl.currentRow=0
    mpp.add_plot('freq2', uspp.StackedFrequency(gl=gl))
    glw2.show()
    mpp.set_pulse(0, t=t, Et=Et, omega=omega, Ef=Ef)

    if qtbot is not None:
        qtbot.addWidget(glw1)
        qtbot.addWidget(glw2)
    return mpp, glw1, glw2
예제 #2
0
 def make_glw(title, amplitude_label, domain='r'):
     label_str = {
         'r': ('x (mm)', 'y (mm)'),
         'q': ('kx (rad/mm)', 'ky (rad/mm)')
     }
     bottom_label, left_label = label_str[domain]
     glw = pg.GraphicsLayoutWidget()
     glw.addLabel(title)
     glw.nextRows()
     gl = glw.addLayout()
     abs_plot = gl.addAlignedPlot(labels={
         'bottom': bottom_label,
         'left': left_label
     },
                                  title='Amplitude')
     abs_image = abs_plot.image(lut=pg.get_colormap_lut())
     gl.addHorizontalSpacer(10)
     gl.addColorBar(image=abs_image, label=amplitude_label, rel_row=2)
     gl.addHorizontalSpacer(20)
     # gl.nextRows()
     phase_plot = gl.addAlignedPlot(labels={
         'bottom': bottom_label,
         'left': left_label
     },
                                    title='Phase')
     phase_plot.setXYLink(abs_plot)
     phase_image = phase_plot.image(lut=pg.get_colormap_lut('bipolar'))
     gl.addHorizontalSpacer(10)
     gl.addColorBar(image=phase_image, label='Waves', rel_row=2)
     return glw, (abs_image, phase_image)
예제 #3
0
파일: profiles.py 프로젝트: draustin/otk
    def plot_r_q_polar(self, flat=False, tilt=False, show=True):
        """Plot approximate plane profile and surface z relative to z_mean."""
        app = self.app
        Er = app.Er_flat if flat else app.Er
        Eq = math.fft2(Er)
        if not tilt:
            Er = Er * mathx.expj(-(app.qs_center[0] * app.x +
                                   app.qs_center[1] * app.y))
            Eq = Eq * mathx.expj(app.rs_center[0] * app.kx +
                                 app.rs_center[1] * app.ky)

        glw = pg.GraphicsLayoutWidget()
        glw.addLabel(self.title_str)
        glw.nextRow()
        gl = glw.addLayout()
        plot = gl.addAlignedPlot(labels={'left': 'y (mm)', 'bottom': 'x (mm)'})
        x, y, zu = sa.unroll_r(self.rs_support, self.z, self.rs_center)
        image = plot.image((zu - self.mean_z) * 1e3,
                           rect=pg.axes_to_rect(x * 1e3, y * 1e3),
                           lut=pg.get_colormap_lut('bipolar'))
        gl.addHorizontalSpacer(10)
        gl.addColorBar(image=image, rel_row=2, label='Relative z (mm)')
        glw.nextRow()

        glw.addLabel('Approximate planar profile')
        glw.nextRow()
        gl = glw.addLayout()
        plots = plotting.plot_r_q_polar(app.rs_support, Er, app.rs_center,
                                        app.qs_center, gl, Eq)

        glw.resize(830, 675)
        if show:
            glw.show()
        return glw, plots
예제 #4
0
파일: profiles.py 프로젝트: draustin/otk
    def plot_r_q_polar(self, flat=False, tilt=False, show=True):
        """Plot amplitude and phase in real and angular space.

        To see self.Er and its transform exactly, set flat=False and tilt=True.

        Args:
            flat (bool): Plot Er_flat instead of Er (both domains).
            tilt (bool): Include the central tilt in the real and angular space phase plots.
            show:

        Returns:
            GraphicsLayoutWidget: Contains the four plots and a heading.
            plots (RQ tuple of AbsPhi tuples): The AlignedPlotItems.
        """
        Er = self.Er_flat if flat else self.Er
        Eq = math.fft2(Er)
        if not tilt:
            Er = Er * mathx.expj(-(self.qs_center[0] * self.x +
                                   self.qs_center[1] * self.y))
            Eq = Eq * mathx.expj(self.rs_center[0] * self.kx +
                                 self.rs_center[1] * self.ky)
        glw = pg.GraphicsLayoutWidget()
        glw.addLabel(self.title_str)
        glw.nextRow()
        gl = glw.addLayout()
        plots = plotting.plot_r_q_polar(self.rs_support, Er, self.rs_center,
                                        self.qs_center, gl, Eq)
        glw.resize(830, 675)
        if show:
            glw.show()
        return glw, plots
예제 #5
0
파일: plot.py 프로젝트: draustin/optphys
def time_and_freq_stacked(temp_kwargs=None,
                          freq_kwargs=None,
                          gl=None,
                          legend=None):
    if gl is None:
        glw = pg.GraphicsLayoutWidget()
        gl = glw.ci
    row_0 = gl.currentRow
    col_0 = gl.currentCol
    mpp = Multi()
    mpp.add_plot('time',
                 StackedTemporal(gl=gl, row=row_0, col=col_0, **temp_kwargs))
    mpp.add_plot(
        'freq', StackedFrequency(gl=gl,
                                 row=row_0 + 9,
                                 col=col_0,
                                 **freq_kwargs))
    gl.currentRow = row_0 + 18
    gl.currentCol = col_0
    if legend is not None:
        domain = legend.pop('domain', 'time')
        type = legend.pop('type', 'intensity')
        leg_plot = getattr(mpp.plots[domain].plots, type)
        pg.addLegend(leg_plot, **legend)
    if 'glw' in locals():
        glw.show()
        mpp.glw = glw
    return mpp
예제 #6
0
    def __init__(self, gl=None, cornertexts=None):
        """Create plot items and colorbar.
        All items are managed by GraphicsLayout gl. If gl is not created,
        a GraphicsLayoutWidget is created too (for interactive plotting).
        The origin (upper left corner cell) is gl's current row and column."""
        def show(plt, axes):
            for axis in axes:
                plt.showAxis(axis)
                plt.getAxis(axis).setStyle(showValues=False)

        s = {}
        if gl is None:
            self.widget = pg.GraphicsLayoutWidget()
            self.widget.show()
            gl = self.widget.ci
        else:
            self.widget = None
        row_0 = gl.currentRow
        col_0 = gl.currentCol
        vspace = 10
        hspace = 10
        vp = gl.addAlignedPlot(
            row_0 + 0, col_0)  # labels={'left':'ω','top':'intensity'}
        show(vp, ('bottom', 'right'))
        vp.getAxis('top').show()
        vp.getAxis('bottom').setHeight(0)
        gl.addHorizontalSpacer(hspace, row_0 + 5, col_0 + 3)
        ip = gl.addAlignedPlot(row_0 + 0, col_0 + 4)
        show(ip, ('top', 'left', 'right', 'bottom'))
        gl.addHorizontalSpacer(hspace, row_0 + 2, col_0 + 7)
        cbar = pg.ColorBarItem()
        gl.addItem(cbar, row_0 + 2, col_0 + 8)
        gl.addVerticalSpacer(vspace, row_0 + 4, col_0)
        hp = gl.addAlignedPlot(row_0 + 5, col_0 +
                               4)  # ,labels={'left':'intensity','bottom':'t'})
        show(hp, ('top', 'right'))
        hp.getAxis('left').setWidth(0)
        hp.getAxis('right').setWidth(0)
        ip.setXLink(hp)
        ip.setYLink(vp)
        gl.setColumnStretchFactor(2, col_0 + 5)
        gl.setRowStretchFactor(2, row_0 + 2)

        self.layout = gl
        self.plots = {'vert': vp, 'horz': hp, 'image': ip}
        self.cbar = cbar

        if cornertexts is not None:
            if len(cornertexts) == 0:
                cornertexts = {'vert': '(a)', 'image': '(b)', 'horz': '(c)'}
            self.cornertexts = {}
            for plot_name, text in cornertexts.items():
                self.cornertexts[plot_name] = pg.cornertext(
                    text, self.plots[plot_name])
예제 #7
0
파일: widgets.py 프로젝트: draustin/otk
    def __init__(self, parent=None):
        ProfileWidget.__init__(self, parent)

        combo_box = QtWidgets.QComboBox()
        self.field_combo_box = combo_box
        combo_box.addItem('true')
        combo_box.addItem('flattened')
        combo_box.currentIndexChanged.connect(self._update)

        check_box = QtWidgets.QCheckBox('Remove tilt')
        self.remove_tilt_check_box = check_box
        check_box.setChecked(True)
        check_box.stateChanged.connect(self._update)

        check_box = QtWidgets.QCheckBox('Remove constant')
        self.remove_constant_check_box = check_box
        check_box.setChecked(True)
        check_box.stateChanged.connect(self._update)

        glw = pg.GraphicsLayoutWidget()
        self.label = glw.addLabel()
        glw.nextRow()
        gl = glw.addLayout()
        absEr_plot, absEr_image, absEr_scatter = self.make_absEr(gl)
        gl.addHorizontalSpacer(10)
        absEq_plot, absEq_image, absEq_scatter = self.make_absEq(gl)
        gl.nextRows()
        wavesr_plot, wavesr_image, wavesr_scatter = self.make_wavesr(
            gl, absEr_plot)
        gl.addHorizontalSpacer(10)
        wavesq_plot, wavesq_image, wavesq_scatter = self.make_wavesr(
            gl, absEq_plot)

        self.plots = sa.RQ(sa.AbsPhase(absEr_plot, wavesr_plot),
                           sa.AbsPhase(absEq_plot, wavesq_plot))
        self.images = sa.RQ(sa.AbsPhase(absEr_image, wavesr_image),
                            sa.AbsPhase(absEq_image, wavesq_image))
        self.scatters = sa.RQ(sa.AbsPhase(absEr_scatter, wavesr_scatter),
                              sa.AbsPhase(absEq_scatter, wavesq_scatter))

        # Place widgets.
        vbox = QtWidgets.QVBoxLayout()
        self.setLayout(vbox)
        hbox = QtWidgets.QHBoxLayout()
        vbox.addLayout(hbox)
        hbox.addWidget(QtWidgets.QLabel('Field:'))
        hbox.addWidget(self.field_combo_box)
        hbox.addWidget(QtWidgets.QLabel('Phase:'))
        hbox.addWidget(self.remove_tilt_check_box)
        hbox.addWidget(self.remove_constant_check_box)
        hbox.setAlignment(Qt.Qt.AlignLeft)
        vbox.addWidget(glw)
예제 #8
0
 def setup_ultrashort_pulse_plot(cls,
                                 ftd,
                                 log10_range=3,
                                 S_transform=None,
                                 gl=None,
                                 lut=None,
                                 t_unit='fs',
                                 omega_unit='rad/fs',
                                 It_scale=1,
                                 If_scale=1,
                                 S_scale=1):
     if gl is None:
         glw = pg.GraphicsLayoutWidget()
         gl = glw.ci
     if lut is None:
         lut = pg.get_colormap_lut()
     scale = dict(x={'fs': 1e-15}[t_unit],
                  k={
                      'rad/fs': 1e15,
                      'eV': SI['e'] / SI['hbar']
                  }[omega_unit],
                  Ix=It_scale,
                  Ik=If_scale,
                  S=S_scale)
     It_str = '|E(t)|<sup>2</sup>'
     If_str = '|E(&omega;)|<sup>2</sup>'
     S_str = 'Spectrogram'
     if It_scale == 'max':
         It_str += ' (norm.)'
     if If_scale == 'max':
         If_str += ' (norm.)'
     if S_scale == 'max':
         S_str += ' (norm.)'
     psp = PhaseSpacePlotAligned(ftd=ftd,
                                 lut=lut,
                                 log10_range=log10_range,
                                 S_transform=S_transform,
                                 scale=scale,
                                 gl=gl)
     vp = psp.plots['vert']
     vp.setLabel('left', '&omega; (%s)' % omega_unit)
     vp.setLabel('top', If_str)
     hp = psp.plots['horz']
     hp.setLabel('bottom', 't (%s)' % t_unit)
     hp.setLabel('left', It_str)
     psp.cbar.setLabel(S_str)
     if 'glw' in locals():
         glw.show()
         psp.widget = glw
     return psp
예제 #9
0
    def show(self):
        rms = (self.ix.var(axis=(-1, -2)) + self.iy.var(axis=(-1, -2)))**0.5
        ixmu = self.ix.mean(axis=(-1, -2))
        iymu = self.iy.mean(axis=(-1, -2))

        glw = pg.GraphicsLayoutWidget()
        # title = 'Input & output aperture side length %.1f mm. %dx%d plane waves, each with %dx%d rays.'%(
        #     self.field_side_length*1e3, num_spots, num_spots, num_rays, num_rays)
        # glw.addLabel(title, colspan=2)
        # glw.nextRow()

        gl = glw.addLayout()
        spot_plot = gl.addAlignedPlot(labels={
            'left': 'field y (mm)',
            'bottom': 'field x (mm)'
        },
                                      title='Spots')
        index = 0
        for ix_, iy_ in zip(self.ix, self.iy):
            for ix, iy in zip(ix_, iy_):
                item = pg.ScatterPlotItem(ix.ravel() * 1e3,
                                          iy.ravel() * 1e3,
                                          pen=None,
                                          brush=pg.tableau20[index % 20],
                                          size=2)
                spot_plot.addItem(item)
                index += 1

        gl = glw.addLayout()
        rms_plot = gl.addAlignedPlot(labels={
            'left': 'theta y (mrad)',
            'bottom': 'theta x (mrad)'
        },
                                     title='RMS spot size')
        rms_image = rms_plot.image(rms * 1e6,
                                   rect=pg.axes_to_rect(
                                       self.thetax * 1e3, self.thetay * 1e3),
                                   lut=pg.get_colormap_lut())
        gl.addHorizontalSpacer()
        gl.addColorBar(image=rms_image, rel_row=2, label='Size (micron)')

        glw.resize(920, 400)
        glw.show()
        return glw
예제 #10
0
파일: pgx.py 프로젝트: draustin/otk
def plot_projection(profile, projected):
    residual = profile.Er - projected

    glw = pg.GraphicsLayoutWidget()
    field_plot = glw.addAlignedPlot(labels={
        'left': 'y (mm)',
        'bottom': 'x (mm)'
    },
                                    title='Field')
    field_image = asbp.make_Er_image_item(profile.rs_support, profile.Er,
                                          profile.rs_center, 'amplitude')
    field_plot.addItem(field_image)
    glw.addHorizontalSpacer()

    projected_plot = glw.addAlignedPlot(labels={
        'left': 'y (mm)',
        'bottom': 'x (mm)'
    },
                                        title='Projected')
    projected_plot.setXYLink(field_plot)
    projected_image = asbp.make_Er_image_item(profile.rs_support, projected,
                                              profile.rs_center, 'amplitude')
    projected_plot.addItem(projected_image)
    glw.addHorizontalSpacer()
    glw.addColorBar(images=(field_image, projected_image), rel_row=2)
    glw.addHorizontalSpacer()

    residual_plot = glw.addAlignedPlot(labels={
        'left': 'y (mm)',
        'bottom': 'x (mm)'
    },
                                       title='Residual')
    residual_image = asbp.make_Er_image_item(profile.rs_support, residual,
                                             profile.rs_center, 'amplitude')
    residual_plot.addItem(residual_image)
    residual_plot.setXYLink(projected_plot)
    glw.addColorBar(image=residual_image, rel_row=2)

    glw.resize(1200, 360)
    glw.show()
    return glw
예제 #11
0
파일: plot.py 프로젝트: draustin/optphys
 def __init__(self, gl=None, row=None, col=None, **kwargs):
     """
     Args:
         gl (pyqtgraph GraphicsLayout): to which the plot is added. If
             None, creates one.
         row_0 (int): row
     """
     super().__init__(**kwargs)
     if gl is None:
         self.glw = pg.GraphicsLayoutWidget()
         self.glw.show()
         self.gl = self.glw.ci
     else:
         self.glw = None
         self.gl = gl
     if row is None:
         row = self.gl.currentRow
     if col is None:
         col = self.gl.currentCol
     self.row = row
     self.col = col
     self.lines = self.Pair({}, {})  # self.line_x_bounds={}
예제 #12
0
def plot_r_q_polar(rs_support, Er, rs_center=(0, 0), qs_center=(0, 0), gl=None, Eq=None):
    if gl is None:
        glw = pg.GraphicsLayoutWidget()
        plots = plot_r_q_polar(rs_support, Er, rs_center, qs_center, glw.ci, Eq)
        glw.resize(830, 675)
        glw.show()
        return glw, plots
    else:
        if Eq is None:
            Eq = math.fft2(Er)
        absEr_plot = gl.addAlignedPlot(labels={'left':'y (mm)', 'bottom':'x (mm)'}, title='Real space amplitude')
        image = make_Er_image_item(rs_support, Er, rs_center, 'amplitude')
        absEr_plot.addItem(image)
        gl.addHorizontalSpacer(10)
        gl.addColorBar(image=image, rel_row=2, label='Amplitude')
        gl.addHorizontalSpacer(10)
        wavesr_plot = gl.addAlignedPlot(labels={'left':'y (mm)', 'bottom':'x (mm)'}, title='Real space wavefront')
        image = make_Er_image_item(rs_support, Er, rs_center, 'waves')
        wavesr_plot.addItem(image)
        wavesr_plot.setXYLink(absEr_plot)
        gl.addHorizontalSpacer(10)
        gl.addColorBar(image=image, rel_row=2, label='Waves')
        gl.nextRows()
        absEq_plot = gl.addAlignedPlot(labels={'left':'ky (rad/mm)', 'bottom':'kx (rad/mm)'}, title='Angular space amplitude')
        image = make_Eq_image_item(rs_support, Eq, qs_center, 'amplitude')
        absEq_plot.addItem(image)
        gl.addHorizontalSpacer(10)
        gl.addColorBar(image=image, rel_row=2, label='Amplitude')
        gl.addHorizontalSpacer(10)
        wavesq_plot = gl.addAlignedPlot(labels={'left':'ky (rad/mm)', 'bottom':'kx (rad/mm)'},
                                       title='Angular space wavefront')
        image = make_Eq_image_item(rs_support, Eq, qs_center, 'waves')
        wavesq_plot.addItem(image)
        wavesq_plot.setXYLink(absEq_plot)
        gl.addHorizontalSpacer(10)
        gl.addColorBar(image=image, rel_row=2, label='Waves')
        return sa.RQ(sa.AbsPhase(absEr_plot, wavesr_plot), sa.AbsPhase(absEq_plot, wavesq_plot))
예제 #13
0
#Et=5*np.random.randn(*t.shape)
Ef = ft.trans(Et)
#Ef=Ef*np.exp(-0.1*omega**2)
beta_2 = -1
gamma = 1


def prop_1(z, Ef, h):
    return np.exp(0.5j * h * beta_2 * omega**2) * Ef


def prop_2(z, Et, h):
    return np.exp(1j * h * gamma * Et * Et.conj()) * Et


glw = pg.GraphicsLayoutWidget()
tplt = glw.addAlignedPlot(labels={'left': '|E(t)|', 'bottom': 't'}, title='-')
tplt.plot(t, abs(Et), pen='b')
tl = tplt.plot(pen='r')
glw.nextRows()
fplt = glw.addAlignedPlot(labels={'left': '|E(omega)|', 'bottom': 'omega'})
fplt.plot(omega, abs(Ef), pen='b')
fl = fplt.plot(pen='r')
glw.show()


def update_plot(_, z, Ef, h, steps, interp):
    if glw.isHidden():
        return True  # terminate
    Et = ft.inv_trans(Ef)
    tplt.setTitle('#%d, z=%.3f, h=%.3f' % (steps, z, h))
예제 #14
0
파일: widgets.py 프로젝트: draustin/otk
    def __init__(self, parent=None):
        ProfileWidget.__init__(self, parent)

        combo_box = QtWidgets.QComboBox()
        self.field_combo_box = combo_box
        combo_box.addItem('true')
        combo_box.addItem('approximate planar')
        combo_box.addItem('approximate planar flattened')
        combo_box.currentIndexChanged.connect(self._update)

        check_box = QtWidgets.QCheckBox('Remove tilt')
        self.remove_tilt_check_box = check_box
        check_box.setChecked(True)
        check_box.stateChanged.connect(self._update)

        check_box = QtWidgets.QCheckBox('Remove constant')
        self.remove_constant_check_box = check_box
        check_box.setChecked(True)
        check_box.stateChanged.connect(self._update)

        glw = pg.GraphicsLayoutWidget()
        self.label = glw.addLabel()
        glw.nextRow()
        gl = glw.addLayout()
        absEr_plot, absEr_image, absEr_scatter = self.make_absEr(gl)
        gl.addHorizontalSpacer(10)
        wavesr_plot, wavesr_image, wavesr_scatter = self.make_wavesr(
            gl, absEr_plot)
        gl.addHorizontalSpacer(10)
        self.dz_plot = gl.addAlignedPlot(labels={
            'left': 'y (mm)',
            'bottom': 'x (mm)'
        })
        self.dz_image = pg.ImageItem(lut=pg.get_colormap_lut())
        self.dz_plot.addItem(self.dz_image)
        self.dz_plot.setXYLink(wavesr_plot)
        gl.addHorizontalSpacer(10)
        gl.addColorBar(image=self.dz_image, rel_row=2, label='Relative z (mm)')

        glw.nextRows()
        gl = glw.addLayout()
        absEq_plot, absEq_image, absEq_scatter = self.make_absEq(gl)
        gl.addHorizontalSpacer(10)
        wavesq_plot, wavesq_image, wavesq_scatter = self.make_wavesr(
            gl, absEq_plot)

        self.plots = sa.RQ(sa.AbsPhase(absEr_plot, wavesr_plot),
                           sa.AbsPhase(absEq_plot, wavesq_plot))
        self.images = sa.RQ(sa.AbsPhase(absEr_image, wavesr_image),
                            sa.AbsPhase(absEq_image, wavesq_image))
        self.scatters = sa.RQ(sa.AbsPhase(absEr_scatter, wavesr_scatter),
                              sa.AbsPhase(absEq_scatter, wavesq_scatter))

        # Place widgets.
        vbox = QtWidgets.QVBoxLayout()
        self.setLayout(vbox)
        hbox = QtWidgets.QHBoxLayout()
        vbox.addLayout(hbox)
        hbox.addWidget(QtWidgets.QLabel('Mode:'))
        hbox.addWidget(self.field_combo_box)
        hbox.addWidget(QtWidgets.QLabel('Phase:'))
        hbox.addWidget(self.remove_tilt_check_box)
        hbox.addWidget(self.remove_constant_check_box)
        hbox.setAlignment(Qt.Qt.AlignLeft)
        vbox.addWidget(glw)
예제 #15
0
def plot_polar_image(r,
                     phi,
                     data,
                     layout=None,
                     r_label_phi=math.pi / 4,
                     grid_r=None,
                     levels=None,
                     lut=None,
                     cbar_label=None,
                     phi_0=0,
                     phi_dir=1,
                     r_label_fmt='%g',
                     aspect_locked=True,
                     mask_array=None,
                     theta_repeats=None,
                     grid_color='w',
                     osamp=1):
    """
    Args:
        r (uniformly sampled vector of shape (n,1) or (n,)): radii
        phi (uniformly sampled vector of shape (m,)): azimuthal angles in radians
        data (array of shape (n,m)): data to plot
        layout (pyqtgraph GraphicsLayout): if None, a GraphicsLayoutWidget is created.
            An AlignedPlotItem is added to the layout.
        mask_array (array of same shape as data): mask for data - where it is negative
            data will be greyed out. The pyqtgraph ImageItem will be in RGB rather
            than scalar format, and the color bar will not be adjustable.
    """
    assert usv.is_usv(r)
    assert usv.is_usv(phi)
    if layout is None:
        layout_ = pg.GraphicsLayoutWidget()
    else:
        layout_ = layout
    plt = layout_.addAlignedPlot()
    plt.hideAxis('left')
    plt.hideAxis('bottom')
    if lut is None:
        lut = pg.get_colormap_lut()
    if isinstance(lut, str):
        lut = pg.get_colormap_lut(lut)
    phip = phi_0 + phi_dir * phi
    x, y, data = mathx.polar_reg_grid_to_rect(r.squeeze(), phip, data,
                                              theta_repeats, osamp)
    if mask_array is not None:
        _, _, mask_array = mathx.polar_reg_grid_to_rect(
            r.squeeze(), phip, mask_array, theta_repeats, osamp)
        if levels is None:
            data_masked = data[mask_array >= 0]
            levels = data_masked.min(), data_masked.max()
        image_data = pg.makeARGB(data.T, lut, levels=levels, useRGBA=True)[0]
        image_data[mask_array.T < 0] = [128, 128, 128, 128]
        image = plt.image(image_data,
                          rect=pg.axes_to_rect(x, y),
                          levels=(0, 255))
    else:
        image = plt.image(data.T, rect=pg.axes_to_rect(x, y), lut=lut)
        if levels is not None:
            image.setLevels(levels)
    if grid_r is None:
        grid_r = np.arange(1, 5) / 5 * r[-1]
    if len(grid_r) > 0:
        plot_radial_grid_lines(plt,
                               grid_r,
                               grid_color,
                               r_label_fmt,
                               label_angle=phi_0 +
                               phi_dir * np.asarray(r_label_phi))
        phi_lines = (np.round(phi[-1] /
                              (math.pi / 2)) - np.arange(4)) * math.pi / 2
        plot_azimuthal_grid_lines(plt,
                                  phi_lines,
                                  grid_r[-1],
                                  grid_color,
                                  '%g&pi;',
                                  unit=math.pi,
                                  phi_0=phi_0,
                                  phi_dir=phi_dir)
    plt.setAspectLocked(aspect_locked)
    plt.setXRange(x[0], x[-1], padding=0)
    plt.setYRange(y[0], y[-1], padding=0)
    if cbar_label is not None:
        layout_.addHorizontalSpacer(5)
        # Add color bar
        cbar = layout_.addColorBar(label=cbar_label, rel_row=2)
        if mask_array is not None:
            cbar.setManual(lut, levels)
        else:
            cbar.setImage(image)
    if layout is None:
        layout_.show()
        return layout_
    else:
        return plt
예제 #16
0
    def __init__(self, gl=None, cornertexts=None):
        self.recursion_prevent = False

        def show(plt, axes):
            for axis in axes:
                plt.showAxis(axis)
                plt.getAxis(axis).setStyle(showValues=False)

        if gl is None:
            self.widget = pg.GraphicsLayoutWidget()
            self.widget.show()
            gl = self.widget.ci
        else:
            self.widget = None
        row_0 = gl.currentRow
        col_0 = gl.currentCol
        vspace = 10
        hspace = 10
        vlog = gl.addAlignedPlot(row_0 + 0, col_0 + 0)
        show(vlog, ('bottom', 'right'))
        vlog.showAxis('top')
        gl.addHorizontalSpacer(2, row_0 + 0, col_0 + 3)
        vproj = gl.addAlignedPlot(row_0 + 0, col_0 + 4)
        show(vproj, ('bottom', 'left', 'right'))
        vproj.showAxis('top')
        vproj.getAxis('left').setWidth(15)
        gl.addHorizontalSpacer(hspace, row_0 + 0, col_0 + 7)
        imageplot = gl.addAlignedPlot(row_0 + 0, col_0 + 8)
        show(imageplot, ('top', 'left', 'right', 'bottom'))
        cbar = pg.ColorBarItem()
        gl.addItem(cbar, row_0 + 2, col_0 + 12)
        gl.addVerticalSpacer(vspace, row_0 + 4, col_0 + 0)
        gl2 = gl.addLayout(row_0 + 5, 0, rowspan=12, colspan=6)
        logimg = gl2.addAlignedPlot(0, 0)
        show(logimg, ('top', 'left', 'right', 'bottom'))
        hproj = gl.addAlignedPlot(row_0 + 5, col_0 + 8)
        show(hproj, ('left', 'bottom', 'top'))
        hproj.showAxis('right')
        gl.addVerticalSpacer(vspace, row_0 + 9, col_0 + 8)
        hlog = gl.addAlignedPlot(row_0 + 10, col_0 + 8)
        show(hlog, ('left', 'top'))
        hlog.showAxis('right')
        gl.setRowStretchFactor(row_0 + 6, col_0 + 2)
        gl.setColumnStretchFactor(row_0 + 6, col_0 + 9)

        self.image_cornertext = pg.cornertext(' ', imageplot)
        self.logimg_cornertext = pg.cornertext(' ', logimg)

        # initialise plots
        self.layout = gl
        self.plots = {
            'vert': vproj,
            'horz': hproj,
            'image': imageplot,
            'vert_log': vlog,
            'horz_log': hlog,
            'log_image': logimg
        }
        self.cbar = cbar
        self.image = imageplot.image()
        self.hproj = hproj.plot()
        self.vproj = vproj.plot()
        self.hproj_log = hproj.plot()
        self.vproj_log = vproj.plot()
        self.hproj_ref = hproj.plot()
        self.vproj_ref = vproj.plot()
        self.hlog = hlog.image()
        self.vlog = vlog.image()
        self.logimg = logimg.image()

        # link axes and colorbar
        imageplot.setXLink(hproj)
        hproj.setXLink(hlog)
        vlog.sigXRangeChanged.connect(lambda: self.log_time_axis_link('v'))
        hlog.sigYRangeChanged.connect(lambda: self.log_time_axis_link('h'))
        imageplot.setYLink(vproj)
        vproj.setYLink(vlog)
        self.cbar.setImages([self.image])