Search in sources :

Example 61 with ImageReader

use of loci.formats.ImageReader in project bioformats by openmicroscopy.

the class TestTools method getFiles.

/**
 * Recursively generate a list of files to test.
 */
public static void getFiles(String root, List files, final ConfigurationTree config, String toplevelConfig, String[] subdirs, String configFileSuffix) {
    Location f = new Location(root);
    String[] subs = f.list();
    if (subs == null)
        subs = new String[0];
    if (subdirs != null) {
        subs = subdirs;
    }
    boolean isToplevel = toplevelConfig != null && new File(toplevelConfig).exists();
    Arrays.sort(subs);
    List<String> subsList = new ArrayList<String>();
    if (config.getConfigDirectory() != null) {
        // Look for a configuration file under the configuration directory
        String configRoot = config.relocateToConfig(root);
        Location configFile = new Location(configRoot, baseConfigName);
        if (configFile.exists()) {
            LOGGER.debug("found config file: {}", configFile.getAbsolutePath());
            subsList.add(configFile.getAbsolutePath());
        }
    }
    // make sure that if a config file exists, it is first on the list
    for (int i = 0; i < subs.length; i++) {
        Location file = new Location(root, subs[i]);
        if ((!isToplevel && isConfigFile(file, configFileSuffix)) || (isToplevel && subs[i].equals(toplevelConfig))) {
            if (config.getConfigDirectory() != null) {
                LOGGER.debug("adding config file: {}", file.getAbsolutePath());
                subsList.add(0, file.getAbsolutePath());
            }
        } else {
            subsList.add(file.getAbsolutePath());
        }
    }
    // special config file for the test suite
    LOGGER.debug("\tconfig file");
    try {
        LOGGER.debug("Parsing {}:", subsList.get(0));
        config.parseConfigFile(subsList.get(0));
    } catch (IOException exc) {
        LOGGER.debug("", exc);
    } catch (Throwable e) {
    }
    Arrays.sort(subs, new Comparator() {

        @Override
        public int compare(Object o1, Object o2) {
            String s1 = o1.toString();
            String s2 = o2.toString();
            Configuration c1 = null;
            Configuration c2 = null;
            try {
                c1 = config.get(s1);
            } catch (IOException e) {
            }
            try {
                c2 = config.get(s2);
            } catch (IOException e) {
            }
            if (c1 == null && c2 != null) {
                return 1;
            } else if (c1 != null && c2 == null) {
                return -1;
            }
            return s1.compareTo(s2);
        }
    });
    ImageReader typeTester = new ImageReader();
    for (int i = 0; i < subsList.size(); i++) {
        Location file = new Location(subsList.get(i));
        LOGGER.debug("Checking {}:", subsList.get(i));
        if (isConfigFile(file, configFileSuffix)) {
            continue;
        } else if (isIgnoredFile(subsList.get(i), config)) {
            LOGGER.debug("\tignored");
            continue;
        } else if (file.isDirectory()) {
            LOGGER.debug("\tdirectory");
            getFiles(subsList.get(i), files, config, null, null, configFileSuffix);
        } else if (!subsList.get(i).endsWith("readme.txt") && !subsList.get(i).endsWith("test_setup.ini")) {
            if (typeTester.isThisType(subsList.get(i))) {
                LOGGER.debug("\tOK");
                files.add(file.getAbsolutePath());
            } else
                LOGGER.debug("\tunknown type");
        }
        file = null;
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) Comparator(java.util.Comparator) ImageReader(loci.formats.ImageReader) File(java.io.File) Location(loci.common.Location)

Example 62 with ImageReader

use of loci.formats.ImageReader in project bioformats by openmicroscopy.

the class SingularityTest method main.

public static void main(String[] args) throws FormatException, IOException {
    if (args.length < 1) {
        LOGGER.info("Usage: java.loci.tests.SingularityTest /path/to/input-file");
        System.exit(1);
    }
    LOGGER.info("Testing {}", args[0]);
    ImageReader reader = new ImageReader();
    boolean isSingleFile = reader.isSingleFile(args[0]);
    reader.setId(args[0]);
    String[] usedFiles = reader.getUsedFiles();
    if (isSingleFile && usedFiles.length > 1) {
        LOGGER.info("  Used files list contains more than one file, " + "but isSingleFile(String) returned true.");
        LOGGER.info("FAILURE");
    } else if (!isSingleFile && usedFiles.length == 1) {
        LOGGER.info("  Used files list only contains one file, " + "but isSingleFile(String) returned false.");
        LOGGER.info("FAILURE");
    } else
        LOGGER.info("SUCCESS");
}
Also used : ImageReader(loci.formats.ImageReader)

Example 63 with ImageReader

use of loci.formats.ImageReader in project bioformats by openmicroscopy.

the class Configuration method populateINI.

// -- Helper methods --
private void populateINI(IFormatReader reader) {
    IMetadata retrieve = (IMetadata) reader.getMetadataStore();
    ini = new IniList();
    IniTable globalTable = new IniTable();
    putTableName(globalTable, reader, " global");
    int seriesCount = reader.getSeriesCount();
    globalTable.put(SERIES_COUNT, String.valueOf(seriesCount));
    IFormatReader r = reader;
    if (r instanceof ImageReader) {
        r = ((ImageReader) r).getReader();
    } else if (r instanceof ReaderWrapper) {
        try {
            r = ((ReaderWrapper) r).unwrap();
        } catch (FormatException e) {
        } catch (IOException e) {
        }
    }
    globalTable.put(READER, TestTools.shortClassName(r));
    globalTable.put(TEST, "true");
    globalTable.put(MEMORY, String.valueOf(TestTools.getUsedMemory()));
    long planeSize = (long) FormatTools.getPlaneSize(reader) * 3;
    boolean canOpenImages = planeSize > 0 && TestTools.canFitInMemory(planeSize);
    long t0 = System.currentTimeMillis();
    if (canOpenImages) {
        try {
            reader.openBytes(0);
        } catch (FormatException e) {
        } catch (IOException e) {
        }
    }
    long t1 = System.currentTimeMillis();
    globalTable.put(ACCESS_TIME, String.valueOf(t1 - t0));
    ini.add(globalTable);
    for (int series = 0; series < seriesCount; series++) {
        reader.setSeries(series);
        IniTable seriesTable = new IniTable();
        putTableName(seriesTable, reader, SERIES + series);
        seriesTable.put(SIZE_X, String.valueOf(reader.getSizeX()));
        seriesTable.put(SIZE_Y, String.valueOf(reader.getSizeY()));
        seriesTable.put(SIZE_Z, String.valueOf(reader.getSizeZ()));
        seriesTable.put(SIZE_C, String.valueOf(reader.getSizeC()));
        seriesTable.put(SIZE_T, String.valueOf(reader.getSizeT()));
        seriesTable.put(DIMENSION_ORDER, reader.getDimensionOrder());
        seriesTable.put(IS_INTERLEAVED, String.valueOf(reader.isInterleaved()));
        seriesTable.put(IS_INDEXED, String.valueOf(reader.isIndexed()));
        seriesTable.put(IS_FALSE_COLOR, String.valueOf(reader.isFalseColor()));
        seriesTable.put(IS_RGB, String.valueOf(reader.isRGB()));
        seriesTable.put(THUMB_SIZE_X, String.valueOf(reader.getThumbSizeX()));
        seriesTable.put(THUMB_SIZE_Y, String.valueOf(reader.getThumbSizeY()));
        seriesTable.put(PIXEL_TYPE, FormatTools.getPixelTypeString(reader.getPixelType()));
        seriesTable.put(IS_LITTLE_ENDIAN, String.valueOf(reader.isLittleEndian()));
        seriesTable.put(CHANNEL_COUNT, String.valueOf(retrieve.getChannelCount(series)));
        try {
            planeSize = DataTools.safeMultiply32(reader.getSizeX(), reader.getSizeY(), reader.getEffectiveSizeC(), FormatTools.getBytesPerPixel(reader.getPixelType()));
            canOpenImages = planeSize > 0 && TestTools.canFitInMemory(planeSize);
        } catch (IllegalArgumentException e) {
            canOpenImages = false;
        }
        if (canOpenImages) {
            try {
                byte[] plane = reader.openBytes(0);
                seriesTable.put(MD5, TestTools.md5(plane));
            } catch (FormatException e) {
            // TODO
            } catch (IOException e) {
            // TODO
            }
        }
        try {
            int w = (int) Math.min(TILE_SIZE, reader.getSizeX());
            int h = (int) Math.min(TILE_SIZE, reader.getSizeY());
            byte[] tile = reader.openBytes(0, 0, 0, w, h);
            seriesTable.put(TILE_MD5, TestTools.md5(tile));
        } catch (FormatException e) {
        // TODO
        } catch (IOException e) {
        // TODO
        }
        seriesTable.put(NAME, retrieve.getImageName(series));
        seriesTable.put(DESCRIPTION, retrieve.getImageDescription(series));
        Length physicalX = retrieve.getPixelsPhysicalSizeX(series);
        if (physicalX != null) {
            seriesTable.put(PHYSICAL_SIZE_X, physicalX.value().toString());
            seriesTable.put(PHYSICAL_SIZE_X_UNIT, physicalX.unit().getSymbol());
        }
        Length physicalY = retrieve.getPixelsPhysicalSizeY(series);
        if (physicalY != null) {
            seriesTable.put(PHYSICAL_SIZE_Y, physicalY.value().toString());
            seriesTable.put(PHYSICAL_SIZE_Y_UNIT, physicalY.unit().getSymbol());
        }
        Length physicalZ = retrieve.getPixelsPhysicalSizeZ(series);
        if (physicalZ != null) {
            seriesTable.put(PHYSICAL_SIZE_Z, physicalZ.value().toString());
            seriesTable.put(PHYSICAL_SIZE_Z_UNIT, physicalZ.unit().getSymbol());
        }
        Time timeIncrement = retrieve.getPixelsTimeIncrement(series);
        if (timeIncrement != null) {
            seriesTable.put(TIME_INCREMENT, timeIncrement.value().toString());
            seriesTable.put(TIME_INCREMENT_UNIT, timeIncrement.unit().getSymbol());
        }
        Timestamp acquisition = retrieve.getImageAcquisitionDate(series);
        if (acquisition != null) {
            String date = acquisition.getValue();
            if (date != null) {
                seriesTable.put(DATE, date);
            }
        }
        for (int c = 0; c < retrieve.getChannelCount(series); c++) {
            seriesTable.put(CHANNEL_NAME + c, retrieve.getChannelName(series, c));
            try {
                seriesTable.put(LIGHT_SOURCE + c, retrieve.getChannelLightSourceSettingsID(series, c));
            } catch (NullPointerException e) {
            }
            try {
                int plane = reader.getIndex(0, c, 0);
                if (plane < retrieve.getPlaneCount(series)) {
                    seriesTable.put(EXPOSURE_TIME + c, retrieve.getPlaneExposureTime(series, plane).value().toString());
                    seriesTable.put(EXPOSURE_TIME_UNIT + c, retrieve.getPlaneExposureTime(series, plane).unit().getSymbol());
                }
            } catch (NullPointerException e) {
            }
            Length emWavelength = retrieve.getChannelEmissionWavelength(series, c);
            if (emWavelength != null) {
                seriesTable.put(EMISSION_WAVELENGTH + c, emWavelength.value().toString());
                seriesTable.put(EMISSION_WAVELENGTH_UNIT + c, emWavelength.unit().getSymbol());
            }
            Length exWavelength = retrieve.getChannelExcitationWavelength(series, c);
            if (exWavelength != null) {
                seriesTable.put(EXCITATION_WAVELENGTH + c, exWavelength.value().toString());
                seriesTable.put(EXCITATION_WAVELENGTH_UNIT + c, exWavelength.unit().getSymbol());
            }
            try {
                seriesTable.put(DETECTOR + c, retrieve.getDetectorSettingsID(series, c));
            } catch (NullPointerException e) {
            }
        }
        for (int p = 0; p < reader.getImageCount(); p++) {
            try {
                Time deltaT = retrieve.getPlaneDeltaT(series, p);
                if (deltaT != null) {
                    seriesTable.put(DELTA_T + p, deltaT.value(UNITS.SECOND).toString());
                }
                Length xPos = retrieve.getPlanePositionX(series, p);
                if (xPos != null) {
                    seriesTable.put(X_POSITION + p, String.valueOf(xPos.value().doubleValue()));
                    seriesTable.put(X_POSITION_UNIT + p, xPos.unit().getSymbol());
                }
                Length yPos = retrieve.getPlanePositionY(series, p);
                if (yPos != null) {
                    seriesTable.put(Y_POSITION + p, String.valueOf(yPos.value().doubleValue()));
                    seriesTable.put(Y_POSITION_UNIT + p, yPos.unit().getSymbol());
                }
                Length zPos = retrieve.getPlanePositionZ(series, p);
                if (zPos != null) {
                    seriesTable.put(Z_POSITION + p, String.valueOf(zPos.value().doubleValue()));
                    seriesTable.put(Z_POSITION_UNIT + p, zPos.unit().getSymbol());
                }
            } catch (IndexOutOfBoundsException e) {
            // only happens if no Plane elements were populated
            }
        }
        ini.add(seriesTable);
    }
}
Also used : IFormatReader(loci.formats.IFormatReader) IniList(loci.common.IniList) Time(ome.units.quantity.Time) IOException(java.io.IOException) Timestamp(ome.xml.model.primitives.Timestamp) ReaderWrapper(loci.formats.ReaderWrapper) FormatException(loci.formats.FormatException) IMetadata(loci.formats.meta.IMetadata) UnitsLength(ome.xml.model.enums.UnitsLength) Length(ome.units.quantity.Length) IniTable(loci.common.IniTable) ImageReader(loci.formats.ImageReader)

Example 64 with ImageReader

use of loci.formats.ImageReader in project bioformats by openmicroscopy.

the class TiffWriterTest method parse.

@Parameters({ "id" })
@BeforeClass
public void parse(String id) throws Exception {
    ServiceFactory factory = new ServiceFactory();
    service = factory.getInstance(OMEXMLService.class);
    metadata = service.createOMEXMLMetadata();
    reader = new ImageReader();
    reader.setMetadataStore(metadata);
    reader.setId(id);
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) ImageReader(loci.formats.ImageReader) OMEXMLService(loci.formats.services.OMEXMLService) BeforeClass(org.testng.annotations.BeforeClass) Parameters(org.testng.annotations.Parameters)

Example 65 with ImageReader

use of loci.formats.ImageReader in project bioformats by openmicroscopy.

the class TiledReaderWriter method initialize.

/**
 * Set up the file reader and writer, ensuring that the input file is
 * associated with the reader and the output file is associated with the
 * writer.
 *
 * @return true if the reader and writer were successfully set up, or false
 *   if an error occurred
 * @throws DependencyException thrown if failed to create an OMEXMLService
 * @throws IOException thrown if unable to setup input or output stream for reader or writer
 * @throws FormatException thrown if invalid ID set for reader or writer or invalid tile size set
 * @throws ServiceException thrown if unable to create OME-XML meta data
 */
private void initialize() throws DependencyException, FormatException, IOException, ServiceException {
    // construct the object that stores OME-XML metadata
    ServiceFactory factory = new ServiceFactory();
    OMEXMLService service = factory.getInstance(OMEXMLService.class);
    IMetadata omexml = service.createOMEXMLMetadata();
    // set up the reader and associate it with the input file
    reader = new ImageReader();
    reader.setMetadataStore(omexml);
    reader.setId(inputFile);
    // set up the writer and associate it with the output file
    writer = new OMETiffWriter();
    writer.setMetadataRetrieve(omexml);
    writer.setInterleaved(reader.isInterleaved());
    // set the tile size height and width for writing
    this.tileSizeX = writer.setTileSizeX(tileSizeX);
    this.tileSizeY = writer.setTileSizeY(tileSizeY);
    writer.setId(outputFile);
}
Also used : OMETiffWriter(loci.formats.out.OMETiffWriter) IMetadata(loci.formats.meta.IMetadata) ServiceFactory(loci.common.services.ServiceFactory) ImageReader(loci.formats.ImageReader) OMEXMLService(loci.formats.services.OMEXMLService)

Aggregations

ImageReader (loci.formats.ImageReader)71 ServiceFactory (loci.common.services.ServiceFactory)23 OMEXMLService (loci.formats.services.OMEXMLService)23 FormatException (loci.formats.FormatException)20 IFormatReader (loci.formats.IFormatReader)20 IMetadata (loci.formats.meta.IMetadata)19 Test (org.testng.annotations.Test)15 IOException (java.io.IOException)11 ChannelFiller (loci.formats.ChannelFiller)11 DependencyException (loci.common.services.DependencyException)10 ServiceException (loci.common.services.ServiceException)10 ChannelSeparator (loci.formats.ChannelSeparator)10 MinMaxCalculator (loci.formats.MinMaxCalculator)10 BufferedImageReader (loci.formats.gui.BufferedImageReader)8 ImageWriter (loci.formats.ImageWriter)7 File (java.io.File)6 FileStitcher (loci.formats.FileStitcher)6 OMETiffWriter (loci.formats.out.OMETiffWriter)6 Location (loci.common.Location)5 DimensionSwapper (loci.formats.DimensionSwapper)5