Search in sources :

Example 76 with ServiceFactory

use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.

the class Upgrade200909Test method setUp.

@BeforeMethod
public void setUp() throws Exception {
    ServiceFactory sf = new ServiceFactory();
    service = sf.getInstance(OMEXMLService.class);
    InputStream s = Upgrade200909Test.class.getResourceAsStream(XML_FILE);
    byte[] b = new byte[s.available()];
    s.read(b);
    s.close();
    xml = new String(b);
    metadata = service.createOMEXMLMetadata(xml);
    ome = (OME) metadata.getRoot();
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) InputStream(java.io.InputStream) OMEXMLService(loci.formats.services.OMEXMLService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 77 with ServiceFactory

use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.

the class Upgrade201106Test method setUp.

@BeforeMethod
public void setUp() throws Exception {
    ServiceFactory sf = new ServiceFactory();
    service = sf.getInstance(OMEXMLService.class);
    InputStream s = Upgrade201106Test.class.getResourceAsStream(XML_FILE);
    byte[] b = new byte[s.available()];
    s.read(b);
    s.close();
    xml = new String(b);
    metadata = service.createOMEXMLMetadata(xml);
    ome = (OME) metadata.getRoot();
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) InputStream(java.io.InputStream) OMEXMLService(loci.formats.services.OMEXMLService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 78 with ServiceFactory

use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.

the class ConvertToOmeTiff method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.out.println("Usage: java ConvertToOmeTiff file1 file2 ...");
        return;
    }
    ImageReader reader = new ImageReader();
    OMETiffWriter writer = new OMETiffWriter();
    for (int i = 0; i < args.length; i++) {
        String id = args[i];
        int dot = id.lastIndexOf(".");
        String outId = (dot >= 0 ? id.substring(0, dot) : id) + ".ome.tif";
        System.out.print("Converting " + id + " to " + outId + " ");
        // record metadata to OME-XML format
        ServiceFactory factory = new ServiceFactory();
        OMEXMLService service = factory.getInstance(OMEXMLService.class);
        IMetadata omexmlMeta = service.createOMEXMLMetadata();
        reader.setMetadataStore(omexmlMeta);
        reader.setId(id);
        // configure OME-TIFF writer
        writer.setMetadataRetrieve(omexmlMeta);
        writer.setId(outId);
        // writer.setCompression("J2K");
        // write out image planes
        int seriesCount = reader.getSeriesCount();
        for (int s = 0; s < seriesCount; s++) {
            reader.setSeries(s);
            writer.setSeries(s);
            int planeCount = reader.getImageCount();
            for (int p = 0; p < planeCount; p++) {
                byte[] plane = reader.openBytes(p);
                // write plane to output file
                writer.saveBytes(p, plane);
                System.out.print(".");
            }
        }
        writer.close();
        reader.close();
        System.out.println(" [done]");
    }
}
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)

Example 79 with ServiceFactory

use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.

the class DisplayHandler method displayOMEXML.

/**
 * Displays OME-XML metadata in a tree in its own window.
 */
public XMLWindow displayOMEXML() throws FormatException, IOException {
    if (!options.isShowOMEXML())
        return null;
    XMLWindow metaWindow = null;
    metaWindow = new XMLWindow("OME Metadata - " + process.getIdName());
    Exception exc = null;
    try {
        ServiceFactory factory = new ServiceFactory();
        OMEXMLService service = factory.getInstance(OMEXMLService.class);
        metaWindow.setXML(service.getOMEXML(process.getOMEMetadata()));
        WindowTools.placeWindow(metaWindow);
        metaWindow.setVisible(true);
    } catch (DependencyException e) {
        exc = e;
    } catch (ServiceException e) {
        exc = e;
    } catch (ParserConfigurationException e) {
        exc = e;
    } catch (SAXException e) {
        exc = e;
    }
    if (exc != null)
        throw new FormatException(exc);
    // save reference to OME-XML window
    xmlWindow = metaWindow;
    return metaWindow;
}
Also used : ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLWindow(loci.formats.gui.XMLWindow) DependencyException(loci.common.services.DependencyException) ServiceException(loci.common.services.ServiceException) DependencyException(loci.common.services.DependencyException) FormatException(loci.formats.FormatException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ReflectException(loci.common.ReflectException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException) SAXException(org.xml.sax.SAXException)

Example 80 with ServiceFactory

use of loci.common.services.ServiceFactory in project bioformats by openmicroscopy.

the class ImportProcess method createBaseReader.

/**
 * Initializes an {@link loci.formats.IFormatReader}
 * according to the current configuration.
 */
private void createBaseReader() throws FormatException, IOException {
    if (options.isLocal() || options.isHTTP()) {
        BF.status(options.isQuiet(), "Identifying " + idName);
        imageReader = LociPrefs.makeImageReader();
        baseReader = imageReader.getReader(options.isUsingPatternIds() ? new FilePattern(options.getId()).getFiles()[0] : options.getId());
    } else if (options.isOMERO()) {
        BF.status(options.isQuiet(), "Establishing server connection");
        try {
            ReflectedUniverse r = new ReflectedUniverse();
            r.exec("import loci.ome.io.OmeroReader");
            r.exec("baseReader = new OmeroReader()");
            ClassList<IFormatReader> classes = new ClassList<IFormatReader>(IFormatReader.class);
            r.setVar("classes", classes);
            r.exec("class = baseReader.getClass()");
            r.exec("classes.addClass(class)");
            imageReader = new ImageReader(classes);
            baseReader = imageReader.getReader(options.getId());
        } catch (Exception exc) {
            WindowTools.reportException(exc, options.isQuiet(), "Sorry, there was a problem communicating with the server.");
            cancel();
            return;
        }
    } else {
        WindowTools.reportException(null, options.isQuiet(), "Sorry, there has been an internal error: unknown data source");
        cancel();
        return;
    }
    // attach OME-XML metadata store
    Exception exc = null;
    try {
        ServiceFactory factory = new ServiceFactory();
        OMEXMLService service = factory.getInstance(OMEXMLService.class);
        meta = service.createOMEXMLMetadata();
        omeXML = null;
    } catch (DependencyException de) {
        exc = de;
    } catch (ServiceException se) {
        exc = se;
    }
    if (exc != null) {
        WindowTools.reportException(exc, options.isQuiet(), "Sorry, there was a problem constructing the OME-XML metadata store");
        throw new FormatException(exc);
    }
    baseReader.setMetadataStore(meta);
    BF.status(options.isQuiet(), "");
    DebugTools.enableIJLogging(IJ.debugMode);
}
Also used : IFormatReader(loci.formats.IFormatReader) ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) FilePattern(loci.formats.FilePattern) ReflectedUniverse(loci.common.ReflectedUniverse) ClassList(loci.formats.ClassList) ImageReader(loci.formats.ImageReader) DependencyException(loci.common.services.DependencyException) EnumerationException(ome.xml.model.enums.EnumerationException) ServiceException(loci.common.services.ServiceException) DependencyException(loci.common.services.DependencyException) FormatException(loci.formats.FormatException) IOException(java.io.IOException) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException)

Aggregations

ServiceFactory (loci.common.services.ServiceFactory)94 OMEXMLService (loci.formats.services.OMEXMLService)73 DependencyException (loci.common.services.DependencyException)49 FormatException (loci.formats.FormatException)38 IMetadata (loci.formats.meta.IMetadata)35 ServiceException (loci.common.services.ServiceException)30 ImageReader (loci.formats.ImageReader)23 MissingLibraryException (loci.formats.MissingLibraryException)15 BeforeMethod (org.testng.annotations.BeforeMethod)15 MetadataStore (loci.formats.meta.MetadataStore)14 PositiveInteger (ome.xml.model.primitives.PositiveInteger)14 IOException (java.io.IOException)13 CoreMetadata (loci.formats.CoreMetadata)13 Length (ome.units.quantity.Length)12 Location (loci.common.Location)11 OMEXMLMetadata (loci.formats.ome.OMEXMLMetadata)10 InputStream (java.io.InputStream)9 ArrayList (java.util.ArrayList)8 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)8 BeforeClass (org.testng.annotations.BeforeClass)8