Search in sources :

Example 1 with Sequence

use of loci.formats.in.PrairieMetadata.Sequence in project bioformats by openmicroscopy.

the class PrairieReader method openBytes.

@Override
public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
    FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h);
    if (singleTiffMode)
        return tiff.openBytes(no, buf, x, y, w, h);
    // convert 1D index to (sequence, index, channel) coordinates.
    final int[] zct = getZCTCoords(no);
    final int z = zct[0], c = zct[1], t = zct[2];
    final Sequence sequence = sequence(t, getSeries());
    final int index = frameIndex(sequence, z, t, getSeries());
    final Frame frame = sequence.getFrame(index);
    if (frame == null) {
        warnFrame(sequence, index);
        return blank(buf);
    }
    final int channel = channels[c];
    final PFile file = frame.getFile(channel);
    if (file == null) {
        warnFile(sequence, index, channel);
        return blank(buf);
    }
    tiff.setId(getPath(file));
    return tiff.openBytes(0, buf, x, y, w, h);
}
Also used : Frame(loci.formats.in.PrairieMetadata.Frame) PFile(loci.formats.in.PrairieMetadata.PFile) Sequence(loci.formats.in.PrairieMetadata.Sequence)

Example 2 with Sequence

use of loci.formats.in.PrairieMetadata.Sequence in project bioformats by openmicroscopy.

the class PrairieReader method populateOriginalMetadata.

/**
 * This steps populates the original metadata table (the tables returned by
 * {@link #getGlobalMetadata()} and {@link #getSeriesMetadata()}).
 */
private void populateOriginalMetadata() {
    final boolean minimumMetadata = isMinimumMetadata();
    if (minimumMetadata)
        return;
    // populate global metadata
    addGlobalMeta("cycleCount", meta.getCycleCount());
    addGlobalMeta("date", meta.getDate());
    addGlobalMeta("waitTime", meta.getWaitTime());
    addGlobalMeta("sequenceCount", sequences.size());
    final ValueTable config = meta.getConfig();
    for (final String key : config.keySet()) {
        addGlobalMeta(key, config.get(key).toString());
    }
    addGlobalMeta("meta", meta);
    // populate series metadata
    final int seriesCount = getSeriesCount();
    for (int s = 0; s < seriesCount; s++) {
        setSeries(s);
        final Sequence sequence = sequence(s);
        addSeriesMeta("cycle", sequence.getCycle());
        addSeriesMeta("indexCount", sequence.getIndexCount());
        addSeriesMeta("type", sequence.getType());
    }
    setSeries(0);
}
Also used : ValueTable(loci.formats.in.PrairieMetadata.ValueTable) Sequence(loci.formats.in.PrairieMetadata.Sequence)

Example 3 with Sequence

use of loci.formats.in.PrairieMetadata.Sequence in project bioformats by openmicroscopy.

the class PrairieReader method populateCoreMetadata.

/**
 * This step populates the {@link CoreMetadata} by extracting relevant values
 * from the parsed {@link #meta} structure.
 */
private void populateCoreMetadata() throws FormatException, IOException {
    LOGGER.info("Populating core metadata");
    // NB: Both stage positions and time points are rasterized into the list
    // of Sequences. So by definition: sequenceCount = sizeT * seriesCount.
    final int sequenceCount = sequences.size();
    final int sizeT = computeSizeT(sequenceCount);
    final int seriesCount = sequenceCount / sizeT;
    final Integer bitDepth = meta.getBitDepth();
    int bpp = bitDepth == null ? -1 : bitDepth;
    core.clear();
    framesAreTime = new boolean[seriesCount];
    for (int s = 0; s < seriesCount; s++) {
        final Sequence sequence = sequence(0, s, seriesCount);
        final Frame frame = sequence.getFirstFrame();
        final PFile file = frame == null ? null : frame.getFirstFile();
        if (frame == null || file == null) {
            throw new FormatException("No metadata for series #" + s);
        }
        // should remedy any resultant inaccuracies in the metadata.
        if (s == 0) {
            tiff.setId(getPath(file));
            if (bpp <= 0)
                bpp = tiff.getBitsPerPixel();
        }
        final Integer linesPerFrame = frame.getLinesPerFrame();
        final Integer pixelsPerLine = frame.getPixelsPerLine();
        final int indexCount = sequence.getIndexCount();
        final int sizeX = pixelsPerLine == null ? tiff.getSizeX() : pixelsPerLine;
        final int sizeY = linesPerFrame == null ? tiff.getSizeY() : linesPerFrame;
        framesAreTime[s] = sequence.isTimeSeries() && sizeT == 1;
        final CoreMetadata cm = new CoreMetadata();
        cm.sizeX = sizeX;
        cm.sizeY = sizeY;
        cm.sizeZ = framesAreTime[s] ? 1 : indexCount;
        cm.sizeC = channels.length;
        cm.sizeT = framesAreTime[s] ? indexCount : sizeT;
        cm.pixelType = tiff.getPixelType();
        cm.bitsPerPixel = bpp;
        cm.imageCount = cm.sizeZ * cm.sizeC * cm.sizeT;
        cm.dimensionOrder = "XYCZT";
        cm.orderCertain = true;
        cm.rgb = false;
        cm.littleEndian = tiff.isLittleEndian();
        cm.interleaved = false;
        cm.indexed = tiff.isIndexed();
        cm.falseColor = false;
        core.add(cm);
    }
}
Also used : Frame(loci.formats.in.PrairieMetadata.Frame) PFile(loci.formats.in.PrairieMetadata.PFile) Sequence(loci.formats.in.PrairieMetadata.Sequence) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException)

Example 4 with Sequence

use of loci.formats.in.PrairieMetadata.Sequence 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)

Example 5 with Sequence

use of loci.formats.in.PrairieMetadata.Sequence in project bioformats by openmicroscopy.

the class PrairieReader method positionsMatch.

/**
 * Verifies that stage coordinates match for all (P, Z) across time.
 */
private boolean positionsMatch(int sizeT, int sizeP) {
    // NB: Rasterization order is XYCZpT, where p is the stage position.
    for (int p = 0; p < sizeP; p++) {
        final Sequence initialSequence = sequence(0, p, sizeP);
        final int indexMin = initialSequence.getIndexMin();
        final int indexCount = initialSequence.getIndexCount();
        for (int z = 0; z < indexCount; z++) {
            final int index = z + indexMin;
            final Frame initialFrame = initialSequence.getFrame(index);
            if (initialFrame == null) {
                warnFrame(initialSequence, index);
                break;
            }
            // obtain the initial XYZ stage coordinates for this position
            final Length xInitial = initialFrame.getPositionX();
            final Length yInitial = initialFrame.getPositionY();
            final Length zInitial = initialFrame.getPositionZ();
            // verify that the initial coordinates match all subsequent time points
            for (int t = 1; t < sizeT; t++) {
                final Sequence sequence = sequence(t, p, sizeP);
                final Frame frame = sequence.getFrame(index);
                if (frame == null) {
                    warnFrame(sequence, index);
                    continue;
                }
                final Length xPos = frame.getPositionX();
                final Length yPos = frame.getPositionY();
                final Length zPos = frame.getPositionZ();
                if (!equal(xPos, xInitial) || !equal(yPos, yInitial) || !equal(zPos, zInitial)) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : Frame(loci.formats.in.PrairieMetadata.Frame) Length(ome.units.quantity.Length) Sequence(loci.formats.in.PrairieMetadata.Sequence)

Aggregations

Sequence (loci.formats.in.PrairieMetadata.Sequence)6 Frame (loci.formats.in.PrairieMetadata.Frame)5 PFile (loci.formats.in.PrairieMetadata.PFile)4 Length (ome.units.quantity.Length)2 ArrayList (java.util.ArrayList)1 CoreMetadata (loci.formats.CoreMetadata)1 FormatException (loci.formats.FormatException)1 ValueTable (loci.formats.in.PrairieMetadata.ValueTable)1 MetadataStore (loci.formats.meta.MetadataStore)1 Power (ome.units.quantity.Power)1 Time (ome.units.quantity.Time)1 PositiveFloat (ome.xml.model.primitives.PositiveFloat)1 Timestamp (ome.xml.model.primitives.Timestamp)1