Search in sources :

Example 6 with PositiveFloat

use of ome.xml.model.primitives.PositiveFloat in project bioformats by openmicroscopy.

the class PrairieReader method populateOMEMetadata.

/**
 * This step populates the OME {@link MetadataStore} by extracting relevant
 * values from the parsed {@link #meta} structure.
 */
private void populateOMEMetadata() throws FormatException {
    LOGGER.info("Populating OME metadata");
    // populate required Pixels metadata
    final boolean minimumMetadata = isMinimumMetadata();
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, !minimumMetadata);
    // populate required AcquisitionDate
    final String date = DateTools.formatDate(meta.getDate(), DATE_FORMAT);
    final Timestamp acquisitionDate = Timestamp.valueOf(date);
    final int seriesCount = getSeriesCount();
    for (int s = 0; s < seriesCount; s++) {
        setSeries(s);
        if (date != null)
            store.setImageAcquisitionDate(acquisitionDate, s);
    }
    if (minimumMetadata)
        return;
    // create an Instrument
    final String instrumentID = MetadataTools.createLSID("Instrument", 0);
    store.setInstrumentID(instrumentID, 0);
    // populate Laser Power, if available
    final Double laserPower = meta.getLaserPower();
    if (laserPower != null) {
        // create a Laser
        final String laserID = MetadataTools.createLSID("LightSource", 0, 0);
        store.setLaserID(laserID, 0, 0);
        store.setLaserPower(new Power(laserPower, UNITS.MILLIWATT), 0, 0);
    }
    String objectiveID = null;
    for (int s = 0; s < seriesCount; s++) {
        setSeries(s);
        final Sequence sequence = sequence(s);
        final Frame firstFrame = sequence.getFirstFrame();
        // link Instrument and Image
        store.setImageInstrumentRef(instrumentID, s);
        // populate PhysicalSizeX
        final PositiveFloat physicalSizeX = pf(firstFrame.getMicronsPerPixelX(), "PhysicalSizeX");
        if (physicalSizeX != null) {
            store.setPixelsPhysicalSizeX(FormatTools.createLength(physicalSizeX, UNITS.MICROMETER), s);
        }
        // populate PhysicalSizeY
        final PositiveFloat physicalSizeY = pf(firstFrame.getMicronsPerPixelY(), "PhysicalSizeY");
        if (physicalSizeY != null) {
            store.setPixelsPhysicalSizeY(FormatTools.createLength(physicalSizeY, UNITS.MICROMETER), s);
        }
        // populate TimeIncrement
        final Double waitTime = meta.getWaitTime();
        if (waitTime != null)
            store.setPixelsTimeIncrement(new Time(waitTime, UNITS.SECOND), s);
        final String[] detectorIDs = new String[channels.length];
        for (int c = 0; c < channels.length; c++) {
            final int channel = channels[c];
            final PFile file = firstFrame.getFile(channel);
            // populate channel name
            final String channelName = file == null ? null : file.getChannelName();
            if (channelName != null)
                store.setChannelName(channelName, s, c);
            // populate emission wavelength
            if (file != null) {
                final Double waveMin = file.getWavelengthMin();
                final Double waveMax = file.getWavelengthMax();
                if (waveMin != null && waveMax != null) {
                    final double waveAvg = (waveMin + waveMax) / 2;
                    final Length wavelength = FormatTools.getEmissionWavelength(waveAvg);
                    store.setChannelEmissionWavelength(wavelength, s, c);
                }
            }
            if (detectorIDs[c] == null) {
                // create a Detector for this channel
                detectorIDs[c] = MetadataTools.createLSID("Detector", 0, c);
                store.setDetectorID(detectorIDs[c], 0, c);
                store.setDetectorType(getDetectorType("Other"), 0, c);
                // NB: Ideally we would populate the detector zoom differently for
                // each Image, rather than globally for the Detector, but
                // unfortunately it is a property of Detector, not DetectorSettings.
                final Double zoom = firstFrame.getOpticalZoom();
                if (zoom != null)
                    store.setDetectorZoom(zoom, 0, c);
            }
            // link DetectorSettings and Detector
            store.setDetectorSettingsID(detectorIDs[c], s, c);
            // populate Offset
            final Double offset = firstFrame.getOffset(c);
            if (offset != null)
                store.setDetectorSettingsOffset(offset, s, c);
            // populate Gain
            final Double gain = firstFrame.getGain(c);
            if (gain != null)
                store.setDetectorSettingsGain(gain, s, c);
        }
        if (objectiveID == null) {
            // create an Objective
            objectiveID = MetadataTools.createLSID("Objective", 0, 0);
            store.setObjectiveID(objectiveID, 0, 0);
            store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
            // populate Objective NominalMagnification
            final Double magnification = firstFrame.getMagnification();
            if (magnification != null) {
                store.setObjectiveNominalMagnification(magnification, 0, 0);
            }
            // populate Objective Manufacturer
            final String objectiveManufacturer = firstFrame.getObjectiveManufacturer();
            store.setObjectiveManufacturer(objectiveManufacturer, 0, 0);
            // populate Objective Immersion
            final String immersion = firstFrame.getImmersion();
            store.setObjectiveImmersion(getImmersion(immersion), 0, 0);
            // populate Objective LensNA
            final Double lensNA = firstFrame.getObjectiveLensNA();
            if (lensNA != null)
                store.setObjectiveLensNA(lensNA, 0, 0);
            // populate Microscope Model
            final String microscopeModel = firstFrame.getImagingDevice();
            store.setMicroscopeModel(microscopeModel, 0);
        }
        // link ObjectiveSettings and Objective
        store.setObjectiveSettingsID(objectiveID, s);
        // populate stage position coordinates
        for (int t = 0; t < getSizeT(); t++) {
            final Sequence tSequence = sequence(t, s);
            for (int z = 0; z < getSizeZ(); z++) {
                final int index = frameIndex(tSequence, z, t, s);
                final Frame zFrame = tSequence.getFrame(index);
                if (zFrame == null) {
                    warnFrame(sequence, index);
                    continue;
                }
                final Length posX = zFrame.getPositionX();
                final Length posY = zFrame.getPositionY();
                final Length posZ = zFrame.getPositionZ();
                final Double deltaT = zFrame.getRelativeTime();
                for (int c = 0; c < getSizeC(); c++) {
                    final int i = getIndex(z, c, t);
                    if (posX != null)
                        store.setPlanePositionX(posX, s, i);
                    if (posY != null)
                        store.setPlanePositionY(posY, s, i);
                    if (posZ != null)
                        store.setPlanePositionZ(posZ, s, i);
                    if (deltaT != null)
                        store.setPlaneDeltaT(new Time(deltaT, UNITS.SECOND), s, i);
                }
            }
        }
    }
    setSeries(0);
}
Also used : Frame(loci.formats.in.PrairieMetadata.Frame) PFile(loci.formats.in.PrairieMetadata.PFile) Time(ome.units.quantity.Time) Sequence(loci.formats.in.PrairieMetadata.Sequence) Timestamp(ome.xml.model.primitives.Timestamp) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) PositiveFloat(ome.xml.model.primitives.PositiveFloat) Power(ome.units.quantity.Power)

Aggregations

PositiveFloat (ome.xml.model.primitives.PositiveFloat)6 Length (ome.units.quantity.Length)4 Element (org.w3c.dom.Element)3 NodeList (org.w3c.dom.NodeList)3 MetadataStore (loci.formats.meta.MetadataStore)2 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 DependencyException (loci.common.services.DependencyException)1 ServiceFactory (loci.common.services.ServiceFactory)1 CoreMetadata (loci.formats.CoreMetadata)1 FormatException (loci.formats.FormatException)1 Frame (loci.formats.in.PrairieMetadata.Frame)1 PFile (loci.formats.in.PrairieMetadata.PFile)1 Sequence (loci.formats.in.PrairieMetadata.Sequence)1 WlzService (loci.formats.services.WlzService)1 Power (ome.units.quantity.Power)1 Time (ome.units.quantity.Time)1 Image (ome.xml.model.Image)1 Pixels (ome.xml.model.Pixels)1 Timestamp (ome.xml.model.primitives.Timestamp)1