Exemple #1
0
class TestHdf5TreeModelSignals(TestCaseQt):

    def setUp(self):
        TestCaseQt.setUp(self)
        self.model = hdf5.Hdf5TreeModel()
        filename = _tmpDirectory + "/data.h5"
        self.h5 = h5py.File(filename)
        self.model.insertH5pyObject(self.h5)

        self.listener = SignalListener()
        self.model.sigH5pyObjectLoaded.connect(self.listener.partial(signal="loaded"))
        self.model.sigH5pyObjectRemoved.connect(self.listener.partial(signal="removed"))
        self.model.sigH5pyObjectSynchronized.connect(self.listener.partial(signal="synchronized"))

    def tearDown(self):
        self.signals = None
        ref = weakref.ref(self.model)
        self.model = None
        self.qWaitForDestroy(ref)
        self.h5.close()
        self.h5 = None
        TestCaseQt.tearDown(self)

    def waitForPendingOperations(self, model):
        for _ in range(10):
            if not model.hasPendingOperations():
                break
            self.qWait(10)
        else:
            raise RuntimeError("Still waiting for a pending operation")

    def testInsert(self):
        filename = _tmpDirectory + "/data.h5"
        h5 = h5py.File(filename)
        self.model.insertH5pyObject(h5)
        self.assertEquals(self.listener.callCount(), 0)

    def testLoaded(self):
        filename = _tmpDirectory + "/data.h5"
        self.model.insertFile(filename)
        self.assertEquals(self.listener.callCount(), 1)
        self.assertEquals(self.listener.karguments(argumentName="signal")[0], "loaded")
        self.assertIsNot(self.listener.arguments(callIndex=0)[0], self.h5)
        self.assertEquals(self.listener.arguments(callIndex=0)[0].filename, filename)

    def testRemoved(self):
        self.model.removeH5pyObject(self.h5)
        self.assertEquals(self.listener.callCount(), 1)
        self.assertEquals(self.listener.karguments(argumentName="signal")[0], "removed")
        self.assertIs(self.listener.arguments(callIndex=0)[0], self.h5)

    def testSynchonized(self):
        self.model.synchronizeH5pyObject(self.h5)
        self.waitForPendingOperations(self.model)
        self.assertEquals(self.listener.callCount(), 1)
        self.assertEquals(self.listener.karguments(argumentName="signal")[0], "synchronized")
        self.assertIs(self.listener.arguments(callIndex=0)[0], self.h5)
        self.assertIsNot(self.listener.arguments(callIndex=0)[1], self.h5)
Exemple #2
0
    def testMaxROI(self):
        """Test Max ROI"""
        origin1 = numpy.array([1., 10.])
        size1 = numpy.array([10., 10.])
        origin2 = numpy.array([2., 3.])
        size2 = numpy.array([10., 10.])

        manager = roi.InteractiveRegionOfInterestManager(self.plot)
        self.roiTableWidget.setRegionOfInterestManager(manager)
        self.assertEqual(manager.getRois(), ())

        changedListener = SignalListener()
        manager.sigRoiChanged.connect(changedListener)

        # Add two point
        item = roi_items.RectangleROI()
        item.setGeometry(origin=origin1, size=size1)
        manager.addRoi(item)
        item = roi_items.RectangleROI()
        item.setGeometry(origin=origin2, size=size2)
        manager.addRoi(item)
        self.qapp.processEvents()
        self.assertEqual(changedListener.callCount(), 2)
        self.assertEqual(len(manager.getRois()), 2)

        # Try to set max ROI to 1 while there is 2 ROIs
        with self.assertRaises(ValueError):
            manager.setMaxRois(1)

        manager.clear()
        self.assertEqual(len(manager.getRois()), 0)
        self.assertEqual(changedListener.callCount(), 3)

        # Set max limit to 1
        manager.setMaxRois(1)

        # Add a point
        item = roi_items.RectangleROI()
        item.setGeometry(origin=origin1, size=size1)
        manager.addRoi(item)
        self.qapp.processEvents()
        self.assertEqual(changedListener.callCount(), 4)

        # Add a 2nd point while max ROI is 1
        item = roi_items.RectangleROI()
        item.setGeometry(origin=origin1, size=size1)
        manager.addRoi(item)
        self.qapp.processEvents()
        self.assertEqual(changedListener.callCount(), 6)
        self.assertEqual(len(manager.getRois()), 1)
Exemple #3
0
 def test_data_event(self):
     listener = SignalListener()
     widget = self.create_widget()
     widget.dataChanged.connect(listener)
     widget.setData(10)
     widget.setData(None)
     self.assertEquals(listener.callCount(), 2)
Exemple #4
0
 def test_data_event(self):
     listener = SignalListener()
     widget = self.create_widget()
     widget.dataChanged.connect(listener)
     widget.setData(10)
     widget.setData(None)
     self.assertEquals(listener.callCount(), 2)
 def test_data_event(self):
     data = numpy.arange(3 * 3 * 3)
     widget = NumpyAxesSelector()
     listener = SignalListener()
     widget.dataChanged.connect(listener)
     widget.setData(data)
     widget.setData(None)
     self.assertEqual(listener.callCount(), 2)
Exemple #6
0
 def test_data_event(self):
     data = numpy.arange(3 * 3 * 3)
     widget = NumpyAxesSelector()
     listener = SignalListener()
     widget.dataChanged.connect(listener)
     widget.setData(data)
     widget.setData(None)
     self.assertEqual(listener.callCount(), 2)
Exemple #7
0
    def testMaxROI(self):
        """Test Max ROI"""
        kind = 'rectangle'
        points = numpy.array((((1., 10.), (11., 20.)),
                              ((2., 3.), (12., 13.))))

        manager = roi.InteractiveRegionOfInterestManager(self.plot)
        self.roiTableWidget.setRegionOfInterestManager(manager)
        self.assertEqual(manager.getRegionOfInterests(), ())

        changedListener = SignalListener()
        manager.sigRegionOfInterestChanged.connect(changedListener)

        # Add two point
        manager.createRegionOfInterest(kind, points[0])
        manager.createRegionOfInterest(kind, points[1])
        self.qapp.processEvents()
        self.assertTrue(numpy.all(numpy.equal(
            manager.getRegionOfInterestPoints(),
            (points[0], points[1]))))
        self.assertEqual(changedListener.callCount(), 2)

        # Try to set max ROI to 1 while there is 2 ROIs
        with self.assertRaises(ValueError):
            manager.setMaxRegionOfInterests(1)

        manager.clearRegionOfInterests()
        self.assertEqual(manager.getRegionOfInterests(), ())
        self.assertEqual(changedListener.callCount(), 3)

        # Set max limit to 1
        manager.setMaxRegionOfInterests(1)

        # Add a point
        manager.createRegionOfInterest(kind, points[0])
        self.qapp.processEvents()
        self.assertTrue(numpy.all(numpy.equal(
            manager.getRegionOfInterestPoints(), (points[0],))))
        self.assertEqual(changedListener.callCount(), 4)

        # Add a 2nd point while max ROI is 1
        manager.createRegionOfInterest(kind, points[1])
        self.qapp.processEvents()
        self.assertTrue(numpy.all(numpy.equal(
            manager.getRegionOfInterestPoints(), (points[1],))))
        self.assertEqual(changedListener.callCount(), 6)
 def test_event(self):
     listener = SignalListener()
     formatter = TextFormatter()
     formatter.formatChanged.connect(listener)
     formatter.setFloatFormat("%.3f")
     formatter.setIntegerFormat("%03i")
     formatter.setUseQuoteForText(False)
     formatter.setImaginaryUnit("z")
     self.assertEquals(listener.callCount(), 4)
Exemple #9
0
 def test_event(self):
     listener = SignalListener()
     formatter = TextFormatter()
     formatter.formatChanged.connect(listener)
     formatter.setFloatFormat("%.3f")
     formatter.setIntegerFormat("%03i")
     formatter.setUseQuoteForText(False)
     formatter.setImaginaryUnit("z")
     self.assertEquals(listener.callCount(), 4)
Exemple #10
0
 def test_selected_data_event(self):
     data = numpy.arange(3 * 3 * 3)
     data.shape = 3, 3, 3
     widget = NumpyAxesSelector()
     listener = SignalListener()
     widget.selectionChanged.connect(listener)
     widget.setData(data)
     widget.setAxisNames(["x"])
     widget.setData(None)
     self.assertEqual(listener.callCount(), 3)
     listener.clear()
Exemple #11
0
 def test_selected_data_event(self):
     data = numpy.arange(3 * 3 * 3)
     data.shape = 3, 3, 3
     widget = NumpyAxesSelector()
     listener = SignalListener()
     widget.selectionChanged.connect(listener)
     widget.setData(data)
     widget.setAxisNames(["x"])
     widget.setData(None)
     self.assertEqual(listener.callCount(), 3)
     listener.clear()
Exemple #12
0
class TestHdf5TreeModelSignals(TestCaseQt):
    def setUp(self):
        TestCaseQt.setUp(self)
        self.model = hdf5.Hdf5TreeModel()
        filename = _tmpDirectory + "/data.h5"
        self.h5 = h5py.File(filename)
        self.model.insertH5pyObject(self.h5)

        self.listener = SignalListener()
        self.model.sigH5pyObjectLoaded.connect(
            self.listener.partial(signal="loaded"))
        self.model.sigH5pyObjectRemoved.connect(
            self.listener.partial(signal="removed"))
        self.model.sigH5pyObjectSynchronized.connect(
            self.listener.partial(signal="synchronized"))

    def tearDown(self):
        self.signals = None
        ref = weakref.ref(self.model)
        self.model = None
        self.qWaitForDestroy(ref)
        self.h5.close()
        self.h5 = None
        TestCaseQt.tearDown(self)

    def waitForPendingOperations(self, model):
        for _ in range(10):
            if not model.hasPendingOperations():
                break
            self.qWait(10)
        else:
            raise RuntimeError("Still waiting for a pending operation")

    def testInsert(self):
        filename = _tmpDirectory + "/data.h5"
        h5 = h5py.File(filename)
        self.model.insertH5pyObject(h5)
        self.assertEquals(self.listener.callCount(), 0)

    def testLoaded(self):
        filename = _tmpDirectory + "/data.h5"
        self.model.insertFile(filename)
        self.assertEquals(self.listener.callCount(), 1)
        self.assertEquals(
            self.listener.karguments(argumentName="signal")[0], "loaded")
        self.assertIsNot(self.listener.arguments(callIndex=0)[0], self.h5)
        self.assertEquals(
            self.listener.arguments(callIndex=0)[0].filename, filename)

    def testRemoved(self):
        self.model.removeH5pyObject(self.h5)
        self.assertEquals(self.listener.callCount(), 1)
        self.assertEquals(
            self.listener.karguments(argumentName="signal")[0], "removed")
        self.assertIs(self.listener.arguments(callIndex=0)[0], self.h5)

    def testSynchonized(self):
        self.model.synchronizeH5pyObject(self.h5)
        self.waitForPendingOperations(self.model)
        self.assertEquals(self.listener.callCount(), 1)
        self.assertEquals(
            self.listener.karguments(argumentName="signal")[0], "synchronized")
        self.assertIs(self.listener.arguments(callIndex=0)[0], self.h5)
        self.assertIsNot(self.listener.arguments(callIndex=0)[1], self.h5)
Exemple #13
0
    def test(self):
        """Test ROI of different shapes"""
        tests = (  # shape, points=[list of (x, y), list of (x, y)]
            ('point', numpy.array(([(10., 15.)], [(20., 25.)]))),
            ('rectangle', numpy.array((((1., 10.), (11., 20.)),
                                       ((2., 3.), (12., 13.))))),
            ('polygon', numpy.array((((0., 1.), (0., 10.), (10., 0.)),
                                     ((5., 6.), (5., 16.), (15., 6.))))),
            ('line', numpy.array((((10., 20.), (10., 30.)),
                                  ((30., 40.), (30., 50.))))),
            ('hline', numpy.array((((10., 20.), (10., 30.)),
                                   ((30., 40.), (30., 50.))))),
            ('vline', numpy.array((((10., 20.), (10., 30.)),
                                   ((30., 40.), (30., 50.))))),
        )

        for kind, points in tests:
            with self.subTest(kind=kind):
                manager = roi.RegionOfInterestManager(self.plot)
                self.roiTableWidget.setRegionOfInterestManager(manager)
                manager.start(kind)

                self.assertEqual(manager.getRegionOfInterests(), ())

                finishListener = SignalListener()
                manager.sigInteractiveModeFinished.connect(finishListener)

                changedListener = SignalListener()
                manager.sigRegionOfInterestChanged.connect(changedListener)

                # Add a point
                manager.createRegionOfInterest(kind, points[0])
                self.qapp.processEvents()
                self.assertTrue(numpy.all(numpy.equal(
                    manager.getRegionOfInterestPoints(), (points[0],))))
                self.assertEqual(changedListener.callCount(), 1)

                # Remove it
                manager.removeRegionOfInterest(manager.getRegionOfInterests()[0])
                self.assertEqual(manager.getRegionOfInterests(), ())
                self.assertEqual(changedListener.callCount(), 2)

                # Add two point
                manager.createRegionOfInterest(kind, points[0])
                self.qapp.processEvents()
                manager.createRegionOfInterest(kind, points[1])
                self.qapp.processEvents()
                self.assertTrue(numpy.all(numpy.equal(
                    manager.getRegionOfInterestPoints(),
                    (points[0], points[1]))))
                self.assertEqual(changedListener.callCount(), 4)

                # Reset it
                result = manager.clearRegionOfInterests()
                self.assertTrue(result)
                self.assertEqual(manager.getRegionOfInterests(), ())
                self.assertEqual(changedListener.callCount(), 5)

                changedListener.clear()

                # Add two point
                manager.createRegionOfInterest(kind, points[0])
                self.qapp.processEvents()
                manager.createRegionOfInterest(kind, points[1])
                self.qapp.processEvents()
                self.assertTrue(numpy.all(numpy.equal(
                    manager.getRegionOfInterestPoints(),
                    (points[0], points[1]))))
                self.assertEqual(changedListener.callCount(), 2)

                # stop
                result = manager.stop()
                self.assertTrue(result)
                self.assertTrue(numpy.all(numpy.equal(
                    manager.getRegionOfInterestPoints(),
                    (points[0], points[1]))))

                self.qapp.processEvents()
                self.assertEqual(finishListener.callCount(), 1)

                manager.clearRegionOfInterests()
Exemple #14
0
    def test(self):
        """Test ROI of different shapes"""
        tests = (  # shape, points=[list of (x, y), list of (x, y)]
            (roi_items.PointROI, numpy.array(([(10., 15.)], [(20., 25.)]))),
            (roi_items.RectangleROI,
                numpy.array((((1., 10.), (11., 20.)),
                            ((2., 3.), (12., 13.))))),
            (roi_items.PolygonROI,
                numpy.array((((0., 1.), (0., 10.), (10., 0.)),
                            ((5., 6.), (5., 16.), (15., 6.))))),
            (roi_items.LineROI,
                numpy.array((((10., 20.), (10., 30.)),
                            ((30., 40.), (30., 50.))))),
            (roi_items.HorizontalLineROI,
                numpy.array((((10., 20.), (10., 30.)),
                            ((30., 40.), (30., 50.))))),
            (roi_items.VerticalLineROI,
                numpy.array((((10., 20.), (10., 30.)),
                            ((30., 40.), (30., 50.))))),
        )

        for roiClass, points in tests:
            with self.subTest(roiClass=roiClass):
                manager = roi.RegionOfInterestManager(self.plot)
                self.roiTableWidget.setRegionOfInterestManager(manager)
                manager.start(roiClass)

                self.assertEqual(manager.getRois(), ())

                finishListener = SignalListener()
                manager.sigInteractiveModeFinished.connect(finishListener)

                changedListener = SignalListener()
                manager.sigRoiChanged.connect(changedListener)

                # Add a point
                manager.createRoi(roiClass, points[0])
                self.qapp.processEvents()
                self.assertTrue(len(manager.getRois()), 1)
                self.assertEqual(changedListener.callCount(), 1)

                # Remove it
                manager.removeRoi(manager.getRois()[0])
                self.assertEqual(manager.getRois(), ())
                self.assertEqual(changedListener.callCount(), 2)

                # Add two point
                manager.createRoi(roiClass, points[0])
                self.qapp.processEvents()
                manager.createRoi(roiClass, points[1])
                self.qapp.processEvents()
                self.assertTrue(len(manager.getRois()), 2)
                self.assertEqual(changedListener.callCount(), 4)

                # Reset it
                result = manager.clear()
                self.assertTrue(result)
                self.assertEqual(manager.getRois(), ())
                self.assertEqual(changedListener.callCount(), 5)

                changedListener.clear()

                # Add two point
                manager.createRoi(roiClass, points[0])
                self.qapp.processEvents()
                manager.createRoi(roiClass, points[1])
                self.qapp.processEvents()
                self.assertTrue(len(manager.getRois()), 2)
                self.assertEqual(changedListener.callCount(), 2)

                # stop
                result = manager.stop()
                self.assertTrue(result)
                self.assertTrue(len(manager.getRois()), 1)
                self.qapp.processEvents()
                self.assertEqual(finishListener.callCount(), 1)

                manager.clear()