Search in sources :

Example 6 with FileStitcher

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

the class FormatReaderTest method setupReader.

// -- Helper methods --
/**
 * Sets up the current IFormatReader.
 */
private void setupReader() {
    // Remove external SlideBook6Reader class for testing purposes
    ImageReader ir = new ImageReader();
    reader = new BufferedImageReader(new FileStitcher(new Memoizer(ir, Memoizer.DEFAULT_MINIMUM_ELAPSED, new File(""))));
    reader.setMetadataOptions(new DefaultMetadataOptions(MetadataLevel.NO_OVERLAYS));
    reader.setNormalized(true);
    reader.setOriginalMetadataPopulated(false);
    reader.setMetadataFiltered(true);
    MetadataStore store = null;
    try {
        store = omexmlService.createOMEXMLMetadata();
    } catch (ServiceException e) {
        LOGGER.warn("Could not parse OME-XML", e);
    }
    reader.setMetadataStore(store);
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) FileStitcher(loci.formats.FileStitcher) ServiceException(loci.common.services.ServiceException) Memoizer(loci.formats.Memoizer) BufferedImageReader(loci.formats.gui.BufferedImageReader) ImageReader(loci.formats.ImageReader) BufferedImageReader(loci.formats.gui.BufferedImageReader) File(java.io.File)

Example 7 with FileStitcher

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

the class FormatReaderTest method testIsThisType.

@Test(groups = { "all", "fast", "automated" })
public void testIsThisType() {
    String testName = "testIsThisType";
    if (!initFile())
        result(testName, false, "initFile");
    boolean success = true;
    String msg = null;
    try {
        IFormatReader r = reader;
        // unwrap reader
        while (true) {
            if (r instanceof ReaderWrapper) {
                r = ((ReaderWrapper) r).getReader();
            } else if (r instanceof FileStitcher) {
                r = ((FileStitcher) r).getReader();
            } else
                break;
        }
        if (r instanceof ImageReader) {
            ImageReader ir = (ImageReader) r;
            r = ir.getReader();
            IFormatReader[] readers = ir.getReaders();
            String[] used = reader.getUsedFiles();
            for (int i = 0; i < used.length && success; i++) {
                // and only one reader, identifies the dataset as its own
                for (int j = 0; j < readers.length; j++) {
                    boolean result = readers[j].isThisType(used[i]);
                    // TIFF reader is allowed to redundantly green-light files
                    if (result && readers[j] instanceof TiffDelegateReader)
                        continue;
                    // green-light PIC files from NRRD datasets
                    if (result && r instanceof NRRDReader && readers[j] instanceof BioRadReader) {
                        String low = used[i].toLowerCase();
                        boolean isPic = low.endsWith(".pic") || low.endsWith(".pic.gz");
                        if (isPic)
                            continue;
                    }
                    // Analyze reader is allowed to redundantly accept NIfTI files
                    if (result && r instanceof NiftiReader && readers[j] instanceof AnalyzeReader) {
                        continue;
                    }
                    if (result && r instanceof MetamorphReader && readers[j] instanceof MetamorphTiffReader) {
                        continue;
                    }
                    if (result && (readers[j] instanceof L2DReader) || ((r instanceof L2DReader) && (readers[j] instanceof GelReader) || readers[j] instanceof L2DReader)) {
                        continue;
                    }
                    // ND2Reader is allowed to accept JPEG-2000 files
                    if (result && r instanceof JPEG2000Reader && readers[j] instanceof ND2Reader) {
                        continue;
                    }
                    if ((result && r instanceof APLReader && readers[j] instanceof SISReader) || (!result && r instanceof APLReader && readers[j] instanceof APLReader)) {
                        continue;
                    }
                    // reader to pick up TIFFs from a Prairie dataset
                    if (result && r instanceof PrairieReader && readers[j] instanceof OMETiffReader) {
                        continue;
                    }
                    // extra metadata files
                    if (result && r instanceof ColumbusReader && readers[j] instanceof OMETiffReader) {
                        continue;
                    }
                    // with an extra metadata file
                    if (result && r instanceof MicromanagerReader && readers[j] instanceof OMETiffReader) {
                        continue;
                    }
                    if (!result && r instanceof MicromanagerReader && readers[j] instanceof MicromanagerReader && (used[i].toLowerCase().endsWith(".ome.tif") || used[i].toLowerCase().endsWith(".ome.tiff"))) {
                        continue;
                    }
                    if (result && r instanceof TrestleReader && (readers[j] instanceof JPEGReader || readers[j] instanceof PGMReader || readers[j] instanceof TiffDelegateReader)) {
                        continue;
                    }
                    if (result && ((r instanceof HitachiReader) || (readers[j] instanceof HitachiReader && (r instanceof TiffDelegateReader || r instanceof JPEGReader || r instanceof BMPReader)))) {
                        continue;
                    }
                    if (result && r instanceof BDReader && readers[j] instanceof BMPReader) {
                        continue;
                    }
                    if (!result && readers[j] instanceof BDReader && (used[i].endsWith(".bmp") || used[i].endsWith(".adf") || used[i].endsWith(".txt") || used[i].endsWith(".roi"))) {
                        continue;
                    }
                    if (!result && r instanceof VolocityReader && readers[j] instanceof VolocityReader) {
                        continue;
                    }
                    if (!result && r instanceof InCellReader && readers[j] instanceof InCellReader && !used[i].toLowerCase().endsWith(".xdce")) {
                        continue;
                    }
                    if (!result && r instanceof BrukerReader && readers[j] instanceof BrukerReader && !used[i].toLowerCase().equals("acqp") && !used[i].toLowerCase().equals("fid")) {
                        continue;
                    }
                    // Volocity reader is allowed to accept files of other formats
                    if (result && r instanceof VolocityReader) {
                        continue;
                    }
                    if (result && r instanceof NikonReader && readers[j] instanceof DNGReader) {
                        continue;
                    }
                    // DICOM reader is not expected to pick up companion files
                    if (!result && r instanceof DicomReader && readers[j] instanceof DicomReader) {
                        continue;
                    }
                    // AFI reader is not expected to pick up .svs files
                    if (r instanceof AFIReader && (readers[j] instanceof AFIReader || readers[j] instanceof SVSReader)) {
                        continue;
                    }
                    if (!result && readers[j] instanceof MIASReader) {
                        continue;
                    }
                    if ((readers[j] instanceof NDPISReader || r instanceof NDPISReader) && used[i].toLowerCase().endsWith(".ndpi")) {
                        continue;
                    }
                    // Hamamatsu VMS dataset
                    if (readers[j] instanceof JPEGReader && r instanceof HamamatsuVMSReader && used[i].toLowerCase().endsWith(".jpg")) {
                        continue;
                    }
                    // the Hamamatsu VMS reader only picks up its .vms file
                    if (!result && !used[i].toLowerCase().endsWith(".vms") && r instanceof HamamatsuVMSReader) {
                        continue;
                    }
                    // QuickTime reader doesn't pick up resource forks
                    if (!result && i > 0 && r instanceof QTReader) {
                        continue;
                    }
                    if (r instanceof CellVoyagerReader && (!result || readers[j] instanceof OMEXMLReader) && used[i].toLowerCase().endsWith(".ome.xml")) {
                        continue;
                    }
                    // the pattern reader only picks up pattern files
                    if (!used[i].toLowerCase().endsWith(".pattern") && r instanceof FilePatternReader) {
                        continue;
                    }
                    // ignore companion files for Leica LIF
                    if (!used[i].toLowerCase().endsWith(".lif") && r instanceof LIFReader) {
                        continue;
                    }
                    boolean expected = r == readers[j];
                    if (result != expected) {
                        success = false;
                        if (result) {
                            msg = TestTools.shortClassName(readers[j]) + " flagged \"" + used[i] + "\" but so did " + TestTools.shortClassName(r);
                        } else {
                            msg = TestTools.shortClassName(readers[j]) + " skipped \"" + used[i] + "\"";
                        }
                        break;
                    }
                }
            }
        } else {
            success = false;
            msg = "Reader " + r.getClass().getName() + " is not an ImageReader";
        }
    } catch (Throwable t) {
        LOGGER.info("", t);
        success = false;
    }
    result(testName, success, msg);
}
Also used : FileStitcher(loci.formats.FileStitcher) IFormatReader(loci.formats.IFormatReader) ReaderWrapper(loci.formats.ReaderWrapper) ImageReader(loci.formats.ImageReader) BufferedImageReader(loci.formats.gui.BufferedImageReader) Test(org.testng.annotations.Test)

Example 8 with FileStitcher

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

the class ImageInfo method configureReaderPreInit.

public void configureReaderPreInit() throws FormatException, IOException {
    if (omexml) {
        reader.setOriginalMetadataPopulated(originalMetadata);
        try {
            ServiceFactory factory = new ServiceFactory();
            OMEXMLService service = factory.getInstance(OMEXMLService.class);
            reader.setMetadataStore(service.createOMEXMLMetadata(null, omexmlVersion));
        } catch (DependencyException de) {
            throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, de);
        } catch (ServiceException se) {
            throw new FormatException(se);
        }
    }
    // check file format
    if (reader instanceof ImageReader) {
        // determine format
        ImageReader ir = (ImageReader) reader;
        if (new Location(id).exists()) {
            LOGGER.info("Checking file format [{}]", ir.getFormat(id));
        }
    } else {
        // verify format
        LOGGER.info("Checking {} format [{}]", reader.getFormat(), reader.isThisType(id) ? "yes" : "no");
    }
    LOGGER.info("Initializing reader");
    if (stitch) {
        reader = new FileStitcher(reader, true);
        Location f = new Location(id);
        String pat = null;
        if (!f.exists()) {
            ((FileStitcher) reader).setUsingPatternIds(true);
            pat = id;
        } else {
            pat = FilePattern.findPattern(f);
        }
        if (pat != null)
            id = pat;
    }
    if (expand)
        reader = new ChannelFiller(reader);
    if (separate)
        reader = new ChannelSeparator(reader);
    if (merge)
        reader = new ChannelMerger(reader);
    if (cache) {
        if (cachedir != null) {
            reader = new Memoizer(reader, 0, new File(cachedir));
        } else {
            reader = new Memoizer(reader, 0);
        }
    }
    minMaxCalc = null;
    if (minmax || autoscale)
        reader = minMaxCalc = new MinMaxCalculator(reader);
    dimSwapper = null;
    if (swapOrder != null || shuffleOrder != null) {
        reader = dimSwapper = new DimensionSwapper(reader);
    }
    reader = biReader = new BufferedImageReader(reader);
    reader.close();
    reader.setNormalized(normalize);
    reader.setMetadataFiltered(filter);
    reader.setGroupFiles(group);
    options.setMetadataLevel(doMeta ? MetadataLevel.ALL : MetadataLevel.MINIMUM);
    options.setValidate(validate);
    reader.setMetadataOptions(options);
    reader.setFlattenedResolutions(flat);
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) Memoizer(loci.formats.Memoizer) ChannelMerger(loci.formats.ChannelMerger) ChannelFiller(loci.formats.ChannelFiller) BufferedImageReader(loci.formats.gui.BufferedImageReader) DependencyException(loci.common.services.DependencyException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) ChannelSeparator(loci.formats.ChannelSeparator) ServiceException(loci.common.services.ServiceException) FileStitcher(loci.formats.FileStitcher) MinMaxCalculator(loci.formats.MinMaxCalculator) MissingLibraryException(loci.formats.MissingLibraryException) DimensionSwapper(loci.formats.DimensionSwapper) ImageReader(loci.formats.ImageReader) BufferedImageReader(loci.formats.gui.BufferedImageReader) File(java.io.File) Location(loci.common.Location)

Example 9 with FileStitcher

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

the class GUITools method buildFileFilters.

// -- File chooser --
/**
 * Constructs a list of file filters for the given file format handler.
 */
public static FileFilter[] buildFileFilters(IFormatHandler handler) {
    FileFilter[] filters = null;
    // unwrap reader
    while (true) {
        if (handler instanceof ReaderWrapper) {
            handler = ((ReaderWrapper) handler).getReader();
        } else if (handler instanceof FileStitcher) {
            handler = ((FileStitcher) handler).getReader();
        } else if (handler instanceof WriterWrapper) {
            handler = ((WriterWrapper) handler).getWriter();
        } else
            break;
    }
    // handle special cases of ImageReader and ImageWriter
    if (handler instanceof ImageReader) {
        ImageReader imageReader = (ImageReader) handler;
        IFormatReader[] readers = imageReader.getReaders();
        Vector filterList = new Vector();
        Vector comboList = new Vector();
        for (int i = 0; i < readers.length; i++) {
            filterList.add(new FormatFileFilter(readers[i]));
            // NB: Some readers need to open a file to determine if it is the
            // proper type, when the extension alone is insufficient to
            // distinguish. This behavior is fine for individual filters, but not
            // for ImageReader's combination filter, because it makes the combo
            // filter too slow. So rather than composing the combo filter from
            // FormatFileFilters, we use faster but less accurate
            // ExtensionFileFilters instead.
            String[] suffixes = readers[i].getSuffixes();
            String format = readers[i].getFormat();
            comboList.add(new ExtensionFileFilter(suffixes, format));
        }
        comboList.add(new NoExtensionFileFilter());
        FileFilter combo = makeComboFilter(sortFilters(comboList));
        if (combo != null)
            filterList.add(combo);
        filters = sortFilters(filterList);
    } else if (handler instanceof ImageWriter) {
        IFormatWriter[] writers = ((ImageWriter) handler).getWriters();
        Vector filterList = new Vector();
        for (int i = 0; i < writers.length; i++) {
            String[] suffixes = writers[i].getSuffixes();
            String format = writers[i].getFormat();
            filterList.add(new ExtensionFileFilter(suffixes, format));
        }
        filters = sortFilters(filterList);
    } else // handle default reader and writer cases
    if (handler instanceof IFormatReader) {
        IFormatReader reader = (IFormatReader) handler;
        filters = new FileFilter[] { new FormatFileFilter(reader) };
    } else {
        String[] suffixes = handler.getSuffixes();
        String format = handler.getFormat();
        filters = new FileFilter[] { new ExtensionFileFilter(suffixes, format) };
    }
    return filters;
}
Also used : IFormatReader(loci.formats.IFormatReader) ImageWriter(loci.formats.ImageWriter) ReaderWrapper(loci.formats.ReaderWrapper) WriterWrapper(loci.formats.WriterWrapper) FileStitcher(loci.formats.FileStitcher) FileFilter(javax.swing.filechooser.FileFilter) ImageReader(loci.formats.ImageReader) Vector(java.util.Vector)

Example 10 with FileStitcher

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

the class FileStitcherTest method testOptionsExplicit.

@Test
public void testOptionsExplicit() throws IOException, FormatException {
    DynamicMetadataOptions opt = new DynamicMetadataOptions();
    opt.set(KEY, VALUE);
    FileStitcher fs = new FileStitcher();
    fs.setMetadataOptions(opt);
    fs.setId("test_z<0-2>.fake");
    checkKV(fs.getUnderlyingReaders(), KEY, VALUE);
    DynamicMetadataOptions newOpt = new DynamicMetadataOptions();
    String newValue = VALUE + "_";
    newOpt.set(KEY, newValue);
    fs.setMetadataOptions(newOpt);
    checkKV(fs.getUnderlyingReaders(), KEY, newValue);
    fs.close();
}
Also used : FileStitcher(loci.formats.FileStitcher) DynamicMetadataOptions(loci.formats.in.DynamicMetadataOptions) Test(org.testng.annotations.Test)

Aggregations

FileStitcher (loci.formats.FileStitcher)17 IFormatReader (loci.formats.IFormatReader)10 Test (org.testng.annotations.Test)9 ImageReader (loci.formats.ImageReader)6 BufferedImageReader (loci.formats.gui.BufferedImageReader)5 Location (loci.common.Location)4 ServiceException (loci.common.services.ServiceException)4 ChannelFiller (loci.formats.ChannelFiller)4 ChannelSeparator (loci.formats.ChannelSeparator)4 FormatException (loci.formats.FormatException)4 MinMaxCalculator (loci.formats.MinMaxCalculator)4 File (java.io.File)3 IOException (java.io.IOException)3 DependencyException (loci.common.services.DependencyException)3 ChannelMerger (loci.formats.ChannelMerger)3 DimensionSwapper (loci.formats.DimensionSwapper)3 Memoizer (loci.formats.Memoizer)3 ReaderWrapper (loci.formats.ReaderWrapper)3 SkipException (org.testng.SkipException)3 ServiceFactory (loci.common.services.ServiceFactory)2