def test_store_pending_flush(self):
        width = 2

        tid, tcols, meta, ftnames = TableStoreHelper.create_table(
            self.sess, self.ft_space, self.name, [width], 'multi', False)
        imageid = unwrap(TableStoreHelper.create_image(self.sess).getId())
        roiid = unwrap(TableStoreHelper.create_roi(self.sess).getId())

        store = FeatureTable(
            self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        store.store_pending([imageid, -1, 'aa'], [10, 20])
        assert store.table.getNumberOfRows() == 0
        store.store_pending([-1, roiid, 'bb'], [90, 80])
        assert store.table.getNumberOfRows() == 0

        store.store_flush()

        assert store.table.getNumberOfRows() == 2
        d = store.table.readCoordinates(range(0, 2)).columns
        assert len(d) == 4
        assert d[0].values == [imageid, -1]
        assert d[1].values == [-1, roiid]
        assert d[2].values == ['aa', 'bb']
        assert d[3].values == [[10, 20], [90, 80]]

        store.store_flush()
        assert store.table.getNumberOfRows() == 2

        store.close()
    def test_filter_raw(self, emptyquery):
        tid = self.create_table_for_fetch(True, [1], 'multi', False)

        store = FeatureTable(
            self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        if emptyquery:
            rvalues = store.filter_raw('')
            assert len(rvalues) == 4
            assert sorted(rvalues) == [
                (-1, 34, 'bb', [90]),
                (12, -1, 'aa', [10]),
                (12, 56, 'cc', [20]),
                (13, -1, 'dd', [30]),
                ]
        else:
            rvalues = store.filter_raw(
                '(ImageID==13) | (RoiID==34) | (Name=="cc")')
            assert len(rvalues) == 3
            assert sorted(rvalues) == [
                (-1, 34, 'bb', [90]),
                (12, 56, 'cc', [20]),
                (13, -1, 'dd', [30]),
                ]

        store.close()
    def test_store_pending_flush(self):
        width = 2

        tid, tcols, meta, ftnames = TableStoreHelper.create_table(
            self.sess, self.ft_space, self.name, [width], "multi", False
        )
        imageid = unwrap(TableStoreHelper.create_image(self.sess).getId())
        roiid = unwrap(TableStoreHelper.create_roi(self.sess).getId())

        store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        store.store_pending([imageid, -1, "aa"], [10, 20])
        assert store.table.getNumberOfRows() == 0
        store.store_pending([-1, roiid, "bb"], [90, 80])
        assert store.table.getNumberOfRows() == 0

        store.store_flush()

        assert store.table.getNumberOfRows() == 2
        d = store.table.readCoordinates(range(0, 2)).columns
        assert len(d) == 4
        assert d[0].values == [imageid, -1]
        assert d[1].values == [-1, roiid]
        assert d[2].values == ["aa", "bb"]
        assert d[3].values == [[10, 20], [90, 80]]

        store.store_flush()
        assert store.table.getNumberOfRows() == 2

        store.close()
    def test_create_file_annotation(self):
        tid, tcols, meta, ftnames = TableStoreHelper.create_table(
            self.sess, self.ft_space, self.name, [1], 'multi', False)
        imageid = unwrap(TableStoreHelper.create_image(self.sess).getId())
        ofile = self.sess.getQueryService().get(
            'omero.model.OriginalFile', tid)
        store = FeatureTable(
            self.sess, self.name, self.ft_space, self.ann_space)

        assert store._file_annotation_exists(
            'Image', imageid, self.ann_space, tid) == []

        link = store.create_file_annotation(
            'Image', imageid, self.ann_space, ofile)
        p = link.getParent()
        c = link.getChild()
        assert isinstance(p, omero.model.Image)
        assert isinstance(c, omero.model.FileAnnotation)
        assert unwrap(p.getId()) == imageid
        assert unwrap(c.getFile().getId()) == tid

        links = store._file_annotation_exists(
            'Image', imageid, self.ann_space, tid)
        assert len(links) == 1
        assert links[0].__class__ == link.__class__ and links[0].id == link.id

        store.close()
    def test_delete(self, owned):
        if owned:
            tablesess = self.sess
        else:
            user2 = self.create_user_same_group()
            tablesess = self.create_client_session(user2)

        iid1 = unwrap(TableStoreHelper.create_image(self.sess).getId())
        iid2 = unwrap(TableStoreHelper.create_image(self.sess).getId())
        store = FeatureTable(
            tablesess, self.name, self.ft_space, self.ann_space)
        store.new_table([('Long', 'id')], ['x'])
        ofile = store.get_table().getOriginalFile()

        link1 = store.create_file_annotation(
            'Image', iid1, self.ann_space, ofile)
        link2 = store.create_file_annotation(
            'Image', iid2, self.ann_space, ofile)

        if not owned:
            store.close()
            # Reopen the store with a different session
            store = FeatureTable(
                self.sess, self.name, self.ft_space, self.ann_space)
            store.open_table(unwrap(ofile.getId()))

        def get(obj):
            # Fetch the latest copy of an object
            return self.sess.getQueryService().find(
                'omero.model.%s' % obj.__class__.__name__, unwrap(obj.getId()))

        assert get(link1) is not None
        assert get(link1.getParent()) is not None
        assert get(link1.getChild())
        assert get(link1.getChild().getFile())

        assert get(link2)
        assert get(link2.getParent())
        assert get(link2.getChild())
        assert get(link2.getChild().getFile())

        if owned:
            store.delete()

            assert get(link1) is None
            assert get(link1.getParent())
            assert get(link1.getChild()) is None
            assert get(link1.getChild().getFile()) is None

            assert get(link2) is None
            assert get(link2.getParent())
            assert get(link2.getChild()) is None
            assert get(link2.getChild().getFile()) is None
        else:
            with pytest.raises(
                    OmeroTablesFeatureStore.FeaturePermissionException):
                store.delete()

        store.close()
    def test_get_table(self):
        store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)
        with pytest.raises(OmeroTablesFeatureStore.TableUsageException):
            store.get_table()

        tcols, meta, ftnames = TableStoreHelper.get_columns([2], "multi", False)
        store.new_table(meta, ftnames)
        assert store.get_table()
        store.close()
    def test_get_table(self):
        store = FeatureTable(
            self.sess, self.name, self.ft_space, self.ann_space)
        with pytest.raises(OmeroTablesFeatureStore.TableUsageException):
            store.get_table()

        tcols, meta, ftnames = TableStoreHelper.get_columns(
            [2], 'multi', False)
        store.new_table(meta, ftnames)
        assert store.get_table()
        store.close()
    def test_delete(self, owned):
        if owned:
            tablesess = self.sess
        else:
            user2 = self.create_user_same_group()
            tablesess = self.create_client_session(user2)

        iid1 = unwrap(TableStoreHelper.create_image(self.sess).getId())
        iid2 = unwrap(TableStoreHelper.create_image(self.sess).getId())
        store = FeatureTable(tablesess, self.name, self.ft_space, self.ann_space)
        store.new_table([("Long", "id")], ["x"])
        ofile = store.get_table().getOriginalFile()

        link1 = store.create_file_annotation("Image", iid1, self.ann_space, ofile)
        link2 = store.create_file_annotation("Image", iid2, self.ann_space, ofile)

        if not owned:
            store.close()
            # Reopen the store with a different session
            store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)
            store.open_table(unwrap(ofile.getId()))

        def get(obj):
            # Fetch the latest copy of an object
            return self.sess.getQueryService().find("omero.model.%s" % obj.__class__.__name__, unwrap(obj.getId()))

        assert get(link1) is not None
        assert get(link1.getParent()) is not None
        assert get(link1.getChild())
        assert get(link1.getChild().getFile())

        assert get(link2)
        assert get(link2.getParent())
        assert get(link2.getChild())
        assert get(link2.getChild().getFile())

        if owned:
            store.delete()

            assert get(link1) is None
            assert get(link1.getParent())
            assert get(link1.getChild()) is None
            assert get(link1.getChild().getFile()) is None

            assert get(link2) is None
            assert get(link2.getParent())
            assert get(link2.getChild()) is None
            assert get(link2.getChild().getFile()) is None
        else:
            with pytest.raises(OmeroTablesFeatureStore.FeaturePermissionException):
                store.delete()

        store.close()
    def test_get_objects(self):
        ims = [
            TableStoreHelper.create_image(self.sess, name="image-test"),
            TableStoreHelper.create_image(self.sess, name="other-test"),
            TableStoreHelper.create_image(self.sess, name="image-test"),
        ]
        store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)

        rs = store.get_objects("Image", {"name": "image-test"})
        assert sorted(unwrap(r.getId()) for r in rs) == unwrap([ims[0].getId(), ims[2].getId()])

        store.close()
Exemplo n.º 10
0
    def test_open_table(self):
        tid, tcols, meta, ftnames = TableStoreHelper.create_table(
            self.sess, self.ft_space, self.name, [1], "multi", False
        )

        store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)
        assert store.table
        TableStoreHelper.assert_coltypes_equal(store.cols, tcols)
        assert store.metadata_names() == tuple(m[1] for m in meta)
        assert store.feature_names() == ftnames

        store.close()
    def test_open_table(self):
        tid, tcols, meta, ftnames = TableStoreHelper.create_table(
            self.sess, self.ft_space, self.name, [1], 'multi', False)

        store = FeatureTable(
            self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)
        assert store.table
        TableStoreHelper.assert_coltypes_equal(store.cols, tcols)
        assert store.metadata_names() == tuple(m[1] for m in meta)
        assert store.feature_names() == ftnames

        store.close()
    def test_get_objects(self):
        ims = [
            TableStoreHelper.create_image(self.sess, name='image-test'),
            TableStoreHelper.create_image(self.sess, name='other-test'),
            TableStoreHelper.create_image(self.sess, name='image-test')
        ]
        store = FeatureTable(
            self.sess, self.name, self.ft_space, self.ann_space)

        rs = store.get_objects('Image', {'name': 'image-test'})
        assert sorted(unwrap(r.getId()) for r in rs) == unwrap(
            [ims[0].getId(), ims[2].getId()])

        store.close()
Exemplo n.º 13
0
    def test_fetch_by_metadata2(self, meta, coltype, interleave):
        tid = self.create_table_for_fetch(True, [1], coltype, interleave)
        store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        fr = store.fetch_by_metadata(meta)

        assert len(fr) == 1
        fr = fr[0]
        assert fr.infonames == ("ImageID", "RoiID", "Name")
        assert fr.infovalues == (12, 56, "cc")
        assert fr.names == ("x1",)
        assert fr.values == (20,)

        store.close()
    def test_fetch_by_metadata2(self, meta, coltype, interleave):
        tid = self.create_table_for_fetch(True, [1], coltype, interleave)
        store = FeatureTable(
            self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        fr = store.fetch_by_metadata(meta)

        assert len(fr) == 1
        fr = fr[0]
        assert fr.infonames == ('ImageID', 'RoiID', 'Name')
        assert fr.infovalues == (12, 56, 'cc')
        assert fr.names == ('x1',)
        assert fr.values == (20,)

        store.close()
Exemplo n.º 15
0
    def test_fetch_by_metadata_raw(self, meta, widths):
        tid = self.create_table_for_fetch(True, widths, "multi", False)
        store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        rvalues = store.fetch_by_metadata_raw(meta)

        assert len(rvalues) == 2
        if widths == [1]:
            assert rvalues[0] == (12, -1, "aa", [10])
            assert rvalues[1] == (12, 56, "cc", [20])
        else:
            assert rvalues[0] == (12, -1, "aa", [11, 12], [13, 14, 15])
            assert rvalues[1] == (12, 56, "cc", [31, 32], [33, 34, 35])

        store.close()
    def test_fetch_by_metadata_raw(self, meta, widths):
        tid = self.create_table_for_fetch(True, widths, 'multi', False)
        store = FeatureTable(
            self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        rvalues = store.fetch_by_metadata_raw(meta)

        assert len(rvalues) == 2
        if widths == [1]:
            assert rvalues[0] == (12, -1, 'aa', [10])
            assert rvalues[1] == (12, 56, 'cc', [20])
        else:
            assert rvalues[0] == (12, -1, 'aa', [11, 12], [13, 14, 15])
            assert rvalues[1] == (12, 56, 'cc', [31, 32], [33, 34, 35])

        store.close()
Exemplo n.º 17
0
    def test_filter(self, coltype, interleave, widths):
        tid = self.create_table_for_fetch(True, widths, coltype, interleave)
        store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        fr = store.filter('(ImageID==12345) | (RoiID==34) | (Name=="abcde")')
        assert len(fr) == 1
        fr = fr[0]
        assert fr.infonames == ("ImageID", "RoiID", "Name")
        assert fr.infovalues == (-1, 34, "bb")
        if widths == [1]:
            assert fr.names == ("x1",)
            assert fr.values == (90,)
        else:
            assert fr.names == ("x1", "x2", "x3", "x4", "x5")
            assert fr.values == (21, 22, 23, 24, 25)

        store.close()
Exemplo n.º 18
0
    def test_store_unowned(self):
        width = 2
        user2 = self.create_user_same_group()
        tablesess = self.create_client_session(user2)

        tid, tcols, meta, ftnames = TableStoreHelper.create_table(
            tablesess, self.ft_space, self.name, [width], "multi", False
        )
        imageid = unwrap(TableStoreHelper.create_image(self.sess).getId())
        assert imageid

        store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        with pytest.raises(OmeroTablesFeatureStore.FeaturePermissionException):
            store.store([0, 0, ""], [10, 20])

        store.close()
    def test_filter(self, coltype, interleave, widths):
        tid = self.create_table_for_fetch(True, widths, coltype, interleave)
        store = FeatureTable(
            self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        fr = store.filter('(ImageID==12345) | (RoiID==34) | (Name=="abcde")')
        assert len(fr) == 1
        fr = fr[0]
        assert fr.infonames == ('ImageID', 'RoiID', 'Name')
        assert fr.infovalues == (-1, 34, 'bb')
        if widths == [1]:
            assert fr.names == ('x1',)
            assert fr.values == (90,)
        else:
            assert fr.names == ('x1', 'x2', 'x3', 'x4', 'x5')
            assert fr.values == (21, 22, 23, 24, 25)

        store.close()
Exemplo n.º 20
0
    def test_new_table(self):
        tcols, meta, ftnames = TableStoreHelper.get_columns([2], "multi", False)

        store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)
        store.new_table(meta, ftnames)
        assert store.table
        TableStoreHelper.assert_coltypes_equal(store.cols, tcols)

        assert store.metadata_names() == tuple(m[1] for m in meta)
        assert store.feature_names() == ftnames

        # Need to reload
        # ofile = store.table.getOriginalFile()
        tid = unwrap(store.table.getOriginalFile().getId())
        ofile = self.sess.getQueryService().get("OriginalFile", tid)
        assert unwrap(ofile.getName()) == self.name
        assert unwrap(ofile.getPath()) == self.ft_space

        store.close()
    def test_store_unowned(self):
        width = 2
        user2 = self.create_user_same_group()
        tablesess = self.create_client_session(user2)

        tid, tcols, meta, ftnames = TableStoreHelper.create_table(
            tablesess, self.ft_space, self.name, [width], 'multi', False)
        imageid = unwrap(TableStoreHelper.create_image(self.sess).getId())
        assert imageid

        store = FeatureTable(
            self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        with pytest.raises(
                OmeroTablesFeatureStore.FeaturePermissionException):
            store.store([0, 0, ''], [10, 20])

        store.close()
Exemplo n.º 22
0
    def test_fetch_by_metadata3(self, coltype, interleave):
        tid = self.create_table_for_fetch(True, [2, 3], coltype, interleave)
        store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        meta = {"ImageID": 12}
        fr = store.fetch_by_metadata(meta)

        assert len(fr) == 2
        fr0, fr1 = fr
        assert fr0.infonames == ("ImageID", "RoiID", "Name")
        assert fr1.infonames == ("ImageID", "RoiID", "Name")
        assert fr0.infovalues == (12, -1, "aa")
        assert fr1.infovalues == (12, 56, "cc")
        assert fr0.names == ("x1", "x2", "x3", "x4", "x5")
        assert fr1.names == ("x1", "x2", "x3", "x4", "x5")
        assert fr0.values == (11, 12, 13, 14, 15)
        assert fr1.values == (31, 32, 33, 34, 35)

        store.close()
Exemplo n.º 23
0
    def test_filter_raw(self, emptyquery):
        tid = self.create_table_for_fetch(True, [1], "multi", False)

        store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        if emptyquery:
            rvalues = store.filter_raw("")
            assert len(rvalues) == 4
            assert sorted(rvalues) == [
                (-1, 34, "bb", [90]),
                (12, -1, "aa", [10]),
                (12, 56, "cc", [20]),
                (13, -1, "dd", [30]),
            ]
        else:
            rvalues = store.filter_raw('(ImageID==13) | (RoiID==34) | (Name=="cc")')
            assert len(rvalues) == 3
            assert sorted(rvalues) == [(-1, 34, "bb", [90]), (12, 56, "cc", [20]), (13, -1, "dd", [30])]

        store.close()
    def test_fetch_by_metadata3(self, coltype, interleave):
        tid = self.create_table_for_fetch(True, [2, 3], coltype,  interleave)
        store = FeatureTable(
            self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        meta = {'ImageID': 12}
        fr = store.fetch_by_metadata(meta)

        assert len(fr) == 2
        fr0, fr1 = fr
        assert fr0.infonames == ('ImageID', 'RoiID', 'Name')
        assert fr1.infonames == ('ImageID', 'RoiID', 'Name')
        assert fr0.infovalues == (12, -1, 'aa')
        assert fr1.infovalues == (12, 56, 'cc')
        assert fr0.names == ('x1', 'x2', 'x3', 'x4', 'x5')
        assert fr1.names == ('x1', 'x2', 'x3', 'x4', 'x5')
        assert fr0.values == (11, 12, 13, 14, 15)
        assert fr1.values == (31, 32, 33, 34, 35)

        store.close()
    def test_new_table(self):
        tcols, meta, ftnames = TableStoreHelper.get_columns(
            [2], 'multi', False)

        store = FeatureTable(
            self.sess, self.name, self.ft_space, self.ann_space)
        store.new_table(meta, ftnames)
        assert store.table
        TableStoreHelper.assert_coltypes_equal(store.cols, tcols)

        assert store.metadata_names() == tuple(m[1] for m in meta)
        assert store.feature_names() == ftnames

        # Need to reload
        # ofile = store.table.getOriginalFile()
        tid = unwrap(store.table.getOriginalFile().getId())
        ofile = self.sess.getQueryService().get('OriginalFile', tid)
        assert unwrap(ofile.getName()) == self.name
        assert unwrap(ofile.getPath()) == self.ft_space

        store.close()
Exemplo n.º 26
0
    def test_create_file_annotation(self):
        tid, tcols, meta, ftnames = TableStoreHelper.create_table(
            self.sess, self.ft_space, self.name, [1], "multi", False
        )
        imageid = unwrap(TableStoreHelper.create_image(self.sess).getId())
        ofile = self.sess.getQueryService().get("omero.model.OriginalFile", tid)
        store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)

        assert store._file_annotation_exists("Image", imageid, self.ann_space, tid) == []

        link = store.create_file_annotation("Image", imageid, self.ann_space, ofile)
        p = link.getParent()
        c = link.getChild()
        assert isinstance(p, omero.model.Image)
        assert isinstance(c, omero.model.FileAnnotation)
        assert unwrap(p.getId()) == imageid
        assert unwrap(c.getFile().getId()) == tid

        links = store._file_annotation_exists("Image", imageid, self.ann_space, tid)
        assert len(links) == 1
        assert links[0].__class__ == link.__class__ and links[0].id == link.id

        store.close()
    def test_store(self, exists, replace):
        width = 2

        tid, tcols, meta, ftnames = TableStoreHelper.create_table(
            self.sess, self.ft_space, self.name, [width], 'multi', False)
        imageid = unwrap(TableStoreHelper.create_image(self.sess).getId())
        roiid = unwrap(TableStoreHelper.create_roi(self.sess).getId())

        store = FeatureTable(
            self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        if exists:
            store.store([imageid, -1, 'aa'], [10, 20])
            assert store.table.getNumberOfRows() == 1

        store.store([imageid, -1, 'aa'], [10, 20], replace=replace)

        if exists and not replace:
            assert store.table.getNumberOfRows() == 2
            d = store.table.readCoordinates(range(0, 2)).columns
            assert len(d) == 4
            assert d[0].values == [imageid, imageid]
            assert d[1].values == [-1, -1]
            assert d[2].values == ['aa', 'aa']
            assert d[3].values == [[10, 20], [10, 20]]
        else:
            assert store.table.getNumberOfRows() == 1
            d = store.table.readCoordinates(range(0, 1)).columns
            assert len(d) == 4
            assert d[0].values == [imageid]
            assert d[1].values == [-1]
            assert d[2].values == ['aa']
            assert d[3].values == [[10, 20]]

        store.store([-1, roiid, 'bb'], [90, 80], replace=replace)

        if exists and not replace:
            assert store.table.getNumberOfRows() == 3
            d = store.table.readCoordinates(range(0, 3)).columns
            assert len(d) == 4
            assert d[0].values == [imageid, imageid, -1]
            assert d[1].values == [-1, -1, roiid]
            assert d[2].values == ['aa', 'aa', 'bb']
            assert d[3].values == [[10, 20], [10, 20], [90, 80]]
        else:
            assert store.table.getNumberOfRows() == 2
            d = store.table.readCoordinates(range(0, 2)).columns
            assert len(d) == 4
            assert d[0].values == [imageid, -1]
            assert d[1].values == [-1, roiid]
            assert d[2].values == ['aa', 'bb']
            assert d[3].values == [[10, 20], [90, 80]]

        # qs = self.sess.getQueryService()
        # q = 'SELECT l.child FROM %sAnnotationLink l WHERE l.parent.id=%d'

        # anns = qs.findAllByQuery(q % ('Image', imageid), None)
        # assert len(anns) == 1
        # assert unwrap(anns[0].getFile().getId()) == tid

        # anns = qs.findAllByQuery(q % ('Roi', roiid), None)
        # assert len(anns) == 1
        # assert unwrap(anns[0].getFile().getId()) == tid

        store.close()
Exemplo n.º 28
0
    def test_store(self, exists, replace):
        width = 2

        tid, tcols, meta, ftnames = TableStoreHelper.create_table(
            self.sess, self.ft_space, self.name, [width], "multi", False
        )
        imageid = unwrap(TableStoreHelper.create_image(self.sess).getId())
        roiid = unwrap(TableStoreHelper.create_roi(self.sess).getId())

        store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        if exists:
            store.store([imageid, -1, "aa"], [10, 20])
            assert store.table.getNumberOfRows() == 1

        store.store([imageid, -1, "aa"], [10, 20], replace=replace)

        if exists and not replace:
            assert store.table.getNumberOfRows() == 2
            d = store.table.readCoordinates(range(0, 2)).columns
            assert len(d) == 4
            assert d[0].values == [imageid, imageid]
            assert d[1].values == [-1, -1]
            assert d[2].values == ["aa", "aa"]
            assert d[3].values == [[10, 20], [10, 20]]
        else:
            assert store.table.getNumberOfRows() == 1
            d = store.table.readCoordinates(range(0, 1)).columns
            assert len(d) == 4
            assert d[0].values == [imageid]
            assert d[1].values == [-1]
            assert d[2].values == ["aa"]
            assert d[3].values == [[10, 20]]

        store.store([-1, roiid, "bb"], [90, 80], replace=replace)

        if exists and not replace:
            assert store.table.getNumberOfRows() == 3
            d = store.table.readCoordinates(range(0, 3)).columns
            assert len(d) == 4
            assert d[0].values == [imageid, imageid, -1]
            assert d[1].values == [-1, -1, roiid]
            assert d[2].values == ["aa", "aa", "bb"]
            assert d[3].values == [[10, 20], [10, 20], [90, 80]]
        else:
            assert store.table.getNumberOfRows() == 2
            d = store.table.readCoordinates(range(0, 2)).columns
            assert len(d) == 4
            assert d[0].values == [imageid, -1]
            assert d[1].values == [-1, roiid]
            assert d[2].values == ["aa", "bb"]
            assert d[3].values == [[10, 20], [90, 80]]

        # qs = self.sess.getQueryService()
        # q = 'SELECT l.child FROM %sAnnotationLink l WHERE l.parent.id=%d'

        # anns = qs.findAllByQuery(q % ('Image', imageid), None)
        # assert len(anns) == 1
        # assert unwrap(anns[0].getFile().getId()) == tid

        # anns = qs.findAllByQuery(q % ('Roi', roiid), None)
        # assert len(anns) == 1
        # assert unwrap(anns[0].getFile().getId()) == tid

        store.close()
Exemplo n.º 29
0
    def test_store_multi(self, coltype, interleave):
        widths = [2, 3]

        tid, tcols, meta, ftnames = TableStoreHelper.create_table(
            self.sess, self.ft_space, self.name, widths, coltype, interleave
        )
        imageid = unwrap(TableStoreHelper.create_image(self.sess).getId())
        roiid = unwrap(TableStoreHelper.create_roi(self.sess).getId())

        store = FeatureTable(self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        store.store([imageid, -1, "aa"], [10, 20, 30, 40, 50])
        assert store.table.getNumberOfRows() == 1

        assert store.table.getNumberOfRows() == 1
        d = store.table.readCoordinates(range(0, 1)).columns

        if coltype == "single":
            assert len(d) == 8
            if interleave:
                assert [c.values for c in d] == [[imageid], [10], [-1], [20], ["aa"], [30], [40], [50]]
            else:
                assert [c.values for c in d] == [[imageid], [-1], ["aa"], [10], [20], [30], [40], [50]]
        else:
            assert len(d) == 5
            if interleave:
                assert [c.values for c in d] == [[imageid], [[10, 20]], [-1], [[30, 40, 50]], ["aa"]]
            else:
                assert [c.values for c in d] == [[imageid], [-1], ["aa"], [[10, 20]], [[30, 40, 50]]]

        store.store([-1, roiid, "bb"], [90, 80, 70, 60, 50])

        assert store.table.getNumberOfRows() == 2
        d = store.table.readCoordinates(range(0, 2)).columns

        if coltype == "single":
            assert len(d) == 8
            if interleave:
                assert [c.values for c in d] == [
                    [imageid, -1],
                    [10, 90],
                    [-1, roiid],
                    [20, 80],
                    ["aa", "bb"],
                    [30, 70],
                    [40, 60],
                    [50, 50],
                ]
            else:
                assert [c.values for c in d] == [
                    [imageid, -1],
                    [-1, roiid],
                    ["aa", "bb"],
                    [10, 90],
                    [20, 80],
                    [30, 70],
                    [40, 60],
                    [50, 50],
                ]
        else:
            assert len(d) == 5
            if interleave:
                assert [c.values for c in d] == [
                    [imageid, -1],
                    [[10, 20], [90, 80]],
                    [-1, roiid],
                    [[30, 40, 50], [70, 60, 50]],
                    ["aa", "bb"],
                ]
            else:
                assert [c.values for c in d] == [
                    [imageid, -1],
                    [-1, roiid],
                    ["aa", "bb"],
                    [[10, 20], [90, 80]],
                    [[30, 40, 50], [70, 60, 50]],
                ]

        store.close()
    def test_store_multi(self, coltype, interleave):
        widths = [2, 3]

        tid, tcols, meta, ftnames = TableStoreHelper.create_table(
            self.sess, self.ft_space, self.name, widths, coltype, interleave)
        imageid = unwrap(TableStoreHelper.create_image(self.sess).getId())
        roiid = unwrap(TableStoreHelper.create_roi(self.sess).getId())

        store = FeatureTable(
            self.sess, self.name, self.ft_space, self.ann_space)
        store.open_table(tid)

        store.store([imageid, -1, 'aa'], [10, 20, 30, 40, 50])
        assert store.table.getNumberOfRows() == 1

        assert store.table.getNumberOfRows() == 1
        d = store.table.readCoordinates(range(0, 1)).columns

        if coltype == 'single':
            assert len(d) == 8
            if interleave:
                assert [c.values for c in d] == [
                    [imageid], [10], [-1], [20], ['aa'], [30], [40], [50]]
            else:
                assert [c.values for c in d] == [
                    [imageid], [-1], ['aa'], [10], [20], [30], [40], [50]]
        else:
            assert len(d) == 5
            if interleave:
                assert [c.values for c in d] == [
                    [imageid], [[10, 20]], [-1], [[30, 40, 50]], ['aa']]
            else:
                assert [c.values for c in d] == [
                    [imageid], [-1], ['aa'], [[10, 20]], [[30, 40, 50]]]

        store.store([-1, roiid, 'bb'], [90, 80, 70, 60, 50])

        assert store.table.getNumberOfRows() == 2
        d = store.table.readCoordinates(range(0, 2)).columns

        if coltype == 'single':
            assert len(d) == 8
            if interleave:
                assert [c.values for c in d] == [
                    [imageid, -1],
                    [10, 90],
                    [-1, roiid],
                    [20, 80],
                    ['aa', 'bb'],
                    [30, 70],
                    [40, 60],
                    [50, 50]]
            else:
                assert [c.values for c in d] == [
                    [imageid, -1],
                    [-1, roiid],
                    ['aa', 'bb'],
                    [10, 90],
                    [20, 80],
                    [30, 70],
                    [40, 60],
                    [50, 50]]
        else:
            assert len(d) == 5
            if interleave:
                assert [c.values for c in d] == [
                    [imageid, -1],
                    [[10, 20], [90, 80]],
                    [-1, roiid],
                    [[30, 40, 50], [70, 60, 50]],
                    ['aa', 'bb']]
            else:
                assert [c.values for c in d] == [
                    [imageid, -1],
                    [-1, roiid],
                    ['aa', 'bb'],
                    [[10, 20], [90, 80]],
                    [[30, 40, 50], [70, 60, 50]]]

        store.close()