Search in sources :

Example 56 with Time

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

the class FluoviewReader method initAlternateMetadataStore.

private void initAlternateMetadataStore() throws FormatException {
    MetadataStore store = makeFilterMetadata();
    store.setImagingEnvironmentTemperature(new Temperature(new Double(temperature.floatValue()), UNITS.CELSIUS), 0);
    String instrumentID = MetadataTools.createLSID("Instrument", 0);
    String detectorID = MetadataTools.createLSID("Detector", 0, 0);
    store.setInstrumentID(instrumentID, 0);
    store.setDetectorID(detectorID, 0, 0);
    store.setDetectorModel(model, 0, 0);
    store.setImageInstrumentRef(instrumentID, 0);
    if (exposureTime != null) {
        for (int i = 0; i < getImageCount(); i++) {
            store.setPlaneExposureTime(new Time(new Double(exposureTime.floatValue()), UNITS.SECOND), 0, i);
        }
    }
    for (int i = 0; i < getEffectiveSizeC(); i++) {
        store.setDetectorSettingsID(detectorID, 0, i);
        store.setDetectorSettingsReadOutRate(new Frequency(new Double(readoutTime.floatValue()), UNITS.HERTZ), 0, i);
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Temperature(ome.units.quantity.Temperature) Frequency(ome.units.quantity.Frequency) Time(ome.units.quantity.Time)

Example 57 with Time

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

the class FluoviewReader method initMetadataStore.

/* @see loci.formats.in.BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
    super.initMetadataStore();
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, true);
    if (date != null) {
        store.setImageAcquisitionDate(new Timestamp(date), 0);
    }
    if (getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM) {
        return;
    }
    if (ifds.get(0).get(MMHEADER) == null) {
        initAlternateMetadataStore();
        return;
    }
    store.setImageDescription(comment, 0);
    // link Instrument and Image
    String instrumentID = MetadataTools.createLSID("Instrument", 0);
    store.setInstrumentID(instrumentID, 0);
    store.setImageInstrumentRef(instrumentID, 0);
    // populate timing data
    if (timeIndex >= 0) {
        for (int s = 0; s < getSeriesCount(); s++) {
            setSeries(s);
            for (int i = 0; i < getImageCount(); i++) {
                int index = getImageIndex(i);
                store.setPlaneDeltaT(new Time(stamps[timeIndex][index], UNITS.SECOND), s, i);
            }
        }
        setSeries(0);
    }
    // populate Dimensions
    for (int i = 0; i < getSeriesCount(); i++) {
        Length sizeX = FormatTools.getPhysicalSizeX(voxelX);
        Length sizeY = FormatTools.getPhysicalSizeY(voxelY);
        Length sizeZ = FormatTools.getPhysicalSizeZ(voxelZ);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, i);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, i);
        }
        if (sizeZ != null) {
            store.setPixelsPhysicalSizeZ(sizeZ, i);
        }
        store.setPixelsTimeIncrement(new Time(voxelT, UNITS.SECOND), i);
        int montage = getMontage(i);
        int field = getField(i);
        double posX = 0d, posY = 0d, posZ = 0d;
        if (montageOffsets != null && montage < montageOffsets.length) {
            if (montageOffsets[montage].length > 0) {
                posX += montageOffsets[montage][0];
            }
            if (montageOffsets[montage].length > 1) {
                posY += montageOffsets[montage][1];
            }
            if (montageOffsets[montage].length > 2) {
                posZ += montageOffsets[montage][2];
            }
        }
        if (fieldOffsets != null && field < fieldOffsets.length) {
            if (fieldOffsets[field].length > 0) {
                posX += fieldOffsets[field][0];
            }
            if (fieldOffsets[field].length > 1) {
                posY += fieldOffsets[field][1];
            }
            if (fieldOffsets[field].length > 2) {
                posZ += fieldOffsets[field][2];
            }
        }
        for (int image = 0; image < getImageCount(); image++) {
            final Length xl = new Length(posX, UNITS.REFERENCEFRAME);
            final Length yl = new Length(posY, UNITS.REFERENCEFRAME);
            Length zl = new Length(posZ, UNITS.REFERENCEFRAME);
            if (zPositions != null && zPositions.length > image) {
                zl = new Length(zPositions[image], UNITS.MICROMETER);
            }
            store.setPlanePositionX(xl, i, image);
            store.setPlanePositionY(yl, i, image);
            store.setPlanePositionZ(zl, i, image);
        }
    }
    if (channelNames != null) {
        for (int i = 0; i < getSizeC(); i++) {
            if (channelNames[i] != null) {
                store.setChannelName(channelNames[i].trim(), 0, i);
            }
        }
    }
    for (int i = 0; i < getSizeC(); i++) {
        if (voltages != null && voltages[i] != null) {
            store.setDetectorSettingsVoltage(new ElectricPotential(new Double(voltages[i]), UNITS.VOLT), 0, i);
        }
        if (gains != null && gains[i] != null) {
            store.setDetectorSettingsGain(new Double(gains[i]), 0, i);
        }
        if (offsets != null && offsets[i] != null) {
            store.setDetectorSettingsOffset(new Double(offsets[i]), 0, i);
        }
        store.setDetectorType(getDetectorType("Other"), 0, i);
        if (detectorManufacturer != null) {
            store.setDetectorManufacturer(detectorManufacturer, 0, i);
        }
        // link DetectorSettings to an actual Detector
        String detectorID = MetadataTools.createLSID("Detector", 0, i);
        store.setDetectorID(detectorID, 0, i);
        store.setDetectorSettingsID(detectorID, 0, i);
    }
    if (mag != null && mag.toLowerCase().endsWith("x")) {
        mag = mag.substring(0, mag.length() - 1);
    } else if (mag == null)
        mag = "1";
    store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
    store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
    if (objectiveManufacturer != null) {
        String[] objectiveData = objectiveManufacturer.split(" ");
        store.setObjectiveModel(objectiveData[0], 0, 0);
        if (objectiveData.length > 2) {
            store.setObjectiveImmersion(getImmersion(objectiveData[2]), 0, 0);
        }
    }
    if (mag != null) {
        store.setObjectiveCalibratedMagnification(new Double(mag), 0, 0);
    }
    if (lensNA != null) {
        for (int i = 0; i < getSizeC(); i++) {
            if (lensNA[i] != null) {
                store.setObjectiveLensNA(new Double(lensNA[i]), 0, i);
            }
        }
    }
    // link Objective to Image using ObjectiveSettings
    String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
    store.setObjectiveID(objectiveID, 0, 0);
    store.setObjectiveSettingsID(objectiveID, 0);
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) Time(ome.units.quantity.Time) Timestamp(ome.xml.model.primitives.Timestamp) ElectricPotential(ome.units.quantity.ElectricPotential)

Example 58 with Time

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

the class IPLabReader 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);
    LOGGER.info("Populating metadata");
    CoreMetadata m = core.get(0);
    m.littleEndian = in.readString(4).equals("iiii");
    in.order(isLittleEndian());
    in.skipBytes(12);
    // read axis sizes from header
    int dataSize = in.readInt() - 28;
    m.sizeX = in.readInt();
    m.sizeY = in.readInt();
    m.sizeC = in.readInt();
    m.sizeZ = in.readInt();
    m.sizeT = in.readInt();
    int filePixelType = in.readInt();
    m.imageCount = getSizeZ() * getSizeT();
    String ptype;
    switch(filePixelType) {
        case 0:
            ptype = "8 bit unsigned";
            m.pixelType = FormatTools.UINT8;
            break;
        case 1:
            ptype = "16 bit signed short";
            m.pixelType = FormatTools.INT16;
            break;
        case 2:
            ptype = "16 bit unsigned short";
            m.pixelType = FormatTools.UINT16;
            break;
        case 3:
            ptype = "32 bit signed long";
            m.pixelType = FormatTools.INT32;
            break;
        case 4:
            ptype = "32 bit single-precision float";
            m.pixelType = FormatTools.FLOAT;
            break;
        case 5:
            ptype = "Color24";
            m.pixelType = FormatTools.UINT32;
            break;
        case 6:
            ptype = "Color48";
            m.pixelType = FormatTools.UINT16;
            break;
        case 10:
            ptype = "64 bit double-precision float";
            m.pixelType = FormatTools.DOUBLE;
            break;
        default:
            // for values 7-9
            ptype = "reserved";
    }
    m.dimensionOrder = "XY";
    if (getSizeC() > 1)
        m.dimensionOrder += "CZT";
    else
        m.dimensionOrder += "ZTC";
    m.rgb = getSizeC() > 1;
    m.interleaved = false;
    m.indexed = false;
    m.falseColor = false;
    m.metadataComplete = true;
    addGlobalMeta("PixelType", ptype);
    addGlobalMeta("Width", getSizeX());
    addGlobalMeta("Height", getSizeY());
    addGlobalMeta("Channels", getSizeC());
    addGlobalMeta("ZDepth", getSizeZ());
    addGlobalMeta("TDepth", getSizeT());
    // The metadata store we're working with.
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, true);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        in.skipBytes(dataSize);
        parseTags(store);
        Length sizeX = FormatTools.getPhysicalSizeX(pixelSize);
        Length sizeY = FormatTools.getPhysicalSizeY(pixelSize);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 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) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata)

Example 59 with Time

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

the class IPLabReader method parseTags.

// -- Helper methods --
private void parseTags(MetadataStore store) throws FormatException, IOException {
    LOGGER.info("Reading tags");
    byte[] tagBytes = new byte[4];
    in.read(tagBytes);
    String tag = new String(tagBytes, Constants.ENCODING);
    while (!tag.equals("fini") && in.getFilePointer() < in.length() - 4) {
        int size = in.readInt();
        if (tag.equals("clut")) {
            // read in Color Lookup Table
            if (size == 8) {
                // indexed lookup table
                in.skipBytes(4);
                int type = in.readInt();
                String[] types = new String[] { "monochrome", "reverse monochrome", "BGR", "classify", "rainbow", "red", "green", "blue", "cyan", "magenta", "yellow", "saturated pixels" };
                String clutType = (type >= 0 && type < types.length) ? types[type] : "unknown";
                addGlobalMeta("LUT type", clutType);
            } else {
                // explicitly defined lookup table
                // length is 772
                in.skipBytes(772);
            }
        } else if (tag.equals("norm")) {
            if (size != (44 * getSizeC())) {
                throw new FormatException("Bad normalization settings");
            }
            String[] types = new String[] { "user", "plane", "sequence", "saturated plane", "saturated sequence", "ROI" };
            for (int i = 0; i < getSizeC(); i++) {
                int source = in.readInt();
                String sourceType = (source >= 0 && source < types.length) ? types[source] : "user";
                addGlobalMetaList("NormalizationSource", sourceType);
                double min = in.readDouble();
                double max = in.readDouble();
                double gamma = in.readDouble();
                double black = in.readDouble();
                double white = in.readDouble();
                addGlobalMetaList("NormalizationMin", min);
                addGlobalMetaList("NormalizationMax", max);
                addGlobalMetaList("NormalizationGamma", gamma);
                addGlobalMetaList("NormalizationBlack", black);
                addGlobalMetaList("NormalizationWhite", white);
            }
        } else if (tag.equals("head")) {
            for (int i = 0; i < size / 22; i++) {
                int num = in.readShort();
                addGlobalMeta("Header" + num, in.readString(20));
            }
        } else if (tag.equals("mmrc")) {
            in.skipBytes(size);
        } else if (tag.equals("roi ") && getMetadataOptions().getMetadataLevel() != MetadataLevel.NO_OVERLAYS) {
            // read in ROI information
            in.skipBytes(4);
            int roiLeft = in.readInt();
            int roiTop = in.readInt();
            int roiRight = in.readInt();
            int roiBottom = in.readInt();
            int numRoiPts = in.readInt();
            store.setRectangleID(MetadataTools.createLSID("Shape", 0, 0), 0, 0);
            store.setRectangleX(new Double(roiLeft), 0, 0);
            store.setRectangleY(new Double(roiTop), 0, 0);
            store.setRectangleWidth(new Double(roiRight - roiLeft), 0, 0);
            store.setRectangleHeight(new Double(roiBottom - roiTop), 0, 0);
            String roiID = MetadataTools.createLSID("ROI", 0, 0);
            store.setROIID(roiID, 0);
            store.setImageROIRef(roiID, 0, 0);
            in.skipBytes(8 * numRoiPts);
        } else if (tag.equals("mask")) {
            // read in Segmentation Mask
            in.skipBytes(size);
        } else if (tag.equals("unit")) {
            for (int i = 0; i < 4; i++) {
                int xResStyle = in.readInt();
                float unitsPerPixel = in.readFloat();
                int xUnitName = in.readInt();
                addGlobalMetaList("ResolutionStyle", xResStyle);
                addGlobalMetaList("UnitsPerPixel", unitsPerPixel);
                switch(xUnitName) {
                    case // mm
                    2:
                        unitsPerPixel *= 1000;
                        break;
                    case // cm
                    3:
                        unitsPerPixel *= 10000;
                        break;
                    case // m
                    4:
                        unitsPerPixel *= 1000000;
                        break;
                    case // inch
                    5:
                        unitsPerPixel *= 3937;
                        break;
                    case // ft
                    6:
                        unitsPerPixel *= 47244;
                        break;
                }
                if (i == 0)
                    pixelSize = new Double(unitsPerPixel);
                addGlobalMetaList("UnitName", xUnitName);
            }
        } else if (tag.equals("view")) {
            // read in view
            in.skipBytes(size);
        } else if (tag.equals("plot")) {
            // read in plot
            // skipping this field for the moment
            in.skipBytes(size);
        } else if (tag.equals("note")) {
            // read in notes (image info)
            String descriptor = in.readString(64);
            String notes = in.readString(512);
            addGlobalMeta("Descriptor", descriptor);
            addGlobalMeta("Notes", notes);
            store.setImageDescription(notes, 0);
        } else if (tagBytes[0] == 0x1a && tagBytes[1] == (byte) 0xd9 && tagBytes[2] == (byte) 0x8b && tagBytes[3] == (byte) 0xef) {
            int units = in.readInt();
            for (int i = 0; i < getSizeT(); i++) {
                float timepoint = in.readFloat();
                // normalize to seconds
                switch(units) {
                    case 0:
                        // time stored in milliseconds
                        timepoint /= 1000;
                        break;
                    case 2:
                        // time stored in minutes
                        timepoint *= 60;
                        break;
                    case 3:
                        // time stored in hours
                        timepoint *= 60 * 60;
                        break;
                }
                addGlobalMetaList("Timestamp", timepoint);
                for (int c = 0; c < getSizeC(); c++) {
                    for (int z = 0; z < getSizeZ(); z++) {
                        int plane = getIndex(z, c, i);
                        store.setPlaneDeltaT(new Time(new Double(timepoint), UNITS.SECOND), 0, plane);
                    }
                }
                if (i == 1) {
                    timeIncrement = new Double(timepoint);
                }
            }
        } else
            in.skipBytes(size);
        if (in.getFilePointer() + 4 <= in.length()) {
            in.read(tagBytes);
            tag = new String(tagBytes, Constants.ENCODING);
        } else {
            tag = "fini";
        }
        if (in.getFilePointer() >= in.length() && !tag.equals("fini")) {
            tag = "fini";
        }
    }
}
Also used : Time(ome.units.quantity.Time) FormatException(loci.formats.FormatException)

Example 60 with Time

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

the class MetamorphTiffReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    List<String> uniqueChannels = new ArrayList<String>();
    final List<Double> uniqueZs = new ArrayList<Double>();
    final List<Length> stageX = new ArrayList<Length>();
    final List<Length> stageY = new ArrayList<Length>();
    CoreMetadata m = core.get(0);
    String filename = id.substring(id.lastIndexOf(File.separator) + 1);
    filename = filename.substring(0, filename.indexOf('.'));
    boolean integerFilename = true;
    try {
        Integer.parseInt(filename);
    } catch (NumberFormatException e) {
        integerFilename = false;
    }
    if (integerFilename && ifds.size() == 1 && ifds.get(0).getIFDIntValue(IFD.NEW_SUBFILE_TYPE) == 2) {
        // look for other files in the dataset
        findTIFFs();
        String stageLabel = null;
        for (String tiff : files) {
            MetamorphHandler handler = new MetamorphHandler();
            parseFile(tiff, handler);
            String label = handler.getStageLabel();
            if (stageLabel == null) {
                stageLabel = label;
            } else if (!label.equals(stageLabel)) {
                break;
            }
            if (!uniqueChannels.contains(handler.getChannelName())) {
                uniqueChannels.add(handler.getChannelName());
            }
            final List<Double> zPositions = handler.getZPositions();
            Double pos = Math.rint(zPositions.get(0));
            if (!uniqueZs.contains(pos)) {
                uniqueZs.add(pos);
            }
        }
        MetamorphHandler handler = new MetamorphHandler();
        parseFile(files[files.length - 1], handler);
        String lastStageLabel = handler.getStageLabel();
        int lastField = getField(lastStageLabel);
        int lastWellRow = getWellRow(lastStageLabel);
        int lastWellColumn = getWellColumn(lastStageLabel);
        int field = getField(stageLabel);
        int fieldRow = getWellRow(stageLabel);
        int fieldColumn = getWellColumn(stageLabel);
        wellCount = lastField - field + 1;
        fieldRowCount = lastWellRow - fieldRow + 1;
        fieldColumnCount = lastWellColumn - fieldColumn + 1;
        m.sizeC = uniqueChannels.size();
        m.sizeZ = uniqueZs.size();
    } else {
        files = new String[] { id };
        wellCount = 1;
        fieldRowCount = 1;
        fieldColumnCount = 1;
        m.sizeC = 0;
    }
    // parse XML comment
    MetamorphHandler handler = new MetamorphHandler(getGlobalMetadata());
    final List<Length> xPositions = new ArrayList<Length>();
    final List<Length> yPositions = new ArrayList<Length>();
    for (IFD ifd : ifds) {
        String xml = XMLTools.sanitizeXML(ifd.getComment());
        XMLTools.parseXML(xml, handler);
        final Length x = handler.getStagePositionX();
        final Length y = handler.getStagePositionY();
        if (xPositions.isEmpty()) {
            xPositions.add(x);
            yPositions.add(y);
        } else {
            final Length previousX = xPositions.get(xPositions.size() - 1);
            final Length previousY = yPositions.get(yPositions.size() - 1);
            final double x1 = x.value(UNITS.REFERENCEFRAME).doubleValue();
            final double x2 = previousX.value(UNITS.REFERENCEFRAME).doubleValue();
            final double y1 = y.value(UNITS.REFERENCEFRAME).doubleValue();
            final double y2 = previousY.value(UNITS.REFERENCEFRAME).doubleValue();
            if (Math.abs(x1 - x2) > 0.21 || Math.abs(y1 - y2) > 0.21) {
                xPositions.add(x);
                yPositions.add(y);
            }
        }
    }
    if (xPositions.size() > 1) {
        fieldRowCount = xPositions.size();
    }
    final List<Integer> wavelengths = handler.getWavelengths();
    final List<Double> zPositions = handler.getZPositions();
    dualCamera = handler.hasDualCamera();
    // calculate axis sizes
    final List<Integer> uniqueC = new ArrayList<Integer>();
    for (Integer c : wavelengths) {
        if (!uniqueC.contains(c)) {
            uniqueC.add(c);
        }
    }
    int effectiveC = uniqueC.size();
    if (effectiveC == 0)
        effectiveC = 1;
    if (getSizeC() == 0)
        m.sizeC = 1;
    int samples = ifds.get(0).getSamplesPerPixel();
    m.sizeC *= effectiveC * samples;
    final List<Double> uniqueZ = new ArrayList<Double>();
    for (Double z : zPositions) {
        if (!uniqueZ.contains(z))
            uniqueZ.add(z);
    }
    if (getSizeZ() == 0)
        m.sizeZ = 1;
    if (uniqueZ.size() > 1)
        m.sizeZ *= uniqueZ.size();
    Double physicalSizeZ = null;
    if (m.sizeZ > 1) {
        Double zRange = zPositions.get(zPositions.size() - 1) - zPositions.get(0);
        physicalSizeZ = Math.abs(zRange);
        physicalSizeZ /= (m.sizeZ - 1);
    }
    int totalPlanes = files.length * ifds.size();
    effectiveC = getSizeC() / samples;
    // account for the multiple actual Z sections
    if (effectiveC * getSizeZ() > totalPlanes && (effectiveC * (getSizeZ() / uniqueC.size()) == totalPlanes || effectiveC == totalPlanes)) {
        if (getSizeZ() >= uniqueC.size()) {
            m.sizeZ /= uniqueC.size();
        } else {
            m.sizeZ = 1;
        }
    }
    m.sizeT = totalPlanes / (wellCount * fieldRowCount * fieldColumnCount * getSizeZ() * effectiveC);
    if (getSizeT() == 0)
        m.sizeT = 1;
    int seriesCount = wellCount * fieldRowCount * fieldColumnCount;
    if (seriesCount > 1 && getSizeZ() > totalPlanes / seriesCount || totalPlanes > getSizeZ() * getSizeT() * effectiveC) {
        m.sizeZ = 1;
        m.sizeT = totalPlanes / (seriesCount * effectiveC);
    }
    m.imageCount = getSizeZ() * getSizeT() * effectiveC;
    if (dualCamera) {
        m.sizeX /= 2;
        m.sizeC *= 2;
        m.imageCount *= 2;
    }
    if (seriesCount > 1) {
        core.clear();
        for (int i = 0; i < seriesCount; i++) {
            core.add(m);
        }
    }
    for (int s = 0; s < wellCount * fieldRowCount * fieldColumnCount; s++) {
        if (files.length > 1) {
            int[] lengths = new int[] { getSizeZ(), getEffectiveSizeC(), fieldColumnCount, fieldRowCount, wellCount, getSizeT() };
            Well well = getWell(s);
            int[] position = new int[] { 0, 0, well.fieldCol, well.fieldRow, well.well, 0 };
            int fileIndex = FormatTools.positionToRaster(lengths, position);
            parseFile(files[fileIndex], handler);
            stageX.add(handler.getStagePositionX());
            stageY.add(handler.getStagePositionY());
        } else {
            stageX.add(xPositions.get(s));
            stageY.add(yPositions.get(s));
        }
    }
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    // effectively useless).
    if (wellCount > 1) {
        store.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
        store.setPlateRows(new PositiveInteger(1), 0);
        store.setPlateColumns(new PositiveInteger(wellCount), 0);
        store.setPlateRowNamingConvention(NamingConvention.LETTER, 0);
        store.setPlateColumnNamingConvention(NamingConvention.NUMBER, 0);
        store.setPlateAcquisitionID(MetadataTools.createLSID("PlateAcquisition", 0, 0), 0, 0);
        for (int well = 0; well < wellCount; well++) {
            store.setWellID(MetadataTools.createLSID("Well", 0, well), 0, well);
            store.setWellRow(new NonNegativeInteger(0), 0, well);
            store.setWellColumn(new NonNegativeInteger(well), 0, well);
            for (int row = 0; row < fieldRowCount; row++) {
                for (int col = 0; col < fieldColumnCount; col++) {
                    int field = row * fieldColumnCount + col;
                    String wellSampleID = MetadataTools.createLSID("WellSample", 0, well, field);
                    store.setWellSampleID(wellSampleID, 0, well, field);
                    int seriesIndex = getSeriesIndex(row, col, well);
                    String imageID = MetadataTools.createLSID("Image", seriesIndex);
                    store.setImageID(imageID, seriesIndex);
                    store.setWellSampleImageRef(imageID, 0, well, field);
                    store.setWellSampleIndex(new NonNegativeInteger(seriesIndex), 0, well, field);
                    store.setPlateAcquisitionWellSampleRef(wellSampleID, 0, 0, seriesIndex);
                }
            }
        }
    }
    final List<String> timestamps = handler.getTimestamps();
    final List<Double> exposures = handler.getExposures();
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        for (int i = 0; i < timestamps.size(); i++) {
            long timestamp = DateTools.getTime(timestamps.get(i), DATE_FORMAT, ".");
            addGlobalMetaList("timestamp", timestamp);
        }
        for (int i = 0; i < exposures.size(); i++) {
            addGlobalMetaList("exposure time (ms)", exposures.get(i).floatValue() * 1000);
        }
    }
    for (int s = 0; s < seriesCount; s++) {
        setSeries(s);
        Well well = getWell(s);
        String name = handler.getImageName();
        if (seriesCount > 1) {
            name = "Field " + (char) (well.fieldRow + 'A') + (well.fieldCol + 1) + ", Well " + (well.well + 1) + ": " + name;
        }
        store.setImageName(name, s);
        String date = DateTools.formatDate(handler.getDate(), DateTools.ISO8601_FORMAT, ".");
        if (date != null) {
            store.setImageAcquisitionDate(new Timestamp(date), s);
        }
        if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
            long startDate = 0;
            if (timestamps.size() > 0) {
                startDate = DateTools.getTime(timestamps.get(0), DATE_FORMAT, ".");
            }
            store.setImageDescription("", s);
            int image = 0;
            for (int c = 0; c < getEffectiveSizeC(); c++) {
                for (int t = 0; t < getSizeT(); t++) {
                    store.setPlaneTheZ(new NonNegativeInteger(0), s, image);
                    store.setPlaneTheC(new NonNegativeInteger(c), s, image);
                    store.setPlaneTheT(new NonNegativeInteger(t), s, image);
                    if (t < timestamps.size()) {
                        String stamp = timestamps.get(t);
                        long ms = DateTools.getTime(stamp, DATE_FORMAT, ".");
                        store.setPlaneDeltaT(new Time((ms - startDate) / 1000.0, UNITS.SECOND), s, image);
                    }
                    int exposureIndex = image;
                    if (dualCamera) {
                        exposureIndex /= getEffectiveSizeC();
                    }
                    if (exposures.size() == 1) {
                        exposureIndex = 0;
                    }
                    if (exposureIndex < exposures.size() && exposures.get(exposureIndex) != null) {
                        store.setPlaneExposureTime(new Time(exposures.get(exposureIndex), UNITS.SECOND), s, image);
                    }
                    if (s < stageX.size()) {
                        store.setPlanePositionX(stageX.get(s), s, image);
                    }
                    if (s < stageY.size()) {
                        store.setPlanePositionY(stageY.get(s), s, image);
                    }
                    image++;
                }
            }
            store.setImagingEnvironmentTemperature(new Temperature(handler.getTemperature(), UNITS.CELSIUS), s);
            Length sizeX = FormatTools.getPhysicalSizeX(handler.getPixelSizeX());
            Length sizeY = FormatTools.getPhysicalSizeY(handler.getPixelSizeY());
            Length sizeZ = physicalSizeZ == null ? null : FormatTools.getPhysicalSizeZ(physicalSizeZ);
            if (sizeX != null) {
                store.setPixelsPhysicalSizeX(sizeX, s);
            }
            if (sizeY != null) {
                store.setPixelsPhysicalSizeY(sizeY, s);
            }
            if (sizeZ != null) {
                store.setPixelsPhysicalSizeZ(sizeZ, s);
            }
            if (uniqueChannels.size() == 0) {
                uniqueChannels = handler.getChannelNames();
            }
            for (int c = 0; c < getEffectiveSizeC(); c++) {
                if (uniqueChannels.size() > c) {
                    store.setChannelName(uniqueChannels.get(c), s, c);
                } else
                    store.setChannelName(handler.getChannelName(), s, c);
                if (c < wavelengths.size()) {
                    store.setChannelEmissionWavelength(FormatTools.getEmissionWavelength(Double.valueOf(wavelengths.get(c))), s, c);
                }
            }
        }
    }
}
Also used : Temperature(ome.units.quantity.Temperature) IFD(loci.formats.tiff.IFD) ArrayList(java.util.ArrayList) Time(ome.units.quantity.Time) Timestamp(ome.xml.model.primitives.Timestamp) PositiveInteger(ome.xml.model.primitives.PositiveInteger) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) CoreMetadata(loci.formats.CoreMetadata) PositiveInteger(ome.xml.model.primitives.PositiveInteger) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length)

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