Example #1
0
class TestOpArrayPiper7(object):
    def setUp(self):
        self.graph = Graph()

        self.operator_identity_1 = OpArrayPiper(graph=self.graph)
        self.operator_identity_2 = OpArrayPiper(graph=self.graph)

        self.operator_identity_1.Input.meta.axistags = vigra.AxisTags("txyzc")
        self.operator_identity_2.Input.meta.axistags = vigra.AxisTags("txyzc")

    def test1(self):
        # Explicitly set has_mask for the input
        self.operator_identity_1.Input.meta.has_mask = True
        self.operator_identity_1.Output.meta.has_mask = True

        # Generate a dataset and grab chunks of it from the operator. The result should be the same as above.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        data = numpy.ma.masked_array(
            data,
            mask=numpy.zeros(data.shape, dtype=bool),
            shrink=False
        )

        # Try to connect the compatible operators.
        self.operator_identity_2.Input.connect(self.operator_identity_1.Output)
        self.operator_identity_1.Input.setValue(data)
        output = self.operator_identity_2.Output[None].wait()

        assert((data == output).all())
        assert(data.mask.shape == output.mask.shape)
        assert((data.mask == output.mask).all())


    def test2(self):
        # Generate a dataset and grab chunks of it from the operator. The result should be the same as above.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        data = numpy.ma.masked_array(
            data,
            mask=numpy.zeros(data.shape, dtype=bool),
            shrink=False
        )

        # Try to connect the compatible operators.
        self.operator_identity_1.Input.setValue(data)
        self.operator_identity_2.Input.connect(self.operator_identity_1.Output)
        output = self.operator_identity_2.Output[None].wait()

        assert((data == output).all())
        assert(data.mask.shape == output.mask.shape)
        assert((data.mask == output.mask).all())

    def tearDown(self):
        # Take down operators
        self.operator_identity_2.Input.disconnect()
        self.operator_identity_2.Output.disconnect()
        self.operator_identity_2.cleanUp()
        self.operator_identity_1.Input.disconnect()
        self.operator_identity_1.Output.disconnect()
        self.operator_identity_1.cleanUp()
Example #2
0
class TestOpArrayPiper4(object):
    def setup_method(self, method):
        self.graph = Graph()

        self.operator_identity = OpArrayPiper(graph=self.graph)
        self.operator_identity.Input.allow_mask = False
        self.operator_identity.Output.allow_mask = False
        self.operator_identity.Input.meta.has_mask = False
        self.operator_identity.Output.meta.has_mask = False

        self.operator_identity.Input.meta.axistags = vigra.AxisTags("txyzc")

    @nose.tools.raises(AllowMaskException)
    def test1(self):
        # Generate a random dataset and see if it we get the right masking from the operator.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        data = numpy.ma.masked_array(data, mask=numpy.zeros(data.shape, dtype=bool), shrink=False)

        # Provide input read all output.
        try:
            self.operator_identity.Input.setValue(data)
        except AssertionError as e:
            raise AllowMaskException(str(e))

    @nose.tools.raises(AllowMaskException)
    def test2(self):
        # Generate a dataset and grab chunks of it from the operator. The result should be the same as above.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        data = numpy.ma.masked_array(data, mask=numpy.zeros(data.shape, dtype=bool), shrink=False)

        # Create array to store results. Don't keep original data.
        output = data.copy()
        output[:] = 0
        output[:] = numpy.ma.nomask

        # Provide input and grab chunks.
        try:
            self.operator_identity.Input.setValue(data)
        except AssertionError as e:
            raise AllowMaskException(str(e))

    @nose.tools.raises(AllowMaskException)
    def test3(self):
        # Generate a random dataset and see if it we get the right masking from the operator.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        data = numpy.ma.masked_array(data, mask=numpy.zeros(data.shape, dtype=bool), shrink=False)

        # Provide input read all output.
        try:
            self.operator_identity.Input.setValue(numpy.zeros_like(data))
        except AssertionError as e:
            raise AllowMaskException(str(e))

    def teardown_method(self, method):
        # Take down operators
        self.operator_identity.Input.disconnect()
        self.operator_identity.Output.disconnect()
        self.operator_identity.cleanUp()
Example #3
0
class TestOpArrayPiper4(object):
    def setup_method(self, method):
        self.graph = Graph()

        self.operator_identity = OpArrayPiper(graph=self.graph)
        self.operator_identity.Input.allow_mask = False
        self.operator_identity.Output.allow_mask = False
        self.operator_identity.Input.meta.has_mask = False
        self.operator_identity.Output.meta.has_mask = False

        self.operator_identity.Input.meta.axistags = vigra.AxisTags("txyzc")

    def test1(self):
        # Generate a random dataset and see if it we get the right masking from the operator.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        data = numpy.ma.masked_array(data, mask=numpy.zeros(data.shape, dtype=bool), shrink=False)

        # Provide input read all output.
        with pytest.raises(AllowMaskException):
            try:
                self.operator_identity.Input.setValue(data)
            except AssertionError as e:
                raise AllowMaskException(str(e))

    def test2(self):
        # Generate a dataset and grab chunks of it from the operator. The result should be the same as above.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        data = numpy.ma.masked_array(data, mask=numpy.zeros(data.shape, dtype=bool), shrink=False)

        # Create array to store results. Don't keep original data.
        output = data.copy()
        output[:] = 0
        output[:] = numpy.ma.nomask

        # Provide input and grab chunks.
        with pytest.raises(AllowMaskException):
            try:
                self.operator_identity.Input.setValue(data)
            except AssertionError as e:
                raise AllowMaskException(str(e))

    def test3(self):
        # Generate a random dataset and see if it we get the right masking from the operator.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        data = numpy.ma.masked_array(data, mask=numpy.zeros(data.shape, dtype=bool), shrink=False)

        # Provide input read all output.
        with pytest.raises(AllowMaskException):
            try:
                self.operator_identity.Input.setValue(numpy.zeros_like(data))
            except AssertionError as e:
                raise AllowMaskException(str(e))

    def teardown_method(self, method):
        # Take down operators
        self.operator_identity.Input.disconnect()
        self.operator_identity.Output.disconnect()
        self.operator_identity.cleanUp()
Example #4
0
class TestOpArrayPiper(object):
    def setup_method(self, method):
        self.graph = Graph()

        self.operator_identity = OpArrayPiper(graph=self.graph)

        self.operator_identity.Input.meta.axistags = vigra.AxisTags("txyzc")

    def test1(self):
        # Generate a random dataset and see if it we get the right masking from the operator.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)

        # Provide input read all output.
        self.operator_identity.Input.setValue(data)
        output = self.operator_identity.Output[None].wait()

        assert (data == output).all()

    def test2(self):
        # Generate a dataset and grab chunks of it from the operator. The result should be the same as above.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)

        # Create array to store results. Don't keep original data.
        output = data.copy()
        output[:] = 0

        # Provide input and grab chunks.
        self.operator_identity.Input.setValue(data)
        output[:2] = self.operator_identity.Output[:2].wait()
        output[2:] = self.operator_identity.Output[2:].wait()

        assert (data == output).all()

    def test3(self):
        # Generate a random dataset and see if it we get the right masking from the operator.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)

        # Provide input read all output.
        self.operator_identity.Input.setValue(numpy.zeros_like(data))
        output = self.operator_identity.Output[None].wait()

        assert (output == 0).all()

        # Try setInSlot
        data_shape_roi = roiFromShape(data.shape)
        data_shape_slice = roiToSlice(*data_shape_roi)
        self.operator_identity.Input[data_shape_slice] = data
        output = self.operator_identity.Output[None].wait()

        assert (data == output).all()

    def teardown_method(self, method):
        # Take down operators
        self.operator_identity.Input.disconnect()
        self.operator_identity.Output.disconnect()
        self.operator_identity.cleanUp()
Example #5
0
class TestOpArrayPiper(object):
    def setUp(self):
        self.graph = Graph()

        self.operator_identity = OpArrayPiper(graph=self.graph)

        self.operator_identity.Input.meta.axistags = vigra.AxisTags("txyzc")

    def test1(self):
        # Generate a random dataset and see if it we get the right masking from the operator.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)

        # Provide input read all output.
        self.operator_identity.Input.setValue(data)
        output = self.operator_identity.Output[None].wait()

        assert((data == output).all())

    def test2(self):
        # Generate a dataset and grab chunks of it from the operator. The result should be the same as above.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)

        # Create array to store results. Don't keep original data.
        output = data.copy()
        output[:] = 0

        # Provide input and grab chunks.
        self.operator_identity.Input.setValue(data)
        output[:2] = self.operator_identity.Output[:2].wait()
        output[2:] = self.operator_identity.Output[2:].wait()

        assert((data == output).all())

    def test3(self):
        # Generate a random dataset and see if it we get the right masking from the operator.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)

        # Provide input read all output.
        self.operator_identity.Input.setValue(numpy.zeros_like(data))
        output = self.operator_identity.Output[None].wait()

        assert((output == 0).all())

        # Try setInSlot
        data_shape_roi = roiFromShape(data.shape)
        data_shape_slice = roiToSlice(*data_shape_roi)
        self.operator_identity.Input[data_shape_slice] = data
        output = self.operator_identity.Output[None].wait()

        assert((data == output).all())

    def tearDown(self):
        # Take down operators
        self.operator_identity.Input.disconnect()
        self.operator_identity.Output.disconnect()
        self.operator_identity.cleanUp()
Example #6
0
class TestOpArrayPiper7(object):
    def setup_method(self, method):
        self.graph = Graph()

        self.operator_identity_1 = OpArrayPiper(graph=self.graph)
        self.operator_identity_2 = OpArrayPiper(graph=self.graph)

        self.operator_identity_1.Input.meta.axistags = vigra.AxisTags("txyzc")
        self.operator_identity_2.Input.meta.axistags = vigra.AxisTags("txyzc")

    def test1(self):
        # Explicitly set has_mask for the input
        self.operator_identity_1.Input.meta.has_mask = True
        self.operator_identity_1.Output.meta.has_mask = True

        # Generate a dataset and grab chunks of it from the operator. The result should be the same as above.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        data = numpy.ma.masked_array(data,
                                     mask=numpy.zeros(data.shape, dtype=bool),
                                     shrink=False)

        # Try to connect the compatible operators.
        self.operator_identity_2.Input.connect(self.operator_identity_1.Output)
        self.operator_identity_1.Input.setValue(data)
        output = self.operator_identity_2.Output[None].wait()

        assert (data == output).all()
        assert data.mask.shape == output.mask.shape
        assert (data.mask == output.mask).all()

    def test2(self):
        # Generate a dataset and grab chunks of it from the operator. The result should be the same as above.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        data = numpy.ma.masked_array(data,
                                     mask=numpy.zeros(data.shape, dtype=bool),
                                     shrink=False)

        # Try to connect the compatible operators.
        self.operator_identity_1.Input.setValue(data)
        self.operator_identity_2.Input.connect(self.operator_identity_1.Output)
        output = self.operator_identity_2.Output[None].wait()

        assert (data == output).all()
        assert data.mask.shape == output.mask.shape
        assert (data.mask == output.mask).all()

    def teardown_method(self, method):
        # Take down operators
        self.operator_identity_2.Input.disconnect()
        self.operator_identity_2.Output.disconnect()
        self.operator_identity_2.cleanUp()
        self.operator_identity_1.Input.disconnect()
        self.operator_identity_1.Output.disconnect()
        self.operator_identity_1.cleanUp()
Example #7
0
class TestOpArrayPiper6(object):
    def setup_method(self, method):
        self.graph = Graph()

        self.operator_identity_1 = OpArrayPiper(graph=self.graph)
        self.operator_identity_2 = OpArrayPiper(graph=self.graph)
        self.operator_identity_2.Input.allow_mask = False
        self.operator_identity_2.Output.allow_mask = False

        self.operator_identity_1.Input.meta.axistags = vigra.AxisTags("txyzc")
        self.operator_identity_2.Input.meta.axistags = vigra.AxisTags("txyzc")

    @nose.tools.raises(AllowMaskException)
    def test1(self):
        # Explicitly set has_mask for the input
        self.operator_identity_1.Input.meta.has_mask = True
        self.operator_identity_1.Output.meta.has_mask = True

        # Try to connect the incompatible operators.
        try:
            self.operator_identity_2.Input.connect(
                self.operator_identity_1.Output)
        except AssertionError as e:
            raise AllowMaskException(str(e))

    @nose.tools.raises(AllowMaskException)
    def test2(self):
        # Generate a dataset and grab chunks of it from the operator. The result should be the same as above.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        data = numpy.ma.masked_array(data,
                                     mask=numpy.zeros(data.shape, dtype=bool),
                                     shrink=False)

        # Implicitly set has_mask for the input by setting the value.
        self.operator_identity_1.Input.setValue(data)

        # Try to connect the incompatible operators.
        try:
            self.operator_identity_2.Input.connect(
                self.operator_identity_1.Output)
        except AssertionError as e:
            raise AllowMaskException(str(e))

    def teardown_method(self, method):
        # Take down operators
        self.operator_identity_2.Input.disconnect()
        self.operator_identity_2.Output.disconnect()
        self.operator_identity_2.cleanUp()
        self.operator_identity_1.Input.disconnect()
        self.operator_identity_1.Output.disconnect()
        self.operator_identity_1.cleanUp()
Example #8
0
class TestOpArrayPiper6(object):
    def setUp(self):
        self.graph = Graph()

        self.operator_identity_1 = OpArrayPiper(graph=self.graph)
        self.operator_identity_2 = OpArrayPiper(graph=self.graph)
        self.operator_identity_2.Input.allow_mask = False
        self.operator_identity_2.Output.allow_mask = False

        self.operator_identity_1.Input.meta.axistags = vigra.AxisTags("txyzc")
        self.operator_identity_2.Input.meta.axistags = vigra.AxisTags("txyzc")

    @nose.tools.raises(AllowMaskException)
    def test1(self):
        # Explicitly set has_mask for the input
        self.operator_identity_1.Input.meta.has_mask = True
        self.operator_identity_1.Output.meta.has_mask = True

        # Try to connect the incompatible operators.
        try:
            self.operator_identity_2.Input.connect(self.operator_identity_1.Output)
        except AssertionError as e:
            raise AllowMaskException(str(e))

    @nose.tools.raises(AllowMaskException)
    def test2(self):
        # Generate a dataset and grab chunks of it from the operator. The result should be the same as above.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        data = numpy.ma.masked_array(
            data,
            mask=numpy.zeros(data.shape, dtype=bool),
            shrink=False
        )

        # Implicitly set has_mask for the input by setting the value.
        self.operator_identity_1.Input.setValue(data)

        # Try to connect the incompatible operators.
        try:
            self.operator_identity_2.Input.connect(self.operator_identity_1.Output)
        except AssertionError as e:
            raise AllowMaskException(str(e))

    def tearDown(self):
        # Take down operators
        self.operator_identity_2.Input.disconnect()
        self.operator_identity_2.Output.disconnect()
        self.operator_identity_2.cleanUp()
        self.operator_identity_1.Input.disconnect()
        self.operator_identity_1.Output.disconnect()
        self.operator_identity_1.cleanUp()
Example #9
0
class TestOpMaskArray3(object):
    def setUp(self):
        self.graph = Graph()

        self.operator_border = OpMaskArray(graph=self.graph)
        self.operator_identity = OpArrayPiper(graph=self.graph)

        self.operator_border.InputArray.meta.axistags = vigra.AxisTags("txyzc")

        self.operator_identity.Input.connect(self.operator_border.Output)

    def test1(self):
        # Generate a random dataset and see if it we get the right masking from the operator.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        mask = numpy.zeros(data.shape, dtype=bool)

        # Mask borders of the expected output.
        left_slicing = (mask.ndim - 1) * (slice(None),) + (slice(None, 1),)
        right_slicing = (mask.ndim - 1) * (slice(None),) + (slice(-1, None),)
        for i in xrange(mask.ndim):
            left_slicing = left_slicing[-1:] + left_slicing[:-1]
            right_slicing = right_slicing[-1:] + right_slicing[:-1]

            mask[left_slicing] = True
            mask[right_slicing] = True

        expected_output = numpy.ma.masked_array(data,
                                                mask=mask,
                                                shrink=False
                          )

        # Provide input read all output.
        self.operator_border.InputArray.setValue(data)
        self.operator_border.InputMask.setValue(mask)
        output = self.operator_identity.Output[None].wait()

        assert((expected_output == output).all())
        assert(expected_output.mask.shape == output.mask.shape)
        assert((expected_output.mask == output.mask).all())

    def test2(self):
        # Generate a dataset and grab chunks of it from the operator. The result should be the same as above.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        mask = numpy.zeros(data.shape, dtype=bool)

        # Mask borders of the expected output.
        left_slicing = (mask.ndim - 1) * (slice(None),) + (slice(None, 1),)
        right_slicing = (mask.ndim - 1) * (slice(None),) + (slice(-1, None),)
        for i in xrange(mask.ndim):
            left_slicing = left_slicing[-1:] + left_slicing[:-1]
            right_slicing = right_slicing[-1:] + right_slicing[:-1]

            mask[left_slicing] = True
            mask[right_slicing] = True

        expected_output = numpy.ma.masked_array(data,
                                                mask=mask,
                                                shrink=False
                          )

        # Create array to store results. Don't keep original data.
        output = expected_output.copy()
        output[:] = 0
        output[:] = numpy.ma.nomask

        # Provide input and grab chunks.
        self.operator_border.InputArray.setValue(data)
        self.operator_border.InputMask.setValue(mask)
        output[:2] = self.operator_identity.Output[:2].wait()
        output[2:] = self.operator_identity.Output[2:].wait()

        assert((expected_output == output).all())
        assert(expected_output.mask.shape == output.mask.shape)
        assert((expected_output.mask == output.mask).all())

    def tearDown(self):
        # Take down operators
        self.operator_identity.Input.disconnect()
        self.operator_identity.Output.disconnect()
        self.operator_identity.cleanUp()
        self.operator_border.InputArray.disconnect()
        self.operator_border.InputMask.disconnect()
        self.operator_border.Output.disconnect()
        self.operator_border.cleanUp()
Example #10
0
class TestOpMaskArray3(object):
    def setUp(self):
        self.graph = Graph()

        self.operator_border = OpMaskArray(graph=self.graph)
        self.operator_identity = OpArrayPiper(graph=self.graph)

        self.operator_border.InputArray.meta.axistags = vigra.AxisTags("txyzc")

        self.operator_identity.Input.connect(self.operator_border.Output)

    def test1(self):
        # Generate a random dataset and see if it we get the right masking from the operator.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        mask = numpy.zeros(data.shape, dtype=bool)

        # Mask borders of the expected output.
        left_slicing = (mask.ndim - 1) * (slice(None), ) + (slice(None, 1), )
        right_slicing = (mask.ndim - 1) * (slice(None), ) + (slice(-1, None), )
        for i in xrange(mask.ndim):
            left_slicing = left_slicing[-1:] + left_slicing[:-1]
            right_slicing = right_slicing[-1:] + right_slicing[:-1]

            mask[left_slicing] = True
            mask[right_slicing] = True

        expected_output = numpy.ma.masked_array(data, mask=mask, shrink=False)

        # Provide input read all output.
        self.operator_border.InputArray.setValue(data)
        self.operator_border.InputMask.setValue(mask)
        output = self.operator_identity.Output[None].wait()

        assert ((expected_output == output).all())
        assert (expected_output.mask.shape == output.mask.shape)
        assert ((expected_output.mask == output.mask).all())

    def test2(self):
        # Generate a dataset and grab chunks of it from the operator. The result should be the same as above.
        data = numpy.random.random((4, 5, 6, 7, 3)).astype(numpy.float32)
        mask = numpy.zeros(data.shape, dtype=bool)

        # Mask borders of the expected output.
        left_slicing = (mask.ndim - 1) * (slice(None), ) + (slice(None, 1), )
        right_slicing = (mask.ndim - 1) * (slice(None), ) + (slice(-1, None), )
        for i in xrange(mask.ndim):
            left_slicing = left_slicing[-1:] + left_slicing[:-1]
            right_slicing = right_slicing[-1:] + right_slicing[:-1]

            mask[left_slicing] = True
            mask[right_slicing] = True

        expected_output = numpy.ma.masked_array(data, mask=mask, shrink=False)

        # Create array to store results. Don't keep original data.
        output = expected_output.copy()
        output[:] = 0
        output[:] = numpy.ma.nomask

        # Provide input and grab chunks.
        self.operator_border.InputArray.setValue(data)
        self.operator_border.InputMask.setValue(mask)
        output[:2] = self.operator_identity.Output[:2].wait()
        output[2:] = self.operator_identity.Output[2:].wait()

        assert ((expected_output == output).all())
        assert (expected_output.mask.shape == output.mask.shape)
        assert ((expected_output.mask == output.mask).all())

    def tearDown(self):
        # Take down operators
        self.operator_identity.Input.disconnect()
        self.operator_identity.Output.disconnect()
        self.operator_identity.cleanUp()
        self.operator_border.InputArray.disconnect()
        self.operator_border.InputMask.disconnect()
        self.operator_border.Output.disconnect()
        self.operator_border.cleanUp()