Search in sources :

Example 1 with PFile

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

use of loci.formats.in.PrairieMetadata.PFile 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 3 with PFile

use of loci.formats.in.PrairieMetadata.PFile 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 4 with PFile

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

the class PrairieReader method getSeriesUsedFiles.

@Override
public String[] getSeriesUsedFiles(boolean noPixels) {
    FormatTools.assertId(currentId, true, 1);
    if (singleTiffMode)
        return tiff.getSeriesUsedFiles(noPixels);
    // add metadata files to the used files list
    final ArrayList<String> usedFiles = new ArrayList<String>();
    if (xmlFile != null)
        usedFiles.add(xmlFile.getAbsolutePath());
    if (cfgFile != null)
        usedFiles.add(cfgFile.getAbsolutePath());
    if (envFile != null)
        usedFiles.add(envFile.getAbsolutePath());
    if (!noPixels) {
        // add TIFF files to the used files list
        final int s = getSeries();
        for (int t = 0; t < getSizeT(); t++) {
            final Sequence sequence = sequence(t, s);
            for (int z = 0; z < getSizeZ(); z++) {
                final int index = frameIndex(sequence, z, t, s);
                final Frame frame = sequence.getFrame(index);
                if (frame == null) {
                    warnFrame(sequence, index);
                    continue;
                }
                for (int c = 0; c < getSizeC(); c++) {
                    final int channel = channels[c];
                    final PFile file = frame.getFile(channel);
                    if (file == null) {
                        warnFile(sequence, index, channel);
                        continue;
                    }
                    final String filename = file.getFilename();
                    if (filename == null) {
                        warnFilename(sequence, index, channel);
                        continue;
                    }
                    usedFiles.add(getPath(file));
                }
            }
        }
    }
    return usedFiles.toArray(new String[usedFiles.size()]);
}
Also used : Frame(loci.formats.in.PrairieMetadata.Frame) PFile(loci.formats.in.PrairieMetadata.PFile) ArrayList(java.util.ArrayList) Sequence(loci.formats.in.PrairieMetadata.Sequence)

Aggregations

Frame (loci.formats.in.PrairieMetadata.Frame)4 PFile (loci.formats.in.PrairieMetadata.PFile)4 Sequence (loci.formats.in.PrairieMetadata.Sequence)4 ArrayList (java.util.ArrayList)1 CoreMetadata (loci.formats.CoreMetadata)1 FormatException (loci.formats.FormatException)1 MetadataStore (loci.formats.meta.MetadataStore)1 Length (ome.units.quantity.Length)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