From 2de69681aabaeda8bf90357cd29459fc99746ec6 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Tue, 7 Nov 2023 16:32:37 -0600 Subject: [PATCH 1/4] Add a test for the image names reported when resolutions are not flattened Some readers report noticeably different image names based on the resolution flattening setting. This allows an alternate image name to be configured, so that both sets of image names can be checked for regressions. --- .../src/loci/tests/testng/Configuration.java | 11 ++++- .../loci/tests/testng/FormatReaderTest.java | 47 ++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/components/test-suite/src/loci/tests/testng/Configuration.java b/components/test-suite/src/loci/tests/testng/Configuration.java index efb2b391b88..2642edb1a30 100644 --- a/components/test-suite/src/loci/tests/testng/Configuration.java +++ b/components/test-suite/src/loci/tests/testng/Configuration.java @@ -42,8 +42,9 @@ import loci.formats.FormatTools; import loci.formats.IFormatReader; import loci.formats.ImageReader; -import loci.formats.in.DynamicMetadataOptions; +import loci.formats.MetadataTools; import loci.formats.ReaderWrapper; +import loci.formats.in.DynamicMetadataOptions; import loci.formats.meta.IMetadata; import ome.xml.model.primitives.PositiveInteger; @@ -108,6 +109,7 @@ public class Configuration { private static final String EXCITATION_WAVELENGTH_UNIT = "ExcitationWavelengthUnit_"; private static final String DETECTOR = "Detector_"; private static final String NAME = "Name"; + private static final String UNFLATTENED_NAME = "Alternate_Name"; private static final String DESCRIPTION = "Description"; private static final String SERIES_COUNT = "series_count"; private static final String RESOLUTION_COUNT = "resolution_count"; @@ -418,6 +420,10 @@ public String getImageName() { return currentTable.get(NAME); } + public String getUnflattenedImageName() { + return currentTable.get(UNFLATTENED_NAME); + } + public boolean hasImageDescription() { return currentTable.containsKey(DESCRIPTION); } @@ -551,6 +557,7 @@ private void populateINI(IFormatReader reader) { IFormatReader unflattenedReader = reader; if (seriesCount > 1) { unflattenedReader = new ImageReader(); + unflattenedReader.setMetadataStore(MetadataTools.createOMEXMLMetadata()); unflattenedReader.setFlattenedResolutions(false); unflattenedReader.setMetadataOptions(new DynamicMetadataOptions()); try { @@ -559,6 +566,7 @@ private void populateINI(IFormatReader reader) { catch (FormatException | IOException e) { } seriesCount = unflattenedReader.getSeriesCount(); } + IMetadata unflattenedRetrieve = (IMetadata) unflattenedReader.getMetadataStore(); globalTable.put(SERIES_COUNT, String.valueOf(seriesCount)); @@ -650,6 +658,7 @@ else if (r instanceof ReaderWrapper) { } seriesTable.put(NAME, retrieve.getImageName(index)); + seriesTable.put(UNFLATTENED_NAME, unflattenedRetrieve.getImageName(series)); seriesTable.put(DESCRIPTION, retrieve.getImageDescription(index)); Length physicalX = retrieve.getPixelsPhysicalSizeX(index); diff --git a/components/test-suite/src/loci/tests/testng/FormatReaderTest.java b/components/test-suite/src/loci/tests/testng/FormatReaderTest.java index b0d1219a212..a7b91ab8b9b 100644 --- a/components/test-suite/src/loci/tests/testng/FormatReaderTest.java +++ b/components/test-suite/src/loci/tests/testng/FormatReaderTest.java @@ -963,7 +963,7 @@ private boolean isEqual(String expected, String real) { if (expected == null && real == null) { return true; - } else if (expected.equals("null") && real == null) { + } else if ("null".equals(expected) && real == null) { return true; } else if (expected == null) { return false; @@ -1421,6 +1421,51 @@ public void testImageNames() { result(testName, true); } + @Test(groups = {"all", "fast", "automated"}) + public void testUnflattenedImageNames() { + if (config == null) throw new SkipException("No config tree"); + String testName = "testUnflattenedImageNames"; + if (!initFile()) result(testName, false, "initFile"); + + boolean success = true; + String msg = null; + IFormatReader resolutionReader = setupReader(false, true); + try { + IMetadata retrieve = (IMetadata) resolutionReader.getMetadataStore(); + + if (resolutionReader.getSeriesCount() != config.getSeriesCount(false)) { + success = false; + msg = "incorrect unflattened series count"; + } + + for (int i=0; i Date: Fri, 10 Nov 2023 11:13:54 -0600 Subject: [PATCH 2/4] Only set the alternate (unflattened) image name if it is different --- .../test-suite/src/loci/tests/testng/Configuration.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/test-suite/src/loci/tests/testng/Configuration.java b/components/test-suite/src/loci/tests/testng/Configuration.java index 2642edb1a30..80bd577aada 100644 --- a/components/test-suite/src/loci/tests/testng/Configuration.java +++ b/components/test-suite/src/loci/tests/testng/Configuration.java @@ -657,8 +657,12 @@ else if (r instanceof ReaderWrapper) { // TODO } - seriesTable.put(NAME, retrieve.getImageName(index)); - seriesTable.put(UNFLATTENED_NAME, unflattenedRetrieve.getImageName(series)); + String flattenedName = retrieve.getImageName(index); + seriesTable.put(NAME, flattenedName); + String unflattenedName = unflattenedRetrieve.getImageName(series); + if ((flattenedName == null && unflattenedName != null) || !flattenedName.equals(unflattenedName)) { + seriesTable.put(UNFLATTENED_NAME, unflattenedName); + } seriesTable.put(DESCRIPTION, retrieve.getImageDescription(index)); Length physicalX = retrieve.getPixelsPhysicalSizeX(index); From 7ed65ecdbcb4391e86a508382c1e92885c7127c5 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Fri, 15 Dec 2023 15:52:20 -0600 Subject: [PATCH 3/4] Rename unflattened image name attribute --- components/test-suite/src/loci/tests/testng/Configuration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/test-suite/src/loci/tests/testng/Configuration.java b/components/test-suite/src/loci/tests/testng/Configuration.java index 80bd577aada..8eed09dd8f0 100644 --- a/components/test-suite/src/loci/tests/testng/Configuration.java +++ b/components/test-suite/src/loci/tests/testng/Configuration.java @@ -109,7 +109,7 @@ public class Configuration { private static final String EXCITATION_WAVELENGTH_UNIT = "ExcitationWavelengthUnit_"; private static final String DETECTOR = "Detector_"; private static final String NAME = "Name"; - private static final String UNFLATTENED_NAME = "Alternate_Name"; + private static final String UNFLATTENED_NAME = "Unflattened_Name"; private static final String DESCRIPTION = "Description"; private static final String SERIES_COUNT = "series_count"; private static final String RESOLUTION_COUNT = "resolution_count"; From 46a435fe4f928d8b8c2fc4a0cb4ef378b50d8ece Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Sat, 23 Dec 2023 19:00:45 -0600 Subject: [PATCH 4/4] Fix unflattened name configuration for single-series datasets --- .../src/loci/tests/testng/Configuration.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/components/test-suite/src/loci/tests/testng/Configuration.java b/components/test-suite/src/loci/tests/testng/Configuration.java index 8eed09dd8f0..6a4b26d35a4 100644 --- a/components/test-suite/src/loci/tests/testng/Configuration.java +++ b/components/test-suite/src/loci/tests/testng/Configuration.java @@ -554,18 +554,15 @@ private void populateINI(IFormatReader reader) { putTableName(globalTable, reader, " global"); int seriesCount = reader.getSeriesCount(); - IFormatReader unflattenedReader = reader; - if (seriesCount > 1) { - unflattenedReader = new ImageReader(); - unflattenedReader.setMetadataStore(MetadataTools.createOMEXMLMetadata()); - unflattenedReader.setFlattenedResolutions(false); - unflattenedReader.setMetadataOptions(new DynamicMetadataOptions()); - try { - unflattenedReader.setId(reader.getCurrentFile()); - } - catch (FormatException | IOException e) { } - seriesCount = unflattenedReader.getSeriesCount(); + IFormatReader unflattenedReader = new ImageReader(); + unflattenedReader.setMetadataStore(MetadataTools.createOMEXMLMetadata()); + unflattenedReader.setFlattenedResolutions(false); + unflattenedReader.setMetadataOptions(new DynamicMetadataOptions()); + try { + unflattenedReader.setId(reader.getCurrentFile()); } + catch (FormatException | IOException e) { } + seriesCount = unflattenedReader.getSeriesCount(); IMetadata unflattenedRetrieve = (IMetadata) unflattenedReader.getMetadataStore(); globalTable.put(SERIES_COUNT, String.valueOf(seriesCount));