@@ -55,6 +55,71 @@ public class PyramidSeries {
5555 /** Description of each resolution in the pyramid. */
5656 List <ResolutionDescriptor > resolutions ;
5757
58+ /** Axes in the underlying array, in order. */
59+ ArrayList <String > axes = new ArrayList <String >();
60+
61+ /**
62+ * Add named axis to ordered list of axes in this resolution.
63+ * Names are stored as upper-case only.
64+ *
65+ * @param axis name e.g. "x"
66+ */
67+ public void addAxis (String axis ) {
68+ axes .add (axis .toUpperCase ());
69+ }
70+
71+ /**
72+ * Find the index in the ordered list of the named axis.
73+ *
74+ * @param axis name e.g. "x"
75+ * @return index into list of axes
76+ */
77+ public int getIndex (String axis ) {
78+ return axes .indexOf (axis .toUpperCase ());
79+ }
80+
81+ /**
82+ * Create an indexing array (e.g. shape or offset) for this resolution,
83+ * which represents the given 5D values.
84+ * Since the resolution's underlying array may have less than 5 dimensions,
85+ * this is mapping from the 5D space of the OME data model to the
86+ * ND space of this resolution's array.
87+ *
88+ * @param ti T index
89+ * @param ci C index
90+ * @param zi Z index
91+ * @param yi Y index
92+ * @param xi X index
93+ * @return array representing the given indexes, in this resolution's
94+ * dimensional space
95+ */
96+ public int [] getArray (int ti , int ci , int zi , int yi , int xi ) {
97+ int [] returnArray = new int [axes .size ()];
98+ for (int i =0 ; i <axes .size (); i ++) {
99+ char axis = axes .get (i ).charAt (0 );
100+ switch (axis ) {
101+ case 'X' :
102+ returnArray [i ] = xi ;
103+ break ;
104+ case 'Y' :
105+ returnArray [i ] = yi ;
106+ break ;
107+ case 'Z' :
108+ returnArray [i ] = zi ;
109+ break ;
110+ case 'C' :
111+ returnArray [i ] = ci ;
112+ break ;
113+ case 'T' :
114+ returnArray [i ] = ti ;
115+ break ;
116+ default :
117+ throw new IllegalArgumentException ("Unexpected axis: " + axis );
118+ }
119+ }
120+ return returnArray ;
121+ }
122+
58123 /**
59124 * Calculate image width and height for each resolution.
60125 * Uses the first tile in the resolution to find the tile size.
@@ -71,9 +136,22 @@ public void describePyramid(ZarrGroup reader, OMEPyramidStore metadata)
71136 (List <Map <String , Object >>) reader .openSubGroup (path ).getAttributes ().get (
72137 "multiscales" );
73138 Map <String , Object > multiscale = multiscales .get (0 );
74- List <Map <String , Object >> axes = null ;
139+ List <Map <String , Object >> storedAxes = null ;
75140 if (multiscales != null ) {
76- axes = (List <Map <String , Object >>) multiscale .get ("axes" );
141+ storedAxes = (List <Map <String , Object >>) multiscale .get ("axes" );
142+ }
143+
144+ if (storedAxes != null ) {
145+ for (Map <String , Object > axis : storedAxes ) {
146+ addAxis (axis .get ("name" ).toString ());
147+ }
148+ }
149+ else {
150+ addAxis ("T" );
151+ addAxis ("C" );
152+ addAxis ("Z" );
153+ addAxis ("Y" );
154+ addAxis ("X" );
77155 }
78156
79157 resolutions = new ArrayList <ResolutionDescriptor >();
@@ -82,25 +160,12 @@ public void describePyramid(ZarrGroup reader, OMEPyramidStore metadata)
82160 descriptor .resolutionNumber = resolution ;
83161 descriptor .path = path + "/" + resolution ;
84162
85- if (axes != null ) {
86- for (Map <String , Object > axis : axes ) {
87- descriptor .addAxis (axis .get ("name" ).toString ());
88- }
89- }
90- else {
91- descriptor .addAxis ("T" );
92- descriptor .addAxis ("C" );
93- descriptor .addAxis ("Z" );
94- descriptor .addAxis ("Y" );
95- descriptor .addAxis ("X" );
96- }
97-
98163 ZarrArray array = reader .openArray (descriptor .path );
99164 int [] dimensions = array .getShape ();
100165 int [] blockSizes = array .getChunks ();
101166
102- int xIndex = descriptor . getIndex ("X" );
103- int yIndex = descriptor . getIndex ("Y" );
167+ int xIndex = getIndex ("X" );
168+ int yIndex = getIndex ("Y" );
104169
105170 descriptor .sizeX = dimensions [xIndex ];
106171 descriptor .sizeY = dimensions [yIndex ];
@@ -147,7 +212,7 @@ public void describePyramid(ZarrGroup reader, OMEPyramidStore metadata)
147212 // dimensionLengths is in ZCT order, independent of dimensionOrder
148213 // the two orders may be different if the --rgb flag was used
149214 String axis = "ZCT" .substring (i , i + 1 );
150- int axisIndex = descriptor . getIndex (axis );
215+ int axisIndex = getIndex (axis );
151216 LOG .debug ("Checking axis {} with index {}, position {}" ,
152217 axis , axisIndex , i );
153218
0 commit comments