Search in sources :

Example 6 with Time

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

Example 7 with Time

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

the class FlexReader method populateMetadataStore.

private void populateMetadataStore(MetadataStore store) throws FormatException {
    LOGGER.info("Populating MetadataStore");
    MetadataTools.populatePixels(store, this, true);
    Location currentFile = new Location(getCurrentFile()).getAbsoluteFile();
    int[] lengths = new int[] { fieldCount, wellCount, plateCount };
    store.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
    String plateAcqID = MetadataTools.createLSID("PlateAcquisition", 0, 0);
    store.setPlateAcquisitionID(plateAcqID, 0, 0);
    PositiveInteger maxFieldCount = FormatTools.getMaxFieldCount(fieldCount);
    if (maxFieldCount != null) {
        store.setPlateAcquisitionMaximumFieldCount(maxFieldCount, 0, 0);
    }
    plateAcqStartTime = DateTools.formatDate(plateAcqStartTime, "dd.MM.yyyy  HH:mm:ss");
    if (plateAcqStartTime != null) {
        store.setPlateAcquisitionStartTime(new Timestamp(plateAcqStartTime), 0, 0);
    }
    for (int row = 0; row < wellRows; row++) {
        for (int col = 0; col < wellColumns; col++) {
            int well = row * wellColumns + col;
            store.setWellID(MetadataTools.createLSID("Well", 0, well), 0, well);
            store.setWellRow(new NonNegativeInteger(row), 0, well);
            store.setWellColumn(new NonNegativeInteger(col), 0, well);
        }
    }
    for (int i = 0; i < getSeriesCount(); i++) {
        int[] pos = FormatTools.rasterToPosition(lengths, i);
        String imageID = MetadataTools.createLSID("Image", i);
        store.setImageID(imageID, i);
        int well = wellNumber[pos[1]][0] * wellColumns + wellNumber[pos[1]][1];
        char wellRow = (char) ('A' + wellNumber[pos[1]][0]);
        store.setImageName("Well " + wellRow + "-" + (wellNumber[pos[1]][1] + 1) + "; Field #" + (pos[0] + 1), i);
        if (acquisitionDates.get(i) != null) {
            store.setImageAcquisitionDate(acquisitionDates.get(i), i);
        }
        if (wellRows == 0 && wellColumns == 0) {
            well = pos[1];
            NonNegativeInteger row = new NonNegativeInteger(wellNumber[pos[1]][0]);
            NonNegativeInteger col = new NonNegativeInteger(wellNumber[pos[1]][1]);
            String wellID = MetadataTools.createLSID("Well", pos[2], well);
            store.setWellID(wellID, pos[2], well);
            store.setWellRow(row, pos[2], pos[1]);
            store.setWellColumn(col, pos[2], pos[1]);
        }
        String wellSample = MetadataTools.createLSID("WellSample", pos[2], well, pos[0]);
        store.setWellSampleID(wellSample, pos[2], well, pos[0]);
        store.setWellSampleIndex(new NonNegativeInteger(i), pos[2], well, pos[0]);
        store.setWellSampleImageRef(imageID, pos[2], well, pos[0]);
        store.setPlateAcquisitionWellSampleRef(wellSample, 0, 0, i);
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        String instrumentID = MetadataTools.createLSID("Instrument", 0);
        store.setInstrumentID(instrumentID, 0);
        if (plateName == null)
            plateName = currentFile.getParentFile().getName();
        if (plateBarcode != null)
            plateName = plateBarcode + " " + plateName;
        store.setPlateName(plateName, 0);
        store.setPlateRowNamingConvention(getNamingConvention("Letter"), 0);
        store.setPlateColumnNamingConvention(getNamingConvention("Number"), 0);
        for (int i = 0; i < getSeriesCount(); i++) {
            int[] pos = FormatTools.rasterToPosition(lengths, i);
            store.setImageInstrumentRef(instrumentID, i);
            int seriesIndex = i * getImageCount();
            if (seriesIndex < objectiveRefs.size()) {
                store.setObjectiveSettingsID(objectiveRefs.get(seriesIndex), i);
            }
            for (int c = 0; c < getEffectiveSizeC(); c++) {
                int channelIndex = seriesIndex + c;
                if (seriesIndex > 0 && channelNames.length == getEffectiveSizeC() * getSeriesCount()) {
                    channelIndex = i * getEffectiveSizeC() + c;
                }
                if (channelNames != null && channelIndex >= channelNames.length) {
                    channelIndex = c;
                }
                if (channelNames != null && channelIndex < channelNames.length) {
                    store.setChannelName(channelNames[channelIndex], i, c);
                }
            }
            if (seriesIndex < lightSourceCombinationRefs.size()) {
                String lightSourceCombo = lightSourceCombinationRefs.get(seriesIndex);
                List<String> lightSources = lightSourceCombinationIDs.get(lightSourceCombo);
                for (int c = 0; c < getEffectiveSizeC(); c++) {
                    int index = seriesIndex + c;
                    if (index < cameraRefs.size()) {
                        store.setDetectorSettingsID(cameraRefs.get(index), i, c);
                        if (index < binnings.size()) {
                            store.setDetectorSettingsBinning(getBinning(binnings.get(index)), i, c);
                        }
                    }
                    if (lightSources != null && c < lightSources.size()) {
                        store.setChannelLightSourceSettingsID(lightSources.get(c), i, c);
                    } else if (c > 0 && lightSources != null && lightSources.size() == 1) {
                        lightSourceCombo = lightSourceCombinationRefs.get(seriesIndex + c);
                        lightSources = lightSourceCombinationIDs.get(lightSourceCombo);
                        store.setChannelLightSourceSettingsID(lightSources.get(0), i, c);
                    }
                    if (index < filterSets.size()) {
                        FilterGroup group = filterSetMap.get(filterSets.get(index));
                        if (group != null) {
                            if (group.emission != null) {
                                store.setLightPathEmissionFilterRef(group.emission, i, c, 0);
                            }
                            if (group.excitation != null) {
                                store.setLightPathExcitationFilterRef(group.excitation, i, c, 0);
                            }
                            if (group.dichroic != null) {
                                store.setLightPathDichroicRef(group.dichroic, i, c);
                            }
                        }
                    }
                }
            }
            if (seriesIndex < xSizes.size()) {
                Length size = FormatTools.getPhysicalSizeX(xSizes.get(seriesIndex));
                if (size != null) {
                    store.setPixelsPhysicalSizeX(size, i);
                }
            }
            if (seriesIndex < ySizes.size()) {
                Length size = FormatTools.getPhysicalSizeY(ySizes.get(seriesIndex));
                if (size != null) {
                    store.setPixelsPhysicalSizeY(size, i);
                }
            }
            int well = wellNumber[pos[1]][0] * wellColumns + wellNumber[pos[1]][1];
            if (wellRows == 0 && wellColumns == 0) {
                well = pos[1];
            }
            if (pos[0] < xPositions.size()) {
                Length l = new Length(xPositions.get(pos[0]), UNITS.REFERENCEFRAME);
                store.setWellSamplePositionX(l, pos[2], well, pos[0]);
            }
            if (pos[0] < yPositions.size()) {
                Length l = new Length(yPositions.get(pos[0]), UNITS.REFERENCEFRAME);
                store.setWellSamplePositionY(l, pos[2], well, pos[0]);
            }
            for (int image = 0; image < getImageCount(); image++) {
                int plane = i * getImageCount() + image;
                int c = getZCTCoords(image)[1];
                if (plane < planePositionX.size()) {
                    store.setPlanePositionX(planePositionX.get(plane), i, image);
                }
                if (plane < planePositionY.size()) {
                    store.setPlanePositionY(planePositionY.get(plane), i, image);
                }
                if (plane < planePositionZ.size()) {
                    store.setPlanePositionZ(planePositionZ.get(plane), i, image);
                }
                if (plane - image + c < planeExposureTime.size()) {
                    if (planeExposureTime.get(plane - image + c) != null) {
                        store.setPlaneExposureTime(new Time(planeExposureTime.get(plane - image + c), UNITS.SECOND), i, image);
                    }
                }
                if (plane < planeDeltaT.size() && planeDeltaT.get(plane) != null) {
                    store.setPlaneDeltaT(new Time(planeDeltaT.get(plane), UNITS.SECOND), i, image);
                }
            }
        }
    }
}
Also used : PositiveInteger(ome.xml.model.primitives.PositiveInteger) Length(ome.units.quantity.Length) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) Time(ome.units.quantity.Time) Timestamp(ome.xml.model.primitives.Timestamp) Location(loci.common.Location)

Example 8 with Time

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

the class GatanReader 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);
    pixelOffset = 0;
    CoreMetadata m = core.get(0);
    LOGGER.info("Verifying Gatan format");
    m.littleEndian = false;
    pixelSizes = new ArrayList<Double>();
    units = new ArrayList<String>();
    shapes = new ArrayList<ROIShape>();
    in.order(isLittleEndian());
    // only support version 3
    version = in.readInt();
    if (version != 3 && version != 4) {
        throw new FormatException("invalid header");
    }
    LOGGER.info("Reading tags");
    in.skipBytes(4);
    skipPadding();
    m.littleEndian = in.readInt() != 1;
    in.order(isLittleEndian());
    // TagGroup instance
    in.skipBytes(2);
    skipPadding();
    int numTags = in.readInt();
    if (numTags > in.length()) {
        m.littleEndian = !isLittleEndian();
        in.order(isLittleEndian());
        adjustEndianness = false;
    }
    LOGGER.debug("tags ({}) {", numTags);
    try {
        parseTags(numTags, null, "  ");
    } catch (Exception e) {
        throw new FormatException("Unable to parse metadata tag", e);
    }
    LOGGER.debug("}");
    LOGGER.info("Populating metadata");
    m.littleEndian = true;
    if (getSizeX() == 0 || getSizeY() == 0) {
        throw new FormatException("Dimensions information not found");
    }
    if (m.sizeZ == 0) {
        m.sizeZ = 1;
    }
    m.sizeC = 1;
    m.sizeT = 1;
    m.dimensionOrder = "XYZTC";
    m.imageCount = getSizeZ() * getSizeC() * getSizeT();
    int bytes = (int) (numPixelBytes / (getSizeX() * getSizeY() * (long) getImageCount()));
    if (bytes != FormatTools.getBytesPerPixel(getPixelType())) {
        m.pixelType = FormatTools.pixelTypeFromBytes(bytes, signed, false);
    }
    m.rgb = false;
    m.interleaved = false;
    m.metadataComplete = true;
    m.indexed = false;
    m.falseColor = false;
    // The metadata store we're working with.
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, true);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        int index = 0;
        if (pixelSizes.size() > 4) {
            index = pixelSizes.size() - 3;
        } else if (pixelSizes.size() == 4) {
            if (Math.abs(pixelSizes.get(0) - 1.0) < Constants.EPSILON) {
                index = pixelSizes.size() - 2;
            }
        }
        if (index + 2 < pixelSizes.size() && Math.abs(pixelSizes.get(index + 1) - pixelSizes.get(index + 2)) < Constants.EPSILON) {
            if (Math.abs(pixelSizes.get(index) - pixelSizes.get(index + 1)) > Constants.EPSILON && getSizeY() > 1) {
                index++;
            }
        }
        if (index < pixelSizes.size() - 1) {
            Double x = pixelSizes.get(index);
            Double y = pixelSizes.get(index + 1);
            String xUnits = index < units.size() ? units.get(index) : "";
            String yUnits = index + 1 < units.size() ? units.get(index + 1) : "";
            Length sizeX = FormatTools.getPhysicalSizeX(x, convertUnits(xUnits));
            Length sizeY = FormatTools.getPhysicalSizeY(y, convertUnits(yUnits));
            if (sizeX != null) {
                store.setPixelsPhysicalSizeX(sizeX, 0);
            }
            if (sizeY != null) {
                store.setPixelsPhysicalSizeY(sizeY, 0);
            }
            if (index < pixelSizes.size() - 2) {
                Double z = pixelSizes.get(index + 2);
                String zUnits = index + 2 < units.size() ? units.get(index + 2) : "";
                Length sizeZ = FormatTools.getPhysicalSizeZ(z, convertUnits(zUnits));
                if (sizeZ != null) {
                    store.setPixelsPhysicalSizeZ(sizeZ, 0);
                }
            }
        }
        String instrument = MetadataTools.createLSID("Instrument", 0);
        store.setInstrumentID(instrument, 0);
        store.setImageInstrumentRef(instrument, 0);
        String objective = MetadataTools.createLSID("Objective", 0, 0);
        store.setObjectiveID(objective, 0, 0);
        store.setObjectiveCorrection(getCorrection("Unknown"), 0, 0);
        store.setObjectiveImmersion(getImmersion("Unknown"), 0, 0);
        store.setObjectiveNominalMagnification(mag, 0, 0);
        store.setObjectiveSettingsID(objective, 0);
        String detector = MetadataTools.createLSID("Detector", 0, 0);
        store.setDetectorID(detector, 0, 0);
        store.setDetectorSettingsID(detector, 0, 0);
        store.setDetectorSettingsVoltage(new ElectricPotential(voltage, UNITS.VOLT), 0, 0);
        if (info == null)
            info = "";
        String[] scopeInfo = info.split("\\(");
        for (String token : scopeInfo) {
            token = token.trim();
            if (token.startsWith("Mode")) {
                token = token.substring(token.indexOf(' ')).trim();
                String mode = token.substring(0, token.indexOf(' ')).trim();
                if (mode.equals("TEM"))
                    mode = "Other";
                store.setChannelAcquisitionMode(getAcquisitionMode(mode), 0, 0);
            }
        }
        store.setPlanePositionX(posX, 0, 0);
        store.setPlanePositionY(posY, 0, 0);
        store.setPlanePositionZ(posZ, 0, 0);
        for (int i = 0; i < getImageCount(); i++) {
            store.setPlaneExposureTime(new Time(sampleTime, UNITS.SECOND), 0, i);
        }
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.NO_OVERLAYS && shapes.size() > 0) {
        for (int i = 0; i < shapes.size(); i++) {
            String roi = MetadataTools.createLSID("ROI", i);
            store.setROIID(roi, i);
            store.setImageROIRef(roi, 0, i);
            String shapeID = MetadataTools.createLSID("Shape", i, 0);
            ROIShape shape = shapes.get(i);
            switch(shape.type) {
                case LINE:
                    store.setLineID(shapeID, i, 0);
                    store.setLineX1(shape.x1, i, 0);
                    store.setLineY1(shape.y1, i, 0);
                    store.setLineX2(shape.x2, i, 0);
                    store.setLineY2(shape.y2, i, 0);
                    store.setLineText(shape.text, i, 0);
                    store.setLineFontSize(shape.fontSize, i, 0);
                    store.setLineStrokeColor(shape.strokeColor, i, 0);
                    break;
                case TEXT:
                    store.setLabelID(shapeID, i, 0);
                    store.setLabelX(shape.x1, i, 0);
                    store.setLabelY(shape.y1, i, 0);
                    store.setLabelText(shape.text, i, 0);
                    store.setLabelFontSize(shape.fontSize, i, 0);
                    store.setLabelStrokeColor(shape.strokeColor, i, 0);
                    break;
                case ELLIPSE:
                    store.setEllipseID(shapeID, i, 0);
                    double radiusX = (shape.x2 - shape.x1) / 2;
                    double radiusY = (shape.y2 - shape.y1) / 2;
                    store.setEllipseX(shape.x1 + radiusX, i, 0);
                    store.setEllipseY(shape.y1 + radiusY, i, 0);
                    store.setEllipseRadiusX(radiusX, i, 0);
                    store.setEllipseRadiusY(radiusY, i, 0);
                    store.setEllipseText(shape.text, i, 0);
                    store.setEllipseFontSize(shape.fontSize, i, 0);
                    store.setEllipseStrokeColor(shape.strokeColor, i, 0);
                    break;
                case RECTANGLE:
                    store.setRectangleID(shapeID, i, 0);
                    store.setRectangleX(shape.x1, i, 0);
                    store.setRectangleY(shape.y1, i, 0);
                    store.setRectangleWidth(shape.x2 - shape.x1, i, 0);
                    store.setRectangleHeight(shape.y2 - shape.y1, i, 0);
                    store.setRectangleText(shape.text, i, 0);
                    store.setRectangleFontSize(shape.fontSize, i, 0);
                    store.setRectangleStrokeColor(shape.strokeColor, i, 0);
                    break;
                default:
                    LOGGER.warn("Unknown ROI type: {}", shape.type);
            }
        }
    }
}
Also used : Time(ome.units.quantity.Time) CoreMetadata(loci.formats.CoreMetadata) ElectricPotential(ome.units.quantity.ElectricPotential) FormatException(loci.formats.FormatException) FormatException(loci.formats.FormatException) IOException(java.io.IOException) ParseException(java.text.ParseException) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 9 with Time

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

the class HISReader 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);
    in.order(true);
    in.skipBytes(14);
    int nSeries = in.readShort();
    pixelOffset = new long[nSeries];
    String[] date = new String[nSeries];
    String[] binning = new String[nSeries];
    double[] offset = new double[nSeries];
    double[] exposureTime = new double[nSeries];
    boolean adjustedBitDepth = false;
    in.seek(0);
    core.clear();
    for (int i = 0; i < nSeries; i++) {
        CoreMetadata ms = new CoreMetadata();
        core.add(ms);
        String checkString = in.readString(2);
        if (!checkString.equals("IM") && i > 0) {
            if (getBitsPerPixel() == 12) {
                core.get(i - 1).bitsPerPixel = 16;
                int prevSkip = (getSizeX() * getSizeY() * getSizeC() * 12) / 8;
                int totalBytes = FormatTools.getPlaneSize(this);
                in.skipBytes(totalBytes - prevSkip);
                adjustedBitDepth = true;
            }
        }
        setSeries(i);
        int commentBytes = in.readShort();
        ms.sizeX = in.readShort();
        ms.sizeY = in.readShort();
        in.skipBytes(4);
        int dataType = in.readShort();
        switch(dataType) {
            case 1:
                ms.pixelType = FormatTools.UINT8;
                break;
            case 2:
                ms.pixelType = FormatTools.UINT16;
                break;
            case 6:
                ms.pixelType = FormatTools.UINT16;
                ms.bitsPerPixel = adjustedBitDepth ? 16 : 12;
                break;
            case 11:
                ms.pixelType = FormatTools.UINT8;
                ms.sizeC = 3;
                break;
            case 12:
                ms.pixelType = FormatTools.UINT16;
                ms.sizeC = 3;
                break;
            case 14:
                ms.pixelType = FormatTools.UINT16;
                ms.sizeC = 3;
                ms.bitsPerPixel = adjustedBitDepth ? 16 : 12;
                break;
        }
        in.skipBytes(50);
        String comment = in.readString(commentBytes);
        if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
            String[] data = comment.split(";");
            for (String token : data) {
                int eq = token.indexOf('=');
                if (eq != -1) {
                    String key = token.substring(0, eq);
                    String value = token.substring(eq + 1);
                    addSeriesMeta(key, value);
                    if (key.equals("vDate")) {
                        date[i] = value;
                    } else if (key.equals("vTime")) {
                        date[i] += " " + value;
                        date[i] = DateTools.formatDate(date[i], "yyyy/MM/dd HH:mm:ss");
                    } else if (key.equals("vOffset")) {
                        offset[i] = Double.parseDouble(value);
                    } else if (key.equals("vBinX")) {
                        binning[i] = value;
                    } else if (key.equals("vBinY")) {
                        binning[i] += "x" + value;
                    } else if (key.equals("vExpTim1")) {
                        exposureTime[i] = Double.parseDouble(value) * 100;
                    }
                }
            }
        }
        pixelOffset[i] = in.getFilePointer();
        ms.littleEndian = true;
        if (ms.sizeC == 0)
            ms.sizeC = 1;
        ms.sizeT = 1;
        ms.sizeZ = 1;
        ms.imageCount = 1;
        ms.rgb = ms.sizeC > 1;
        ms.interleaved = isRGB();
        ms.dimensionOrder = "XYCZT";
        in.skipBytes((getSizeX() * getSizeY() * getSizeC() * getBitsPerPixel()) / 8);
    }
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, true);
    String instrumentID = MetadataTools.createLSID("Instrument", 0);
    store.setInstrumentID(instrumentID, 0);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        for (int i = 0; i < nSeries; i++) {
            store.setImageInstrumentRef(instrumentID, i);
            if (date[i] != null) {
                store.setImageAcquisitionDate(new Timestamp(date[i]), i);
            }
            store.setPlaneExposureTime(new Time(exposureTime[i], UNITS.SECOND), i, 0);
            String detectorID = MetadataTools.createLSID("Detector", 0, i);
            store.setDetectorID(detectorID, 0, i);
            store.setDetectorOffset(offset[i], 0, i);
            store.setDetectorType(getDetectorType("Other"), 0, i);
            store.setDetectorSettingsID(detectorID, i, 0);
            store.setDetectorSettingsBinning(getBinning(binning[i]), i, 0);
        }
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Time(ome.units.quantity.Time) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp)

Example 10 with Time

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

the class PCORAWReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    if (checkSuffix(id, "rec")) {
        paramFile = new Location(id).getAbsolutePath();
        String base = new Location(id).getAbsoluteFile().getAbsolutePath();
        base = base.substring(0, base.lastIndexOf("."));
        id = base + ".pcoraw";
        if (!new Location(id).exists()) {
            throw new FormatException("Could not find image file.");
        }
    }
    super.initFile(id);
    imageFile = new Location(id).getAbsolutePath();
    reader.close();
    reader.setMetadataStore(getMetadataStore());
    reader.setId(id);
    core = reader.getCoreMetadataList();
    metadata = reader.getGlobalMetadata();
    in = new RandomAccessInputStream(id);
    try {
        if (in.length() >= Math.pow(2, 32)) {
            // even though BigTIFF is likely being used, the offsets
            // are still recorded as though only 32 bits are available
            long add = 0;
            long prevOffset = 0;
            for (IFD ifd : reader.ifds) {
                long[] offsets = ifd.getStripOffsets();
                for (int i = 0; i < offsets.length; i++) {
                    offsets[i] += add;
                    if (offsets[i] < prevOffset) {
                        add += 0x100000000L;
                        offsets[i] += 0x100000000L;
                    }
                    prevOffset = offsets[i];
                }
                ifd.put(IFD.STRIP_OFFSETS, offsets);
            }
        }
    } finally {
        in.close();
    }
    if (paramFile == null) {
        String base = imageFile.substring(0, imageFile.lastIndexOf("."));
        base += ".rec";
        if (new Location(base).exists()) {
            paramFile = base;
        }
    }
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, true);
    if (paramFile != null) {
        // parse extra metadata from the parameter file
        store.setInstrumentID(MetadataTools.createLSID("Instrument", 0), 0);
        String detector = MetadataTools.createLSID("Detector", 0, 0);
        store.setDetectorID(detector, 0, 0);
        String[] lines = DataTools.readFile(paramFile).split("\n");
        for (int i = 0; i < lines.length; i++) {
            String line = lines[i];
            int sep = line.indexOf(':');
            if (sep < 0) {
                continue;
            }
            String key = line.substring(0, sep).trim();
            String value = line.substring(sep + 1).trim();
            addGlobalMeta(key, value);
            if (key.equals("Exposure / Delay")) {
                // set the exposure time
                String exp = value.substring(0, value.indexOf(' '));
                Double parsedExp = new Double(exp);
                Time exposure = null;
                if (parsedExp != null) {
                    exposure = new Time(parsedExp / 1000, UNITS.SECOND);
                }
                for (int plane = 0; plane < getImageCount(); plane++) {
                    store.setPlaneExposureTime(exposure, 0, plane);
                }
            } else if (key.equals("Camera serial number")) {
                // set the serial number
                store.setDetectorSerialNumber(value, 0, 0);
            } else if (key.equals("Binning horz./vert.")) {
                store.setDetectorSettingsID(detector, 0, 0);
                value = value.charAt(1) + value;
                value = value.substring(0, 3);
                store.setDetectorSettingsBinning(getBinning(value), 0, 0);
            } else if (key.equals("Comment")) {
                final StringBuilder description = new StringBuilder();
                for (int j = i + 1; j < lines.length; j++) {
                    lines[j] = lines[j].trim();
                    if (lines[j].length() > 0) {
                        description.append(lines[j]);
                        description.append(" ");
                    }
                }
                store.setImageDescription(description.toString().trim(), 0);
                break;
            }
        }
    }
}
Also used : IFD(loci.formats.tiff.IFD) Time(ome.units.quantity.Time) FormatException(loci.formats.FormatException) MetadataStore(loci.formats.meta.MetadataStore) RandomAccessInputStream(loci.common.RandomAccessInputStream) Location(loci.common.Location)

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