Search in sources :

Example 6 with Timestamp

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

the class OpenlabRawReader 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);
    // read the 12 byte file header
    LOGGER.info("Verifying Openlab RAW format");
    if (!in.readString(4).equals("OLRW")) {
        throw new FormatException("Openlab RAW magic string not found.");
    }
    LOGGER.info("Populating metadata");
    CoreMetadata m = core.get(0);
    int version = in.readInt();
    m.imageCount = in.readInt();
    offsets = new int[getImageCount()];
    offsets[0] = 12;
    in.skipBytes(8);
    m.sizeX = in.readInt();
    m.sizeY = in.readInt();
    in.skipBytes(1);
    m.sizeC = in.read();
    bytesPerPixel = in.read();
    in.skipBytes(1);
    long stampMs = in.readLong();
    if (stampMs > 0) {
        stampMs /= 1000000;
        stampMs -= (67 * 365.25 * 24 * 60 * 60);
    } else
        stampMs = System.currentTimeMillis();
    String stamp = DateTools.convertDate(stampMs, DateTools.UNIX);
    in.skipBytes(4);
    int len = in.read() & 0xff;
    String imageName = in.readString(len - 1).trim();
    if (getSizeC() <= 1)
        m.sizeC = 1;
    else
        m.sizeC = 3;
    int plane = getSizeX() * getSizeY() * bytesPerPixel;
    for (int i = 1; i < getImageCount(); i++) {
        offsets[i] = offsets[i - 1] + HEADER_SIZE + plane;
    }
    m.sizeZ = getImageCount();
    m.sizeT = 1;
    m.rgb = getSizeC() > 1;
    m.dimensionOrder = isRGB() ? "XYCZT" : "XYZTC";
    m.interleaved = false;
    m.littleEndian = false;
    m.metadataComplete = true;
    m.indexed = false;
    m.falseColor = false;
    switch(bytesPerPixel) {
        case 1:
        case 3:
            m.pixelType = FormatTools.UINT8;
            break;
        case 2:
            m.pixelType = FormatTools.UINT16;
            break;
        default:
            m.pixelType = FormatTools.FLOAT;
    }
    addGlobalMeta("Width", getSizeX());
    addGlobalMeta("Height", getSizeY());
    addGlobalMeta("Bytes per pixel", bytesPerPixel);
    addGlobalMeta("Image name", imageName);
    addGlobalMeta("Timestamp", stamp);
    addGlobalMeta("Version", version);
    // The metadata store we're working with.
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    if (stamp != null) {
        store.setImageAcquisitionDate(new Timestamp(stamp), 0);
    }
    store.setImageName(imageName, 0);
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp) FormatException(loci.formats.FormatException)

Example 7 with Timestamp

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

the class OxfordInstrumentsReader 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);
    CoreMetadata m = core.get(0);
    m.littleEndian = true;
    in.order(isLittleEndian());
    in.seek(48);
    String comment = in.readString(32);
    String dateTime = readDate();
    in.skipBytes(8);
    double xSize = -in.readFloat() + in.readFloat();
    in.skipBytes(20);
    double ySize = -in.readFloat() + in.readFloat();
    in.skipBytes(24);
    double zMin = in.readFloat();
    double zMax = in.readFloat();
    in.skipBytes(864);
    m.sizeX = in.readInt();
    m.sizeY = in.readInt();
    in.skipBytes(28);
    if (getSizeX() == 0 && getSizeY() == 0) {
        m.sizeX = in.readInt();
        m.sizeY = in.readInt();
        in.skipBytes(196);
    } else
        in.skipBytes(204);
    m.pixelType = FormatTools.UINT16;
    m.sizeZ = 1;
    m.sizeC = 1;
    m.sizeT = 1;
    m.imageCount = 1;
    m.rgb = false;
    m.indexed = false;
    m.dimensionOrder = "XYZCT";
    m.interleaved = false;
    if (FormatTools.getPlaneSize(this) + in.getFilePointer() > in.length()) {
        m.sizeY = 1;
    }
    int lutSize = in.readInt();
    in.skipBytes(lutSize);
    headerSize = in.getFilePointer();
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        in.skipBytes(FormatTools.getPlaneSize(this));
        int nMetadataStrings = in.readInt();
        for (int i = 0; i < nMetadataStrings; i++) {
            int length = in.readInt();
            String s = in.readString(length);
            if (s.indexOf(':') != -1) {
                String key = s.substring(0, s.indexOf(':')).trim();
                String value = s.substring(s.indexOf(':') + 1).trim();
                if (!value.equals("-")) {
                    addGlobalMeta(key, value);
                }
            }
        }
        addGlobalMeta("Description", comment);
        addGlobalMeta("Acquisition date", dateTime);
        addGlobalMeta("X size (um)", xSize);
        addGlobalMeta("Y size (um)", ySize);
        addGlobalMeta("Z minimum (um)", zMin);
        addGlobalMeta("Z maximum (um)", zMax);
    }
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    store.setImageDescription(comment, 0);
    if (dateTime != null) {
        store.setImageAcquisitionDate(new Timestamp(dateTime), 0);
    }
    double physicalSizeX = xSize / getSizeX();
    double physicalSizeY = ySize / getSizeY();
    Length sizeX = FormatTools.getPhysicalSizeX(physicalSizeX);
    Length sizeY = FormatTools.getPhysicalSizeY(physicalSizeY);
    if (sizeX != null) {
        store.setPixelsPhysicalSizeX(sizeX, 0);
    }
    if (sizeY != null) {
        store.setPixelsPhysicalSizeY(sizeY, 0);
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp)

Example 8 with Timestamp

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

the class LEOReader method initMetadataStore.

/* @see BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
    super.initMetadataStore();
    MetadataStore store = makeFilterMetadata();
    date = DateTools.formatDate(date, "HH:mm dd-MMM-yyyy");
    if (date != null) {
        store.setImageAcquisitionDate(new Timestamp(date), 0);
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        Length sizeX = FormatTools.getPhysicalSizeX(xSize);
        Length sizeY = FormatTools.getPhysicalSizeY(xSize);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
        String instrument = MetadataTools.createLSID("Instrument", 0);
        store.setInstrumentID(instrument, 0);
        store.setImageInstrumentRef(instrument, 0);
        store.setObjectiveID(MetadataTools.createLSID("Objective", 0, 0), 0, 0);
        store.setObjectiveWorkingDistance(new Length(workingDistance, UNITS.MICROMETER), 0, 0);
        store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
        store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) Timestamp(ome.xml.model.primitives.Timestamp)

Example 9 with Timestamp

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

the class LeicaSCNReader method initMetadataStore.

/* @see loci.formats.BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
    super.initMetadataStore();
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, true);
    HashMap<String, Integer> instrumentIDs = new HashMap<String, Integer>();
    int instrumentidno = 0;
    HashMap<String, String> objectives = new HashMap<String, String>();
    int objectiveidno = 0;
    int parent = 0;
    for (int s = 0; s < getSeriesCount(); s++) {
        int coreIndex = seriesToCoreIndex(s);
        ImageCollection c = handler.collection;
        Image i = handler.imageMap.get(coreIndex);
        int subresolution = coreIndex - parent;
        if (!hasFlattenedResolutions()) {
            subresolution = 0;
        }
        if (core.get(s).resolutionCount > 1) {
            parent = s;
        } else if (core.get(parent).resolutionCount - 1 == subresolution) {
            parent = s + 1;
        }
        Dimension dimension = i.pixels.lookupDimension(0, 0, subresolution);
        if (dimension == null) {
            throw new FormatException("No dimension information for subresolution=" + subresolution);
        }
        // Leica units are nanometres; convert to µm
        double sizeX = i.vSizeX / 1000.0;
        double sizeY = i.vSizeY / 1000.0;
        final Length offsetX = new Length(i.vOffsetX, UNITS.REFERENCEFRAME);
        final Length offsetY = new Length(i.vOffsetY, UNITS.REFERENCEFRAME);
        double sizeZ = i.vSpacingZ / 1000.0;
        store.setPixelsPhysicalSizeX(FormatTools.getPhysicalSizeX(sizeX / dimension.sizeX), s);
        store.setPixelsPhysicalSizeY(FormatTools.getPhysicalSizeY(sizeY / dimension.sizeY), s);
        store.setPixelsPhysicalSizeZ(FormatTools.getPhysicalSizeZ(sizeZ), s);
        if (instrumentIDs.get(i.devModel) == null) {
            String instrumentID = MetadataTools.createLSID("Instrument", instrumentidno);
            instrumentIDs.put(i.devModel, instrumentidno);
            store.setInstrumentID(instrumentID, instrumentidno);
            instrumentidno++;
        }
        int inst = instrumentIDs.get(i.devModel);
        String objectiveName = i.devModel + ":" + i.objMag;
        if (objectives.get(objectiveName) == null) {
            String objectiveID = MetadataTools.createLSID("Objective", inst, objectiveidno);
            objectives.put(objectiveName, objectiveID);
            store.setObjectiveID(objectiveID, inst, objectiveidno);
            Double mag = Double.parseDouble(i.objMag);
            store.setObjectiveNominalMagnification(mag, inst, objectiveidno);
            store.setObjectiveCalibratedMagnification(mag, inst, objectiveidno);
            store.setObjectiveLensNA(new Double(i.illumNA), inst, objectiveidno);
            objectiveidno++;
        }
        store.setImageInstrumentRef(MetadataTools.createLSID("Instrument", inst), s);
        store.setObjectiveSettingsID(objectives.get(objectiveName), s);
        // TODO: Only "brightfield" has been seen in example files
        if (i.illumSource.equals("brightfield")) {
            store.setChannelIlluminationType(IlluminationType.TRANSMITTED, s, 0);
        } else {
            store.setChannelIlluminationType(IlluminationType.OTHER, s, 0);
            LOGGER.debug("Unknown illumination source {}", i.illumSource);
        }
        CoreMetadata ms = core.get(s);
        for (int q = 0; q < ms.imageCount; q++) {
            store.setPlanePositionX(offsetX, s, q);
            store.setPlanePositionY(offsetY, s, q);
        }
        store.setImageName(i.name + " (R" + subresolution + ")", s);
        store.setImageDescription("Collection " + c.name, s);
        store.setImageAcquisitionDate(new Timestamp(i.creationDate), s);
        // Original metadata...
        addSeriesMeta("collection.name", c.name);
        addSeriesMeta("collection.uuid", c.uuid);
        addSeriesMeta("collection.barcode", c.barcode);
        addSeriesMeta("collection.ocr", c.ocr);
        addSeriesMeta("creationDate", i.creationDate);
        addSeriesMeta("device.model for image", i.devModel);
        addSeriesMeta("device.version for image", i.devVersion);
        addSeriesMeta("view.sizeX for image", i.vSizeX);
        addSeriesMeta("view.sizeY for image", i.vSizeY);
        addSeriesMeta("view.offsetX for image", i.vOffsetX);
        addSeriesMeta("view.offsetY for image", i.vOffsetY);
        addSeriesMeta("view.spacingZ for image", i.vSpacingZ);
        addSeriesMeta("scanSettings.objectiveSettings.objective for image", i.objMag);
        addSeriesMeta("scanSettings.illuminationSettings.numericalAperture for image", i.illumNA);
        addSeriesMeta("scanSettings.illuminationSettings.illuminationSource for image", i.illumSource);
    }
}
Also used : HashMap(java.util.HashMap) CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp) FormatException(loci.formats.FormatException) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length)

Example 10 with Timestamp

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

the class FEITiffReader method initMetadataStore.

/* @see BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
    super.initMetadataStore();
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    if (date != null) {
        date = DateTools.formatDate(date, DATE_FORMAT);
        if (date != null) {
            store.setImageAcquisitionDate(new Timestamp(date), 0);
        }
    }
    if (imageName != null) {
        store.setImageName(imageName, 0);
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        if (imageDescription != null) {
            store.setImageDescription(imageDescription, 0);
        }
        if (userName != null) {
            store.setExperimenterID(MetadataTools.createLSID("Experimenter", 0), 0);
            store.setExperimenterLastName(userName, 0);
        }
        if (microscopeModel != null) {
            String instrument = MetadataTools.createLSID("Instrument", 0);
            store.setInstrumentID(instrument, 0);
            store.setImageInstrumentRef(instrument, 0);
            store.setMicroscopeModel(microscopeModel, 0);
        }
        if (detectors != null && detectors.size() > 0) {
            String instrument = MetadataTools.createLSID("Instrument", 0);
            store.setInstrumentID(instrument, 0);
            store.setImageInstrumentRef(instrument, 0);
            for (int i = 0; i < detectors.size(); i++) {
                String detectorID = MetadataTools.createLSID("Detector", 0, i);
                store.setDetectorID(detectorID, 0, i);
                store.setDetectorModel(detectors.get(i), 0, i);
                store.setDetectorType(getDetectorType("Other"), 0, i);
            }
        }
        if (magnification != null) {
            store.setObjectiveID(MetadataTools.createLSID("Objective", 0, 0), 0, 0);
            store.setObjectiveNominalMagnification(magnification, 0, 0);
            store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
            store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
        }
        store.setStageLabelX(stageX, 0);
        store.setStageLabelY(stageY, 0);
        store.setStageLabelZ(stageZ, 0);
        store.setStageLabelName("", 0);
        boolean helios = ifds.get(0).containsKey(HELIOS_TAG);
        Unit<Length> unit = UNITS.MICROMETER;
        if (helios) {
            unit = UNITS.METER;
        }
        Length physicalSizeX = FormatTools.getPhysicalSizeX(sizeX, unit);
        Length physicalSizeY = FormatTools.getPhysicalSizeY(sizeY, unit);
        if (physicalSizeX != null) {
            store.setPixelsPhysicalSizeX(physicalSizeX, 0);
        }
        if (physicalSizeY != null) {
            store.setPixelsPhysicalSizeY(physicalSizeY, 0);
        }
        if (timeIncrement != null) {
            store.setPixelsTimeIncrement(new Time(timeIncrement, UNITS.SECOND), 0);
        }
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) Time(ome.units.quantity.Time) Timestamp(ome.xml.model.primitives.Timestamp)

Aggregations

Timestamp (ome.xml.model.primitives.Timestamp)76 MetadataStore (loci.formats.meta.MetadataStore)54 Length (ome.units.quantity.Length)52 CoreMetadata (loci.formats.CoreMetadata)44 Time (ome.units.quantity.Time)33 Location (loci.common.Location)28 RandomAccessInputStream (loci.common.RandomAccessInputStream)28 FormatException (loci.formats.FormatException)23 ArrayList (java.util.ArrayList)20 IFD (loci.formats.tiff.IFD)11 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)10 TiffParser (loci.formats.tiff.TiffParser)9 IOException (java.io.IOException)8 IFDList (loci.formats.tiff.IFDList)8 PositiveInteger (ome.xml.model.primitives.PositiveInteger)8 Temperature (ome.units.quantity.Temperature)7 Hashtable (java.util.Hashtable)4 StringTokenizer (java.util.StringTokenizer)4 Frequency (ome.units.quantity.Frequency)4 File (java.io.File)3