Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def make_Er_image_item(r_support, Er, rs_center=(0, 0), quantity='waves'):
    x, y, Eru = sa.unroll_r(r_support, Er, rs_center)
    if quantity == 'amplitude':
        data = abs(Eru)
        lut = pg.get_colormap_lut()
        levels = 0, data.max()
    elif quantity == 'waves':
        data = np.angle(Eru)/(2*np.pi)
        lut = pg.get_colormap_lut('bipolar')
        levels = -0.5, 0.5
    item = pg.ImageItem(data, lut=lut)
    item.setRect(pg.axes_to_rect(x*1e3, y*1e3))
    item.setLevels(levels)
    return item
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
def test_PhaseSpacePlot(qtbot):
    ipp = pgr.ImageWithProjsAlignedPlot()
    psp = optphys.PhaseSpacePlot(ipp.plots,
                                 ftd=sft.FTD(x=t, k=omega, sign=1),
                                 Ex=Et,
                                 cbar=ipp.cbar,
                                 lut=pg.get_colormap_lut())
    return psp
Ejemplo n.º 5
0
 def make_absEq(cls, gl):
     plot = gl.addAlignedPlot(labels={
         'left': 'ky (rad/mm)',
         'bottom': 'kx (rad/mm)'
     },
                              title='Angular space amplitude')
     image = pg.ImageItem(lut=pg.get_colormap_lut())
     plot.addItem(image)
     scatter = pg.ScatterPlotItem(**scatter_kwargs)
     plot.addItem(scatter)
     gl.addHorizontalSpacer(10)
     gl.addColorBar(image=image, rel_row=2, label='Amplitude')
     return plot, image, scatter
Ejemplo n.º 6
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
Ejemplo n.º 7
0
 def make_wavesq(cls, gl, absEq_plot):
     plot = gl.addAlignedPlot(labels={
         'left': 'ky (rad/mm)',
         'bottom': 'kx (rad/mm)'
     },
                              title='Angular space wavefront')
     image = pg.ImageItem(lut=pg.get_colormap_lut('bipolar'))
     plot.addItem(image)
     plot.setXYLink(absEq_plot)
     scatter = pg.ScatterPlotItem(**scatter_kwargs)
     plot.addItem(scatter)
     gl.addHorizontalSpacer(10)
     gl.addColorBar(image=image, rel_row=2, label='Waves')
     return plot, image, scatter
Ejemplo n.º 8
0
 def __init__(self,
              y_label='y',
              color_bar=True,
              symmetric_phase_colormap=False,
              luts=None,
              **kwargs):
     if luts is None:
         luts = {}
     super().__init__(**kwargs)
     intensity_plot = pg.add_right_axis(self.plots.intensity, 'k', y_label)
     phase_plot = pg.add_right_axis(self.plots.phase, 'k', y_label)
     phase_plot.setYLink(intensity_plot)
     self.image_plots = self.Pair(intensity_plot, phase_plot)
     intensity_image = pg.ImageItem(np.zeros((2, 2)),
                                    lut=luts.pop('intensity',
                                                 pg.get_colormap_lut()))
     intensity_plot.addItem(intensity_image)
     phase_image = pg.ImageItem(
         np.zeros((2, 2)),
         lut=luts.pop('phase', pg.get_colormap_lut('bipolar')))
     phase_plot.addItem(phase_image)
     self.images = self.Pair(intensity_image, phase_image)
     self.symmetric_phase_colormap = symmetric_phase_colormap
     if color_bar:
         self.gl.addHorizontalSpacer(30, row=self.row + 2, col=self.col + 3)
         # labels on color bar unnecessary
         self.gl.addColorBar(image=intensity_image,
                             row=self.row + 2,
                             col=self.col + 4)  # label=intensity_label,
         self.gl.addColorBar(image=phase_image,
                             row=self.row + 7,
                             col=self.col + 4)  # label=phase_label,
     # Seems necessary for autorange at startup
     self.plots.intensity.enableAutoRange()
     self.gl.currentRow = self.row  # +8
     self.gl.currentCol = self.col + 5
     self.image_annotations = self.Pair({}, {})
Ejemplo n.º 9
0
def test_plot_polar_image_2(qtbot):
    r = np.linspace(0, 3)[:, None]
    num_phi = 50
    phi = np.arange(0, num_phi) / num_phi * math.pi * 2
    data = np.cos(phi - math.pi / 4) * r * np.exp(-r)
    fig = pgr.plot_polar_image(r,
                               phi,
                               data,
                               theta_repeats=True,
                               r_label_phi=3 * math.pi / 4,
                               grid_r=[0, 1, 2],
                               lut=pg.get_colormap_lut('grey'),
                               levels=(-0.1, 0.1),
                               cbar_label='intensity')
    return fig
Ejemplo n.º 10
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
Ejemplo n.º 11
0
"""
Check out how ImageItem behaves with nan values and how to make a mask e.g. to
grey out undefined phase values.
More investigation than testing.
"""
import numpy as np
import pyqtgraph_extended as pg
##
x=np.arange(100)
y=np.arange(120)[:,None]
f=np.exp(-((x-50)**2+(y-60)**2)/200)
fp=f.copy()
fp[0,0]=float('nan')
fp[f<0.2]=float('nan')
plt=pg.plot()
im=pg.ImageItem(fp)
im.setRect(pg.axes_to_rect(x,y))
im.setLookupTable(pg.get_colormap_lut())
im.setLevels((0,1))
plt.addItem(im)
##
f3=pg.makeARGB(f,pg.get_colormap_lut(),levels=(0,1),useRGBA=True)[0]#[:,:,[1,2,3,0]]
f3[f<0.1]=[128,128,128,128]
plt=pg.plot()
im=pg.ImageItem(f3)
im.setRect(pg.axes_to_rect(x,y))
#im.setLookupTable(pg.get_colormap_lut())
plt.addItem(im)
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
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