@@ -129,13 +129,17 @@ public void testZstdLibrary(int clevel, boolean checksumFlag) throws IOException
129
129
130
130
@ ParameterizedTest
131
131
@ ValueSource (strings = {"blosc" , "gzip" , "zstd" , "bytes" , "transpose" , "sharding_start" , "sharding_end" , "crc32c" })
132
- public void testWriteToZarrita (String codec ) throws IOException , ZarrException , InterruptedException {
132
+ public void testWriteRead (String codec ) throws IOException , ZarrException , InterruptedException {
133
+ int [] testData = new int [16 * 16 * 16 ];
134
+ Arrays .setAll (testData , p -> p );
135
+
133
136
StoreHandle storeHandle = new FilesystemStore (TESTOUTPUT ).resolve ("write_to_zarrita" , codec );
134
137
ArrayMetadataBuilder builder = Array .metadataBuilder ()
135
- .withShape (16 , 16 )
138
+ .withShape (16 , 16 , 16 )
136
139
.withDataType (DataType .UINT32 )
137
- .withChunkShape (8 , 8 )
138
- .withFillValue (0 );
140
+ .withChunkShape (2 , 4 , 8 )
141
+ .withFillValue (0 )
142
+ .withAttributes (Map .of ("test_key" , "test_value" ));
139
143
140
144
switch (codec ) {
141
145
case "blosc" :
@@ -151,13 +155,13 @@ public void testWriteToZarrita(String codec) throws IOException, ZarrException,
151
155
builder = builder .withCodecs (c -> c .withBytes ("LITTLE" ));
152
156
break ;
153
157
case "transpose" :
154
- builder = builder .withCodecs (c -> c .withTranspose (new int []{1 , 0 }));
158
+ builder = builder .withCodecs (c -> c .withTranspose (new int []{1 , 0 , 2 }));
155
159
break ;
156
160
case "sharding_start" :
157
- builder = builder .withCodecs (c -> c .withSharding (new int []{4 , 4 }, c1 -> c1 .withBytes ("LITTLE" ), "start" ));
161
+ builder = builder .withCodecs (c -> c .withSharding (new int []{2 , 2 , 4 }, c1 -> c1 .withBytes ("LITTLE" ), "start" ));
158
162
break ;
159
163
case "sharding_end" :
160
- builder = builder .withCodecs (c -> c .withSharding (new int []{4 , 4 }, c1 -> c1 .withBytes ("LITTLE" ), "end" ));
164
+ builder = builder .withCodecs (c -> c .withSharding (new int []{2 , 2 , 4 }, c1 -> c1 .withBytes ("LITTLE" ), "end" ));
161
165
break ;
162
166
case "crc32c" :
163
167
builder = builder .withCodecs (CodecBuilder ::withCrc32c );
@@ -166,12 +170,21 @@ public void testWriteToZarrita(String codec) throws IOException, ZarrException,
166
170
throw new IllegalArgumentException ("Invalid Codec: " + codec );
167
171
}
168
172
169
- Array array = Array .create (storeHandle , builder .build ());
173
+ Array writeArray = Array .create (storeHandle , builder .build ());
174
+ writeArray .write (ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , new int []{16 , 16 , 16 }, testData ));
175
+
176
+ //read in zarr-java
177
+ Array readArray = Array .open (storeHandle );
178
+ ucar .ma2 .Array result = readArray .read ();
170
179
171
- int [] data = new int [16 * 16 ];
172
- Arrays .setAll (data , p -> p );
173
- array .write (ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , new int []{16 , 16 }, data ));
180
+ Assertions .assertArrayEquals (new int []{16 , 16 , 16 }, result .getShape ());
181
+ Assertions .assertEquals (DataType .UINT32 , readArray .metadata .dataType );
182
+ Assertions .assertArrayEquals (new int []{2 , 4 , 8 }, readArray .metadata .chunkShape ());
183
+ Assertions .assertEquals ("test_value" , readArray .metadata .attributes .get ("test_key" ));
174
184
185
+ Assertions .assertArrayEquals (testData , (int []) result .get1DJavaArray (ucar .ma2 .DataType .INT ));
186
+
187
+ //read in zarrita
175
188
String command = pythonPath ();
176
189
177
190
ProcessBuilder pb = new ProcessBuilder (command , PYTHON_TEST_PATH .resolve ("zarrita_read.py" ).toString (), codec , TESTOUTPUT .toString ());
@@ -192,64 +205,6 @@ public void testWriteToZarrita(String codec) throws IOException, ZarrException,
192
205
assert exitCode == 0 ;
193
206
}
194
207
195
-
196
- @ ParameterizedTest
197
- @ ValueSource (strings = {"blosc" , "gzip" , "zstd" , "bytes" , "transpose" , "sharding_start" , "sharding_end" , "crc32c" })
198
- public void testCodecsWriteRead (String codec ) throws IOException , ZarrException {
199
- int [] testData = new int [16 * 16 * 16 ];
200
- Arrays .setAll (testData , p -> p );
201
-
202
- StoreHandle storeHandle = new FilesystemStore (TESTOUTPUT ).resolve ("testWriteAndRead3d" , codec );
203
- ArrayMetadataBuilder builder = Array .metadataBuilder ()
204
- .withShape (16 , 16 , 16 )
205
- .withDataType (DataType .UINT32 )
206
- .withChunkShape (2 , 4 , 8 )
207
- .withFillValue (0 )
208
- .withAttributes (Map .of ("test_key" , "test_value" ));
209
-
210
- switch (codec ) {
211
- case "blosc" :
212
- builder = builder .withCodecs (CodecBuilder ::withBlosc );
213
- break ;
214
- case "gzip" :
215
- builder = builder .withCodecs (CodecBuilder ::withGzip );
216
- break ;
217
- case "zstd" :
218
- builder = builder .withCodecs (c -> c .withZstd (0 ));
219
- break ;
220
- case "bytes" :
221
- builder = builder .withCodecs (c -> c .withBytes ("LITTLE" ));
222
- break ;
223
- case "transpose" :
224
- builder = builder .withCodecs (c -> c .withTranspose (new int []{1 , 0 , 2 }));
225
- break ;
226
- case "sharding_start" :
227
- builder = builder .withCodecs (c -> c .withSharding (new int []{2 , 2 , 4 }, c1 -> c1 .withBytes ("LITTLE" ), "end" ));
228
- break ;
229
- case "sharding_end" :
230
- builder = builder .withCodecs (c -> c .withSharding (new int []{2 , 2 , 4 }, c1 -> c1 .withBytes ("LITTLE" ), "start" ));
231
- break ;
232
- case "crc32c" :
233
- builder = builder .withCodecs (CodecBuilder ::withCrc32c );
234
- break ;
235
- default :
236
- throw new IllegalArgumentException ("Invalid Codec: " + codec );
237
- }
238
-
239
- Array writeArray = Array .create (storeHandle , builder .build ());
240
- writeArray .write (ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , new int []{16 , 16 , 16 }, testData ));
241
-
242
- Array readArray = Array .open (storeHandle );
243
- ucar .ma2 .Array result = readArray .read ();
244
-
245
- Assertions .assertArrayEquals (new int []{16 , 16 , 16 }, result .getShape ());
246
- Assertions .assertEquals (DataType .UINT32 , readArray .metadata .dataType );
247
- Assertions .assertArrayEquals (new int []{2 , 4 , 8 }, readArray .metadata .chunkShape ());
248
- Assertions .assertEquals ("test_value" , readArray .metadata .attributes .get ("test_key" ));
249
-
250
- Assertions .assertArrayEquals (testData , (int []) result .get1DJavaArray (ucar .ma2 .DataType .INT ));
251
- }
252
-
253
208
@ ParameterizedTest
254
209
@ CsvSource ({"0,true" , "0,false" , "5, true" , "5, false" })
255
210
public void testZstdCodecReadWrite (int clevel , boolean checksum ) throws ZarrException , IOException {
0 commit comments