def test(self): from lazyflow.graph import Graph, MetaDict from lazyflow.operators import OpArrayPiper graph = Graph() opDataSource = OpArrayPiper(graph=graph) opDataSource.Input.setValue( numpy.ndarray((9,10), dtype=numpy.uint8) ) # Create some metadata shape = (1,2,3,4,5) data = numpy.indices(shape, dtype=int).sum(0) meta = MetaDict() meta.specialdata = "Salutations" meta.notsospecial = "Hey" opProvider = OpOutputProvider( data, meta, graph=graph ) op = OpMetadataMerge(graph=graph) op.Input.connect( opDataSource.Output ) op.MetadataSource.connect( opProvider.Output ) op.FieldsToClone.setValue( ['specialdata'] ) assert op.Output.ready() assert op.Output.meta.shape == opDataSource.Output.meta.shape assert op.Output.meta.dtype == opDataSource.Output.meta.dtype assert op.Output.meta.specialdata == meta.specialdata assert op.Output.meta.notsospecial is None
def test(self): from lazyflow.graph import Graph, MetaDict from lazyflow.operators import OpArrayPiper graph = Graph() opDataSource = OpArrayPiper(graph=graph) opDataSource.Input.setValue(numpy.ndarray((9, 10), dtype=numpy.uint8)) # Create some metadata shape = (1, 2, 3, 4, 5) data = numpy.indices(shape, dtype=int).sum(0) meta = MetaDict() meta.specialdata = "Salutations" meta.notsospecial = "Hey" opProvider = OpOutputProvider(data, meta, graph=graph) op = OpMetadataMerge(graph=graph) op.Input.connect(opDataSource.Output) op.MetadataSource.connect(opProvider.Output) op.FieldsToClone.setValue(["specialdata"]) assert op.Output.ready() assert op.Output.meta.shape == opDataSource.Output.meta.shape assert op.Output.meta.dtype == opDataSource.Output.meta.dtype assert op.Output.meta.specialdata == meta.specialdata assert op.Output.meta.notsospecial is None
def meta_dict(self) -> MetaDict: return MetaDict( dtype=self.dtype if self.dtype else None, shape=self.shape, axistags=vigra.defaultAxistags(self.axistags) if self.axistags else None, )
def testMinimalRequest(): """ Make sure that unneeded slices are not requested by the stacker. """ graph = Graph() ops = [] for op in range(10): data = numpy.random.random( (100,100) ) data = vigra.taggedView( data, 'yx' ) meta = MetaDict( { 'shape' : data.shape, 'dtype' : data.dtype, 'axistags' : data.axistags } ) opData = OpTrackedOutputProvider( data, meta, graph=graph ) ops.append( opData ) opStacker = OpMultiArrayStacker(graph=graph) opStacker.AxisFlag.setValue('z') opStacker.AxisIndex.setValue(0) opStacker.Images.resize( len(ops) ) for islot, opData in zip( opStacker.Images, ops ): islot.connect( opData.Output ) assert opStacker.Output.meta.getTaggedShape()['z'] == len(ops) stacked_data = opStacker.Output[3:5,:,:].wait() assert stacked_data.shape == (2, 100, 100) stacked_data = vigra.taggedView( stacked_data, 'zyx' ) expected_data = numpy.concatenate( (ops[3]._data[numpy.newaxis, :], ops[4]._data[numpy.newaxis, :]) ) expected_data = vigra.taggedView( expected_data, 'zyx' ) assert (stacked_data == expected_data).all(), "Stacker returned the wrong data" for index, op in enumerate(ops): assert len(op.requested_rois) == 0 or index in range(3,5), "Stacker requested more data than it needed."
def test(self): from lazyflow.graph import Graph, MetaDict g = Graph() # Create some data to give shape = (1,2,3,4,5) data = numpy.indices(shape, dtype=int).sum(0) meta = MetaDict() meta.axistags = vigra.defaultAxistags( 'xtycz' ) meta.shape = shape meta.dtype = int opProvider = OpOutputProvider( data, meta, graph=g ) assert (opProvider.Output[0:1, 1:2, 0:3, 2:4, 3:5].wait() == data[0:1, 1:2, 0:3, 2:4, 3:5]).all() for k,v in meta.items(): if k != '_ready' and k != '_dirty': assert opProvider.Output.meta[k] == v
def test(self): from lazyflow.graph import Graph, MetaDict g = Graph() # Create some data to give shape = (1,2,3,4,5) data = numpy.indices(shape, dtype=int).sum(0) meta = MetaDict() meta.axistags = vigra.defaultAxistags( 'xtycz' ) meta.shape = shape meta.dtype = int opProvider = OpOutputProvider( data, meta, graph=g ) op = OpMetadataSelector(graph=g) op.Input.connect( opProvider.Output ) op.MetadataKey.setValue('shape') assert op.Output.value == shape op.MetadataKey.setValue('axistags') assert op.Output.value == meta.axistags
def test(self): from lazyflow.graph import Graph, MetaDict g = Graph() # Create some data to give shape = (1, 2, 3, 4, 5) data = numpy.indices(shape, dtype=int).sum(0) meta = MetaDict() meta.axistags = vigra.defaultAxistags('xtycz') meta.shape = shape meta.dtype = int opProvider = OpOutputProvider(data, meta, graph=g) op = OpMetadataSelector(graph=g) op.Input.connect(opProvider.Output) op.MetadataKey.setValue('shape') assert op.Output.value == shape op.MetadataKey.setValue('axistags') assert op.Output.value == meta.axistags