Search in sources :

Example 61 with Time

use of ome.units.quantity.Time in project bioformats by openmicroscopy.

the class NiftiReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    // the dataset has two files - we want the one ending in '.hdr'
    if (id.endsWith(".img")) {
        LOGGER.info("Looking for header file");
        String header = id.substring(0, id.lastIndexOf(".")) + ".hdr";
        if (new Location(header).exists()) {
            setId(header);
            return;
        } else
            throw new FormatException("Header file not found.");
    }
    super.initFile(id);
    in = new RandomAccessInputStream(id);
    CoreMetadata m = core.get(0);
    in.seek(40);
    short check = in.readShort();
    boolean little = check < 1 || check > 7;
    in.seek(40);
    if (id.endsWith(".hdr")) {
        pixelsFilename = id.substring(0, id.lastIndexOf(".")) + ".img";
        pixelFile = new RandomAccessInputStream(pixelsFilename);
    } else if (checkSuffix(id, "nii")) {
        pixelsFilename = id;
        pixelFile = in;
    } else {
        throw new FormatException("File does not have one of the required NIfTI extensions (.img, .hdr, .nii, .nii.gz)");
    }
    in.order(little);
    pixelFile.order(little);
    m.littleEndian = little;
    LOGGER.info("Reading header");
    nDimensions = in.readShort();
    m.sizeX = in.readShort();
    m.sizeY = in.readShort();
    m.sizeZ = in.readShort();
    m.sizeT = in.readShort();
    m.sizeC = 1;
    int[] extraDims = new int[3];
    extraDims[0] = in.readShort();
    extraDims[1] = in.readShort();
    extraDims[2] = in.readShort();
    if (nDimensions > 4) {
        LOGGER.debug("nDimensions = {}", nDimensions);
        for (int i = 0; i < nDimensions - 4; i++) {
            LOGGER.debug("  processing dimension = {}, Z = {}, T = {}, C = {}", extraDims[i], getSizeZ(), getSizeT(), getSizeC());
            m.sizeC *= extraDims[i];
        }
    }
    in.skipBytes(14);
    short dataType = in.readShort();
    in.skipBytes(36);
    pixelOffset = (int) in.readFloat();
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        populateExtendedMetadata();
    }
    LOGGER.info("Populating core metadata");
    if (getSizeZ() == 0)
        m.sizeZ = 1;
    if (getSizeT() == 0)
        m.sizeT = 1;
    m.imageCount = getSizeZ() * getSizeT() * getSizeC();
    m.indexed = false;
    m.dimensionOrder = "XYCZT";
    populatePixelType(dataType);
    m.rgb = getSizeC() > 1 && getImageCount() == getSizeZ() * getSizeT();
    m.interleaved = isRGB();
    LOGGER.info("Populating MetadataStore");
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        store.setImageDescription(description, 0);
        Length sizeX = FormatTools.getPhysicalSizeX(new Double(voxelWidth), spatialUnit);
        Length sizeY = FormatTools.getPhysicalSizeY(new Double(voxelHeight), spatialUnit);
        Length sizeZ = FormatTools.getPhysicalSizeZ(new Double(sliceThickness), spatialUnit);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
        if (sizeZ != null) {
            store.setPixelsPhysicalSizeZ(sizeZ, 0);
        }
        store.setPixelsTimeIncrement(new Time(new Double(deltaT), timeUnit), 0);
    }
}
Also used : Time(ome.units.quantity.Time) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) RandomAccessInputStream(loci.common.RandomAccessInputStream) Location(loci.common.Location)

Example 62 with Time

use of ome.units.quantity.Time in project bioformats by openmicroscopy.

the class NikonElementsTiffReader method initMetadataStore.

/* @see BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
    super.initMetadataStore();
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, true);
    String date = handler.getDate();
    if (date != null) {
        store.setImageAcquisitionDate(new Timestamp(date), 0);
    }
    if (getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM) {
        return;
    }
    Length sizeX = FormatTools.getPhysicalSizeX(handler.getPixelSizeX());
    Length sizeY = FormatTools.getPhysicalSizeY(handler.getPixelSizeY());
    Length sizeZ = FormatTools.getPhysicalSizeZ(handler.getPixelSizeZ());
    if (sizeX != null) {
        store.setPixelsPhysicalSizeX(sizeX, 0);
    }
    if (sizeY != null) {
        store.setPixelsPhysicalSizeY(sizeY, 0);
    }
    if (sizeZ != null) {
        store.setPixelsPhysicalSizeZ(sizeZ, 0);
    }
    String instrument = MetadataTools.createLSID("Instrument", 0);
    store.setInstrumentID(instrument, 0);
    store.setImageInstrumentRef(instrument, 0);
    ArrayList<Double> exposureTimes = handler.getExposureTimes();
    ArrayList<Length> posX = handler.getXPositions();
    ArrayList<Length> posY = handler.getYPositions();
    ArrayList<Length> posZ = handler.getZPositions();
    for (int i = 0; i < getImageCount(); i++) {
        int c = getZCTCoords(i)[1];
        if (c < exposureTimes.size() && exposureTimes.get(c) != null) {
            store.setPlaneExposureTime(new Time(exposureTimes.get(c), UNITS.SECOND), 0, i);
        }
        if (i < posX.size()) {
            store.setPlanePositionX(posX.get(i), 0, i);
        }
        if (i < posY.size()) {
            store.setPlanePositionY(posY.get(i), 0, i);
        }
        if (i < posZ.size()) {
            store.setPlanePositionZ(posZ.get(i), 0, i);
        }
    }
    String detector = MetadataTools.createLSID("Detector", 0, 0);
    store.setDetectorID(detector, 0, 0);
    store.setDetectorModel(handler.getCameraModel(), 0, 0);
    store.setDetectorType(getDetectorType("Other"), 0, 0);
    ArrayList<String> channelNames = handler.getChannelNames();
    ArrayList<String> modality = handler.getModalities();
    ArrayList<String> binning = handler.getBinnings();
    ArrayList<Double> speed = handler.getSpeeds();
    ArrayList<Double> gain = handler.getGains();
    ArrayList<Double> temperature = handler.getTemperatures();
    ArrayList<Double> exWave = handler.getExcitationWavelengths();
    ArrayList<Double> emWave = handler.getEmissionWavelengths();
    ArrayList<Integer> power = handler.getPowers();
    ArrayList<Hashtable<String, String>> rois = handler.getROIs();
    Double pinholeSize = handler.getPinholeSize();
    for (int c = 0; c < getEffectiveSizeC(); c++) {
        if (pinholeSize != null) {
            store.setChannelPinholeSize(new Length(pinholeSize, UNITS.MICROMETER), 0, c);
        }
        if (c < channelNames.size()) {
            store.setChannelName(channelNames.get(c), 0, c);
        }
        if (c < modality.size()) {
            store.setChannelAcquisitionMode(getAcquisitionMode(modality.get(c)), 0, c);
        }
        if (c < emWave.size()) {
            Length em = FormatTools.getEmissionWavelength(emWave.get(c));
            if (em != null) {
                store.setChannelEmissionWavelength(em, 0, c);
            }
        }
        if (c < exWave.size()) {
            Length ex = FormatTools.getExcitationWavelength(exWave.get(c));
            if (ex != null) {
                store.setChannelExcitationWavelength(ex, 0, c);
            }
        }
        if (c < binning.size()) {
            store.setDetectorSettingsBinning(getBinning(binning.get(c)), 0, c);
        }
        if (c < gain.size()) {
            store.setDetectorSettingsGain(gain.get(c), 0, c);
        }
        if (c < speed.size()) {
            store.setDetectorSettingsReadOutRate(new Frequency(speed.get(c), UNITS.HERTZ), 0, c);
        }
        store.setDetectorSettingsID(detector, 0, c);
    }
    if (temperature.size() > 0) {
        store.setImagingEnvironmentTemperature(new Temperature(temperature.get(0), UNITS.CELSIUS), 0);
    }
    Double voltage = handler.getVoltage();
    if (voltage != null) {
        store.setDetectorSettingsVoltage(new ElectricPotential(voltage, UNITS.VOLT), 0, 0);
    }
    Double na = handler.getNumericalAperture();
    if (na != null)
        store.setObjectiveLensNA(na, 0, 0);
    Double mag = handler.getMagnification();
    if (mag != null)
        store.setObjectiveCalibratedMagnification(mag, 0, 0);
    store.setObjectiveModel(handler.getObjectiveModel(), 0, 0);
    String immersion = handler.getImmersion();
    if (immersion == null)
        immersion = "Other";
    store.setObjectiveImmersion(getImmersion(immersion), 0, 0);
    String correction = handler.getCorrection();
    if (correction == null || correction.length() == 0)
        correction = "Other";
    store.setObjectiveCorrection(getCorrection(correction), 0, 0);
    String objective = MetadataTools.createLSID("Objective", 0, 0);
    store.setObjectiveID(objective, 0, 0);
    store.setObjectiveSettingsID(objective, 0);
    Double refractiveIndex = handler.getRefractiveIndex();
    if (refractiveIndex != null) {
        store.setObjectiveSettingsRefractiveIndex(refractiveIndex, 0);
    }
    if (getMetadataOptions().getMetadataLevel() == MetadataLevel.NO_OVERLAYS) {
        return;
    }
    handler.populateROIs(store);
}
Also used : Temperature(ome.units.quantity.Temperature) Hashtable(java.util.Hashtable) Time(ome.units.quantity.Time) Timestamp(ome.xml.model.primitives.Timestamp) ElectricPotential(ome.units.quantity.ElectricPotential) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) Frequency(ome.units.quantity.Frequency)

Example 63 with Time

use of ome.units.quantity.Time in project bioformats by openmicroscopy.

the class PCIReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    imageFiles = new HashMap<Integer, String>();
    timestamps = new HashMap<Integer, Double>();
    uniqueZ = new ArrayList<Double>();
    CoreMetadata m = core.get(0);
    initPOIService();
    double scaleFactor = 1;
    final List<String> allFiles = poi.getDocumentList();
    if (allFiles.isEmpty()) {
        throw new FormatException("No files were found - the .cxd may be corrupt.");
    }
    double firstZ = 0d, secondZ = 0d;
    int mode = 0;
    for (String name : allFiles) {
        int separator = name.lastIndexOf(File.separator);
        String parent = name.substring(0, separator);
        String relativePath = name.substring(separator + 1);
        RandomAccessInputStream stream = null;
        if (!(relativePath.startsWith("Bitmap") || (relativePath.equals("Data") && parent.indexOf("Image") != -1))) {
            stream = poi.getDocumentStream(name);
            stream.order(true);
        }
        if (stream != null && stream.length() == 8) {
            double value = stream.readDouble();
            stream.seek(0);
            String key = name.replace(File.separatorChar, ' ');
            key = key.replaceAll("Root Entry ", "");
            key = key.replaceAll("Field Data ", "");
            key = key.replaceAll("Details ", "");
            addGlobalMeta(key, value);
        }
        if (relativePath.equals("Field Count")) {
            m.imageCount = stream.readInt();
        } else if (relativePath.equals("File Has Image")) {
            if (stream.readShort() == 0) {
                throw new FormatException("This file does not contain image data.");
            }
        } else if (relativePath.startsWith("Bitmap") || (relativePath.equals("Data") && parent.indexOf("Image") != -1)) {
            imageFiles.put(imageFiles.size(), name);
            if (getSizeX() != 0 && getSizeY() != 0) {
                int bpp = FormatTools.getBytesPerPixel(getPixelType());
                int plane = getSizeX() * getSizeY() * bpp;
                if (getSizeC() == 0 || getSizeC() * plane > poi.getFileSize(name)) {
                    m.sizeC = poi.getFileSize(name) / plane;
                }
            }
        } else if (relativePath.indexOf("Image_Depth") != -1) {
            boolean firstBits = m.bitsPerPixel == 0;
            int bits = (int) stream.readDouble();
            m.bitsPerPixel = bits;
            while (bits % 8 != 0 || bits == 0) bits++;
            if (bits % 3 == 0) {
                m.sizeC = 3;
                bits /= 3;
                m.bitsPerPixel /= 3;
            }
            bits /= 8;
            m.pixelType = FormatTools.pixelTypeFromBytes(bits, false, false);
            if (getSizeC() > 1 && firstBits) {
                m.sizeC /= bits;
            }
        } else if (relativePath.indexOf("Image_Height") != -1 && getSizeY() == 0) {
            m.sizeY = (int) stream.readDouble();
        } else if (relativePath.indexOf("Image_Width") != -1 && getSizeX() == 0) {
            m.sizeX = (int) stream.readDouble();
        } else if (relativePath.indexOf("Time_From_Start") != -1) {
            timestamps.put(getTimestampIndex(parent), stream.readDouble());
        } else if (relativePath.indexOf("Position_Z") != -1) {
            double zPos = stream.readDouble();
            if (!uniqueZ.contains(zPos) && getSizeZ() <= 1) {
                uniqueZ.add(zPos);
            }
            if (name.indexOf("Field 1" + File.separator) != -1)
                firstZ = zPos;
            else if (name.indexOf("Field 2" + File.separator) != -1)
                secondZ = zPos;
        } else if (relativePath.equals("First Field Date & Time")) {
            long date = (long) stream.readDouble() * 1000;
            creationDate = DateTools.convertDate(date, DateTools.COBOL);
        } else if (relativePath.equals("GroupMode")) {
            mode = stream.readInt();
        } else if (relativePath.equals("GroupSelectedFields")) {
            m.sizeZ = (int) (stream.length() / 8);
        } else if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
            if (relativePath.equals("Binning")) {
                binning = (int) stream.readDouble();
            } else if (relativePath.equals("Comments")) {
                String comments = stream.readString((int) stream.length());
                String[] lines = comments.split("\n");
                for (String line : lines) {
                    int eq = line.indexOf('=');
                    if (eq != -1) {
                        String key = line.substring(0, eq).trim();
                        String value = line.substring(eq + 1).trim();
                        addGlobalMeta(key, value);
                        if (key.equals("factor")) {
                            if (value.indexOf(';') != -1) {
                                value = value.substring(0, value.indexOf(';'));
                            }
                            scaleFactor = Double.parseDouble(value.trim());
                        }
                    }
                }
            }
        }
        if (stream != null) {
            stream.close();
        }
    }
    boolean zFirst = Math.abs(firstZ - secondZ) > Constants.EPSILON;
    if (getSizeC() == 0)
        m.sizeC = 1;
    if (mode == 0) {
        m.sizeZ = 0;
    }
    if (getSizeZ() <= 1 || (getImageCount() % getSizeZ()) != 0) {
        m.sizeZ = uniqueZ.isEmpty() ? 1 : uniqueZ.size();
    }
    m.sizeT = getImageCount() / getSizeZ();
    while (getSizeZ() * getSizeT() < getImageCount()) {
        m.sizeZ++;
        m.sizeT = getImageCount() / getSizeZ();
    }
    m.rgb = getSizeC() > 1;
    if (imageFiles.size() > getImageCount() && getSizeC() == 1) {
        m.sizeC = imageFiles.size() / getImageCount();
        m.imageCount *= getSizeC();
    } else {
        m.imageCount = getSizeZ() * getSizeT();
    }
    m.interleaved = false;
    m.dimensionOrder = zFirst ? "XYCZT" : "XYCTZ";
    m.littleEndian = true;
    m.indexed = false;
    m.falseColor = false;
    m.metadataComplete = true;
    // re-index image files
    String[] files = imageFiles.values().toArray(new String[imageFiles.size()]);
    for (String file : files) {
        int separator = file.lastIndexOf(File.separator);
        String parent = file.substring(0, separator);
        imageFiles.put(getImageIndex(parent), file);
    }
    int bpp = FormatTools.getBytesPerPixel(m.pixelType);
    int expectedPlaneSize = m.sizeX * m.sizeY * bpp * m.sizeC;
    String file = imageFiles.get(0);
    RandomAccessInputStream s = poi.getDocumentStream(file);
    TiffParser tp = new TiffParser(s);
    // don't correct the image width if it's stored as a TIFF
    if (!tp.isValidHeader() && s.length() > expectedPlaneSize) {
        m.sizeX += (s.length() - expectedPlaneSize) / (m.sizeY * bpp * m.sizeC);
    }
    s.close();
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, true);
    if (creationDate != null) {
        store.setImageAcquisitionDate(new Timestamp(creationDate), 0);
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        Length sizeX = FormatTools.getPhysicalSizeX(scaleFactor);
        Length sizeY = FormatTools.getPhysicalSizeY(scaleFactor);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
        for (int i = 0; i < timestamps.size(); i++) {
            if (i >= getImageCount()) {
                break;
            }
            Double timestamp = timestamps.get(i);
            if (timestamp != null) {
                store.setPlaneDeltaT(new Time(timestamp, UNITS.SECOND), 0, i);
            }
            if (i == 2) {
                Double first = timestamps.get(1);
                Double increment = timestamp - first;
                if (increment != null) {
                    store.setPixelsTimeIncrement(new Time(increment, UNITS.SECOND), 0);
                }
            }
        }
        if (binning > 0) {
            String instrumentID = MetadataTools.createLSID("Instrument", 0);
            String detectorID = MetadataTools.createLSID("Detector", 0);
            store.setInstrumentID(instrumentID, 0);
            store.setDetectorID(detectorID, 0, 0);
            store.setDetectorType(getDetectorType("Other"), 0, 0);
            store.setImageInstrumentRef(instrumentID, 0);
            Binning binningEnum = getBinning(binning + "x" + binning);
            for (int c = 0; c < getEffectiveSizeC(); c++) {
                store.setDetectorSettingsID(detectorID, 0, c);
                store.setDetectorSettingsBinning(binningEnum, 0, c);
            }
        }
    }
}
Also used : Time(ome.units.quantity.Time) CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp) FormatException(loci.formats.FormatException) MetadataStore(loci.formats.meta.MetadataStore) Binning(ome.xml.model.enums.Binning) Length(ome.units.quantity.Length) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 64 with Time

use of ome.units.quantity.Time 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 65 with Time

use of ome.units.quantity.Time in project bioformats by openmicroscopy.

the class KodakReader method readExtraMetadata.

private void readExtraMetadata(MetadataStore store) throws IOException {
    if (getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM) {
        return;
    }
    in.seek(0);
    findString("Image Capture Source");
    String metadata = in.readCString();
    if (metadata == null) {
        return;
    }
    String[] lines = metadata.split("\n");
    for (String line : lines) {
        int index = line.indexOf(':');
        if (index < 0 || line.startsWith("#") || line.startsWith("-")) {
            continue;
        }
        String key = line.substring(0, index).trim();
        String value = line.substring(index + 1).trim();
        addGlobalMeta(key, value);
        if (key.equals("Image Capture Source")) {
            String instrument = MetadataTools.createLSID("Instrument", 0);
            store.setInstrumentID(instrument, 0);
            store.setImageInstrumentRef(instrument, 0);
            store.setMicroscopeModel(value, 0);
        } else if (key.equals("Capture Time/Date")) {
            String date = DateTools.formatDate(value, DATE_FORMAT);
            if (date != null) {
                store.setImageAcquisitionDate(new Timestamp(date), 0);
            }
        } else if (key.equals("Exposure Time")) {
            Double exposureTime = new Double(value.substring(0, value.indexOf(' ')));
            if (exposureTime != null) {
                store.setPlaneExposureTime(new Time(exposureTime, UNITS.SECOND), 0, 0);
            }
        } else if (key.equals("Vertical Resolution")) {
            // resolution stored in pixels per inch
            if (value.indexOf(' ') > 0) {
                value = value.substring(0, value.indexOf(' '));
            }
            Double size = new Double(value);
            size = 1.0 / (size * (1.0 / 25400));
            Length sizeY = FormatTools.getPhysicalSizeY(size);
            if (sizeY != null) {
                store.setPixelsPhysicalSizeY(sizeY, 0);
            }
        } else if (key.equals("Horizontal Resolution")) {
            // resolution stored in pixels per inch
            if (value.indexOf(' ') > 0) {
                value = value.substring(0, value.indexOf(' '));
            }
            Double size = new Double(value);
            size = 1.0 / (size * (1.0 / 25400));
            Length sizeX = FormatTools.getPhysicalSizeX(size);
            if (sizeX != null) {
                store.setPixelsPhysicalSizeX(sizeX, 0);
            }
        } else if (key.equals("CCD Temperature")) {
            Double temp;
            Matcher hexMatcher = Pattern.compile("0x([0-9A-F]+)").matcher(value);
            if (hexMatcher.matches()) {
                // CCD temperature stored as a hexadecimal string such as "0xEB".
                temp = new Double(Integer.parseInt(hexMatcher.group(1), 16));
                LOGGER.debug("CCD temperature detected as {}; assumed to be invalid", temp);
            } else {
                temp = new Double(value.substring(0, value.indexOf(' ')));
                store.setImagingEnvironmentTemperature(new Temperature(temp, UNITS.CELSIUS), 0);
            }
        }
    }
}
Also used : Temperature(ome.units.quantity.Temperature) Length(ome.units.quantity.Length) Matcher(java.util.regex.Matcher) Time(ome.units.quantity.Time) Timestamp(ome.xml.model.primitives.Timestamp)

Aggregations

Time (ome.units.quantity.Time)74 Length (ome.units.quantity.Length)46 MetadataStore (loci.formats.meta.MetadataStore)41 Timestamp (ome.xml.model.primitives.Timestamp)33 CoreMetadata (loci.formats.CoreMetadata)30 FormatException (loci.formats.FormatException)24 RandomAccessInputStream (loci.common.RandomAccessInputStream)21 Location (loci.common.Location)20 ArrayList (java.util.ArrayList)17 PositiveInteger (ome.xml.model.primitives.PositiveInteger)13 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)12 IOException (java.io.IOException)10 Temperature (ome.units.quantity.Temperature)9 IFD (loci.formats.tiff.IFD)8 ElectricPotential (ome.units.quantity.ElectricPotential)7 Color (ome.xml.model.primitives.Color)7 IMetadata (loci.formats.meta.IMetadata)6 File (java.io.File)5 DependencyException (loci.common.services.DependencyException)5 ServiceException (loci.common.services.ServiceException)5