Skip to content

Commit

Permalink
add status bars for saving
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPreibisch committed Sep 13, 2024
1 parent 2dd834d commit c3295bb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
//
Expand All @@ -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)
{
Expand All @@ -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." );

//
Expand All @@ -192,8 +203,6 @@ public static SpimData2 resaveN5(
for ( int level = 1; level < downsamplings.length; ++level )
{
final int s = level;
//final ArrayList<long[][]> allBlocks =
// N5ApiTools.assembleJobs( vidsToResave, viewIdToMrInfo, level );

final List<long[][]> allBlocks =
vidsToResave.stream().map( viewId ->
Expand All @@ -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();

Expand All @@ -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)
Expand All @@ -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." );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
//
Expand All @@ -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)
{
Expand All @@ -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." );

//
Expand All @@ -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);
Expand All @@ -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." );
}

Expand Down

0 comments on commit c3295bb

Please sign in to comment.