Exemplo n.º 1
0
    def test_unready_propagation(self):
        # The array piper copies its input to its output, creating an "implicit" connection
        op = operators.OpArrayPiper(graph=self.g)
        op.name = "op"

        # op2 gets his input as a clone from op.Input
        op2 = operators.OpArrayPiper(graph=self.g)
        op2.Input.connect(op.Input)
        op2.name = "op2"

        # op3 gets his input as a clone from op.Output
        op3 = operators.OpArrayPiper(graph=self.g)
        op3.Input.connect(op.Output)
        op3.name = "op3"

        #
        # op.Input  --> op2.Input
        #   .Output --> op3.Input
        #

        # This should trigger setupOutputs and everything to become ready
        data = numpy.zeros((10, 10, 10, 10, 10))
        op.Input.setValue(data)

        assert op.Input.ready()
        assert op.Output.ready()
        assert op2.Input.ready()
        assert op2.Output.ready()
        assert op3.Input.ready()
        assert op3.Output.ready()

        assert op.Input.connected()
        assert not op.Output.connected()  # Not connected

        # Disonnecting the head of the chain should cause everything to become unready
        op.Input.disconnect()

        assert not op.Input.ready()
        assert not op.Output.ready()
        assert not op2.Input.ready()
        assert not op2.Output.ready()
        assert not op3.Input.ready()
        assert not op3.Output.ready()
Exemplo n.º 2
0
    def test_implicitlyConnectedOutputs(self):
        # The array piper copies its input to its output, creating an "implicit" connection
        op = operators.OpArrayPiper(graph=self.g)

        assert not op.Input.connected()
        assert not op.Output.connected()

        assert not op.Input.ready()
        assert not op.Output.ready()

        connectedSlots = {op.Input: False, op.Output: False}

        def handleConnect(slot):
            connectedSlots[slot] = True

        # Test notifyConnect
        op.Input._notifyConnect(handleConnect)
        op.Output._notifyConnect(handleConnect)

        readySlots = {op.Input: False, op.Output: False}

        def handleReady(slot):
            readySlots[slot] = True

        # Test notifyReady
        op.Input.notifyReady(handleReady)
        op.Output.notifyReady(handleReady)

        data = numpy.zeros((10, 10, 10, 10, 10))
        op.Input.setValue(data)

        assert op.Input.ready()
        assert op.Output.ready()

        assert op.Input.connected()
        assert not op.Output.connected()  # Not connected

        assert connectedSlots[op.Input] == True
        assert connectedSlots[op.Output] == False

        assert readySlots[op.Input] == True
        assert readySlots[op.Output] == True
Exemplo n.º 3
0
    def testIssue130(self):
        # Verify the fix for issue ilastik/lazyflow#130
        op = operators.OpArrayPiper(graph=self.g)

        dirty_flag = [False]
        def handleDirty(*args):
            dirty_flag[0] = True
        
        op.Input.notifyDirty(handleDirty)
        
        a = numpy.zeros( 5*(10,), dtype=int )
        op.Input.setValue( a )
        dirty_flag[0] = False
        
        # If setting the same value, still not dirty...
        op.Input.setValue(a)
        assert dirty_flag[0] is False

        # Now if we set an array with different shape, but still broadcastable to the original,
        #  dirtiness should be detected.
        a = numpy.zeros( 4*(10,) + (1,), dtype=int)
        op.Input.setValue(a)
        assert dirty_flag[0] is True
Exemplo n.º 4
0
    def test_clonedSlotState(self):
        """
        Create a graph that involves "cloned" inputs and outputs,
        and verify that their states are changed correctly at the correct times, with callbacks.
        """
        # The array piper copies its input to its output, creating an "implicit" connection
        op = operators.OpArrayPiper(graph=self.g)

        # op2 gets his input as a clone from op.Input
        op2 = operators.OpArrayPiper(graph=self.g)
        op2.Input.connect(op.Input)

        # op3 gets his input as a clone from op.Output
        op3 = operators.OpArrayPiper(graph=self.g)
        op3.Input.connect(op.Output)

        assert not op.Input.connected()
        assert not op.Output.connected()

        assert not op.Input.ready()
        assert not op.Output.ready()
        assert not op2.Input.ready()
        assert not op2.Output.ready()
        assert not op3.Input.ready()
        assert not op3.Output.ready()

        connectedSlots = {op.Input: False, op.Output: False}

        def handleConnect(slot):
            connectedSlots[slot] = True

        # Test notifyConnect
        op.Input._notifyConnect(handleConnect)
        op.Output._notifyConnect(handleConnect)

        readySlots = {op.Input: False, op.Output: False}

        def handleReady(slot):
            readySlots[slot] = True

        # Test notifyReady
        op.Input.notifyReady(handleReady)
        op.Output.notifyReady(handleReady)
        op2.Input.notifyReady(handleReady)
        op2.Output.notifyReady(handleReady)
        op3.Input.notifyReady(handleReady)
        op3.Output.notifyReady(handleReady)

        # This should trigger setupOutputs and everything to become ready
        data = numpy.zeros((10, 10, 10, 10, 10))
        op.Input.setValue(data)

        assert op.Input.ready()
        assert op.Output.ready()
        assert op2.Input.ready()
        assert op2.Output.ready()
        assert op3.Input.ready()
        assert op3.Output.ready()

        assert op.Input.connected()
        assert not op.Output.connected()  # Not connected

        assert connectedSlots[op.Input] == True
        assert connectedSlots[op.Output] == False

        assert readySlots[op.Input] == True
        assert readySlots[op.Output] == True
        assert readySlots[op2.Input] == True
        assert readySlots[op2.Output] == True
        assert readySlots[op3.Input] == True
        assert readySlots[op3.Output] == True
Exemplo n.º 5
0
#     for i in range(1,mcount):
#       msg = socket.recv()
#       socket.send("")#, flags = zmq.NOBLOCK)
#


class C(object):
    def __init__(self, shape, dtype=numpy.uint8):
        self.array = numpy.ndarray(shape, dtype)

    def __getitem__(self, key):
        return self.array[key]


cache = operators.OpArrayCache(graph=g)
piper = operators.OpArrayPiper(graph=g)

arr = numpy.ndarray((100, 100, 100, 1), numpy.uint8)
arr = arr.view(vigra.VigraArray)
arr.axistags = vigra.defaultAxistags('xyzc')

piper.Input.setValue(arr)
cache.inputs["Input"].connect(piper.Output)

features = operators.OpPixelFeaturesPresmoothed(graph=g)
matrix = numpy.ndarray((6, 2), numpy.uint8)
matrix[:] = 0
matrix[0, :] = 1
features.inputs["Scales"].setValue((1.0, 3.0))
features.inputs["Input"].connect(cache.outputs["Output"])
features.inputs["Matrix"].setValue(matrix)
def testFullAllocate():

    nx = 5
    ny = 10
    nz = 2
    nc = 7
    stack = vigra.VigraArray((nx, ny, nz, nc),
                             axistags=vigra.defaultAxistags('xyzc'))
    stack[...] = numpy.random.rand(nx, ny, nz, nc)

    g = Graph()

    #assume that the slicer works
    slicerX = OpMultiArraySlicer_REDUCE_DIM(graph=g)
    slicerX.inputs["Input"].setValue(stack)
    slicerX.inputs["AxisFlag"].setValue('x')

    #insert the x dimension
    stackerX = OpMultiArrayStacker(graph=g)
    stackerX.inputs["AxisFlag"].setValue('x')
    stackerX.inputs["AxisIndex"].setValue(0)
    stackerX.inputs["Images"].connect(slicerX.outputs["Slices"])

    newdata = stackerX.outputs["Output"][:].wait()
    assert_array_equal(newdata, stack.view(numpy.ndarray))

    print("1st part ok.................")
    #merge stuff that already has an x dimension
    stack2 = vigra.VigraArray((nx - 1, ny, nz, nc),
                              axistags=vigra.defaultAxistags('xyzc'))
    stack2[...] = numpy.random.rand(nx - 1, ny, nz, nc)

    stackerX2 = OpMultiArrayStacker(graph=g)

    stackerX2.Images.resize(2)

    ap1 = operators.OpArrayPiper(graph=g)
    ap2 = operators.OpArrayPiper(graph=g)
    ap1.Input.setValue(stack)
    ap2.Input.setValue(stack2)
    stackerX2.Images[0].connect(ap1.Output)
    stackerX2.Images[1].connect(ap2.Output)

    stackerX2.inputs["AxisFlag"].setValue('x')
    stackerX2.inputs["AxisIndex"].setValue(0)

    #print "STACKER: ", stackerX2.outputs["Output"].meta.shape

    newdata = stackerX2.outputs["Output"][:].wait()
    bothstacks = numpy.concatenate((stack, stack2), axis=0)
    assert_array_equal(newdata, bothstacks.view(numpy.ndarray))
    #print newdata.shape, bothstacks.shape

    print("2nd part ok.................")
    #print "------------------------------------------------------------"
    #print "------------------------------------------------------------"
    #print "------------------------------------------------------------"
    ##### channel

    #assume that the slicer works
    slicerC = OpMultiArraySlicer_REDUCE_DIM(graph=g)
    slicerC.inputs["Input"].setValue(stack)
    slicerC.inputs["AxisFlag"].setValue('c')

    #insert the c dimension

    stackerC = OpMultiArrayStacker(graph=g)
    stackerC.inputs["AxisFlag"].setValue('c')
    stackerC.inputs["AxisIndex"].setValue(3)
    stackerC.inputs["Images"].connect(slicerC.outputs["Slices"])

    newdata = stackerC.outputs["Output"][:].wait()
    assert_array_equal(newdata, stack.view(numpy.ndarray))

    print("3rd part ok.................")
    #print "STACKER: ", stackerC.outputs["Output"].meta.shape

    #merge stuff that already has an x dimension
    stack3 = vigra.VigraArray((nx, ny, nz, nc - 1),
                              axistags=vigra.defaultAxistags('xyzc'))
    stack3[...] = numpy.random.rand(nx, ny, nz, nc - 1)

    ap3 = operators.OpArrayPiper(graph=g)
    ap3.Input.setValue(stack3)

    stackerC2 = OpMultiArrayStacker(graph=g)
    stackerC2.inputs["AxisFlag"].setValue('c')
    stackerC2.inputs["AxisIndex"].setValue(3)
    stackerC2.Images.resize(2)
    stackerC2.Images[0].connect(ap1.Output)
    stackerC2.Images[1].connect(ap3.Output)

    newdata = stackerC2.outputs["Output"][:].wait()
    bothstacks = numpy.concatenate((stack, stack3), axis=3)
    assert_array_equal(newdata, bothstacks.view(numpy.ndarray))
    print("4th part ok.................")