Beispiel #1
0
 def setUp(self):
     super(TestStackViewMainWindow, self).setUp()
     self.stackview = StackViewMainWindow()
     self.stackview.show()
     self.qWaitForWindowExposed(self.stackview)
     self.mystack = numpy.fromfunction(
         lambda i, j, k: numpy.sin(i / 15.) + numpy.cos(j / 4.) + 2 * numpy.
         sin(k / 6.), (10, 20, 30))
    def plot_data3D(self, data3D, dataE, dataX, dataY, tabs_canvas_index, plot_canvas_index, title="", xtitle="", ytitle=""):

        for i in range(1+self.tab[tabs_canvas_index].layout().count()):
            self.tab[tabs_canvas_index].layout().removeItem(self.tab[tabs_canvas_index].layout().itemAt(i))

        #self.tab[tabs_canvas_index].layout().removeItem(self.tab[tabs_canvas_index].layout().itemAt(0))


        xmin = numpy.min(dataX)
        xmax = numpy.max(dataX)
        ymin = numpy.min(dataY)
        ymax = numpy.max(dataY)

        origin = (xmin, ymin)
        scale = (abs((xmax-xmin)/len(dataX)), abs((ymax-ymin)/len(dataY)))



        dim0_calib = (dataE[0],dataE[1]-dataE[0])
        dim1_calib = (ymin, dataY[1]-dataY[0])
        dim2_calib = (xmin, dataX[1]-dataX[0])

        data_to_plot = numpy.swapaxes(data3D,1,2)

        colormap = {"name":"temperature", "normalization":"linear", "autoscale":True, "vmin":0, "vmax":0, "colors":256}

        self.plot_canvas[plot_canvas_index] = StackViewMainWindow()

        self.plot_canvas[plot_canvas_index].setGraphTitle(title)
        self.plot_canvas[plot_canvas_index].setLabels(["Photon Energy [eV]",ytitle,xtitle])
        self.plot_canvas[plot_canvas_index].setColormap(colormap=colormap)

        self.plot_canvas[plot_canvas_index].setStack(numpy.array(data_to_plot),
                                                     calibrations=[dim0_calib, dim1_calib, dim2_calib] )
        self.tab[tabs_canvas_index].layout().addWidget(self.plot_canvas[plot_canvas_index])
    def plot_3D(self, data3D, dataE, dataX, dataY, progressBarValue, plot_canvas_index,  title, xtitle, ytitle, xum="", yum=""):
        if self.plot_canvas[plot_canvas_index] is None:
            self.plot_canvas[plot_canvas_index] = StackViewMainWindow()
            self.tab[plot_canvas_index].layout().addWidget(self.plot_canvas[plot_canvas_index])

        xmin = numpy.min(dataX)
        xmax = numpy.max(dataX)
        ymin = numpy.min(dataY)
        ymax = numpy.max(dataY)

        stepX = dataX[1]-dataX[0]
        stepY = dataY[1]-dataY[0]
        if len(dataE) > 1: stepE = dataE[1]-dataE[0]
        else: stepE = 1.0

        if stepE == 0.0: stepE = 1.0
        if stepX == 0.0: stepX = 1.0
        if stepY == 0.0: stepY = 1.0

        dim0_calib = (dataE[0],stepE)
        dim1_calib = (ymin, stepY)
        dim2_calib = (xmin, stepX)

        data_to_plot = numpy.swapaxes(data3D, 1, 2)

        colormap = {"name":"temperature", "normalization":"linear", "autoscale":True, "vmin":0, "vmax":0, "colors":256}

        self.plot_canvas[plot_canvas_index].setGraphTitle(title)
        self.plot_canvas[plot_canvas_index].setLabels(["Photon Energy [eV]",ytitle,xtitle])
        self.plot_canvas[plot_canvas_index].setColormap(colormap=colormap)
        self.plot_canvas[plot_canvas_index].setStack(numpy.array(data_to_plot),
                                                     calibrations=[dim0_calib, dim1_calib, dim2_calib] )
Beispiel #4
0
 def setUp(self):
     super(TestStackViewMainWindow, self).setUp()
     self.stackview = StackViewMainWindow()
     self.stackview.show()
     self.qWaitForWindowExposed(self.stackview)
     self.mystack = numpy.fromfunction(
         lambda i, j, k: numpy.sin(i/15.) + numpy.cos(j/4.) + 2 * numpy.sin(k/6.),
         (10, 20, 30)
     )
Beispiel #5
0
    def plot_data3D(self, data3D, dataE, dataX, dataY, tabs_canvas_index, plot_canvas_index,
                    title="", xtitle="", ytitle="", color_limits_uniform=False):

        for i in range(1+self.tab[tabs_canvas_index].layout().count()):
            self.tab[tabs_canvas_index].layout().removeItem(self.tab[tabs_canvas_index].layout().itemAt(i))

        xmin = numpy.min(dataX)
        xmax = numpy.max(dataX)
        ymin = numpy.min(dataY)
        ymax = numpy.max(dataY)


        stepX = dataX[1]-dataX[0]
        stepY = dataY[1]-dataY[0]
        if len(dataE) > 1: stepE = dataE[1]-dataE[0]
        else: stepE = 1.0

        if stepE == 0.0: stepE = 1.0
        if stepX == 0.0: stepX = 1.0
        if stepY == 0.0: stepY = 1.0

        dim0_calib = (dataE[0],stepE)
        dim1_calib = (ymin, stepY)
        dim2_calib = (xmin, stepX)


        data_to_plot = numpy.swapaxes(data3D,1,2)

        if color_limits_uniform:
            colormap = {"name":"temperature", "normalization":"linear", "autoscale":False, "vmin":data3D.min(), "vmax":data3D.max(), "colors":256}

        else:
            colormap = {"name":"temperature", "normalization":"linear", "autoscale":True, "vmin":0, "vmax":0, "colors":256}

        self.plot_canvas[plot_canvas_index] = StackViewMainWindow()

        self.plot_canvas[plot_canvas_index].setGraphTitle(title)
        self.plot_canvas[plot_canvas_index].setLabels(["Photon Energy [eV]",ytitle,xtitle])
        self.plot_canvas[plot_canvas_index].setColormap(colormap=colormap)
        self.plot_canvas[plot_canvas_index].setTitleCallback(lambda idx: "Energy: %6.3f eV"%dataE[idx])

        self.plot_canvas[plot_canvas_index].setStack(numpy.array(data_to_plot),
                                                     calibrations=[dim0_calib, dim1_calib, dim2_calib] )
        self.tab[tabs_canvas_index].layout().addWidget(self.plot_canvas[plot_canvas_index])
Beispiel #6
0
class TestStackViewMainWindow(TestCaseQt):
    """Base class for tests of StackView."""

    def setUp(self):
        super(TestStackViewMainWindow, self).setUp()
        self.stackview = StackViewMainWindow()
        self.stackview.show()
        self.qWaitForWindowExposed(self.stackview)
        self.mystack = numpy.fromfunction(
            lambda i, j, k: numpy.sin(i/15.) + numpy.cos(j/4.) + 2 * numpy.sin(k/6.),
            (10, 20, 30)
        )

    def tearDown(self):
        self.stackview.setAttribute(qt.Qt.WA_DeleteOnClose)
        self.stackview.close()
        del self.stackview
        super(TestStackViewMainWindow, self).tearDown()

    def testSetStack(self):
        self.stackview.setStack(self.mystack)
        self.stackview.setColormap("viridis", autoscale=True)
        my_trans_stack, params = self.stackview.getStack()
        self.assertEqual(my_trans_stack.shape, self.mystack.shape)
        self.assertTrue(numpy.array_equal(self.mystack,
                                          my_trans_stack))
        self.assertEqual(params["colormap"]["name"],
                         "viridis")

    def testSetStackPerspective(self):
        self.stackview.setStack(self.mystack, perspective=1)
        my_trans_stack, params = self.stackview.getCurrentView()
        # get stack returns the transposed data, depending on the perspective
        self.assertEqual(my_trans_stack.shape,
                         (self.mystack.shape[1], self.mystack.shape[0], self.mystack.shape[2]))
        self.assertTrue(numpy.array_equal(numpy.transpose(self.mystack, axes=(1, 0, 2)),
                                          my_trans_stack))
Beispiel #7
0
#
# ###########################################################################*/
"""This script is a simple example to illustrate how to use the StackView
widget.
"""
import numpy
import sys
from silx.gui import qt
# from silx.gui.plot import StackView
from silx.gui.plot.StackView import StackViewMainWindow

app = qt.QApplication(sys.argv[1:])
    
x, y, z = numpy.meshgrid(numpy.linspace(-10, 10, 200),
                         numpy.linspace(-10, 5, 150),
                         numpy.linspace(-5, 10, 120),
                         indexing="ij")
mystack = numpy.asarray(numpy.sin(x * y * z) / (x * y * z),
                        dtype='float32')

# sv = StackView()
sv = StackViewMainWindow()
sv.setColormap("jet", autoscale=True)
sv.setStack(mystack)
sv.setLabels(["x: -10 to 10 (200 samples)",
              "y: -10 to 5 (150 samples)",
              "z: -5 to 10 (120 samples)"])
sv.show()

app.exec_()
Beispiel #8
0
class TestStackViewMainWindow(TestCaseQt):
    """Base class for tests of StackView."""
    def setUp(self):
        super(TestStackViewMainWindow, self).setUp()
        self.stackview = StackViewMainWindow()
        self.stackview.show()
        self.qWaitForWindowExposed(self.stackview)
        self.mystack = numpy.fromfunction(
            lambda i, j, k: numpy.sin(i / 15.) + numpy.cos(j / 4.) + 2 * numpy.
            sin(k / 6.), (10, 20, 30))

    def tearDown(self):
        self.stackview.setAttribute(qt.Qt.WA_DeleteOnClose)
        self.stackview.close()
        del self.stackview
        super(TestStackViewMainWindow, self).tearDown()

    def testSetStack(self):
        self.stackview.setStack(self.mystack)
        self.stackview.setColormap("viridis", autoscale=True)
        my_trans_stack, params = self.stackview.getStack()
        self.assertEqual(my_trans_stack.shape, self.mystack.shape)
        self.assertTrue(numpy.array_equal(self.mystack, my_trans_stack))
        self.assertEqual(params["colormap"]["name"], "viridis")

    def testSetStackPerspective(self):
        self.stackview.setStack(self.mystack, perspective=1)
        my_trans_stack, params = self.stackview.getCurrentView()
        # get stack returns the transposed data, depending on the perspective
        self.assertEqual(my_trans_stack.shape,
                         (self.mystack.shape[1], self.mystack.shape[0],
                          self.mystack.shape[2]))
        self.assertTrue(
            numpy.array_equal(numpy.transpose(self.mystack, axes=(1, 0, 2)),
                              my_trans_stack))
Beispiel #9
0
app = qt.QApplication(sys.argv[1:])

a, b, c = numpy.meshgrid(numpy.linspace(-10, 10, 200),
                         numpy.linspace(-10, 5, 150),
                         numpy.linspace(-5, 10, 120),
                         indexing="ij")
mystack = numpy.asarray(numpy.sin(a * b * c) / (a * b * c), dtype='float32')

# linear calibrations (a, b), x -> a + bx
dim0_calib = (-10., 20. / 200.)
dim1_calib = (-10., 15. / 150.)
dim2_calib = (-5., 15. / 120.)

# sv = StackView()
sv = StackViewMainWindow()
sv.setStack(mystack, calibrations=[dim0_calib, dim1_calib, dim2_calib])
sv.setLabels([
    "dim0: -10 to 10 (200 samples)", "dim1: -10 to 5 (150 samples)",
    "dim2: -5 to 10 (120 samples)"
])
sv.setColormap("jet")
sv.scaleColormapRangeToStack()

# Enable use of mask in other tools: colormap autoscale, histogram, profile
maskToolsWidget = sv.getPlotWidget().getMaskToolsDockWidget().widget()
maskToolsWidget.setItemMaskUpdated(True)

sv.show()

app.exec_()
def plot_data3D(data3D,
                dataScan,
                dataX,
                dataY,
                title="",
                xtitle="",
                ytitle=""):

    xmin = numpy.min(dataX)
    xmax = numpy.max(dataX)
    ymin = numpy.min(dataY)
    ymax = numpy.max(dataY)

    stepX = dataX[1] - dataX[0]
    stepY = dataY[1] - dataY[0]
    if len(dataScan) > 1: stepScan = dataScan[1] - dataScan[0]
    else: stepScan = 1.0

    if stepScan == 0.0: stepScan = 1.0
    if stepX == 0.0: stepX = 1.0
    if stepY == 0.0: stepY = 1.0

    dim0_calib = (dataScan[0], stepScan)
    dim1_calib = (ymin, stepY)
    dim2_calib = (xmin, stepX)

    data_to_plot = numpy.swapaxes(data3D, 1, 2)

    colormap = {
        "name": "temperature",
        "normalization": "linear",
        "autoscale": True,
        "vmin": 0,
        "vmax": 0,
        "colors": 256
    }

    plot_canvas = StackViewMainWindow()

    plot_canvas.setGraphTitle(title)
    plot_canvas.setLabels(["Scanned Variable", ytitle, xtitle])
    plot_canvas.setColormap(colormap=colormap)

    plot_canvas.setStack(numpy.array(data_to_plot),
                         calibrations=[dim0_calib, dim1_calib, dim2_calib])

    plot_canvas.show()
Beispiel #11
0
    def do_plot(self):

        old_tab_index = self.tabs.currentIndex()

        try:
            for i in range(len(self.tab_titles)):
                self.tab[i].layout().removeItem(self.tab[i].layout().itemAt(0))
        except:
            pass

        if self.INDIVIDUAL_MODES:
            self.tab_titles = [
                "SPECTRUM",
                "CUMULATED SPECTRUM",
                "SPECTRAL DENSITY (INTENSITY)",
                "SPECTRAL INTENSITY FROM MODES",
                "REFERENCE ELECRON DENSITY",
                "REFERENCE UNDULATOR WAVEFRONT",
                "INDIVIDUAL MODES",
            ]
        else:
            self.tab_titles = [
                "SPECTRUM",
                "CUMULATED SPECTRUM",
                "SPECTRAL DENSITY (INTENSITY)",
                "REFERENCE ELECRON DENSITY",
                "REFERENCE UNDULATOR WAVEFRONT",
                "MODE INDEX: %d" % self.MODE_INDEX,
            ]

        self.initialize_tabs()

        if self.TYPE_PRESENTATION == 0:
            myprocess = self._square_modulus
            title0 = "Intensity of eigenvalues"
            title1 = "Intensity of eigenvector"
        if self.TYPE_PRESENTATION == 1:
            myprocess = numpy.absolute
            title0 = "Modulus of eigenvalues"
            title1 = "Modulus of eigenvector"
        elif self.TYPE_PRESENTATION == 2:
            myprocess = numpy.real
            title0 = "Real part of eigenvalues"
            title1 = "Real part of eigenvector"
        elif self.TYPE_PRESENTATION == 3:
            myprocess = numpy.imag
            title0 = "Imaginary part of eigenvalues"
            title1 = "Imaginary part of eigenvectos"
        elif self.TYPE_PRESENTATION == 4:
            myprocess = numpy.angle
            title0 = "Angle of eigenvalues [rad]"
            title1 = "Angle of eigenvector [rad]"

        if self._input_available:
            x_values = numpy.arange(self.af.number_modes())
            x_label = "Mode index"
            y_label = "Occupation"

            xx = self.af.x_coordinates()
            yy = self.af.y_coordinates()

            xmin = numpy.min(xx)
            xmax = numpy.max(xx)
            ymin = numpy.min(yy)
            ymax = numpy.max(yy)

        else:
            raise Exception("Nothing to plot")

        #
        # plot spectrum
        #
        tab_index = 0
        self.plot_canvas[tab_index] = PlotWindow(parent=None,
                                                 backend=None,
                                                 resetzoom=True,
                                                 autoScale=False,
                                                 logScale=True,
                                                 grid=True,
                                                 curveStyle=True,
                                                 colormap=False,
                                                 aspectRatio=False,
                                                 yInverted=False,
                                                 copy=True,
                                                 save=True,
                                                 print_=True,
                                                 control=False,
                                                 position=True,
                                                 roi=False,
                                                 mask=False,
                                                 fit=False)

        self.tab[tab_index].layout().addWidget(self.plot_canvas[tab_index])

        self.plot_canvas[tab_index].setDefaultPlotLines(True)
        self.plot_canvas[tab_index].setXAxisLogarithmic(False)
        self.plot_canvas[tab_index].setYAxisLogarithmic(False)
        self.plot_canvas[tab_index].setGraphXLabel(x_label)
        self.plot_canvas[tab_index].setGraphYLabel(y_label)
        self.plot_canvas[tab_index].addCurve(x_values,
                                             numpy.abs(
                                                 self.af.occupation_array()),
                                             title0,
                                             symbol='',
                                             xlabel="X",
                                             ylabel="Y",
                                             replace=False)  #'+', '^', ','

        self.tab[tab_index].layout().addWidget(self.plot_canvas[tab_index])
        #
        # plot cumulated spectrum
        #
        tab_index += 1
        self.plot_canvas[tab_index] = PlotWindow(parent=None,
                                                 backend=None,
                                                 resetzoom=True,
                                                 autoScale=False,
                                                 logScale=True,
                                                 grid=True,
                                                 curveStyle=True,
                                                 colormap=False,
                                                 aspectRatio=False,
                                                 yInverted=False,
                                                 copy=True,
                                                 save=True,
                                                 print_=True,
                                                 control=False,
                                                 position=True,
                                                 roi=False,
                                                 mask=False,
                                                 fit=False)

        self.tab[tab_index].layout().addWidget(self.plot_canvas[tab_index])

        self.plot_canvas[tab_index].setDefaultPlotLines(True)
        self.plot_canvas[tab_index].setXAxisLogarithmic(False)
        self.plot_canvas[tab_index].setYAxisLogarithmic(False)
        self.plot_canvas[tab_index].setGraphXLabel(x_label)
        self.plot_canvas[tab_index].setGraphYLabel("Cumulated occupation")
        self.plot_canvas[tab_index].addCurve(
            x_values,
            self.af.cumulated_occupation_array(),
            "Cumulated occupation",
            symbol='',
            xlabel="X",
            ylabel="Y",
            replace=False)  #'+', '^', ','

        self.plot_canvas[tab_index].setGraphYLimits(0.0, 1.0)

        self.tab[tab_index].layout().addWidget(self.plot_canvas[tab_index])

        #
        # plot spectral density
        #
        tab_index += 1
        image = myprocess((self.af.spectral_density()))
        self.plot_data2D(image,
                         1e6 * self.af.x_coordinates(),
                         1e6 * self.af.y_coordinates(),
                         tab_index,
                         title="Spectral Density (Intensity)",
                         xtitle="X [um] (%d pixels)" % (image.shape[0]),
                         ytitle="Y [um] (%d pixels)" % (image.shape[1]))

        #
        # plot spectral density from modes
        #
        if self.INDIVIDUAL_MODES:
            tab_index += 1
            image = myprocess((self.af.intensity_from_modes()))
            self.plot_data2D(image,
                             1e6 * self.af.x_coordinates(),
                             1e6 * self.af.y_coordinates(),
                             tab_index,
                             title="Spectral Density (Intensity)",
                             xtitle="X [um] (%d pixels)" % (image.shape[0]),
                             ytitle="Y [um] (%d pixels)" % (image.shape[1]))

        #
        # plot reference electron density
        #
        tab_index += 1
        image = numpy.abs(self.af.reference_electron_density()
                          )**2  #TODO: Correct? it is complex...
        self.plot_data2D(image,
                         1e6 * self.af.x_coordinates(),
                         1e6 * self.af.y_coordinates(),
                         tab_index,
                         title="Reference electron density",
                         xtitle="X [um] (%d pixels)" % (image.shape[0]),
                         ytitle="Y [um] (%d pixels)" % (image.shape[1]))

        #
        # plot reference undulator radiation
        #
        tab_index += 1
        image = self.af.reference_undulator_radiation()[
            0, :, :, 0]  #TODO: Correct? is polarized?
        self.plot_data2D(image,
                         1e6 * self.af.x_coordinates(),
                         1e6 * self.af.y_coordinates(),
                         tab_index,
                         title="Reference undulator radiation",
                         xtitle="X [um] (%d pixels)" % (image.shape[0]),
                         ytitle="Y [um] (%d pixels)" % (image.shape[1]))

        #
        # plot all modes
        #

        if self.INDIVIDUAL_MODES:
            tab_index += 1
            dim0_calib = (0, 1)
            dim1_calib = (1e6 * yy[0], 1e6 * (yy[1] - yy[0]))
            dim2_calib = (1e6 * xx[0], 1e6 * (xx[1] - xx[0]))

            colormap = {
                "name": "temperature",
                "normalization": "linear",
                "autoscale": True,
                "vmin": 0,
                "vmax": 0,
                "colors": 256
            }

            self.plot_canvas[tab_index] = StackViewMainWindow()
            self.plot_canvas[tab_index].setGraphTitle(title1)
            self.plot_canvas[tab_index].setLabels([
                "Mode number",
                "Y index from %4.2f to %4.2f um" % (1e6 * ymin, 1e6 * ymax),
                "X index from %4.2f to %4.2f um" % (1e6 * xmin, 1e6 * xmax),
            ])
            self.plot_canvas[tab_index].setColormap(colormap=colormap)

            self.plot_canvas[tab_index].setStack(
                myprocess(numpy.swapaxes(self.af.modes(), 2, 1)),
                calibrations=[dim0_calib, dim1_calib, dim2_calib])

            self.tab[tab_index].layout().addWidget(self.plot_canvas[tab_index])
        else:
            tab_index += 1
            image = myprocess((self.af.mode(self.MODE_INDEX)))
            self.plot_data2D(image,
                             1e6 * self.af.x_coordinates(),
                             1e6 * self.af.y_coordinates(),
                             tab_index,
                             title="Mode %d" % self.MODE_INDEX,
                             xtitle="X [um] (%d pixels)" % (image.shape[0]),
                             ytitle="Y [um] (%d pixels)" % (image.shape[1]))

        #
        try:
            self.tabs.setCurrentIndex(old_tab_index)
        except:
            pass
Beispiel #12
0
def plot_stack(mystack,what="intensity",title0="X",title1="Y",title2="Z"):

    from silx.gui.plot.StackView import StackViewMainWindow
    from silx.gui import qt


    app = qt.QApplication(sys.argv[1:])

    sv = StackViewMainWindow()
    sv.setColormap("jet", autoscale=True)
    if what == "intensity":
        sv.setStack(numpy.absolute(mystack))
    elif what == "real":
        sv.setStack(numpy.real(mystack))
    elif what == "imaginary":
        sv.setStack(numpy.imag(mystack))
    elif what == "phase":
        sv.setStack(numpy.angle(mystack))
    elif what == "phase_deg":
        sv.setStack(numpy.angle(mystack,deg=True))
    else:
        raise Exception("Undefined label "+what)

    sv.setLabels([title0,title1,title2])
    sv.show()

    app.exec_()
Beispiel #13
0
import numpy
import sys
from silx.gui import qt
from silx.gui.plot.StackView import StackViewMainWindow

app = qt.QApplication(sys.argv[1:])
    
a, b, c = numpy.meshgrid(numpy.linspace(-10, 10, 200),
                         numpy.linspace(-10, 5, 150),
                         numpy.linspace(-5, 10, 120),
                         indexing="ij")
mystack = numpy.asarray(numpy.sin(a * b * c) / (a * b * c),
                        dtype='float32')

# linear calibrations (a, b), x -> a + bx
dim0_calib = (-10., 20. / 200.)
dim1_calib = (-10., 15. / 150.)
dim2_calib = (-5., 15. / 120.)

# sv = StackView()
sv = StackViewMainWindow()
sv.setColormap("jet", autoscale=True)
sv.setStack(mystack,
            calibrations=[dim0_calib, dim1_calib, dim2_calib])
sv.setLabels(["dim0: -10 to 10 (200 samples)",
              "dim1: -10 to 5 (150 samples)",
              "dim2: -5 to 10 (120 samples)"])
sv.show()

app.exec_()