Skip to content

Commit

Permalink
3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jul 10, 2024
1 parent fc0bc6b commit fa26773
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
25 changes: 20 additions & 5 deletions src/main/java/org/embl/mobie/io/OMEZarrWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.janelia.saalfeldlab.n5.ij.N5ScalePyramidExporter;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Field;
import java.net.URISyntaxException;
import java.sql.Array;
import java.util.ArrayList;
Expand All @@ -65,18 +66,16 @@ public static void write( ImagePlus imp, String uri, ImageType imageType, boolea

// TODO: https://github.com/saalfeldlab/n5-ij/issues/82
String chunkSizeArg = getChunkSizeArg( imp );
IJ.log("Using chunk sizes: " + chunkSizeArg );

IJ.log("Writing data to: " + uri );
IJ.log("Chunking: " + chunkSizeArg );

try
{
N5URI n5URI = new N5URI( uri );
String containerPath = n5URI.getContainerPath();
String groupPath = n5URI.getGroupPath();

// TODO: set number of threads!
// https://github.com/saalfeldlab/n5-ij/issues/83
// we could do it now with reflection...

N5ScalePyramidExporter exporter = new N5ScalePyramidExporter(
imp,
containerPath,
Expand All @@ -88,13 +87,29 @@ public static void write( ImagePlus imp, String uri, ImageType imageType, boolea
N5Importer.MetadataOmeZarrKey,
GZIP_COMPRESSION
);

// TODO: https://github.com/saalfeldlab/n5-ij/issues/83
Field nThreads = N5ScalePyramidExporter.class.getDeclaredField( "nThreads" );
nThreads.setAccessible( true );
nThreads.setInt( exporter, Runtime.getRuntime().availableProcessors() - 1 );

exporter.setOverwrite( overwrite );

// TODO: Log progress: https://github.com/saalfeldlab/n5-ij/issues/84
exporter.run();
}
catch ( URISyntaxException e )
{
throw new RuntimeException( e );
}
catch ( NoSuchFieldException e )
{
throw new RuntimeException( e );
}
catch ( IllegalAccessException e )
{
throw new RuntimeException( e );
}

// TODO: If we wanted to give the dataset a name we also have to
// update how we refer to such an image or segmentation in the dataset.JSON
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/develop/WriteOMEZarr.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import static org.janelia.saalfeldlab.n5.ij.N5ScalePyramidExporter.GZIP_COMPRESSION;
import static org.janelia.saalfeldlab.n5.ij.N5ScalePyramidExporter.ZARR_FORMAT;

public class WriteOMEZarr
public class WriteOMEZarr
{
public static void main( String[] args )
{
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/examples/SaveOMEZarrExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package examples;

import bdv.cache.SharedQueue;
import bdv.util.BdvFunctions;
import ij.IJ;
import ij.ImagePlus;
import net.imagej.ImageJ;
import org.embl.mobie.io.OMEZarrWriter;
import org.embl.mobie.io.imagedata.N5ImageData;

public class SaveOMEZarrExample
{
public static void main( String[] args )
{
new ImageJ().ui().showUI(); // initialise services such that progress bar can be shown

ImagePlus imp = IJ.createImage( "image", 500, 500, 500, 8 );

long start = System.currentTimeMillis();
OMEZarrWriter.write( imp,
"/Users/tischer/Desktop/zarr-test",
OMEZarrWriter.ImageType.Intensities,
true );
System.out.println("Saving time [ms]: " + ( System.currentTimeMillis() - start ));
}
}

0 comments on commit fa26773

Please sign in to comment.