Ejemplo n.º 1
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))
Ejemplo n.º 2
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_()
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()
Ejemplo n.º 4
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))
Ejemplo n.º 5
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_()
Ejemplo n.º 6
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_()