def test_2_ReadTranslated(self): # Start by reading some data graph = Graph() op = OpRESTfulBlockwiseFilesetReader(graph=graph) op.DescriptionFilePath.setValue( self.descriptionFilePath ) logger.debug("test_2_Read(): Reading data") slice1 = numpy.s_[ 20:30, 30:40, 40:50 ] readData = op.Output[ slice1 ].wait() assert readData.shape == (10, 10, 10) logger.debug("test_2_Read(): Creating translated description") # Create a copy of the original description, but specify a translated (and smaller) view desc = BlockwiseFileset.readDescription(self.descriptionFilePath) desc.view_origin = [20, 30, 40] offsetConfigPath = self.descriptionFilePath + '_offset' BlockwiseFileset.writeDescription(offsetConfigPath, desc) # Read the same data as before using the translated view (offset our roi) opTranslated = OpRESTfulBlockwiseFilesetReader(graph=graph) opTranslated.DescriptionFilePath.setValue( offsetConfigPath ) logger.debug("test_2_Read(): Reading translated data") sliceTranslated = numpy.s_[ 0:10, 0:10, 0:10 ] translatedReadData = op.Output[ sliceTranslated ].wait() assert translatedReadData.shape == (10, 10, 10) assert (translatedReadData == readData).all(), "Data doesn't match!"
def test_6_TestView(self): """ Load some of the dataset again; this time with an offset view """ # Create a copy of the original description, but specify a translated (and smaller) view desc = BlockwiseFileset.readDescription(self.configpath) desc.view_origin = [0, 300, 200, 100, 0] desc.view_shape = [1, 50, 50, 50, 1] offsetConfigPath = self.configpath + '_offset' BlockwiseFileset.writeDescription(offsetConfigPath, desc) # Open the fileset using the special description file bfs = BlockwiseFileset( offsetConfigPath, 'r' ) assert (bfs.description.view_origin == desc.view_origin).all() assert (bfs.description.view_shape == desc.view_shape).all() # Read some data logger.debug( "Reading data..." ) disk_slicing = numpy.s_[:, 300:350, 200:250, 100:150, :] view_slicing = numpy.s_[:, 0:50, 0:50, 0:50, :] roi = sliceToRoi( view_slicing, self.dataShape ) roiShape = roi[1] - roi[0] read_data = numpy.zeros( tuple(roiShape), dtype=numpy.uint8 ) bfs.readData( roi, read_data ) # The data we read should match the correct part of the original dataset. logger.debug( "Checking data..." ) assert self.data[disk_slicing].shape == read_data.shape assert (self.data[disk_slicing] == read_data).all(), "Data didn't match."