Search in sources :

Example 16 with IMetadata

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);
}
Also used : IMetadata(loci.formats.meta.IMetadata) Length(ome.units.quantity.Length) SkipException(org.testng.SkipException) Test(org.testng.annotations.Test)

Example 17 with IMetadata

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);
}
Also used : IMetadata(loci.formats.meta.IMetadata) SkipException(org.testng.SkipException) Test(org.testng.annotations.Test)

Example 18 with IMetadata

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);
}
Also used : IMetadata(loci.formats.meta.IMetadata) Length(ome.units.quantity.Length) SkipException(org.testng.SkipException) Test(org.testng.annotations.Test)

Example 19 with IMetadata

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);
}
Also used : IMetadata(loci.formats.meta.IMetadata) Length(ome.units.quantity.Length) SkipException(org.testng.SkipException) Test(org.testng.annotations.Test)

Example 20 with IMetadata

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);
}
Also used : IMetadata(loci.formats.meta.IMetadata) ServiceFactory(loci.common.services.ServiceFactory) File(java.io.File) OMEXMLService(loci.formats.services.OMEXMLService) Test(org.testng.annotations.Test)

Aggregations

IMetadata (loci.formats.meta.IMetadata)62 ServiceFactory (loci.common.services.ServiceFactory)35 OMEXMLService (loci.formats.services.OMEXMLService)35 FormatException (loci.formats.FormatException)19 ImageReader (loci.formats.ImageReader)19 ServiceException (loci.common.services.ServiceException)17 Test (org.testng.annotations.Test)17 DependencyException (loci.common.services.DependencyException)15 SkipException (org.testng.SkipException)15 Length (ome.units.quantity.Length)13 IOException (java.io.IOException)9 ImageWriter (loci.formats.ImageWriter)6 Time (ome.units.quantity.Time)6 PositiveInteger (ome.xml.model.primitives.PositiveInteger)6 File (java.io.File)5 IFormatReader (loci.formats.IFormatReader)5 IFormatWriter (loci.formats.IFormatWriter)5 OMETiffWriter (loci.formats.out.OMETiffWriter)5 TiffWriter (loci.formats.out.TiffWriter)5 EnumerationException (ome.xml.model.enums.EnumerationException)4