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);
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations