Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Jul 25, 2024
1 parent c9d3819 commit a6ed52c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/main/java/org/embl/mobie/io/imagedata/N5ImageData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() : "/";
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/embl/mobie/io/util/S3Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 32 additions & 0 deletions src/test/java/develop/LazyConvertAndSaveOMEZarr.java
Original file line number Diff line number Diff line change
@@ -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 );
}
}
24 changes: 24 additions & 0 deletions src/test/java/develop/OpenOMEZarrFromS3WithCredentials.java
Original file line number Diff line number Diff line change
@@ -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 ));
}
}

0 comments on commit a6ed52c

Please sign in to comment.