3232import java .util .HashMap ;
3333import java .util .List ;
3434import java .util .Map ;
35- import java .util .OptionalInt ;
3635import java .util .stream .IntStream ;
3736
3837import org .junit .Assert ;
@@ -192,8 +191,7 @@ public Path writeTestZarr(
192191 int sizeY ,
193192 int sizeX ,
194193 String pixelType ,
195- int resolutions ,
196- String order ) throws IOException {
194+ int resolutions ) throws IOException {
197195
198196 Path input = fake (
199197 "sizeT" , Integer .toString (sizeT ),
@@ -204,21 +202,14 @@ public Path writeTestZarr(
204202 "pixelType" , pixelType ,
205203 "resolutions" , Integer .toString (resolutions ));
206204 Path output = tmpDir .getRoot ().toPath ().resolve ("output.zarr" );
207- if (order != null ) {
208- assertBioFormats2Raw (input , output , "--dimension-order" , order );
209- } else {
210- assertBioFormats2Raw (input , output );
211- }
205+ assertBioFormats2Raw (input , output );
212206
213207 List <Object > msArray = new ArrayList <>();
214208 Map <String , Object > msData = new HashMap <>();
215209 Map <String , Object > msMetadata = new HashMap <>();
216210 msMetadata .put ("method" , "loci.common.image.SimpleImageScaler" );
217211 msMetadata .put ("version" , "Bio-Formats 6.5.1" );
218212 msData .put ("metadata" , msMetadata );
219- if (order != null ) {
220- msData .put ("axes" , getAxes (new StringBuffer (order ).reverse ().toString ()));
221- }
222213 msData .put ("datasets" , getDatasets (resolutions ));
223214 msData .put ("version" , "0.1" );
224215 msArray .add (msData );
@@ -229,17 +220,6 @@ public Path writeTestZarr(
229220 return output ;
230221
231222 }
232- public Path writeTestZarr (
233- int sizeT ,
234- int sizeC ,
235- int sizeZ ,
236- int sizeY ,
237- int sizeX ,
238- String pixelType ,
239- int resolutions ) throws IOException {
240- return writeTestZarr (sizeT , sizeC , sizeZ , sizeY , sizeX , pixelType ,
241- resolutions , null );
242- }
243223
244224 List <Map <String , String >> getDatasets (int resolutions ) {
245225 List <Map <String , String >> datasets = new ArrayList <>();
@@ -852,14 +832,26 @@ public void testReadDataNonDefaultAxes()
852832 int sizeZ = 4 ;
853833 int sizeY = 1024 ;
854834 int sizeX = 2048 ;
855- int resolutions = 1 ;
856- String order = DimensionOrder . VALUE_XYCTZ ;
835+ String order = DimensionOrder . VALUE_XYCTZ ; // Default XYZCT
836+ String rev_order = new StringBuilder ( order ). reverse (). toString () ;
857837 Pixels pixels = new Pixels (
858- null , new PixelsType (PixelsType .VALUE_INT32 ),
859- sizeX , sizeY , sizeZ , sizeC , sizeT , "" , new DimensionOrder (order ));
860- Path output = writeTestZarr (
861- sizeT , sizeC , sizeZ , sizeY , sizeX , "int32" , resolutions , order );
862- String reverse_order = new StringBuilder (order ).reverse ().toString ();
838+ null , null , sizeX , sizeY , sizeZ , sizeC , sizeT , "" , new DimensionOrder (order ));
839+
840+ Path output = tmpDir .getRoot ().toPath ().resolve ("test.zarr" );
841+ new TestZarr ()
842+ .setPath (output )
843+ .setOverwrite (true )
844+ .setSizeX (sizeX )
845+ .setSizeY (sizeY )
846+ .setSizeZ (sizeZ )
847+ .setSizeT (sizeT )
848+ .setSizeC (sizeC )
849+ .setOrder (rev_order )
850+ .setDataType (com .bc .zarr .DataType .i4 ) // getStack expects int32
851+ .init ()
852+ .createImage ()
853+ .createMetadata ();
854+
863855 try (ZarrPixelBuffer zpbuf =
864856 createPixelBuffer (pixels , output .resolve ("0" ), sizeX , sizeY )) {
865857 for (int t = 0 ; t < sizeT ; t ++) {
@@ -869,14 +861,14 @@ null, new PixelsType(PixelsType.VALUE_INT32),
869861 // Assert stack
870862 byte [] stack = zpbuf .getStack (c , t ).getData ().array ();
871863 byte [] stackFromTimepoint =
872- getStack (timepoint , c , sizeC , sizeZ , sizeX , sizeY , reverse_order );
864+ getStack (timepoint , c , sizeC , sizeZ , sizeX , sizeY , rev_order );
873865 Assert .assertArrayEquals (stack , stackFromTimepoint );
874866 for (int z = 0 ; z < sizeZ ; z ++) {
875867 // Assert plane
876868 byte [] plane =
877869 zpbuf .getPlane (z , c , t ).getData ().array ();
878870 byte [] planeFromStack =
879- getPlane (stack , z , sizeZ , sizeX , sizeY );
871+ getPlane (stack , z , sizeZ , sizeX , sizeY , rev_order );
880872 Assert .assertArrayEquals (plane , planeFromStack );
881873 // Assert row
882874 int y = sizeY / 2 ;
@@ -898,37 +890,7 @@ null, new PixelsType(PixelsType.VALUE_INT32),
898890 }
899891
900892 @ Test
901- public void testNonDefaultAxes ()
902- throws IOException , InvalidRangeException {
903- int sizeT = 1 ;
904- int sizeC = 2 ;
905- int sizeZ = 16 ;
906- int sizeY = 256 ;
907- int sizeX = 512 ;
908- int resolutions = 1 ;
909- String order = DimensionOrder .VALUE_XYCTZ ; // Default: TCZYX -> XYZCT
910- Pixels pixels = new Pixels (
911- null , null , sizeX , sizeY , sizeZ , sizeC , sizeT , "" , new DimensionOrder (order ));
912- Path output = writeTestZarr (
913- sizeT , sizeC , sizeZ , sizeY , sizeX , "uint8" , resolutions , order );
914- try (ZarrPixelBuffer zpbuf =
915- createPixelBuffer (pixels , output .resolve ("0" ), sizeX , sizeY )) {
916- Map <Axis , Integer > axes = zpbuf .getAxesOrder ();
917- Assert .assertEquals (0 , axes .get (Axis .Z ).intValue ());
918- Assert .assertEquals (1 , axes .get (Axis .T ).intValue ());
919- Assert .assertEquals (2 , axes .get (Axis .C ).intValue ());
920- Assert .assertEquals (3 , axes .get (Axis .Y ).intValue ());
921- Assert .assertEquals (4 , axes .get (Axis .X ).intValue ());
922- Assert .assertEquals (sizeT , zpbuf .getSizeT ());
923- Assert .assertEquals (sizeC , zpbuf .getSizeC ());
924- Assert .assertEquals (sizeZ , zpbuf .getSizeZ ());
925- Assert .assertEquals (sizeY , zpbuf .getSizeY ());
926- Assert .assertEquals (sizeX , zpbuf .getSizeX ());
927- }
928- }
929-
930- @ Test
931- public void testDefaultAxes ()
893+ public void test_default_order ()
932894 throws IOException , InvalidRangeException {
933895 // Check that if access are not in the file it defaults to TCZYX order when no axes found
934896
@@ -1000,6 +962,64 @@ public void test_XY() throws IOException, InvalidRangeException {
1000962 testDimensions (512 , 1024 , 0 , 0 , 0 );
1001963 }
1002964
965+ @ Test
966+ public void test_Order_XYCTZ () throws IOException , InvalidRangeException {
967+ testOrder (DimensionOrder .VALUE_XYCTZ );
968+ }
969+
970+ @ Test
971+ public void test_Order_XYCZT () throws IOException , InvalidRangeException {
972+ testOrder (DimensionOrder .VALUE_XYCZT );
973+ }
974+
975+ @ Test
976+ public void test_Order_XYTCZ () throws IOException , InvalidRangeException {
977+ testOrder (DimensionOrder .VALUE_XYTCZ );
978+ }
979+
980+ @ Test
981+ public void test_Order_XYTZC () throws IOException , InvalidRangeException {
982+ testOrder (DimensionOrder .VALUE_XYTZC );
983+ }
984+
985+ @ Test
986+ public void test_Order_XYZCT () throws IOException , InvalidRangeException {
987+ testOrder (DimensionOrder .VALUE_XYZCT );
988+ }
989+
990+ @ Test
991+ public void test_Order_XYZTC () throws IOException , InvalidRangeException {
992+ testOrder (DimensionOrder .VALUE_XYZTC );
993+ }
994+
995+ private void testOrder (String order ) throws IOException , InvalidRangeException {
996+ Path testZarrPath = tmpDir .getRoot ().toPath ().resolve ("test.zarr" );
997+ TestZarr testZarr = new TestZarr ()
998+ .setPath (testZarrPath )
999+ .setOrder (new StringBuilder (order ).reverse ().toString ())
1000+ .init ()
1001+ .createImage ()
1002+ .createMetadata ();
1003+
1004+ Pixels pixels = new Pixels (
1005+ null , null , testZarr .getSizeX (), testZarr .getSizeY (), testZarr .getSizeZ (), testZarr .getSizeC (), testZarr .getSizeT (), "" , new DimensionOrder (order ));
1006+
1007+ try (ZarrPixelBuffer zpbuf =
1008+ createPixelBuffer (pixels , testZarrPath .resolve ("0" ), testZarr .getSizeX (), testZarr .getSizeY ())) {
1009+ Map <Axis , Integer > axes = zpbuf .getAxesOrder ();
1010+ Assert .assertEquals (4 - order .indexOf ("Z" ), axes .get (Axis .Z ).intValue ());
1011+ Assert .assertEquals (4 - order .indexOf ("T" ), axes .get (Axis .T ).intValue ());
1012+ Assert .assertEquals (4 - order .indexOf ("C" ), axes .get (Axis .C ).intValue ());
1013+ Assert .assertEquals (4 - order .indexOf ("Y" ), axes .get (Axis .Y ).intValue ());
1014+ Assert .assertEquals (4 - order .indexOf ("X" ), axes .get (Axis .X ).intValue ());
1015+ Assert .assertEquals (testZarr .getSizeT (), zpbuf .getSizeT ());
1016+ Assert .assertEquals (testZarr .getSizeC (), zpbuf .getSizeC ());
1017+ Assert .assertEquals (testZarr .getSizeZ (), zpbuf .getSizeZ ());
1018+ Assert .assertEquals (testZarr .getSizeY (), zpbuf .getSizeY ());
1019+ Assert .assertEquals (testZarr .getSizeX (), zpbuf .getSizeX ());
1020+ }
1021+ }
1022+
10031023 private void testDimensions (int sizeX , int sizeY , int sizeZ , int sizeC , int sizeT ) throws IOException , InvalidRangeException {
10041024 int textX = 10 ;
10051025 int textY = 10 ;
0 commit comments