66import com .fasterxml .jackson .databind .ObjectMapper ;
77import com .github .luben .zstd .Zstd ;
88import com .github .luben .zstd .ZstdCompressCtx ;
9- import dev .zarr .zarrjava .store .FilesystemStore ;
10- import dev .zarr .zarrjava .store .HttpStore ;
11- import dev .zarr .zarrjava .store .S3Store ;
12- import dev .zarr .zarrjava .store .StoreHandle ;
9+ import dev .zarr .zarrjava .store .*;
1310import dev .zarr .zarrjava .utils .MultiArrayUtils ;
1411import dev .zarr .zarrjava .v3 .*;
12+ import dev .zarr .zarrjava .v3 .codec .Codec ;
1513import dev .zarr .zarrjava .v3 .codec .CodecBuilder ;
1614import dev .zarr .zarrjava .v3 .codec .core .BytesCodec ;
1715import dev .zarr .zarrjava .v3 .codec .core .TransposeCodec ;
@@ -65,13 +63,15 @@ public static void clearTestoutputFolder() throws IOException {
6563 @ CsvSource ({
6664 "blosc,blosclz_noshuffle_0" , "blosc,lz4_shuffle_6" , "blosc,lz4hc_bitshuffle_3" , "blosc,zlib_shuffle_5" , "blosc,zstd_bitshuffle_9" ,
6765 "gzip,0" , "gzip,5" ,
68- "zstd,0_true" , "zstd,5_true" ,"zstd,0_false" , "zstd,5_false" ,
66+ "zstd,0_true" , "zstd,5_true" , "zstd,0_false" , "zstd,5_false" ,
6967 "bytes,BIG" , "bytes,LITTLE" ,
7068 "transpose,_" ,
7169 "sharding,start" , "sharding,end" ,
7270 "sharding_nested,_" ,
7371 "crc32c,_" ,
74- }) public void testReadFromZarrita (String codec , String codecParam ) throws IOException , ZarrException , InterruptedException {
72+ })
73+
74+ public void testReadFromZarrita (String codec , String codecParam ) throws IOException , ZarrException , InterruptedException {
7575 String command = pythonPath ();
7676 ProcessBuilder pb = new ProcessBuilder (command , PYTHON_TEST_PATH .resolve ("zarrita_write.py" ).toString (), codec , codecParam , TESTOUTPUT .toString ());
7777 Process process = pb .start ();
@@ -142,7 +142,7 @@ public void testZstdLibrary(int clevel, boolean checksumFlag) throws IOException
142142 @ CsvSource ({
143143 "blosc,blosclz_noshuffle_0" , "blosc,lz4_shuffle_6" , "blosc,lz4hc_bitshuffle_3" , "blosc,zlib_shuffle_5" , "blosc,zstd_bitshuffle_9" ,
144144 "gzip,0" , "gzip,5" ,
145- "zstd,0_true" , "zstd,5_true" ,"zstd,0_false" , "zstd,5_false" ,
145+ "zstd,0_true" , "zstd,5_true" , "zstd,0_false" , "zstd,5_false" ,
146146 "bytes,BIG" , "bytes,LITTLE" ,
147147 "transpose,_" ,
148148 "sharding,start" , "sharding,end" ,
@@ -233,12 +233,12 @@ public void testWriteReadWithZarrita(String codec, String codecParam) throws Exc
233233 assert exitCode == 0 ;
234234 }
235235
236- static Stream <Function <CodecBuilder , CodecBuilder >> invalidCodecBuilder (){
236+ static Stream <Function <CodecBuilder , CodecBuilder >> invalidCodecBuilder () {
237237 return Stream .of (
238238 c -> c .withBytes (BytesCodec .Endian .LITTLE ).withBytes (BytesCodec .Endian .LITTLE ),
239239 c -> c .withBlosc ().withBytes (BytesCodec .Endian .LITTLE ),
240- c -> c .withBytes (BytesCodec .Endian .LITTLE ).withTranspose (new int []{1 ,0 }),
241- c -> c .withTranspose (new int []{1 ,0 }).withBytes (BytesCodec .Endian .LITTLE ).withTranspose (new int []{1 ,0 })
240+ c -> c .withBytes (BytesCodec .Endian .LITTLE ).withTranspose (new int []{1 , 0 }),
241+ c -> c .withTranspose (new int []{1 , 0 }).withBytes (BytesCodec .Endian .LITTLE ).withTranspose (new int []{1 , 0 })
242242 );
243243 }
244244
@@ -247,9 +247,9 @@ static Stream<Function<CodecBuilder, CodecBuilder>> invalidCodecBuilder(){
247247 public void testCheckInvalidCodecConfiguration (Function <CodecBuilder , CodecBuilder > codecBuilder ) throws Exception {
248248 StoreHandle storeHandle = new FilesystemStore (TESTOUTPUT ).resolve ("invalid_codec_config" , String .valueOf (codecBuilder .hashCode ()));
249249 ArrayMetadataBuilder builder = Array .metadataBuilder ()
250- .withShape (new long [] {4 , 4 })
250+ .withShape (new long []{4 , 4 })
251251 .withDataType (DataType .UINT32 )
252- .withChunkShape (new int []{2 ,2 })
252+ .withChunkShape (new int []{2 , 2 })
253253 .withCodecs (codecBuilder );
254254
255255 assertThrows (ZarrException .class , () -> Array .create (storeHandle , builder .build ()));
@@ -287,7 +287,7 @@ static Stream<int[]> invalidChunkSizes() {
287287 @ ParameterizedTest
288288 @ MethodSource ("invalidChunkSizes" )
289289 public void testCheckInvalidChunkDimensions (int [] chunkSize ) {
290- long [] shape = new long [] {4 , 4 };
290+ long [] shape = new long []{4 , 4 };
291291
292292 StoreHandle storeHandle = new FilesystemStore (TESTOUTPUT ).resolve ("invalid_chunksize" );
293293 ArrayMetadataBuilder builder = Array .metadataBuilder ()
@@ -312,8 +312,8 @@ static Stream<int[]> invalidShardSizes() {
312312 @ ParameterizedTest
313313 @ MethodSource ("invalidShardSizes" )
314314 public void testCheckShardingBounds (int [] shardSize ) throws Exception {
315- long [] shape = new long [] {10 , 10 };
316- int [] innerChunkSize = new int [] {2 , 2 };
315+ long [] shape = new long []{10 , 10 };
316+ int [] innerChunkSize = new int []{2 , 2 };
317317
318318 ArrayMetadataBuilder builder = Array .metadataBuilder ()
319319 .withShape (shape )
@@ -371,8 +371,8 @@ static Stream<int[]> invalidTransposeOrder() {
371371 return Stream .of (
372372 new int []{1 , 0 , 0 },
373373 new int []{1 , 2 , 3 },
374- new int []{1 ,2 , 3 , 0 },
375- new int []{1 ,2 }
374+ new int []{1 , 2 , 3 , 0 },
375+ new int []{1 , 2 }
376376 );
377377 }
378378
@@ -392,6 +392,7 @@ public void testCheckInvalidTransposeOrder(int[] transposeOrder) throws Exceptio
392392 ucar .ma2 .Array testData = ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , shapeInt );
393393 assertThrows (ZarrException .class , () -> transposeCodec .encode (testData ));
394394 }
395+
395396 @ Test
396397 public void testFileSystemStores () throws IOException , ZarrException {
397398 FilesystemStore fsStore = new FilesystemStore (TESTDATA );
@@ -564,4 +565,70 @@ public void testV2() throws IOException {
564565 }
565566
566567
568+ @ Test
569+ public void testReadme1 () throws IOException , ZarrException {
570+ Group hierarchy = Group .open (
571+ new HttpStore ("https://static.webknossos.org/data/zarr_v3" )
572+ .resolve ("l4_sample" )
573+ );
574+ Group color = (Group ) hierarchy .get ("color" );
575+ Array array = (Array ) color .get ("1" );
576+ ucar .ma2 .Array outArray = array .read (
577+ new long []{0 , 3073 , 3073 , 513 }, // offset
578+ new int []{1 , 64 , 64 , 64 } // shape
579+ );
580+ }
581+
582+ @ Test
583+ public void testReadme2 () throws IOException , ZarrException {
584+ Array array = Array .create (
585+ new FilesystemStore (TESTOUTPUT ).resolve ("testoutput" , "color" , "1" ),
586+ Array .metadataBuilder ()
587+ .withShape (1 , 4096 , 4096 , 1536 )
588+ .withDataType (DataType .UINT32 )
589+ .withChunkShape (1 , 1024 , 1024 , 1024 )
590+ .withFillValue (0 )
591+ .withCodecs (c -> c .withSharding (new int []{1 , 32 , 32 , 32 }, c1 -> c1 .withBlosc ()))
592+ .build ()
593+ );
594+ ucar .ma2 .Array data = ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , new int []{1 , 1 , 2 , 2 }, new int []{1 , 2 , 3 , 4 });
595+ array .write (
596+ new long []{0 , 0 , 0 , 0 }, // offset
597+ data
598+ );
599+ ucar .ma2 .Array output = array .read (new long []{0 , 0 , 0 , 0 }, new int []{1 , 1 , 2 , 2 });
600+ assert MultiArrayUtils .allValuesEqual (data , output );
601+
602+ }
603+
604+ @ ParameterizedTest
605+ @ ValueSource (strings = {"1" , "2-2-1" , "4-4-1" , "16-16-4" })
606+ public void testReadL4Sample (String mag ) throws IOException , ZarrException {
607+ StoreHandle httpStoreHandle = new HttpStore ("https://static.webknossos.org/data/zarr_v3/" ).resolve ("l4_sample" , "color" , mag );
608+ StoreHandle localStoreHandle = new FilesystemStore (TESTDATA ).resolve ("l4_sample" , "color" , mag );
609+
610+ Array httpArray = Array .open (httpStoreHandle );
611+ Array localArray = Array .open (localStoreHandle );
612+ System .out .println (httpArray );
613+ System .out .println (localArray );
614+
615+ ucar .ma2 .Array httpData1 = httpArray .read (new long []{0 , 0 , 0 , 0 }, new int []{1 , 64 , 64 , 64 });
616+ ucar .ma2 .Array localData1 = localArray .read (new long []{0 , 0 , 0 , 0 }, new int []{1 , 64 , 64 , 64 });
617+
618+ assert MultiArrayUtils .allValuesEqual (httpData1 , localData1 );
619+
620+ //offset to where l4_sample contains non-zero values
621+ long [] offset = new long [4 ];
622+ long [] originalOffset = new long []{0 , 3073 , 3073 , 513 };
623+ long [] originalShape = new long []{1 , 4096 , 4096 , 2048 };
624+ long [] arrayShape = httpArray .metadata .shape ;
625+ for (int i = 0 ; i < 4 ; i ++) {
626+ offset [i ] = originalOffset [i ] / (originalShape [i ] / arrayShape [i ]);
627+ }
628+
629+ ucar .ma2 .Array httpData2 = httpArray .read (offset , new int []{1 , 64 , 64 , 64 });
630+ ucar .ma2 .Array localData2 = localArray .read (offset , new int []{1 , 64 , 64 , 64 });
631+
632+ assert MultiArrayUtils .allValuesEqual (httpData2 , localData2 );
633+ }
567634}
0 commit comments