Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for image names when resolutions are not flattened #4114

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 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 = "Alternate_Name";
sbesson marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -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 {
Expand All @@ -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));

Expand Down Expand Up @@ -649,7 +657,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