Skip to content

Commit 11581a5

Browse files
Add group path to series index mapping in root attributes
Fixes glencoesoftware#126. The root level attributes (if they are written) will now contain a "groups" dictionary that maps each group with multiscales metadata to the corresponding Bio-Formats series index (== Image index in METADATA.ome.xml).
1 parent 34b6842 commit 11581a5

File tree

2 files changed

+77
-8
lines changed

2 files changed

+77
-8
lines changed

src/main/java/com/glencoesoftware/bioformats2raw/Converter.java

+26-8
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,32 @@ public void convert()
665665
scaleFormatString = "%s/%s/%d/%d";
666666
}
667667

668+
// fileset level metadata
669+
if (!noRootGroup) {
670+
final ZarrGroup root = ZarrGroup.create(getRootPath());
671+
Map<String, Object> attributes = new HashMap<String, Object>();
672+
attributes.put("bioformats2raw.layout", LAYOUT);
673+
674+
// record the path to each series (multiscales) and the corresponding
675+
// series (OME-XML Image) index
676+
// using the index as the key would mean that the index is stored
677+
// as a string instead of an integer
678+
Map<String, Integer> groupMap = new HashMap<String, Integer>();
679+
for (Integer index : seriesList) {
680+
String resolutionString = String.format(
681+
scaleFormatString, getScaleFormatStringArgs(index, 0));
682+
String seriesString = "";
683+
if (resolutionString.indexOf('/') >= 0) {
684+
seriesString = resolutionString.substring(0,
685+
resolutionString.lastIndexOf('/'));
686+
}
687+
groupMap.put(seriesString, index);
688+
}
689+
attributes.put("groups", groupMap);
690+
691+
root.writeAttributes(attributes);
692+
}
693+
668694
for (Integer index : seriesList) {
669695
try {
670696
write(index);
@@ -1215,14 +1241,6 @@ public void saveResolutions(int series)
12151241
sizeX, tileWidth, sizeY, tileHeight, sizeZ, chunkDepth, imageCount
12161242
);
12171243

1218-
// fileset level metadata
1219-
if (!noRootGroup) {
1220-
final ZarrGroup root = ZarrGroup.create(getRootPath());
1221-
Map<String, Object> attributes = new HashMap<String, Object>();
1222-
attributes.put("bioformats2raw.layout", LAYOUT);
1223-
root.writeAttributes(attributes);
1224-
}
1225-
12261244
// series level metadata
12271245
setSeriesLevelMetadata(series, resolutions);
12281246

src/test/java/com/glencoesoftware/bioformats2raw/test/ZarrTest.java

+51
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ public void testAdditionalScaleFormatStringArgs() throws Exception {
210210
series0.openArray("0");
211211
series0 = ZarrGroup.open(output.resolve("ghi/999/1").toString());
212212
series0.openArray("0");
213+
214+
ZarrGroup z = ZarrGroup.open(output.toString());
215+
Map<String, Integer> groupMap =
216+
(Map<String, Integer>) z.getAttributes().get("groups");
217+
assertEquals(groupMap.size(), 2);
218+
assertEquals(groupMap.get("abc/888/0"), 0);
219+
assertEquals(groupMap.get("ghi/999/1"), 1);
213220
}
214221

215222
/**
@@ -240,6 +247,12 @@ public void testDefaultLayoutIsSetAndIsNested() throws Exception {
240247
ZarrGroup z = ZarrGroup.open(output.toString());
241248
Integer layout = (Integer)
242249
z.getAttributes().get("bioformats2raw.layout");
250+
251+
Map<String, Integer> groupMap =
252+
(Map<String, Integer>) z.getAttributes().get("groups");
253+
assertEquals(groupMap.size(), 1);
254+
assertEquals(groupMap.get("0"), 0);
255+
243256
ZarrArray series0 = ZarrGroup.open(output.resolve("0")).openArray("0");
244257

245258
// no getter for DimensionSeparator in ZarrArray
@@ -428,6 +441,12 @@ public void testMultiSeries() throws Exception {
428441
assertTool();
429442
ZarrGroup z = ZarrGroup.open(output.toString());
430443

444+
Map<String, Integer> groupMap =
445+
(Map<String, Integer>) z.getAttributes().get("groups");
446+
assertEquals(groupMap.size(), 2);
447+
assertEquals(groupMap.get("0"), 0);
448+
assertEquals(groupMap.get("1"), 1);
449+
431450
// Check series 0 dimensions and special pixels
432451
ZarrArray series0 = z.openArray("0/0");
433452
assertArrayEquals(new int[] {1, 1, 1, 512, 512}, series0.getShape());
@@ -461,6 +480,10 @@ public void testSingleBeginningSeries() throws Exception {
461480
input = fake("series", "2");
462481
assertTool("-s", "0");
463482
ZarrGroup z = ZarrGroup.open(output.toString());
483+
Map<String, Integer> groupMap =
484+
(Map<String, Integer>) z.getAttributes().get("groups");
485+
assertEquals(groupMap.size(), 1);
486+
assertEquals(groupMap.get("0"), 0);
464487

465488
// Check series 0 dimensions and special pixels
466489
ZarrArray series0 = z.openArray("0/0");
@@ -488,6 +511,10 @@ public void testSingleEndSeries() throws Exception {
488511
input = fake("series", "2");
489512
assertTool("-s", "1");
490513
ZarrGroup z = ZarrGroup.open(output.toString());
514+
Map<String, Integer> groupMap =
515+
(Map<String, Integer>) z.getAttributes().get("groups");
516+
assertEquals(groupMap.size(), 1);
517+
assertEquals(groupMap.get("0"), 1);
491518

492519
// Check series 1 dimensions and special pixels
493520
ZarrArray series0 = z.openArray("0/0");
@@ -515,6 +542,10 @@ public void testSingleMiddleSeries() throws Exception {
515542
input = fake("series", "3");
516543
assertTool("-s", "1");
517544
ZarrGroup z = ZarrGroup.open(output.toString());
545+
Map<String, Integer> groupMap =
546+
(Map<String, Integer>) z.getAttributes().get("groups");
547+
assertEquals(groupMap.size(), 1);
548+
assertEquals(groupMap.get("0"), 1);
518549

519550
// Check series 1 dimensions and special pixels
520551
ZarrArray series0 = z.openArray("0/0");
@@ -911,6 +942,12 @@ public void testNoHCSOption() throws Exception {
911942
assertTool("--no-hcs");
912943

913944
ZarrGroup z = ZarrGroup.open(output);
945+
Map<String, Integer> groupMap =
946+
(Map<String, Integer>) z.getAttributes().get("groups");
947+
assertEquals(groupMap.size(), 12);
948+
for (int i=0; i<12; i++) {
949+
assertEquals(groupMap.get(String.valueOf(i)), i);
950+
}
914951

915952
// Check dimensions and block size
916953
ZarrArray series0 = z.openArray("0/0");
@@ -952,6 +989,20 @@ public void testHCSMetadata() throws Exception {
952989
int rowCount = 2;
953990
int colCount = 3;
954991
int fieldCount = 2;
992+
993+
Map<String, Integer> groupMap =
994+
(Map<String, Integer>) z.getAttributes().get("groups");
995+
assertEquals(groupMap.size(), 12);
996+
int index = 0;
997+
for (int r=0; r<rowCount; r++) {
998+
for (int c=0; c<colCount; c++) {
999+
for (int f=0; f<fieldCount; f++) {
1000+
String groupPath = (char) (r + 'A') + "/" + (c + 1) + "/" + f;
1001+
assertEquals(groupMap.get(groupPath), index++);
1002+
}
1003+
}
1004+
}
1005+
9551006
Map<String, List<String>> plateMap = new HashMap<String, List<String>>();
9561007
plateMap.put("A", Arrays.asList("1", "2", "3"));
9571008
plateMap.put("B", Arrays.asList("1", "2", "3"));

0 commit comments

Comments
 (0)