コード例 #1
0
ファイル: slicesources.py プロジェクト: JensNRAD/volumina
    def setUp(self):
        import numpy as np
        from datasources import ArraySource

        self.raw = np.random.randint(0, 100, (10, 3, 3, 128, 3))
        self.a = ArraySource(self.raw)
        self.ss = SliceSource(self.a, projectionAlongTZC)
コード例 #2
0
 def createDataSource(dset, withShape=False):
     dset_5d = H5pyDset5DWrapper(dset)
     src = ArraySource(dset_5d)
     if withShape:
         return src, dset_5d.shape
     else:
         return src
コード例 #3
0
ファイル: slicesources.py プロジェクト: JensNRAD/volumina
class SliceSourceTest(ut.TestCase):
    def setUp(self):
        import numpy as np
        from datasources import ArraySource

        self.raw = np.random.randint(0, 100, (10, 3, 3, 128, 3))
        self.a = ArraySource(self.raw)
        self.ss = SliceSource(self.a, projectionAlongTZC)

    def testRequest(self):
        self.ss.setThrough(0, 1)
        self.ss.setThrough(2, 2)
        self.ss.setThrough(1, 127)

        sl = self.ss.request((slice(None), slice(None))).wait()
        self.assertTrue(np.all(sl == self.raw[1, :, :, 127, 2]))

        sl_bounded = self.ss.request((slice(0, 3), slice(1, None))).wait()
        self.assertTrue(np.all(sl_bounded == self.raw[1, 0:3, 1:, 127, 2]))

    def testDirtynessPropagation(self):
        self.ss.setThrough(0, 1)
        self.ss.setThrough(2, 2)
        self.ss.setThrough(1, 127)

        self.triggered = False

        def check1(dirty_area):
            self.triggered = True
            self.assertEqual(dirty_area, sl[:, 1:2])

        self.ss.isDirty.connect(check1)
        self.a.setDirty(sl[1:2, :, 1:2, 127:128, 2:3])
        self.ss.isDirty.disconnect(check1)
        self.assertTrue(self.triggered)
        del self.triggered

        def check2(dirty_area):
            assert False

        self.ss.isDirty.connect(check2)
        self.a.setDirty(sl[1:2, :, 1:2, 127:128, 3:4])
        self.ss.isDirty.disconnect(check2)
コード例 #4
0
class SliceSourceTest(ut.TestCase):
    def setUp(self):
        import numpy as np
        from datasources import ArraySource
        self.raw = np.random.randint(0, 100, (10, 3, 3, 128, 3))
        self.a = ArraySource(self.raw)
        self.ss = SliceSource(self.a, projectionAlongTZC)

    def testRequest(self):
        self.ss.setThrough(0, 1)
        self.ss.setThrough(2, 2)
        self.ss.setThrough(1, 127)

        sl = self.ss.request((slice(None), slice(None))).wait()
        self.assertTrue(np.all(sl == self.raw[1, :, :, 127, 2]))

        sl_bounded = self.ss.request((slice(0, 3), slice(1, None))).wait()
        self.assertTrue(np.all(sl_bounded == self.raw[1, 0:3, 1:, 127, 2]))

    def testDirtynessPropagation(self):
        self.ss.setThrough(0, 1)
        self.ss.setThrough(2, 2)
        self.ss.setThrough(1, 127)

        self.triggered = False

        def check1(dirty_area):
            self.triggered = True
            self.assertEqual(dirty_area, sl[:, 1:2])

        self.ss.isDirty.connect(check1)
        self.a.setDirty(sl[1:2, :, 1:2, 127:128, 2:3])
        self.ss.isDirty.disconnect(check1)
        self.assertTrue(self.triggered)
        del self.triggered

        def check2(dirty_area):
            assert False

        self.ss.isDirty.connect(check2)
        self.a.setDirty(sl[1:2, :, 1:2, 127:128, 3:4])
        self.ss.isDirty.disconnect(check2)
コード例 #5
0
def _createArrayDataSource(source,withShape = False):
    #has to handle NumpyArray
    #check if the array is 5d, if not so embed it in a canonical way
    if len(source.shape) == 2:
        source = source.reshape( (1,) + source.shape + (1,1) )
    elif len(source.shape) == 3 and source.shape[2] <= 4:
        source = source.reshape( (1,) + source.shape[0:2] + (1,) + (source.shape[2],) )
    elif len(source.shape) == 3:
        source = source.reshape( (1,) + source.shape + (1,) )
    elif len(source.shape) == 4:
        source = source.reshape( (1,) + source.shape )
    src = ArraySource(source)
    if withShape:
        return src,source.shape
    else:
        return src
コード例 #6
0
 def setUp(self):
     import numpy as np
     from datasources import ArraySource
     self.raw = np.random.randint(0, 100, (10, 3, 3, 128, 3))
     self.a = ArraySource(self.raw)
     self.ss = SliceSource(self.a, projectionAlongTZC)
コード例 #7
0
import dask.array
from datasources import ArraySource
from in_memory_catalog import Catalog

# Build Catalog of Catalogs.
subcatalogs = {}
for name, size, fruit, animal in zip(
    ["tiny", "small", "medium", "large"],
    [3, 100, 1000, 10_000],
    ["apple", "banana", "orange", "grape"],
    ["bird", "cat", "dog", "penguin"],
):
    subcatalogs[name] = Catalog(
        {
            k: ArraySource(v * dask.array.ones((size, size)))
            for k, v in zip(["ones", "twos", "threes"], [1, 2, 3])
        },
        metadata={
            "fruit": fruit,
            "animal": animal
        },
    )
catalog = Catalog(subcatalogs)