Skip to content

Commit

Permalink
consolidated all helper methods in two classes N5ApiTools.java and Sp…
Browse files Browse the repository at this point in the history
…imData2Tools.java
  • Loading branch information
StephanPreibisch committed Sep 11, 2024
1 parent 37be616 commit 287d813
Show file tree
Hide file tree
Showing 9 changed files with 961 additions and 1,221 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import net.preibisch.mvrecon.fiji.plugin.resave.Generic_Resave_HDF5.ParametersResaveHDF5;
import net.preibisch.mvrecon.fiji.spimdata.SpimData2;
import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2;
import net.preibisch.mvrecon.process.resave.SpimData2Tools;
import net.preibisch.mvrecon.process.n5api.SpimData2Tools;

public class Resave_HDF5 implements PlugIn
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@
import net.preibisch.mvrecon.fiji.spimdata.SpimData2;
import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2;
import net.preibisch.mvrecon.process.export.ExportN5API.StorageType;
import net.preibisch.mvrecon.process.export.ExportTools;
import net.preibisch.mvrecon.process.export.ExportTools.MultiResolutionLevelInfo;
import net.preibisch.mvrecon.process.resave.N5ResaveTools;
import net.preibisch.mvrecon.process.resave.SpimData2Tools;
import net.preibisch.mvrecon.process.n5api.N5ApiTools;
import net.preibisch.mvrecon.process.n5api.SpimData2Tools;
import net.preibisch.mvrecon.process.n5api.N5ApiTools.MultiResolutionLevelInfo;
import util.Grid;
import util.URITools;

Expand Down Expand Up @@ -123,24 +122,24 @@ public static SpimData2 resaveN5(
computeBlockSize[ d ] = blockSize[ d ] * n5Params.blockSizeFactor[ d ];

final HashMap<Integer, long[]> dimensions =
N5ResaveTools.assembleDimensions( data, vidsToResave );
N5ApiTools.assembleDimensions( data, vidsToResave );

final int[][] downsamplings =
N5ResaveTools.mipMapInfoToDownsamplings( n5Params.proposedMipmaps );
N5ApiTools.mipMapInfoToDownsamplings( n5Params.proposedMipmaps );

final ArrayList<long[][]> grid =
N5ResaveTools.assembleS0Jobs( vidsToResave, dimensions, blockSize, computeBlockSize );
N5ApiTools.assembleS0Jobs( vidsToResave, dimensions, blockSize, computeBlockSize );

final Map<Integer, DataType> dataTypes =
N5ResaveTools.assembleDataTypes( data, dimensions.keySet() );
N5ApiTools.assembleDataTypes( data, dimensions.keySet() );

// create all datasets and write BDV metadata for all ViewIds (including downsampling)
final HashMap< ViewId, MultiResolutionLevelInfo[] > viewIdToMrInfo = new HashMap<>();

long time = System.currentTimeMillis();

for ( final ViewId viewId : vidsToResave )
viewIdToMrInfo.put( viewId , ExportTools.setupBdvDatasetsN5(
viewIdToMrInfo.put( viewId , N5ApiTools.setupBdvDatasetsN5(
n5Writer, viewId,
dataTypes.get( viewId.getViewSetupId() ),
dimensions.get( viewId.getViewSetupId() ),
Expand All @@ -164,11 +163,11 @@ public static SpimData2 resaveN5(
try
{
myPool.submit(() -> grid.parallelStream().forEach(
gridBlock -> N5ResaveTools.resaveS0Block(
gridBlock -> N5ApiTools.resaveS0Block(
data,
n5Writer,
dataTypes.get( N5ResaveTools.gridBlockToViewId( gridBlock ).getViewSetupId() ),
N5ResaveTools.gridToDatasetBdv( 0, StorageType.N5 ), // a function mapping the gridblock to the dataset name for level 0 and N5
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();
}
catch (InterruptedException | ExecutionException e)
Expand All @@ -186,9 +185,9 @@ public static SpimData2 resaveN5(
for ( int level = 1; level < downsamplings.length; ++level )
{
final int s = level;
final int[] ds = N5ResaveTools.computeRelativeDownsampling( downsamplings, s );
final int[] ds = N5ApiTools.computeRelativeDownsampling( downsamplings, s );
final ArrayList<long[][]> allBlocks =
N5ResaveTools.assembleDownsamplingJobs( vidsToResave, viewIdToMrInfo, level );
N5ApiTools.assembleDownsamplingJobs( vidsToResave, viewIdToMrInfo, level );

IOFunctions.println( "Downsampling: " + Util.printCoordinates( downsamplings[ s ] ) + " with relative downsampling of " + Util.printCoordinates( ds ));
IOFunctions.println( "Number of compute blocks: " + allBlocks.size() );
Expand All @@ -200,10 +199,10 @@ public static SpimData2 resaveN5(
myPool.submit(() -> allBlocks.parallelStream().forEach(
gridBlock ->
{
N5ResaveTools.writeDownsampledBlock(
N5ApiTools.writeDownsampledBlock(
n5Writer,
viewIdToMrInfo.get( N5ResaveTools.gridBlockToViewId( gridBlock ) )[ s ], //N5ResaveTools.gridToDatasetBdv( s, StorageType.N5 ),
viewIdToMrInfo.get( N5ResaveTools.gridBlockToViewId( gridBlock ) )[ s - 1 ],//N5ResaveTools.gridToDatasetBdv( s - 1, StorageType.N5 ),
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 );
} ) ).get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import net.preibisch.mvrecon.fiji.spimdata.SpimData2;
import net.preibisch.mvrecon.fiji.spimdata.imgloaders.StackImgLoaderIJ;
import net.preibisch.mvrecon.process.export.Save3dTIFF;
import net.preibisch.mvrecon.process.resave.SpimData2Tools;
import net.preibisch.mvrecon.process.n5api.SpimData2Tools;
import util.URITools;

public class Resave_TIFF implements PlugIn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import net.preibisch.mvrecon.fiji.spimdata.explorer.ExplorerWindow;
import net.preibisch.mvrecon.fiji.spimdata.explorer.FilteredAndGroupedExplorerPanel;
import net.preibisch.mvrecon.fiji.spimdata.interestpoints.ViewInterestPointLists;
import net.preibisch.mvrecon.process.resave.SpimData2Tools;
import net.preibisch.mvrecon.process.n5api.SpimData2Tools;
import util.URITools;

public class ResavePopup extends JMenu implements ExplorerWindowSetable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@
import net.preibisch.mvrecon.fiji.plugin.resave.PluginHelper;
import net.preibisch.mvrecon.fiji.plugin.util.GUIHelper;
import net.preibisch.mvrecon.process.deconvolution.DeconViews;
import net.preibisch.mvrecon.process.export.ExportTools.InstantiateViewSetupBigStitcher;
import net.preibisch.mvrecon.process.interestpointregistration.pairwise.constellation.grouping.Group;
import net.preibisch.mvrecon.process.resave.N5ResaveTools;
import net.preibisch.mvrecon.process.n5api.N5ApiTools;
import net.preibisch.mvrecon.process.n5api.SpimData2Tools;
import net.preibisch.mvrecon.process.n5api.SpimData2Tools.InstantiateViewSetupBigStitcher;
import util.Grid;
import util.URITools;

Expand Down Expand Up @@ -225,7 +226,7 @@ else if ( FloatType.class.isInstance( type ) )

IOFunctions.println( "Assigning ViewId " + Group.pvid( viewId ) );

dataset = ExportTools.createBDVPath( viewId, 0, this.storageType );
dataset = N5ApiTools.createBDVPath( viewId, 0, this.storageType );
}

//
Expand Down Expand Up @@ -264,7 +265,7 @@ else if ( FloatType.class.isInstance( type ) )
try
{
// the first time the XML does not exist, thus instantiate is not called
if ( ExportTools.writeBDVMetaData(
if ( SpimData2Tools.writeBDVMetaData(
driverVolumeWriter,
storageType,
dataType,
Expand Down Expand Up @@ -359,7 +360,7 @@ else if ( FloatType.class.isInstance( type ) )
for ( int level = 1; level < this.downsampling.length; ++level )
{
final int s = level;
final int[] ds = N5ResaveTools.computeRelativeDownsampling( this.downsampling, level );
final int[] ds = N5ApiTools.computeRelativeDownsampling( this.downsampling, level );

IOFunctions.println( "Downsampling: " + Util.printCoordinates( this.downsampling[ level ] ) + " with relative downsampling of " + Util.printCoordinates( ds ));

Expand All @@ -368,7 +369,7 @@ else if ( FloatType.class.isInstance( type ) )
dim[ d ] = previousDim[ d ] / ds[ d ];

final String datasetDownsampling = bdv ?
ExportTools.createDownsampledBDVPath(dataset, level, storageType) : dataset.substring(0, dataset.length() - 3) + "/s" + level;
N5ApiTools.createDownsampledBDVPath(dataset, level, storageType) : dataset.substring(0, dataset.length() - 3) + "/s" + level;

try
{
Expand Down Expand Up @@ -400,7 +401,7 @@ else if ( FloatType.class.isInstance( type ) )
final Function<long[][], String> gridBlockToDatasetPreviousScale = (gridBlock -> datasetPrev); // there is only one ViewId

e.submit( () -> gridDS.parallelStream().forEach(
gridBlock -> N5ResaveTools.writeDownsampledBlock(
gridBlock -> N5ApiTools.writeDownsampledBlock(
driverVolumeWriter,
gridBlockToDataset,
gridBlockToDatasetPreviousScale,
Expand Down
Loading

0 comments on commit 287d813

Please sign in to comment.