Ejemplo n.º 1
0
        def test_contour3d(self):
            """Test contour3d function"""
            coords = numpy.linspace(-10, 10, 64)
            z = coords.reshape(-1, 1, 1)
            y = coords.reshape(1, -1, 1)
            x = coords.reshape(1, 1, -1)
            data = numpy.sin(x * y * z) / (x * y * z)

            # Just data
            window = sx.contour3d(data)

            isosurfaces = window.getIsosurfaces()
            self.assertEqual(len(isosurfaces), 1)

            self._expose_and_close(window)

            # N contours + color
            colors = ['red', 'green', 'blue']
            window = sx.contour3d(data,
                                  copy=False,
                                  contours=len(colors),
                                  color=colors)

            isosurfaces = window.getIsosurfaces()
            self.assertEqual(len(isosurfaces), len(colors))
            for iso, color in zip(isosurfaces, colors):
                self.assertEqual(rgba(iso.getColor()), rgba(color))

            self._expose_and_close(window)

            # by isolevel, single color
            contours = 0.2, 0.5
            window = sx.contour3d(data,
                                  copy=False,
                                  contours=contours,
                                  color='yellow')

            isosurfaces = window.getIsosurfaces()
            self.assertEqual(len(isosurfaces), len(contours))
            for iso, level in zip(isosurfaces, contours):
                self.assertEqual(iso.getLevel(), level)
                self.assertEqual(rgba(iso.getColor()), rgba('yellow'))

            self._expose_and_close(window)

            # Single isolevel, colormap
            window = sx.contour3d(data,
                                  copy=False,
                                  contours=0.5,
                                  colormap='gray',
                                  vmin=0.6,
                                  opacity=0.4)

            isosurfaces = window.getIsosurfaces()
            self.assertEqual(len(isosurfaces), 1)
            self.assertEqual(isosurfaces[0].getLevel(), 0.5)
            self.assertEqual(rgba(isosurfaces[0].getColor()),
                             (0., 0., 0., 0.4))

            self._expose_and_close(window)
Ejemplo n.º 2
0
    def test_contour3d(self):
        """Test contour3d function"""
        from silx import sx  # Lazy loading to avoid it to create QApplication

        coords = numpy.linspace(-10, 10, 64)
        z = coords.reshape(-1, 1, 1)
        y = coords.reshape(1, -1, 1)
        x = coords.reshape(1, 1, -1)
        data = numpy.sin(x * y * z) / (x * y * z)

        # Just data
        window = sx.contour3d(data)

        isosurfaces = window.getIsosurfaces()
        self.assertEqual(len(isosurfaces), 1)

        if not window.getPlot3DWidget().isValid():
            self.skipTest("OpenGL context is not valid")

        # N contours + color
        colors = ['red', 'green', 'blue']
        window = sx.contour3d(data,
                              copy=False,
                              contours=len(colors),
                              color=colors)

        isosurfaces = window.getIsosurfaces()
        self.assertEqual(len(isosurfaces), len(colors))
        for iso, color in zip(isosurfaces, colors):
            self.assertEqual(rgba(iso.getColor()), rgba(color))

        # by isolevel, single color
        contours = 0.2, 0.5
        window = sx.contour3d(data,
                              copy=False,
                              contours=contours,
                              color='yellow')

        isosurfaces = window.getIsosurfaces()
        self.assertEqual(len(isosurfaces), len(contours))
        for iso, level in zip(isosurfaces, contours):
            self.assertEqual(iso.getLevel(), level)
            self.assertEqual(rgba(iso.getColor()), rgba('yellow'))

        # Single isolevel, colormap
        window = sx.contour3d(data,
                              copy=False,
                              contours=0.5,
                              colormap='gray',
                              vmin=0.6,
                              opacity=0.4)

        isosurfaces = window.getIsosurfaces()
        self.assertEqual(len(isosurfaces), 1)
        self.assertEqual(isosurfaces[0].getLevel(), 0.5)
        self.assertEqual(rgba(isosurfaces[0].getColor()), (0., 0., 0., 0.4))
Ejemplo n.º 3
0
    def test_contour3d(self):
        """Test contour3d function"""
        coords = numpy.linspace(-10, 10, 64)
        z = coords.reshape(-1, 1, 1)
        y = coords.reshape(1, -1, 1)
        x = coords.reshape(1, 1, -1)
        data = numpy.sin(x * y * z) / (x * y * z)

        # Just data
        window = sx.contour3d(data)

        isosurfaces = window.getIsosurfaces()
        self.assertEqual(len(isosurfaces), 1)

        self._expose_and_close(window)
        if not window.getPlot3DWidget().isValid():
            self.skipTest("OpenGL context is not valid")

        # N contours + color
        colors = ['red', 'green', 'blue']
        window = sx.contour3d(data, copy=False, contours=len(colors),
                              color=colors)

        isosurfaces = window.getIsosurfaces()
        self.assertEqual(len(isosurfaces), len(colors))
        for iso, color in zip(isosurfaces, colors):
            self.assertEqual(rgba(iso.getColor()), rgba(color))

        self._expose_and_close(window)

        # by isolevel, single color
        contours = 0.2, 0.5
        window = sx.contour3d(data, copy=False, contours=contours,
                              color='yellow')

        isosurfaces = window.getIsosurfaces()
        self.assertEqual(len(isosurfaces), len(contours))
        for iso, level in zip(isosurfaces, contours):
            self.assertEqual(iso.getLevel(), level)
            self.assertEqual(rgba(iso.getColor()),
                             rgba('yellow'))

        self._expose_and_close(window)

        # Single isolevel, colormap
        window = sx.contour3d(data, copy=False, contours=0.5,
                              colormap='gray', vmin=0.6, opacity=0.4)

        isosurfaces = window.getIsosurfaces()
        self.assertEqual(len(isosurfaces), 1)
        self.assertEqual(isosurfaces[0].getLevel(), 0.5)
        self.assertEqual(rgba(isosurfaces[0].getColor()),
                         (0., 0., 0., 0.4))

        self._expose_and_close(window)
Ejemplo n.º 4
0
def test_contour3d(sx, qapp_utils):
    """Test contour3d function"""
    coords = numpy.linspace(-10, 10, 64)
    z = coords.reshape(-1, 1, 1)
    y = coords.reshape(1, -1, 1)
    x = coords.reshape(1, 1, -1)
    data = numpy.sin(x * y * z) / (x * y * z)

    # Just data
    window = sx.contour3d(data)

    isosurfaces = window.getIsosurfaces()
    assert len(isosurfaces) == 1

    if not window.getPlot3DWidget().isValid():
        del window, isosurfaces  # Release widget reference
        pytest.skip("OpenGL context is not valid")

    # N contours + color
    colors = ['red', 'green', 'blue']
    window = sx.contour3d(data, copy=False, contours=len(colors), color=colors)

    isosurfaces = window.getIsosurfaces()
    assert len(isosurfaces) == len(colors)
    for iso, color in zip(isosurfaces, colors):
        assert rgba(iso.getColor()) == rgba(color)

    # by isolevel, single color
    contours = 0.2, 0.5
    window = sx.contour3d(data, copy=False, contours=contours, color='yellow')

    isosurfaces = window.getIsosurfaces()
    assert len(isosurfaces) == len(contours)
    for iso, level in zip(isosurfaces, contours):
        assert iso.getLevel() == level
        assert rgba(iso.getColor()) == rgba('yellow')

    # Single isolevel, colormap
    window = sx.contour3d(data,
                          copy=False,
                          contours=0.5,
                          colormap='gray',
                          vmin=0.6,
                          opacity=0.4)

    isosurfaces = window.getIsosurfaces()
    assert len(isosurfaces) == 1
    assert isosurfaces[0].getLevel() == 0.5
    assert rgba(isosurfaces[0].getColor()) == (0., 0., 0., 0.4)