Ejemplo n.º 1
0
    def test_readroi(self):
        lb = [9, 15, 15]
        ub = [11, 99, 99]
        img = pyklb.readroi(self.testread_filepath, lb, ub)
        self.assertEqual(np.prod(img.shape), np.prod([ 1+ub[i]-lb[i] for i in range(len(lb)) ]))
        self.assertEqual(round(np.mean(img)), 568)

        with self.assertRaises(IndexError):
            img = pyklb.readroi(self.testread_filepath, [9, 15, 15], [66, 99, 99])
            img = pyklb.readroi(self.testread_filepath, [-1, 15, 15], [11, 99, 99])
Ejemplo n.º 2
0
    def test_readroi(self):
        lb = [9, 15, 15]
        ub = [11, 99, 99]
        img = pyklb.readroi(self.testread_filepath, lb, ub)
        self.assertEqual(np.prod(img.shape),
                         np.prod([1 + ub[i] - lb[i] for i in range(len(lb))]))
        self.assertEqual(round(np.mean(img)), 568)

        with self.assertRaises(IndexError):
            img = pyklb.readroi(self.testread_filepath, [9, 15, 15],
                                [66, 99, 99])
            img = pyklb.readroi(self.testread_filepath, [-1, 15, 15],
                                [11, 99, 99])
Ejemplo n.º 3
0
def test_pyklb():
    """
    This merely tests pyklb itself, to make sure it was compiled correctly.
    """
    if not _klb_available:
        raise nose.SkipTest

    # Create some simple data. Should compress well.
    shape = (1, 1, 30, 40, 50)
    data_tczyx = np.indices(shape).sum(0).astype(np.uint8)
    assert data_tczyx.shape == shape

    # Write the data as KLB
    #print "writing..."
    filepath = '/tmp/test_data.klb'
    pyklb.writefull(data_tczyx,
                    filepath,
                    blocksize_xyzct=np.array([10, 10, 10, 1, 1],
                                             dtype=np.uint32))

    # Read it back
    #print "reading..."
    #readback = pyklb.readfull(filepath)
    readback = pyklb.readroi(filepath, (0, 0, 0, 0, 0), np.array(shape) - 1)

    assert (readback == data_tczyx).all()
Ejemplo n.º 4
0
 def execute(self, slot, subindex, roi, result):
     if result.flags.c_contiguous:
         pyklb.readroi_inplace(result,
                               self._filepath,
                               roi.start,
                               roi.stop - 1,
                               nochecks=False)
     else:
         result[:] = pyklb.readroi(self._filepath, roi.start, roi.stop - 1)
Ejemplo n.º 5
0
def sample(filename, n):

    header = pyklb.readheader(filename)
    size = header['imagesize_tczyx'][-3:]

    points = []

    print("Sampling points...")
    while len(points) < n:

        z = random.randint(0, size[0] - 1)
        y = random.randint(0, size[1] - 1)
        x = random.randint(0, size[2] - 1)

        if pyklb.readroi(filename, (z, y, x), (z, y, x)) > foreground_threshold:
            points.append((z, y, x))

    print("Done.")

    return points
Ejemplo n.º 6
0
 def testBasic(self):
     tmpdir = tempfile.mkdtemp()        
     try:
         filepath = tmpdir + '/random_data.klb'
         shape = (1,1,30,40,50)
         data_tczyx = np.indices( shape ).sum(0).astype( np.uint8 )
         pyklb.writefull( data_tczyx, filepath, blocksize_xyzct=np.array([10,10,10,1,1], dtype=np.uint32) )
         readback = pyklb.readroi(filepath, (0,0,0,0,0), np.array(shape)-1)
                        
         op = OpKlbReader( graph=Graph() )
         op.FilePath.setValue( filepath )
           
         assert op.Output.meta.shape == shape
         assert op.Output.meta.dtype == np.uint8
           
         read_data = op.Output[:].wait()
         assert ( read_data == data_tczyx ).all()
           
     finally:
         shutil.rmtree(tmpdir)
Ejemplo n.º 7
0
def test_pyklb():
    """
    This merely tests pyklb itself, to make sure it was compiled correctly.
    """
    if not _klb_available:
        raise nose.SkipTest

    # Create some simple data. Should compress well.
    shape = (1,1,30,40,50)
    data_tczyx = np.indices( shape ).sum(0).astype( np.uint8 )
    assert data_tczyx.shape == shape
    
    # Write the data as KLB
    #print "writing..."
    filepath = '/tmp/test_data.klb'    
    pyklb.writefull( data_tczyx, filepath, blocksize_xyzct=np.array([10,10,10,1,1], dtype=np.uint32) )
    
    # Read it back
    #print "reading..."
    #readback = pyklb.readfull(filepath)
    readback = pyklb.readroi(filepath, (0,0,0,0,0), np.array(shape)-1)
    
    assert (readback == data_tczyx).all()
Ejemplo n.º 8
0
    def testBasic(self):
        tmpdir = tempfile.mkdtemp()
        try:
            filepath = tmpdir + '/random_data.klb'
            shape = (1, 1, 30, 40, 50)
            data_tczyx = np.indices(shape).sum(0).astype(np.uint8)
            pyklb.writefull(data_tczyx,
                            filepath,
                            blocksize_xyzct=np.array([10, 10, 10, 1, 1],
                                                     dtype=np.uint32))
            readback = pyklb.readroi(filepath, (0, 0, 0, 0, 0),
                                     np.array(shape) - 1)

            op = OpKlbReader(graph=Graph())
            op.FilePath.setValue(filepath)

            assert op.Output.meta.shape == shape
            assert op.Output.meta.dtype == np.uint8

            read_data = op.Output[:].wait()
            assert (read_data == data_tczyx).all()

        finally:
            shutil.rmtree(tmpdir)
Ejemplo n.º 9
0
 def execute(self, slot, subindex, roi, result):
     if result.flags.c_contiguous:
         pyklb.readroi_inplace(result, self._filepath, roi.start, roi.stop-1, nochecks=False)
     else:
         result[:] = pyklb.readroi(self._filepath, roi.start, roi.stop-1)