Search in sources :

Example 41 with DependencyException

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

the class WlzWriter method setId.

// -- FormatWriter API methods --
/* @see loci.formats.FormatWriter#setId(String) */
@Override
public void setId(String id) throws FormatException, IOException {
    super.setId(id);
    try {
        ServiceFactory factory = new ServiceFactory();
        wlz = factory.getInstance(WlzService.class);
    } catch (DependencyException e) {
        throw new FormatException(NO_WLZ_MSG, e);
    }
    if (wlz != null) {
        MetadataRetrieve meta = getMetadataRetrieve();
        MetadataTools.verifyMinimumPopulated(meta, series);
        wlz.open(id, "w");
        String stageLabelName = null;
        try {
            stageLabelName = meta.getStageLabelName(0);
        } catch (NullPointerException e) {
        }
        int oX = 0;
        int oY = 0;
        int oZ = 0;
        if ((stageLabelName != null) && stageLabelName.equals(wlz.getWlzOrgLabelName())) {
            final Length stageX = meta.getStageLabelX(0);
            final Length stageY = meta.getStageLabelY(0);
            final Length stageZ = meta.getStageLabelZ(0);
            oX = (int) Math.rint(stageX.value(UNITS.REFERENCEFRAME).doubleValue());
            oY = (int) Math.rint(stageY.value(UNITS.REFERENCEFRAME).doubleValue());
            oZ = (int) Math.rint(stageZ.value(UNITS.REFERENCEFRAME).doubleValue());
        }
        int nX = meta.getPixelsSizeX(series).getValue().intValue();
        int nY = meta.getPixelsSizeY(series).getValue().intValue();
        int nZ = meta.getPixelsSizeZ(series).getValue().intValue();
        int nC = meta.getPixelsSizeC(series).getValue().intValue();
        int nT = meta.getPixelsSizeT(series).getValue().intValue();
        double vX = 1.0;
        double vY = 1.0;
        double vZ = 1.0;
        if (meta.getPixelsPhysicalSizeX(0) != null) {
            vX = meta.getPixelsPhysicalSizeX(0).value(UNITS.MICROMETER).doubleValue();
        }
        if (meta.getPixelsPhysicalSizeY(0) != null) {
            vY = meta.getPixelsPhysicalSizeY(0).value(UNITS.MICROMETER).doubleValue();
        }
        if (meta.getPixelsPhysicalSizeZ(0) != null) {
            vZ = meta.getPixelsPhysicalSizeZ(0).value(UNITS.MICROMETER).doubleValue();
        }
        int gType = FormatTools.pixelTypeFromString(meta.getPixelsType(series).toString());
        wlz.setupWrite(oX, oY, oZ, nX, nY, nZ, nC, nT, vX, vY, vZ, gType);
    }
}
Also used : WlzService(loci.formats.services.WlzService) ServiceFactory(loci.common.services.ServiceFactory) Length(ome.units.quantity.Length) DependencyException(loci.common.services.DependencyException) MetadataRetrieve(loci.formats.meta.MetadataRetrieve) FormatException(loci.formats.FormatException)

Example 42 with DependencyException

use of loci.common.services.DependencyException 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 43 with DependencyException

use of loci.common.services.DependencyException 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)

Example 44 with DependencyException

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

the class OMEXMLReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    in = new RandomAccessInputStream(id);
    in.setEncoding("ASCII");
    binData = new ArrayList<BinData>();
    binDataOffsets = new ArrayList<Long>();
    compression = new ArrayList<String>();
    DefaultHandler handler = new OMEXMLHandler();
    try {
        RandomAccessInputStream s = new RandomAccessInputStream(id);
        XMLTools.parseXML(s, handler);
        s.close();
    } catch (IOException e) {
        throw new FormatException("Malformed OME-XML", e);
    }
    int lineNumber = 1;
    for (BinData bin : binData) {
        int line = bin.getRow();
        int col = bin.getColumn();
        while (lineNumber < line) {
            in.readLine();
            lineNumber++;
        }
        binDataOffsets.add(in.getFilePointer() + col - 1);
    }
    LOGGER.info("Populating metadata");
    OMEXMLMetadata omexmlMeta;
    OMEXMLService service;
    try {
        ServiceFactory factory = new ServiceFactory();
        service = factory.getInstance(OMEXMLService.class);
        omexmlMeta = service.createOMEXMLMetadata(omexml);
    } catch (DependencyException de) {
        throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, de);
    } catch (ServiceException se) {
        throw new FormatException(se);
    }
    hasSPW = omexmlMeta.getPlateCount() > 0;
    // TODO
    // Hashtable originalMetadata = omexmlMeta.getOriginalMetadata();
    // if (originalMetadata != null) metadata = originalMetadata;
    int numDatasets = omexmlMeta.getImageCount();
    int oldSeries = getSeries();
    core.clear();
    for (int i = 0; i < numDatasets; i++) {
        CoreMetadata ms = new CoreMetadata();
        core.add(ms);
        setSeries(i);
        Integer w = omexmlMeta.getPixelsSizeX(i).getValue();
        Integer h = omexmlMeta.getPixelsSizeY(i).getValue();
        Integer t = omexmlMeta.getPixelsSizeT(i).getValue();
        Integer z = omexmlMeta.getPixelsSizeZ(i).getValue();
        Integer c = omexmlMeta.getPixelsSizeC(i).getValue();
        if (w == null || h == null || t == null || z == null | c == null) {
            throw new FormatException("Image dimensions not found");
        }
        Boolean endian = null;
        if (binData.size() > 0) {
            endian = false;
            if (omexmlMeta.getPixelsBigEndian(i) != null) {
                endian = omexmlMeta.getPixelsBigEndian(i).booleanValue();
            } else if (omexmlMeta.getPixelsBinDataCount(i) != 0) {
                endian = omexmlMeta.getPixelsBinDataBigEndian(i, 0).booleanValue();
            }
        }
        String pixType = omexmlMeta.getPixelsType(i).toString();
        ms.dimensionOrder = omexmlMeta.getPixelsDimensionOrder(i).toString();
        ms.sizeX = w.intValue();
        ms.sizeY = h.intValue();
        ms.sizeT = t.intValue();
        ms.sizeZ = z.intValue();
        ms.sizeC = c.intValue();
        ms.imageCount = getSizeZ() * getSizeC() * getSizeT();
        ms.littleEndian = endian == null ? false : !endian.booleanValue();
        ms.rgb = false;
        ms.interleaved = false;
        ms.indexed = false;
        ms.falseColor = true;
        ms.pixelType = FormatTools.pixelTypeFromString(pixType);
        ms.orderCertain = true;
        if (omexmlMeta.getPixelsSignificantBits(i) != null) {
            ms.bitsPerPixel = omexmlMeta.getPixelsSignificantBits(i).getValue();
        }
    }
    setSeries(oldSeries);
    // populate assigned metadata store with the
    // contents of the internal OME-XML metadata object
    MetadataStore store = getMetadataStore();
    service.convertMetadata(omexmlMeta, store);
    MetadataTools.populatePixels(store, this, false, false);
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) IOException(java.io.IOException) DependencyException(loci.common.services.DependencyException) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException) OMEXMLService(loci.formats.services.OMEXMLService) DefaultHandler(org.xml.sax.helpers.DefaultHandler) MetadataStore(loci.formats.meta.MetadataStore) ServiceException(loci.common.services.ServiceException) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) MissingLibraryException(loci.formats.MissingLibraryException) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 45 with DependencyException

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

the class OMEXMLWriter method setId.

// -- FormatWriter API methods --
/* @see loci.formats.FormatWriter#setId(String) */
@Override
public void setId(String id) throws FormatException, IOException {
    if (id.equals(currentId)) {
        return;
    }
    super.setId(id);
    MetadataRetrieve retrieve = getMetadataRetrieve();
    String xml;
    try {
        ServiceFactory factory = new ServiceFactory();
        service = factory.getInstance(OMEXMLService.class);
        xml = service.getOMEXML(retrieve);
        OMEXMLMetadata noBin = service.createOMEXMLMetadata(xml);
        service.removeBinData(noBin);
        OMEXMLMetadataRoot root = (OMEXMLMetadataRoot) noBin.getRoot();
        root.setCreator(FormatTools.CREATOR);
        xml = service.getOMEXML(noBin);
    } catch (DependencyException de) {
        throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, de);
    } catch (ServiceException se) {
        throw new FormatException(se);
    }
    xmlFragments = new ArrayList<String>();
    currentFragment = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    XMLTools.parseXML(xml, new OMEHandler());
    xmlFragments.add(currentFragment);
}
Also used : ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) OMEXMLMetadataRoot(ome.xml.meta.OMEXMLMetadataRoot) MissingLibraryException(loci.formats.MissingLibraryException) DependencyException(loci.common.services.DependencyException) MetadataRetrieve(loci.formats.meta.MetadataRetrieve) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException)

Aggregations

DependencyException (loci.common.services.DependencyException)51 ServiceFactory (loci.common.services.ServiceFactory)49 FormatException (loci.formats.FormatException)39 ServiceException (loci.common.services.ServiceException)32 OMEXMLService (loci.formats.services.OMEXMLService)32 MissingLibraryException (loci.formats.MissingLibraryException)15 MetadataStore (loci.formats.meta.MetadataStore)14 CoreMetadata (loci.formats.CoreMetadata)13 IMetadata (loci.formats.meta.IMetadata)13 IOException (java.io.IOException)12 Location (loci.common.Location)10 ImageReader (loci.formats.ImageReader)10 Length (ome.units.quantity.Length)10 PositiveInteger (ome.xml.model.primitives.PositiveInteger)9 OMEXMLMetadata (loci.formats.ome.OMEXMLMetadata)8 ArrayList (java.util.ArrayList)7 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)6 EnumerationException (ome.xml.model.enums.EnumerationException)6 File (java.io.File)5 IFormatWriter (loci.formats.IFormatWriter)5