6
6
import com .fasterxml .jackson .databind .ObjectMapper ;
7
7
import com .github .luben .zstd .Zstd ;
8
8
import 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 .*;
13
10
import dev .zarr .zarrjava .utils .MultiArrayUtils ;
14
11
import dev .zarr .zarrjava .v3 .*;
12
+ import dev .zarr .zarrjava .v3 .codec .Codec ;
15
13
import dev .zarr .zarrjava .v3 .codec .CodecBuilder ;
16
14
import dev .zarr .zarrjava .v3 .codec .core .BytesCodec ;
17
15
import dev .zarr .zarrjava .v3 .codec .core .TransposeCodec ;
@@ -65,13 +63,15 @@ public static void clearTestoutputFolder() throws IOException {
65
63
@ CsvSource ({
66
64
"blosc,blosclz_noshuffle_0" , "blosc,lz4_shuffle_6" , "blosc,lz4hc_bitshuffle_3" , "blosc,zlib_shuffle_5" , "blosc,zstd_bitshuffle_9" ,
67
65
"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" ,
69
67
"bytes,BIG" , "bytes,LITTLE" ,
70
68
"transpose,_" ,
71
69
"sharding,start" , "sharding,end" ,
72
70
"sharding_nested,_" ,
73
71
"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 {
75
75
String command = pythonPath ();
76
76
ProcessBuilder pb = new ProcessBuilder (command , PYTHON_TEST_PATH .resolve ("zarrita_write.py" ).toString (), codec , codecParam , TESTOUTPUT .toString ());
77
77
Process process = pb .start ();
@@ -142,7 +142,7 @@ public void testZstdLibrary(int clevel, boolean checksumFlag) throws IOException
142
142
@ CsvSource ({
143
143
"blosc,blosclz_noshuffle_0" , "blosc,lz4_shuffle_6" , "blosc,lz4hc_bitshuffle_3" , "blosc,zlib_shuffle_5" , "blosc,zstd_bitshuffle_9" ,
144
144
"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" ,
146
146
"bytes,BIG" , "bytes,LITTLE" ,
147
147
"transpose,_" ,
148
148
"sharding,start" , "sharding,end" ,
@@ -233,12 +233,12 @@ public void testWriteReadWithZarrita(String codec, String codecParam) throws Exc
233
233
assert exitCode == 0 ;
234
234
}
235
235
236
- static Stream <Function <CodecBuilder , CodecBuilder >> invalidCodecBuilder (){
236
+ static Stream <Function <CodecBuilder , CodecBuilder >> invalidCodecBuilder () {
237
237
return Stream .of (
238
238
c -> c .withBytes (BytesCodec .Endian .LITTLE ).withBytes (BytesCodec .Endian .LITTLE ),
239
239
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 })
242
242
);
243
243
}
244
244
@@ -247,9 +247,9 @@ static Stream<Function<CodecBuilder, CodecBuilder>> invalidCodecBuilder(){
247
247
public void testCheckInvalidCodecConfiguration (Function <CodecBuilder , CodecBuilder > codecBuilder ) throws Exception {
248
248
StoreHandle storeHandle = new FilesystemStore (TESTOUTPUT ).resolve ("invalid_codec_config" , String .valueOf (codecBuilder .hashCode ()));
249
249
ArrayMetadataBuilder builder = Array .metadataBuilder ()
250
- .withShape (new long [] {4 , 4 })
250
+ .withShape (new long []{4 , 4 })
251
251
.withDataType (DataType .UINT32 )
252
- .withChunkShape (new int []{2 ,2 })
252
+ .withChunkShape (new int []{2 , 2 })
253
253
.withCodecs (codecBuilder );
254
254
255
255
assertThrows (ZarrException .class , () -> Array .create (storeHandle , builder .build ()));
@@ -287,7 +287,7 @@ static Stream<int[]> invalidChunkSizes() {
287
287
@ ParameterizedTest
288
288
@ MethodSource ("invalidChunkSizes" )
289
289
public void testCheckInvalidChunkDimensions (int [] chunkSize ) {
290
- long [] shape = new long [] {4 , 4 };
290
+ long [] shape = new long []{4 , 4 };
291
291
292
292
StoreHandle storeHandle = new FilesystemStore (TESTOUTPUT ).resolve ("invalid_chunksize" );
293
293
ArrayMetadataBuilder builder = Array .metadataBuilder ()
@@ -312,8 +312,8 @@ static Stream<int[]> invalidShardSizes() {
312
312
@ ParameterizedTest
313
313
@ MethodSource ("invalidShardSizes" )
314
314
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 };
317
317
318
318
ArrayMetadataBuilder builder = Array .metadataBuilder ()
319
319
.withShape (shape )
@@ -371,8 +371,8 @@ static Stream<int[]> invalidTransposeOrder() {
371
371
return Stream .of (
372
372
new int []{1 , 0 , 0 },
373
373
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 }
376
376
);
377
377
}
378
378
@@ -392,6 +392,7 @@ public void testCheckInvalidTransposeOrder(int[] transposeOrder) throws Exceptio
392
392
ucar .ma2 .Array testData = ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , shapeInt );
393
393
assertThrows (ZarrException .class , () -> transposeCodec .encode (testData ));
394
394
}
395
+
395
396
@ Test
396
397
public void testFileSystemStores () throws IOException , ZarrException {
397
398
FilesystemStore fsStore = new FilesystemStore (TESTDATA );
@@ -564,4 +565,70 @@ public void testV2() throws IOException {
564
565
}
565
566
566
567
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
+ }
567
634
}
0 commit comments