use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class FormatReaderTest method testEmissionWavelengths.
@Test(groups = { "all", "fast", "automated" })
public void testEmissionWavelengths() {
if (config == null)
throw new SkipException("No config tree");
String testName = "EmissionWavelengths";
if (!initFile())
result(testName, false, "initFile");
IMetadata retrieve = (IMetadata) reader.getMetadataStore();
for (int i = 0; i < reader.getSeriesCount(); i++) {
config.setSeries(i);
for (int c = 0; c < config.getChannelCount(); c++) {
Length realWavelength = retrieve.getChannelEmissionWavelength(i, c);
Length expectedWavelength = config.getEmissionWavelength(c);
if (realWavelength == null && expectedWavelength == null) {
continue;
}
if (!isAlmostEqual(expectedWavelength, realWavelength)) {
result(testName, false, "Series " + i + " channel " + c + " (expected " + expectedWavelength + ", actual " + realWavelength + ")");
}
}
}
result(testName, true);
}
use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class FormatReaderTest method testChannelNames.
@Test(groups = { "all", "fast", "automated" })
public void testChannelNames() {
if (config == null)
throw new SkipException("No config tree");
String testName = "ChannelNames";
if (!initFile())
result(testName, false, "initFile");
IMetadata retrieve = (IMetadata) reader.getMetadataStore();
for (int i = 0; i < reader.getSeriesCount(); i++) {
config.setSeries(i);
for (int c = 0; c < config.getChannelCount(); c++) {
String realName = retrieve.getChannelName(i, c);
String expectedName = config.getChannelName(c);
if (!expectedName.equals(realName) && (realName == null && !expectedName.equals("null"))) {
result(testName, false, "Series " + i + " channel " + c + " (got '" + realName + "', expected '" + expectedName + "')");
}
}
}
result(testName, true);
}
use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class FormatReaderTest method testPhysicalSizeX.
@Test(groups = { "all", "fast", "automated" })
public void testPhysicalSizeX() {
if (config == null)
throw new SkipException("No config tree");
String testName = "PhysicalSizeX";
if (!initFile())
result(testName, false, "initFile");
IMetadata retrieve = (IMetadata) reader.getMetadataStore();
for (int i = 0; i < reader.getSeriesCount(); i++) {
config.setSeries(i);
Length expectedSize = config.getPhysicalSizeX();
Length realSize = retrieve.getPixelsPhysicalSizeX(i);
if (!isAlmostEqual(realSize, expectedSize)) {
result(testName, false, "Series " + i + " (expected " + expectedSize + ", actual " + realSize + ")");
}
}
result(testName, true);
}
use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class FormatReaderTest method testExcitationWavelengths.
@Test(groups = { "all", "fast", "automated" })
public void testExcitationWavelengths() {
if (config == null)
throw new SkipException("No config tree");
String testName = "ExcitationWavelengths";
if (!initFile())
result(testName, false, "initFile");
IMetadata retrieve = (IMetadata) reader.getMetadataStore();
for (int i = 0; i < reader.getSeriesCount(); i++) {
config.setSeries(i);
for (int c = 0; c < config.getChannelCount(); c++) {
Length realWavelength = retrieve.getChannelExcitationWavelength(i, c);
Length expectedWavelength = config.getExcitationWavelength(c);
if (!isAlmostEqual(expectedWavelength, realWavelength)) {
result(testName, false, "Series " + i + " channel " + c + " (expected " + expectedWavelength + ", actual " + realWavelength + ")");
}
}
}
result(testName, true);
}
use of loci.formats.meta.IMetadata in project bioformats by openmicroscopy.
the class FormatWriterTest method testWriterConsistency.
// -- Tests --
@Test(groups = { "all" }, dataProvider = "getWriterList")
public void testWriterConsistency(IFormatWriter writer) {
String testName = TestTools.shortClassName(writer) + " " + writer.getCompression() + " testWriterConsistency";
boolean success = true;
String msg = null;
try {
reader.close();
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
reader.setMetadataStore(service.createOMEXMLMetadata());
reader.setId(id);
int type = reader.getPixelType();
if (!writer.isSupportedType(type)) {
success = true;
result(testName, success, msg);
return;
}
config = configTree.get(id);
String prefix = id.substring(id.lastIndexOf(File.separator) + 1, id.lastIndexOf("."));
// will throw an exception
while (prefix.length() < 3) prefix = "x" + prefix;
String suffix = "." + writer.getSuffixes()[0];
File tmpFile = File.createTempFile(prefix, suffix);
tmpFile.deleteOnExit();
String convertedFile = tmpFile.getAbsolutePath();
IMetadata meta = (IMetadata) reader.getMetadataStore();
writer.close();
writer.setMetadataRetrieve((MetadataRetrieve) meta);
// convert the input file
writer.setId(convertedFile);
int seriesCount = writer.canDoStacks() ? reader.getSeriesCount() : 1;
for (int series = 0; series < seriesCount; series++) {
reader.setSeries(series);
writer.setSeries(series);
int imageCount = writer.canDoStacks() ? reader.getImageCount() : 1;
for (int image = 0; image < imageCount; image++) {
writer.saveBytes(image, reader.openBytes(image));
}
}
writer.close();
// verify that the dimensions are accurate
convertedReader.setId(convertedFile);
boolean seriesMatch = convertedReader.getSeriesCount() == config.getSeriesCount();
boolean expectRGB = config.isRGB();
int expectedCount = config.getSizeZ() * config.getSizeT() * (expectRGB ? 1 : config.getSizeC());
boolean imageMatch = convertedReader.getImageCount() == expectedCount;
if (!seriesMatch && writer.canDoStacks()) {
int totalImages = 0;
for (int i = 0; i < reader.getSeriesCount(); i++) {
reader.setSeries(i);
totalImages += reader.getImageCount();
}
reader.setSeries(0);
if (convertedReader.getImageCount() != totalImages) {
success = false;
msg = "Series counts do not match (found " + convertedReader.getSeriesCount() + ", expected " + config.getSeriesCount() + ")";
} else
imageMatch = true;
}
if (success) {
for (int series = 0; series < seriesCount; series++) {
if (series >= convertedReader.getSeriesCount()) {
break;
}
convertedReader.setSeries(series);
config.setSeries(series);
int expectedX = config.getSizeX();
int expectedY = config.getSizeY();
expectRGB = config.isRGB();
if (TestTools.shortClassName(writer).equals("OMEXMLWriter")) {
expectRGB = false;
} else if (TestTools.shortClassName(writer).equals("JPEGWriter")) {
expectRGB = expectRGB || config.isIndexed();
}
int expectedPixelType = FormatTools.pixelTypeFromString(config.getPixelType());
expectedCount = config.getSizeZ() * config.getSizeT() * (expectRGB ? 1 : config.getSizeC());
String expectedMD5 = config.getMD5();
int x = convertedReader.getSizeX();
int y = convertedReader.getSizeY();
int count = convertedReader.getImageCount();
boolean rgb = convertedReader.isRGB();
int pixelType = convertedReader.getPixelType();
boolean isQuicktime = TestTools.shortClassName(writer).equals("QTWriter");
String md5 = TestTools.md5(convertedReader.openBytes(0));
if (msg == null)
msg = checkMismatch(x, expectedX, series, "X");
if (msg == null)
msg = checkMismatch(y, expectedY, series, "Y");
if (msg == null && writer.canDoStacks() && !imageMatch) {
msg = checkMismatch(count, expectedCount, series, "Image count");
}
if (msg == null && !isQuicktime) {
msg = checkMismatch(rgb, expectRGB, series, "RGB");
}
if (msg == null && !isQuicktime) {
msg = checkMismatch(pixelType, expectedPixelType, series, "Pixel type");
}
if (msg == null && isLosslessWriter(writer) && config.isRGB() == expectRGB) {
msg = checkMismatch(md5, expectedMD5, series, "Pixels hash");
}
success = msg == null;
if (!success)
break;
}
}
convertedReader.close();
} catch (Throwable t) {
LOGGER.info("", t);
success = false;
}
result(testName, success, msg);
}
Aggregations