Skip to content

Commit

Permalink
Merge pull request #4114 from melissalinkert/image-name-test
Browse files Browse the repository at this point in the history
Add test for image names when resolutions are not flattened
  • Loading branch information
dgault committed Jan 10, 2024
2 parents 404da56 + 46a435f commit ff12362
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 13 deletions.
34 changes: 22 additions & 12 deletions components/test-suite/src/loci/tests/testng/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = "Unflattened_Name";
private static final String DESCRIPTION = "Description";
private static final String SERIES_COUNT = "series_count";
private static final String RESOLUTION_COUNT = "resolution_count";
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -548,17 +554,16 @@ private void populateINI(IFormatReader reader) {
putTableName(globalTable, reader, " global");

int seriesCount = reader.getSeriesCount();
IFormatReader unflattenedReader = reader;
if (seriesCount > 1) {
unflattenedReader = new ImageReader();
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));

Expand Down Expand Up @@ -649,7 +654,12 @@ else if (r instanceof ReaderWrapper) {
// TODO
}

seriesTable.put(NAME, retrieve.getImageName(index));
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<resolutionReader.getSeriesCount() && success; i++) {
config.setSeries(i, false);

String realName = retrieve.getImageName(i);
String expectedName = config.getImageName();

if (!isEqual(expectedName, realName)) {
String unflattenedName = config.getUnflattenedImageName();
if (!isEqual(unflattenedName, realName)) {
msg = "Series " + i + " (got '" + realName +
"', expected '" + expectedName + "' or '" + unflattenedName + "')";
success = false;
}
}
}
}
finally {
try {
resolutionReader.close();
}
catch (IOException e) {
success = false;
msg = "Could not close reader";
}
}
result(testName, success, msg);
}

@Test(groups = {"all", "fast", "automated"})
public void testImageDescriptions() {
if (config == null) throw new SkipException("No config tree");
Expand Down

0 comments on commit ff12362

Please sign in to comment.