Skip to content

Commit

Permalink
N5ApiTools.setupMultiResolutionPyramid() now also creates s0 ...
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPreibisch committed Sep 12, 2024
1 parent ec7db26 commit 8ebe6d1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,6 @@ else if ( FloatType.class.isInstance( type ) )
// this is the relative path to the dataset inside the Zarr/N5/HDF5 container, thus using File here seems fine
final String dataset = new File( new File( baseDataset , title ).toString(), datasetExtension ).toString();

// create s0 dataset
driverVolumeWriter.createDataset(
dataset,
bb.dimensionsAsLongArray(),
blocksize(),
dataType,
compression );

// setup multi-resolution pyramid
mrInfo = N5ApiTools.setupMultiResolutionPyramid(
driverVolumeWriter,
Expand Down
66 changes: 31 additions & 35 deletions src/main/java/net/preibisch/mvrecon/process/n5api/N5ApiTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -212,14 +213,26 @@ public static MultiResolutionLevelInfo[] setupMultiResolutionPyramid(
{
final MultiResolutionLevelInfo[] mrInfo = new MultiResolutionLevelInfo[ downsamplings.length];

// set up s0
int[] relativeDownsampling = downsamplings[ 0 ].clone();
Arrays.setAll( relativeDownsampling, i -> 1 );

mrInfo[ 0 ] = new MultiResolutionLevelInfo(
viewIdToDataset.apply( viewId, 0 ), dimensionsS0.clone(), dataType, downsamplings[ 0 ], downsamplings[ 0 ], blockSize );
viewIdToDataset.apply( viewId, 0 ), dimensionsS0.clone(), dataType, relativeDownsampling, downsamplings[ 0 ], blockSize );

driverVolumeWriter.createDataset(
viewIdToDataset.apply( viewId, 0 ),
dimensionsS0,
blockSize,
dataType,
compression );

long[] previousDim = dimensionsS0.clone();

// set up s1 ... sN
for ( int level = 1; level < downsamplings.length; ++level )
{
final int[] relativeDownsampling = computeRelativeDownsampling( downsamplings, level );
relativeDownsampling = computeRelativeDownsampling( downsamplings, level );

final String datasetLevel = viewIdToDataset.apply( viewId, level );

Expand Down Expand Up @@ -313,19 +326,21 @@ public static MultiResolutionLevelInfo[] setupBdvDatasetsN5(
final long[] dimensions,
final Compression compression,
final int[] blockSize,
final int[][] downsamplings )
int[][] downsamplings )
{
final String s0Dataset = createBDVPath( viewId, 0, StorageType.N5 );
final String setupDataset = s0Dataset.substring(0, s0Dataset.indexOf( "/timepoint" ));
final String timepointDataset = s0Dataset.substring(0, s0Dataset.indexOf("/s0" ));

driverVolumeWriter.createDataset(
s0Dataset,
final MultiResolutionLevelInfo[] mrInfo = setupMultiResolutionPyramid(
driverVolumeWriter,
viewId,
viewIdToDatasetBdv( StorageType.N5 ),
dataType,
dimensions,
compression,
blockSize,
dataType,
compression );

final String setupDataset = s0Dataset.substring(0, s0Dataset.indexOf( "/timepoint" ));
final String timepointDataset = s0Dataset.substring(0, s0Dataset.indexOf("/s0" ));
downsamplings);

final Map<String, Class<?>> attribs = driverVolumeWriter.listAttributes( setupDataset );

Expand Down Expand Up @@ -357,38 +372,19 @@ public static MultiResolutionLevelInfo[] setupBdvDatasetsN5(
driverVolumeWriter.setAttribute(timepointDataset, "saved_completely", true );
driverVolumeWriter.setAttribute(timepointDataset, "multiScale", downsamplings != null && downsamplings.length != 0 );

final MultiResolutionLevelInfo[] mrInfo;

if ( downsamplings == null || downsamplings.length == 0 )
{
// set additional N5 attributes for s0 dataset
driverVolumeWriter.setAttribute( s0Dataset, "downsamplingFactors", new int[] {1,1,1} );

mrInfo = new MultiResolutionLevelInfo[] { new MultiResolutionLevelInfo( s0Dataset, dimensions.clone(), dataType, new int[] {1,1,1}, new int[] {1,1,1}, blockSize ) };
downsamplings = new int[1][ dimensions.length ];
Arrays.setAll( downsamplings[ 0 ], i -> 1 );
}
else
{
mrInfo = setupMultiResolutionPyramid(
driverVolumeWriter,
viewId,
viewIdToDatasetBdv( StorageType.N5 ),
dataType,
dimensions,
compression,
blockSize,
downsamplings);

driverVolumeWriter.setAttribute( s0Dataset, "downsamplingFactors", downsamplings[ 0 ] );

for ( int level = 1; level < downsamplings.length; ++level )
{
// set additional N5 attributes for s0 ... sN datasets
driverVolumeWriter.setAttribute( mrInfo[ level ].dataset, "downsamplingFactors", downsamplings[ level ] );
}
}
// set additional N5 attributes for s0 ... sN datasets
for ( int level = 0; level < downsamplings.length; ++level )
driverVolumeWriter.setAttribute( mrInfo[ level ].dataset, "downsamplingFactors", mrInfo[ level ].absoluteDownsampling );

return mrInfo;
}

public static void writeDownsampledBlock(
final N5Writer n5,
final MultiResolutionLevelInfo mrInfo,
Expand Down

0 comments on commit 8ebe6d1

Please sign in to comment.