Search in sources :

Example 16 with OMEXMLMetadata

use of loci.formats.ome.OMEXMLMetadata in project bioformats by openmicroscopy.

the class OMEXMLServiceTest method testOriginalMetadata.

@Test
public void testOriginalMetadata() throws ServiceException {
    OMEXMLMetadata metadata = service.createOMEXMLMetadata();
    service.populateOriginalMetadata(metadata, "testKey", "testValue");
    Hashtable metadataTable = service.getOriginalMetadata(metadata);
    assertEquals(metadataTable.size(), 1);
    assertTrue("testValue".equals(metadataTable.get("testKey")));
    OME root = (OME) metadata.getRoot();
    StructuredAnnotations annotations = root.getStructuredAnnotations();
    assertEquals(annotations.sizeOfXMLAnnotationList(), 1);
    XMLAnnotation xmlAnn = annotations.getXMLAnnotation(0);
    String txt = "<OriginalMetadata><Key>testKey</Key><Value>testValue</Value></OriginalMetadata>";
    assertEquals(txt, xmlAnn.getValue());
    OriginalMetadataAnnotation omAnn = (OriginalMetadataAnnotation) xmlAnn;
    assertEquals("testValue", omAnn.getValueForKey());
}
Also used : OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) Hashtable(java.util.Hashtable) OME(ome.xml.model.OME) StructuredAnnotations(ome.xml.model.StructuredAnnotations) XMLAnnotation(ome.xml.model.XMLAnnotation) OriginalMetadataAnnotation(loci.formats.meta.OriginalMetadataAnnotation) Test(org.testng.annotations.Test)

Example 17 with OMEXMLMetadata

use of loci.formats.ome.OMEXMLMetadata in project bioformats by openmicroscopy.

the class OMEXMLServiceTest method testIntegerUnitProperty.

/**
 * Test that the XML serialization of integer unit properties does not
 * include a decimal point. In the schema a shape's font size is
 * {@code type="OME:NonNegativeInt"} which in OMERO is mapped to a
 * {@code double}.
 * @throws ServiceException unexpected
 */
@Test
public void testIntegerUnitProperty() throws ServiceException {
    final Length propertyValue = new Length(12.0d, UNITS.POINT);
    final StringBuffer expectedText = new StringBuffer();
    expectedText.append(" FontSize=");
    expectedText.append('"');
    expectedText.append(propertyValue.value().longValue());
    expectedText.append('"');
    final OMEXMLMetadata metadata = service.createOMEXMLMetadata();
    metadata.setROIID("test ROI", 0);
    metadata.setPointID("test point", 0, 0);
    metadata.setPointX(0.0, 0, 0);
    metadata.setPointY(0.0, 0, 0);
    metadata.setPointFontSize(propertyValue, 0, 0);
    final String xml = service.getOMEXML(metadata);
    assertTrue(xml.contains(expectedText));
}
Also used : Length(ome.units.quantity.Length) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) Test(org.testng.annotations.Test)

Example 18 with OMEXMLMetadata

use of loci.formats.ome.OMEXMLMetadata in project bioformats by openmicroscopy.

the class OMEXMLServiceTest method testFloatingPointUnitProperty.

/**
 * Test that the XML serialization of floating point unit properties
 * includes a decimal point. In the schema a shape's stroke width is
 * {@code type="xsd:float"} which in OMERO is mapped to a {@code double}.
 * @throws ServiceException unexpected
 */
@Test
public void testFloatingPointUnitProperty() throws ServiceException {
    final Length propertyValue = new Length(3.0d, UNITS.PIXEL);
    final StringBuffer expectedText = new StringBuffer();
    expectedText.append(" StrokeWidth=");
    expectedText.append('"');
    expectedText.append(propertyValue.value().doubleValue());
    expectedText.append('"');
    final OMEXMLMetadata metadata = service.createOMEXMLMetadata();
    metadata.setROIID("test ROI", 0);
    metadata.setPointID("test point", 0, 0);
    metadata.setPointX(0.0, 0, 0);
    metadata.setPointY(0.0, 0, 0);
    metadata.setPointStrokeWidth(propertyValue, 0, 0);
    final String xml = service.getOMEXML(metadata);
    assertTrue(xml.contains(expectedText));
}
Also used : Length(ome.units.quantity.Length) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) Test(org.testng.annotations.Test)

Example 19 with OMEXMLMetadata

use of loci.formats.ome.OMEXMLMetadata in project bioformats by openmicroscopy.

the class FileWriteSPW method initializeMetadata.

/**
 * Populate the minimum amount of metadata required to export a Plate.
 */
private IMetadata initializeMetadata(int[][] nFovs) {
    Exception exception = null;
    try {
        // create the OME-XML metadata storage object
        ServiceFactory factory = new ServiceFactory();
        service = factory.getInstance(OMEXMLService.class);
        OMEXMLMetadata meta = service.createOMEXMLMetadata();
        // IMetadata meta = service.createOMEXMLMetadata();
        meta.createRoot();
        int plateIndex = 0;
        // count of images
        int series = 0;
        int well = 0;
        meta.setPlateDescription(plateDescription, 0);
        meta.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
        meta.setPlateRowNamingConvention(NamingConvention.LETTER, 0);
        meta.setPlateColumnNamingConvention(NamingConvention.NUMBER, 0);
        meta.setPlateRows(new PositiveInteger(rows), 0);
        meta.setPlateColumns(new PositiveInteger(cols), 0);
        meta.setPlateName("First test Plate", 0);
        PositiveInteger pwidth = new PositiveInteger(width);
        PositiveInteger pheight = new PositiveInteger(height);
        char rowChar = 'A';
        for (int row = 0; row < rows; row++) {
            for (int column = 0; column < cols; column++) {
                // set up well
                String wellID = MetadataTools.createLSID("Well", well);
                meta.setWellID(wellID, plateIndex, well);
                meta.setWellRow(new NonNegativeInteger(row), plateIndex, well);
                meta.setWellColumn(new NonNegativeInteger(column), plateIndex, well);
                int nFOV = nFovs[row][column];
                for (int fov = 0; fov < nFOV; fov++) {
                    // Create Image NB numberng in the Name goes from 1->n not 0-> n-1
                    String imageName = rowChar + ":" + Integer.toString(column + 1) + ":FOV:" + Integer.toString(fov + 1);
                    String imageID = MetadataTools.createLSID("Image", well, fov);
                    meta.setImageID(imageID, series);
                    meta.setImageName(imageName, series);
                    String pixelsID = MetadataTools.createLSID("Pixels", well, fov);
                    meta.setPixelsID(pixelsID, series);
                    // specify that the pixel data is stored in big-endian format
                    // change 'TRUE' to 'FALSE' to specify little-endian format
                    meta.setPixelsBigEndian(Boolean.TRUE, series);
                    // specify that the image is stored in ZCT order
                    meta.setPixelsDimensionOrder(DimensionOrder.XYZCT, series);
                    // specify the pixel type of the image
                    meta.setPixelsType(PixelType.fromString(FormatTools.getPixelTypeString(pixelType)), series);
                    // specify the dimensions of the image
                    meta.setPixelsSizeX(pwidth, series);
                    meta.setPixelsSizeY(pheight, series);
                    meta.setPixelsSizeZ(new PositiveInteger(1), series);
                    meta.setPixelsSizeC(new PositiveInteger(1), series);
                    meta.setPixelsSizeT(new PositiveInteger(sizet), series);
                    // define each channel and specify the number of samples in the channel
                    // the number of samples is 3 for RGB images and 1 otherwise
                    String channelID = MetadataTools.createLSID("Channel", well, fov);
                    meta.setChannelID(channelID, series, 0);
                    meta.setChannelSamplesPerPixel(new PositiveInteger(1), series, 0);
                    // set sample
                    String wellSampleID = MetadataTools.createLSID("WellSample", well, fov);
                    meta.setWellSampleID(wellSampleID, 0, well, fov);
                    // NB sampleIndex here == series ie the image No
                    meta.setWellSampleIndex(new NonNegativeInteger(series), 0, well, fov);
                    meta.setWellSampleImageRef(imageID, 0, well, fov);
                    if (exposureTimes != null && exposureTimes.length == sizet) {
                        for (int t = 0; t < sizet; t++) {
                            meta.setPlaneTheT(new NonNegativeInteger(t), series, t);
                            meta.setPlaneTheC(new NonNegativeInteger(0), series, t);
                            meta.setPlaneTheZ(new NonNegativeInteger(0), series, t);
                            meta.setPlaneExposureTime(new Time(exposureTimes[t], ome.units.UNITS.SECOND), series, t);
                        }
                    }
                    // add FLIM ModuloAlongT annotation if required
                    if (delays != null) {
                        CoreMetadata modlo = createModuloAnn(meta);
                        service.addModuloAlong(meta, modlo, series);
                    }
                    series++;
                }
                // end of samples
                well++;
            }
            rowChar++;
        }
        expectedImages = new int[series];
        // System.out.println(dump);
        return meta;
    } catch (DependencyException | ServiceException | EnumerationException e) {
        exception = e;
    }
    System.err.println("Failed to populate OME-XML metadata object.");
    return null;
}
Also used : PositiveInteger(ome.xml.model.primitives.PositiveInteger) ServiceFactory(loci.common.services.ServiceFactory) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) Time(ome.units.quantity.Time) DependencyException(loci.common.services.DependencyException) CoreMetadata(loci.formats.CoreMetadata) 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) ServiceException(loci.common.services.ServiceException) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) EnumerationException(ome.xml.model.enums.EnumerationException)

Example 20 with OMEXMLMetadata

use of loci.formats.ome.OMEXMLMetadata 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)

Aggregations

OMEXMLMetadata (loci.formats.ome.OMEXMLMetadata)24 ServiceException (loci.common.services.ServiceException)12 ServiceFactory (loci.common.services.ServiceFactory)10 OMEXMLService (loci.formats.services.OMEXMLService)10 DependencyException (loci.common.services.DependencyException)9 IOException (java.io.IOException)8 FormatException (loci.formats.FormatException)8 MetadataStore (loci.formats.meta.MetadataStore)7 OMEXMLMetadataRoot (ome.xml.meta.OMEXMLMetadataRoot)7 Location (loci.common.Location)6 PositiveInteger (ome.xml.model.primitives.PositiveInteger)6 CoreMetadata (loci.formats.CoreMetadata)5 Length (ome.units.quantity.Length)5 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)5 Test (org.testng.annotations.Test)5 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 TransformerException (javax.xml.transform.TransformerException)3 MissingLibraryException (loci.formats.MissingLibraryException)3 Image (ome.xml.model.Image)3 EnumerationException (ome.xml.model.enums.EnumerationException)3