From c3295bbcd063e2097b99b3f71355a83e51bbbe07 Mon Sep 17 00:00:00 2001 From: Stephan Preibisch Date: Fri, 13 Sep 2024 12:02:06 -0400 Subject: [PATCH] add status bars for saving --- .../mvrecon/fiji/plugin/resave/Resave_N5.java | 21 +++++++++++++++---- .../mvrecon/process/export/ExportN5API.java | 19 +++++++++++++++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java index b538a63b..840732ab 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java @@ -32,6 +32,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import org.janelia.saalfeldlab.n5.Compression; @@ -41,6 +42,7 @@ import bdv.export.ExportMipmapInfo; import bdv.export.ProgressWriter; import bdv.img.n5.N5ImageLoader; +import ij.IJ; import ij.plugin.PlugIn; import mpicbg.spim.data.sequence.TimePoint; import mpicbg.spim.data.sequence.ViewId; @@ -160,6 +162,9 @@ public static SpimData2 resaveN5( IOFunctions.println( "Downsamplings: " + Arrays.deepToString( downsamplings ) ); IOFunctions.println( "Number of compute blocks: " + grid.size() ); + final AtomicInteger progress = new AtomicInteger( 0 ); + IJ.showProgress( progress.get(), grid.size() ); + // // Save full resolution dataset (s0) // @@ -170,12 +175,17 @@ public static SpimData2 resaveN5( try { myPool.submit(() -> grid.parallelStream().forEach( - gridBlock -> N5ApiTools.resaveS0Block( + gridBlock -> + { + N5ApiTools.resaveS0Block( data, n5Writer, dataTypes.get( N5ApiTools.gridBlockToViewId( gridBlock ).getViewSetupId() ), N5ApiTools.gridToDatasetBdv( 0, StorageType.N5 ), // a function mapping the gridblock to the dataset name for level 0 and N5 - gridBlock ) ) ).get(); + gridBlock ); + + IJ.showProgress( progress.incrementAndGet(), grid.size() ); + })).get(); } catch (InterruptedException | ExecutionException e) { @@ -184,6 +194,7 @@ public static SpimData2 resaveN5( return null; } + IJ.showProgress( progress.getAndSet( 0 ), grid.size() ); IOFunctions.println( "Saved level s0, took: " + (System.currentTimeMillis() - time ) + " ms." ); // @@ -192,8 +203,6 @@ public static SpimData2 resaveN5( for ( int level = 1; level < downsamplings.length; ++level ) { final int s = level; - //final ArrayList allBlocks = - // N5ApiTools.assembleJobs( vidsToResave, viewIdToMrInfo, level ); final List allBlocks = vidsToResave.stream().map( viewId -> @@ -203,6 +212,7 @@ public static SpimData2 resaveN5( IOFunctions.println( "Downsampling level s" + s + "... " ); IOFunctions.println( "Number of compute blocks: " + allBlocks.size() ); + IJ.showProgress( progress.get(), allBlocks.size() ); time = System.currentTimeMillis(); @@ -216,6 +226,8 @@ public static SpimData2 resaveN5( viewIdToMrInfo.get( N5ApiTools.gridBlockToViewId( gridBlock ) )[ s ], //N5ResaveTools.gridToDatasetBdv( s, StorageType.N5 ), viewIdToMrInfo.get( N5ApiTools.gridBlockToViewId( gridBlock ) )[ s - 1 ],//N5ResaveTools.gridToDatasetBdv( s - 1, StorageType.N5 ), gridBlock ); + + IJ.showProgress( progress.incrementAndGet(), allBlocks.size() ); } ) ).get(); } catch (InterruptedException | ExecutionException e) @@ -225,6 +237,7 @@ public static SpimData2 resaveN5( return null; } + IJ.showProgress( progress.getAndSet( 0 ), allBlocks.size() ); IOFunctions.println( "Resaved N5 s" + s + " level, took: " + (System.currentTimeMillis() - time ) + " ms." ); } diff --git a/src/main/java/net/preibisch/mvrecon/process/export/ExportN5API.java b/src/main/java/net/preibisch/mvrecon/process/export/ExportN5API.java index 59babbd7..760f511a 100644 --- a/src/main/java/net/preibisch/mvrecon/process/export/ExportN5API.java +++ b/src/main/java/net/preibisch/mvrecon/process/export/ExportN5API.java @@ -34,6 +34,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import org.janelia.saalfeldlab.n5.Compression; import org.janelia.saalfeldlab.n5.DataType; @@ -46,6 +47,7 @@ import bdv.export.ExportMipmapInfo; import bdv.export.ProposeMipmaps; import fiji.util.gui.GenericDialogPlus; +import ij.IJ; import ij.gui.GenericDialog; import mpicbg.spim.data.SpimDataException; import mpicbg.spim.data.generic.sequence.BasicViewSetup; @@ -279,6 +281,9 @@ else if ( FloatType.class.isInstance( type ) ) IOFunctions.println( "num blocks = " + Grid.create( bb.dimensionsAsLongArray(), blocksize() ).size() + ", size = " + bsX + "x" + bsY + "x" + bsZ ); IOFunctions.println( "num compute blocks = " + grid.size() + ", size = " + bsX*bsFactorX + "x" + bsY*bsFactorY + "x" + bsZ*bsFactorZ ); + final AtomicInteger progress = new AtomicInteger( 0 ); + IJ.showProgress( progress.get(), grid.size() ); + // // save full-resolution data (s0) // @@ -304,6 +309,8 @@ else if ( FloatType.class.isInstance( type ) ) final RandomAccessibleInterval sourceGridBlock = Views.offsetInterval(source, gridBlock[0], gridBlock[1]); N5Utils.saveBlock(sourceGridBlock, driverVolumeWriter, mrInfo[ 0 ].dataset, gridBlock[2]); + + IJ.showProgress( progress.incrementAndGet(), grid.size() ); } catch (Exception e) { @@ -323,6 +330,7 @@ else if ( FloatType.class.isInstance( type ) ) } //System.out.println( "Saved, e.g. view with './n5-view -i " + n5Path + " -d " + n5Dataset ); + IJ.showProgress( progress.getAndSet( 0 ), grid.size() ); IOFunctions.println( new Date( System.currentTimeMillis() ) + ": Saved full resolution, took: " + (System.currentTimeMillis() - time ) + " ms." ); // @@ -336,17 +344,23 @@ else if ( FloatType.class.isInstance( type ) ) IOFunctions.println( new Date( System.currentTimeMillis() ) + ": Downsampling: " + Util.printCoordinates( mrInfo[ level ].absoluteDownsampling ) + " with relative downsampling of " + Util.printCoordinates( mrInfo[ level ].relativeDownsampling )); IOFunctions.println( new Date( System.currentTimeMillis() ) + ": s" + level + " num blocks=" + allBlocks.size() ); IOFunctions.println( new Date( System.currentTimeMillis() ) + ": Loading '" + mrInfo[ level - 1 ].dataset + "', downsampled will be written as '" + mrInfo[ level ].dataset + "'." ); + IJ.showProgress( progress.get(), allBlocks.size() ); time = System.currentTimeMillis(); try { myPool.submit( () -> allBlocks.parallelStream().forEach( - gridBlock -> N5ApiTools.writeDownsampledBlock( + gridBlock -> + { + N5ApiTools.writeDownsampledBlock( driverVolumeWriter, mrInfo[ s ], mrInfo[ s - 1 ], - gridBlock ) ) ).get(); + gridBlock ); + + IJ.showProgress( progress.incrementAndGet(), allBlocks.size() ); + })).get(); myPool.shutdown(); myPool.awaitTermination( Long.MAX_VALUE, TimeUnit.HOURS); @@ -358,6 +372,7 @@ else if ( FloatType.class.isInstance( type ) ) return false; } + IJ.showProgress( progress.getAndSet( 0 ), allBlocks.size() ); IOFunctions.println( new Date( System.currentTimeMillis() ) + ": Saved level s " + level + ", took: " + (System.currentTimeMillis() - time ) + " ms." ); }