From 8cfde84046f9263ed77e22ec614676101f7ed51c Mon Sep 17 00:00:00 2001 From: Stephan Preibisch Date: Tue, 29 Oct 2024 16:30:16 -0400 Subject: [PATCH 01/24] registering CoordinateTransform GSON serializer for OME-ZARR --- src/main/java/util/URITools.java | 64 ++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/src/main/java/util/URITools.java b/src/main/java/util/URITools.java index ec3171ac..4cab21b7 100644 --- a/src/main/java/util/URITools.java +++ b/src/main/java/util/URITools.java @@ -35,7 +35,6 @@ import java.io.PrintWriter; import java.net.URI; import java.net.URISyntaxException; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.Date; import java.util.regex.Pattern; @@ -51,6 +50,8 @@ import org.janelia.saalfeldlab.n5.s3.AmazonS3Utils; import org.janelia.saalfeldlab.n5.universe.N5Factory; import org.janelia.saalfeldlab.n5.universe.N5Factory.StorageFormat; +import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.CoordinateTransformation; +import org.janelia.saalfeldlab.n5.universe.metadata.ome.ngff.v04.coordinateTransformations.CoordinateTransformationAdapter; import org.janelia.saalfeldlab.n5.zarr.N5ZarrReader; import org.janelia.saalfeldlab.n5.zarr.N5ZarrWriter; import org.jdom2.Document; @@ -59,6 +60,8 @@ import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; +import com.google.gson.GsonBuilder; + import bdv.ViewerImgLoader; import mpicbg.spim.data.SpimDataException; import mpicbg.spim.data.SpimDataIOException; @@ -261,10 +264,15 @@ else if ( format.equals( StorageFormat.HDF5 )) { N5Writer n5w; + final GsonBuilder builder = new GsonBuilder().registerTypeAdapter( + CoordinateTransformation.class, + new CoordinateTransformationAdapter() ); + try { //System.out.println( "Trying writing with credentials ..." ); - N5Factory factory = new N5Factory(); + final N5Factory factory = new N5Factory(); + factory.gsonBuilder( builder ); factory.s3UseCredentials(); n5w = factory.openWriter( format, uri ); } @@ -272,11 +280,12 @@ else if ( format.equals( StorageFormat.HDF5 )) { System.out.println( "With credentials failed; trying anonymous ..." ); - n5w = new N5Factory().openWriter( format, uri ); + final N5Factory factory = new N5Factory(); + factory.gsonBuilder( builder ); + n5w = factory.openWriter( format, uri ); } return n5w; - //return new N5Factory().openWriter( format, uri ); // cloud support, avoid dependency hell if it is a local file } } @@ -295,21 +304,28 @@ else if ( format.equals( StorageFormat.ZARR )) { N5Reader n5r; + final GsonBuilder builder = new GsonBuilder().registerTypeAdapter( + CoordinateTransformation.class, + new CoordinateTransformationAdapter() ); + try { //System.out.println( "Trying reading with credentials ..." ); - N5Factory factory = new N5Factory(); + final N5Factory factory = new N5Factory(); + factory.gsonBuilder( builder ); factory.s3UseCredentials(); n5r = factory.openReader( format, uri ); } catch ( Exception e ) { - System.out.println( "With credentials failed; trying anonymous ..." ); - n5r = new N5Factory().openReader( format, uri ); + System.out.println( "With credentials failed; trying anonymous with gson builder ..." ); + + final N5Factory factory = new N5Factory(); + factory.gsonBuilder( builder ); + n5r = factory.openReader( format, uri ); } return n5r; - //return new N5Factory().openReader( format, uri ); // cloud support, avoid dependency hell if it is a local file } } @@ -328,21 +344,27 @@ else if ( uri.toString().toLowerCase().endsWith( ".n5" ) ) { N5Reader n5r; + final GsonBuilder builder = new GsonBuilder().registerTypeAdapter( + CoordinateTransformation.class, + new CoordinateTransformationAdapter() ); + try { //System.out.println( "Trying reading with credentials ..." ); - N5Factory factory = new N5Factory(); + final N5Factory factory = new N5Factory(); + factory.gsonBuilder( builder ); factory.s3UseCredentials(); n5r = factory.openReader( uri.toString() ); } catch ( Exception e ) { System.out.println( "With credentials failed; trying anonymous ..." ); - n5r = new N5Factory().openReader( uri.toString() ); + final N5Factory factory = new N5Factory(); + factory.gsonBuilder( builder ); + n5r = factory.openReader( uri.toString() ); } return n5r; - //return new N5Factory().openReader( uri.toString() ); // cloud support, avoid dependency hell if it is a local file } } @@ -361,22 +383,27 @@ else if ( uri.toString().toLowerCase().endsWith( ".n5" ) ) { N5Writer n5w; + final GsonBuilder builder = new GsonBuilder().registerTypeAdapter( + CoordinateTransformation.class, + new CoordinateTransformationAdapter() ); + try { //System.out.println( "Trying writing with credentials ..." ); - N5Factory factory = new N5Factory(); + final N5Factory factory = new N5Factory(); + factory.gsonBuilder( builder ); factory.s3UseCredentials(); n5w = factory.openWriter( uri.toString() ); } catch ( Exception e ) { System.out.println( "Writing with credentials failed; trying anonymous writing ..." ); - n5w = new N5Factory().openWriter( uri.toString() ); + final N5Factory factory = new N5Factory(); + factory.gsonBuilder( builder ); + n5w = factory.openWriter( uri.toString() ); } return n5w; - - //return new N5Factory().openWriter( uri.toString() ); // cloud support, avoid dependency hell if it is a local file } } @@ -411,6 +438,7 @@ else if ( URITools.isS3( xmlURI ) || URITools.isGC( xmlURI ) ) final SpimData2 data = io.fromXml( docRoot, xmlURI ); // more threads for cloud-based fetching + System.out.println( "Setting num fetcher threads to " + cloudThreads + " for cloud access." ); ( (ViewerImgLoader) data.getSequenceDescription().getImgLoader() ).setNumFetcherThreads( cloudThreads ); return data; @@ -686,6 +714,12 @@ public static void minimalExampleTobiS3GS() throws URISyntaxException, IOExcepti public static void main( String[] args ) throws SpimDataException, IOException, URISyntaxException { + URI uri1 = URITools.toURI( "s3://aind-open-data/exaSPIM_708373_2024-04-02_19-49-38/SPIM.ome.zarr" ); + + System.out.println( uri1.getHost() ); + System.out.println( uri1.getPath() ); + System.exit( 0 ); + minimalExampleTobiS3GS(); System.exit( 0 ); From 42695bdb4fb9a8fb8c3d5b5a2b206472d1de7594 Mon Sep 17 00:00:00 2001 From: Stephan Preibisch Date: Tue, 29 Oct 2024 16:30:52 -0400 Subject: [PATCH 02/24] use a SNAPSHOT version of bigdataviewer-core that contains generalizations of N5ImageLoader --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 195f4f1d..65535a02 100644 --- a/pom.xml +++ b/pom.xml @@ -112,9 +112,9 @@ like Selective Plane Illumination Microscopy (SPIM) Data. 0.16.0 0.15.1 7.0.2 - 10.6.1 1.0.0-beta-36 --> + 10.6.3-SNAPSHOT 2.3.5 - 10.6.3-SNAPSHOT + 10.6.3 2.3.5