From a6ed52c6891af9be400b7ca8ad1faacb06c65a2c Mon Sep 17 00:00:00 2001 From: Christian Tischer Date: Thu, 25 Jul 2024 11:47:36 +0200 Subject: [PATCH] Fixes https://github.com/mobie/mobie-viewer-fiji/issues/1181 --- .../embl/mobie/io/imagedata/N5ImageData.java | 5 +-- .../java/org/embl/mobie/io/util/S3Utils.java | 2 ++ .../develop/LazyConvertAndSaveOMEZarr.java | 32 +++++++++++++++++++ .../OpenOMEZarrFromS3WithCredentials.java | 24 ++++++++++++++ 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 src/test/java/develop/LazyConvertAndSaveOMEZarr.java create mode 100644 src/test/java/develop/OpenOMEZarrFromS3WithCredentials.java diff --git a/src/main/java/org/embl/mobie/io/imagedata/N5ImageData.java b/src/main/java/org/embl/mobie/io/imagedata/N5ImageData.java index 538e2d3..e152d95 100644 --- a/src/main/java/org/embl/mobie/io/imagedata/N5ImageData.java +++ b/src/main/java/org/embl/mobie/io/imagedata/N5ImageData.java @@ -16,6 +16,7 @@ import net.imglib2.util.ValuePair; import org.embl.mobie.io.ngff.Labels; import org.embl.mobie.io.util.IOHelper; +import org.embl.mobie.io.util.S3Utils; import org.janelia.saalfeldlab.n5.*; import org.janelia.saalfeldlab.n5.bdv.N5Viewer; import org.janelia.saalfeldlab.n5.ui.DataSelection; @@ -150,10 +151,6 @@ private synchronized void open() { n5Factory = n5Factory.s3UseCredentials( new BasicAWSCredentials( s3AccessAndSecretKey[ 0 ], s3AccessAndSecretKey[ 1 ] ) ); } - else - { - n5Factory = n5Factory.s3UseCredentials( new AnonymousAWSCredentials() ); - } N5Reader n5 = n5Factory.openReader( containerPath ); String rootGroup = n5URI.getGroupPath() != null ? n5URI.getGroupPath() : "/"; diff --git a/src/main/java/org/embl/mobie/io/util/S3Utils.java b/src/main/java/org/embl/mobie/io/util/S3Utils.java index 27b68b3..8fc72df 100644 --- a/src/main/java/org/embl/mobie/io/util/S3Utils.java +++ b/src/main/java/org/embl/mobie/io/util/S3Utils.java @@ -51,11 +51,13 @@ public abstract class S3Utils private static boolean useCredentialsChain; // FIXME: We should remove this! + @Deprecated // instead use ImageDataFormat.setS3AccessAndSecretKey public static void setS3AccessAndSecretKey( String[] s3AccessAndSecretKey ) { S3Utils.s3AccessAndSecretKey = s3AccessAndSecretKey; } // FIXME: We should remove this! + @Deprecated public static String[] getS3AccessAndSecretKey() { return s3AccessAndSecretKey; diff --git a/src/test/java/develop/LazyConvertAndSaveOMEZarr.java b/src/test/java/develop/LazyConvertAndSaveOMEZarr.java new file mode 100644 index 0000000..22b3169 --- /dev/null +++ b/src/test/java/develop/LazyConvertAndSaveOMEZarr.java @@ -0,0 +1,32 @@ +package develop; + +import ij.IJ; +import ij.ImagePlus; +import net.imglib2.RandomAccessibleInterval; +import net.imglib2.converter.Converters; +import net.imglib2.img.display.imagej.ImageJFunctions; +import net.imglib2.type.numeric.integer.UnsignedShortType; +import net.imglib2.type.numeric.real.FloatType; +import org.embl.mobie.io.OMEZarrWriter; + +public class LazyConvertAndSaveOMEZarr +{ + public static void main( String[] args ) + { + // Open + ImagePlus floatImp = IJ.openVirtual("/Users/tischer/Desktop/blobs-float.tif"); + + // Lazy convert from float to short + float min = 0.0F; + float max = 255.0F; + float scale = 65535 / ( max - min); + RandomAccessibleInterval< FloatType > floatTypes = ImageJFunctions.wrapFloat( floatImp ); + RandomAccessibleInterval< UnsignedShortType > shortTypes = + Converters.convert( floatTypes, ( floatType, shortType ) + -> shortType.setReal( scale * ( floatType.get() - min ) ), new UnsignedShortType() ); + ImagePlus shortImp = ImageJFunctions.wrap( shortTypes, "converted image" ); + + // Save + OMEZarrWriter.write( shortImp, "/Users/tischer/Desktop/test.zarr", OMEZarrWriter.ImageType.Intensities, true ); + } +} diff --git a/src/test/java/develop/OpenOMEZarrFromS3WithCredentials.java b/src/test/java/develop/OpenOMEZarrFromS3WithCredentials.java new file mode 100644 index 0000000..c9375b8 --- /dev/null +++ b/src/test/java/develop/OpenOMEZarrFromS3WithCredentials.java @@ -0,0 +1,24 @@ +package develop; + +import bdv.cache.SharedQueue; +import org.embl.mobie.io.ImageDataFormat; +import org.embl.mobie.io.ImageDataOpener; +import org.embl.mobie.io.imagedata.ImageData; + +import java.util.Arrays; + +public class OpenOMEZarrFromS3WithCredentials +{ + public static void main( String[] args ) + { + ImageDataFormat omeZarr = ImageDataFormat.OmeZarr; + // If the below is commented it will look in ~/.aws/credentials + //omeZarr.setS3SecretAndAccessKey( new String[]{"tr4UedW5", "XfECV2scqKkpAM"} ); + ImageData< ? > imageData = ImageDataOpener.open( + "https://s3.embl.de/wsi-unihd/mitosis-5D.ome.zarr", + omeZarr, + new SharedQueue( 4 ) ); + long[] dimensions = imageData.getSourcePair( 0 ).getA().getSource( 0, 0 ).dimensionsAsLongArray(); + System.out.println( Arrays.toString( dimensions )); + } +}