def testBasic_2d_Sequence(self): data = 255 * numpy.random.random((10, 50, 100, 3)) data = data.astype(numpy.uint8) data = vigra.taggedView(data, vigra.defaultAxistags("zyxc")) # Must run this through an operator # Can't use opExport.setValue() because because OpStackWriter can't work with ValueRequests graph = Graph() opData = OpBlockedArrayCache(graph=graph) opData.BlockShape.setValue(data.shape) opData.Input.setValue(data) filepattern = self._tmpdir + "/test_export_x{x_start}-{x_stop}_y{y_start}-{y_stop}_z{slice_index}" opExport = OpExportSlot(graph=graph) opExport.Input.connect(opData.Output) opExport.OutputFormat.setValue("png sequence") opExport.OutputFilenameFormat.setValue(filepattern) opExport.CoordinateOffset.setValue((10, 20, 30, 0)) opExport.run_export() export_pattern = opExport.ExportPath.value globstring = export_pattern.format(slice_index=999) globstring = globstring.replace("999", "*") opReader = OpStackLoader(graph=graph) try: opReader.globstring.setValue(globstring) assert opReader.stack.meta.shape == data.shape, "Exported files were of the wrong shape or number." assert (opReader.stack[:].wait() == data.view(numpy.ndarray)).all(), "Exported data was not correct" finally: opReader.cleanUp()
def test_Writer(self): opData = OpArrayCache( graph=self.graph ) opData.blockShape.setValue( self.testData.shape ) opData.Input.setValue( self.testData ) opExport = OpExportMultipageTiffSequence(graph=self.graph) opExport.FilepathPattern.setValue( self._stack_filepattern ) opExport.Input.connect( opData.Output ) opExport.SliceIndexOffset.setValue(22) # Run the export opExport.run_export() globstring = self._stack_filepattern.format( slice_index=999 ) globstring = globstring.replace('999', '*') opReader = OpStackLoader( graph=self.graph ) opReader.globstring.setValue( globstring ) # (The OpStackLoader produces txyzc order.) opReorderAxes = OpReorderAxes( graph=self.graph ) opReorderAxes.AxisOrder.setValue( self._axisorder ) opReorderAxes.Input.connect( opReader.stack ) readData = opReorderAxes.Output[:].wait() logger.debug("Expected shape={}".format( self.testData.shape ) ) logger.debug("Read shape={}".format( readData.shape ) ) assert opReorderAxes.Output.meta.shape == self.testData.shape, "Exported files were of the wrong shape or number." assert (opReorderAxes.Output[:].wait() == self.testData.view( numpy.ndarray )).all(), "Exported data was not correct" opReorderAxes.cleanUp() opReader.cleanUp()
def testLotsOfOptions(self): #OLD_LAZYFLOW_STATUS_MONITOR_SECONDS = os.getenv("LAZYFLOW_STATUS_MONITOR_SECONDS", None) #os.environ["LAZYFLOW_STATUS_MONITOR_SECONDS"] = "1" # NOTE: In this test, cmd-line args to nosetests will also end up getting "parsed" by ilastik. # That shouldn't be an issue, since the pixel classification workflow ignores unrecognized options. # See if __name__ == __main__ section, below. args = [] args.append( "--project=" + self.PROJECT_FILE ) args.append( "--headless" ) #args.append( "--sys_tmp_dir=/tmp" ) # Batch export options args.append( '--export_source=Simple Segmentation' ) args.append( '--output_format=png sequence' ) # If we were actually launching from the command line, 'png sequence' would be in quotes... args.append( "--output_filename_format={dataset_dir}/{nickname}_segmentation_z{slice_index}.png" ) args.append( "--export_dtype=uint8" ) args.append( "--output_axis_order=zxyc" ) args.append( "--pipeline_result_drange=(0,2)" ) args.append( "--export_drange=(0,255)" ) args.append( "--cutout_subregion=[(0,50,50,0,0), (1, 150, 150, 50, 1)]" ) args.append( self.SAMPLE_DATA ) old_sys_argv = list(sys.argv) sys.argv = ['ilastik.py'] # Clear the existing commandline args so it looks like we're starting fresh. sys.argv += args # Start up the ilastik.py entry script as if we had launched it from the command line # This will execute the batch mode script try: self.ilastik_startup.main() finally: sys.argv = old_sys_argv # if OLD_LAZYFLOW_STATUS_MONITOR_SECONDS: # os.environ["LAZYFLOW_STATUS_MONITOR_SECONDS"] = OLD_LAZYFLOW_STATUS_MONITOR_SECONDS output_path = self.SAMPLE_DATA[:-4] + "_segmentation_z{slice_index}.png" globstring = output_path.format( slice_index=999 ) globstring = globstring.replace('999', '*') opReader = OpStackLoader( graph=Graph() ) opReader.globstring.setValue( globstring ) # (The OpStackLoader produces txyzc order.) opReorderAxes = OpReorderAxes( graph=Graph() ) opReorderAxes.AxisOrder.setValue( 'tzyxc' ) opReorderAxes.Input.connect( opReader.stack ) try: readData = opReorderAxes.Output[:].wait() # Check basic attributes assert readData.shape[:-1] == self.data[0:1, 50:150, 50:150, 0:50, 0:1].shape[:-1] # Assume channel is last axis assert readData.shape[-1] == 1, "Wrong number of channels. Expected 1, got {}".format( readData.shape[-1] ) finally: # Clean-up. opReorderAxes.cleanUp() opReader.cleanUp()
def test_Writer(self): opData = OpArrayCache(graph=self.graph) opData.blockShape.setValue(self.testData.shape) opData.Input.setValue(self.testData) opExport = OpExportMultipageTiffSequence(graph=self.graph) opExport.FilepathPattern.setValue(self._stack_filepattern) opExport.Input.connect(opData.Output) opExport.SliceIndexOffset.setValue(22) # Run the export opExport.run_export() globstring = self._stack_filepattern.format(slice_index=999) globstring = globstring.replace('999', '*') opReader = OpStackLoader(graph=self.graph) opReader.globstring.setValue(globstring) # (The OpStackLoader produces txyzc order.) opReorderAxes = OpReorderAxes(graph=self.graph) opReorderAxes.AxisOrder.setValue(self._axisorder) opReorderAxes.Input.connect(opReader.stack) readData = opReorderAxes.Output[:].wait() logger.debug("Expected shape={}".format(self.testData.shape)) logger.debug("Read shape={}".format(readData.shape)) assert opReorderAxes.Output.meta.shape == self.testData.shape, "Exported files were of the wrong shape or number." assert (opReorderAxes.Output[:].wait() == self.testData.view( numpy.ndarray)).all(), "Exported data was not correct" opReorderAxes.cleanUp() opReader.cleanUp()
def testLotsOfOptions(self): # NOTE: In this test, cmd-line args to nosetests will also end up getting "parsed" by ilastik. # That shouldn't be an issue, since the pixel classification workflow ignores unrecognized options. # See if __name__ == __main__ section, below. args = [] args.append("--project=" + self.PROJECT_FILE) args.append("--headless") #args.append( "--sys_tmp_dir=/tmp" ) # Batch export options args.append( '--output_format=png sequence' ) # If we were actually launching from the command line, 'png sequence' would be in quotes... args.append( "--output_filename_format={dataset_dir}/{nickname}_prediction_z{slice_index}.png" ) args.append("--export_dtype=uint8") args.append("--output_axis_order=zxyc") args.append("--pipeline_result_drange=(0.0,1.0)") args.append("--export_drange=(0,255)") args.append("--cutout_subregion=[(0,50,50,0,0), (1, 150, 150, 50, 2)]") args.append(self.SAMPLE_DATA) sys.argv = [ 'ilastik.py' ] # Clear the existing commandline args so it looks like we're starting fresh. sys.argv += args # Start up the ilastik.py entry script as if we had launched it from the command line # This will execute the batch mode script self.ilastik_startup.main() output_path = self.SAMPLE_DATA[:-4] + "_prediction_z{slice_index}.png" globstring = output_path.format(slice_index=999) globstring = globstring.replace('999', '*') opReader = OpStackLoader(graph=Graph()) opReader.globstring.setValue(globstring) # (The OpStackLoader produces txyzc order.) opReorderAxes = OpReorderAxes(graph=Graph()) opReorderAxes.AxisOrder.setValue('txyzc') opReorderAxes.Input.connect(opReader.stack) readData = opReorderAxes.Output[:].wait() # Check basic attributes assert readData.shape[:-1] == self.data[ 0:1, 50:150, 50:150, 0:50, 0:2].shape[:-1] # Assume channel is last axis assert readData.shape[ -1] == 2, "Wrong number of channels. Expected 2, got {}".format( readData.shape[-1]) # Clean-up. opReorderAxes.cleanUp() opReader.cleanUp()
def testLotsOfOptions(self): # NOTE: In this test, cmd-line args to nosetests will also end up getting "parsed" by ilastik. # That shouldn't be an issue, since the pixel classification workflow ignores unrecognized options. # See if __name__ == __main__ section, below. args = [] args.append( "--project=" + self.PROJECT_FILE ) args.append( "--headless" ) args.append( "--sys_tmp_dir=/tmp" ) # Batch export options args.append( '--output_format=png sequence' ) # If we were actually launching from the command line, 'png sequence' would be in quotes... args.append( "--output_filename_format={dataset_dir}/{nickname}_prediction_z{slice_index}.png" ) args.append( "--export_dtype=uint8" ) args.append( "--output_axis_order=zxyc" ) args.append( "--pipeline_result_drange=(0.0,1.0)" ) args.append( "--export_drange=(0,255)" ) args.append( "--cutout_subregion=[(0,50,50,0,0), (1, 150, 150, 50, 2)]" ) args.append( self.SAMPLE_DATA ) sys.argv = ['ilastik.py'] # Clear the existing commandline args so it looks like we're starting fresh. sys.argv += args # Start up the ilastik.py entry script as if we had launched it from the command line # This will execute the batch mode script ilastik_entry_file_path = os.path.join( os.path.split( ilastik.__file__ )[0], "../ilastik.py" ) imp.load_source( 'main', ilastik_entry_file_path ) output_path = self.SAMPLE_DATA[:-4] + "_prediction_z{slice_index}.png" globstring = output_path.format( slice_index=999 ) globstring = globstring.replace('999', '*') opReader = OpStackLoader( graph=Graph() ) opReader.globstring.setValue( globstring ) # (The OpStackLoader produces txyzc order.) opReorderAxes = OpReorderAxes( graph=Graph() ) opReorderAxes.AxisOrder.setValue( 'txyzc' ) opReorderAxes.Input.connect( opReader.stack ) readData = opReorderAxes.Output[:].wait() # Check basic attributes assert readData.shape[:-1] == self.data[0:1, 50:150, 50:150, 0:50, 0:2].shape[:-1] # Assume channel is last axis assert readData.shape[-1] == 2, "Wrong number of channels. Expected 2, got {}".format( readData.shape[-1] ) # Clean-up. opReorderAxes.cleanUp() opReader.cleanUp()
def testBasic_MultipageTiffSequence(self): data = 255 * numpy.random.random((5, 10, 50, 100, 3)) data = data.astype(numpy.uint8) data = vigra.taggedView(data, vigra.defaultAxistags('tzyxc')) # Must run this through an operator # Can't use opExport.setValue() because because OpStackWriter can't work with ValueRequests graph = Graph() opData = OpArrayCache(graph=graph) opData.blockShape.setValue(data.shape) opData.Input.setValue(data) filepattern = self._tmpdir + '/test_export_x{x_start}-{x_stop}_y{y_start}-{y_stop}_t{slice_index}' opExport = OpExportSlot(graph=graph) opExport.Input.connect(opData.Output) opExport.OutputFormat.setValue('multipage tiff sequence') opExport.OutputFilenameFormat.setValue(filepattern) opExport.CoordinateOffset.setValue((7, 10, 20, 30, 0)) opExport.run_export() export_pattern = opExport.ExportPath.value globstring = export_pattern.format(slice_index=999) globstring = globstring.replace('999', '*') opReader = OpStackLoader(graph=graph) opReader.globstring.setValue(globstring) # (The OpStackLoader produces txyzc order.) opReorderAxes = OpReorderAxes(graph=graph) opReorderAxes.AxisOrder.setValue('tzyxc') opReorderAxes.Input.connect(opReader.stack) assert opReorderAxes.Output.meta.shape == data.shape, "Exported files were of the wrong shape or number." assert (opReorderAxes.Output[:].wait() == data.view( numpy.ndarray)).all(), "Exported data was not correct" # Cleanup opReorderAxes.cleanUp() opReader.cleanUp()
def testBasic_MultipageTiffSequence(self): data = 255 * numpy.random.random( (5, 10, 50,100, 3) ) data = data.astype( numpy.uint8 ) data = vigra.taggedView( data, vigra.defaultAxistags('tzyxc') ) # Must run this through an operator # Can't use opExport.setValue() because because OpStackWriter can't work with ValueRequests graph = Graph() opData = OpArrayCache( graph=graph ) opData.blockShape.setValue( data.shape ) opData.Input.setValue( data ) filepattern = self._tmpdir + '/test_export_x{x_start}-{x_stop}_y{y_start}-{y_stop}_t{slice_index}' opExport = OpExportSlot(graph=graph) opExport.Input.connect( opData.Output ) opExport.OutputFormat.setValue( 'multipage tiff sequence' ) opExport.OutputFilenameFormat.setValue( filepattern ) opExport.CoordinateOffset.setValue( (7, 10, 20, 30, 0) ) opExport.run_export() export_pattern = opExport.ExportPath.value globstring = export_pattern.format( slice_index=999 ) globstring = globstring.replace('999', '*') opReader = OpStackLoader( graph=graph ) opReader.globstring.setValue( globstring ) # (The OpStackLoader produces txyzc order.) opReorderAxes = OpReorderAxes( graph=graph ) opReorderAxes.AxisOrder.setValue( 'tzyxc' ) opReorderAxes.Input.connect( opReader.stack ) assert opReorderAxes.Output.meta.shape == data.shape, "Exported files were of the wrong shape or number." assert (opReorderAxes.Output[:].wait() == data.view( numpy.ndarray )).all(), "Exported data was not correct" # Cleanup opReorderAxes.cleanUp() opReader.cleanUp()
def testLotsOfOptions(self): # OLD_LAZYFLOW_STATUS_MONITOR_SECONDS = os.getenv("LAZYFLOW_STATUS_MONITOR_SECONDS", None) # os.environ["LAZYFLOW_STATUS_MONITOR_SECONDS"] = "1" # NOTE: In this test, cmd-line args to tests will also end up getting "parsed" by ilastik. # That shouldn't be an issue, since the pixel classification workflow ignores unrecognized options. # See if __name__ == __main__ section, below. args = [] args.append("--project=" + self.PROJECT_FILE) args.append("--headless") # args.append( "--sys_tmp_dir=/tmp" ) # Batch export options args.append("--export_source=Simple Segmentation") args.append( "--output_format=png sequence" ) # If we were actually launching from the command line, 'png sequence' would be in quotes... args.append("--output_filename_format={dataset_dir}/{nickname}_segmentation_z{slice_index}.png") args.append("--export_dtype=uint8") args.append("--output_axis_order=zxyc") args.append("--pipeline_result_drange=(0,2)") args.append("--export_drange=(0,255)") args.append("--cutout_subregion=[(0,10,10,0,0), (1, 20, 20, 5, 1)]") args.append(self.SAMPLE_DATA) old_sys_argv = list(sys.argv) sys.argv = ["ilastik.py"] # Clear the existing commandline args so it looks like we're starting fresh. sys.argv += args # Start up the ilastik.py entry script as if we had launched it from the command line # This will execute the batch mode script try: self.ilastik_startup.main() finally: sys.argv = old_sys_argv # if OLD_LAZYFLOW_STATUS_MONITOR_SECONDS: # os.environ["LAZYFLOW_STATUS_MONITOR_SECONDS"] = OLD_LAZYFLOW_STATUS_MONITOR_SECONDS output_path = self.SAMPLE_DATA[:-4] + "_segmentation_z{slice_index}.png" globstring = output_path.format(slice_index=999) globstring = globstring.replace("999", "*") opReader = OpStackLoader(graph=Graph()) opReader.globstring.setValue(globstring) # (The OpStackLoader produces txyzc order.) opReorderAxes = OpReorderAxes(graph=Graph()) opReorderAxes.AxisOrder.setValue("tzyxc") opReorderAxes.Input.connect(opReader.stack) try: readData = opReorderAxes.Output[:].wait() # Check basic attributes assert readData.shape[:-1] == (1, 10, 10, 5), readData.shape[:-1] # Assume channel is last axis assert readData.shape[-1] == 1, "Wrong number of channels. Expected 1, got {}".format(readData.shape[-1]) finally: # Clean-up. opReorderAxes.cleanUp() opReader.cleanUp()