Search in sources :

Example 66 with Time

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

the class LeicaHandler method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
    if (attributes.getLength() > 0 && !qName.equals("Element") && !qName.equals("Attachment") && !qName.equals("LMSDataContainerHeader")) {
        nameStack.push(qName);
    }
    int oldSeriesCount = numDatasets;
    Hashtable h = getSeriesHashtable(numDatasets);
    if (qName.equals("LDM_Block_Sequential_Master")) {
        canParse = false;
    } else if (qName.startsWith("LDM")) {
        linkedInstruments = true;
    }
    if (!canParse)
        return;
    final StringBuilder key = new StringBuilder();
    final Iterator<String> nameStackIterator = nameStack.descendingIterator();
    while (nameStackIterator.hasNext()) {
        final String k = nameStackIterator.next();
        key.append(k);
        key.append("|");
    }
    String suffix = attributes.getValue("Identifier");
    String value = attributes.getValue("Variant");
    if (suffix == null)
        suffix = attributes.getValue("Description");
    if (level != MetadataLevel.MINIMUM) {
        if (suffix != null && value != null) {
            storeKeyValue(h, key.toString() + suffix, value);
        } else {
            for (int i = 0; i < attributes.getLength(); i++) {
                String name = attributes.getQName(i);
                storeKeyValue(h, key.toString() + name, attributes.getValue(i));
            }
        }
    }
    if (qName.equals("Element")) {
        elementName = attributes.getValue("Name");
    } else if (qName.equals("Collection")) {
        collection = elementName;
    } else if (qName.equals("Image")) {
        if (!linkedInstruments && level != MetadataLevel.MINIMUM) {
            int c = 0;
            for (Detector d : detectors) {
                String id = MetadataTools.createLSID("Detector", numDatasets, detectorChannel);
                store.setDetectorID(id, numDatasets, detectorChannel);
                try {
                    DetectorTypeEnumHandler handler = new DetectorTypeEnumHandler();
                    store.setDetectorType((DetectorType) handler.getEnumeration(d.type), numDatasets, detectorChannel);
                } catch (EnumerationException e) {
                }
                store.setDetectorModel(d.model, numDatasets, detectorChannel);
                store.setDetectorZoom(d.zoom, numDatasets, detectorChannel);
                store.setDetectorOffset(d.offset, numDatasets, detectorChannel);
                store.setDetectorVoltage(new ElectricPotential(d.voltage, UNITS.VOLT), numDatasets, detectorChannel);
                if (c < numChannels) {
                    if (d.active) {
                        store.setDetectorSettingsOffset(d.offset, numDatasets, c);
                        store.setDetectorSettingsID(id, numDatasets, c);
                        c++;
                    }
                }
                detectorChannel++;
            }
            int filter = 0;
            for (int i = 0; i < nextFilter; i++) {
                while (filter < detectors.size() && !detectors.get(filter).active) {
                    filter++;
                }
                if (filter >= detectors.size() || filter >= nextFilter)
                    break;
                String id = MetadataTools.createLSID("Filter", numDatasets, filter);
                if (i < numChannels && detectors.get(filter).active) {
                    String lsid = MetadataTools.createLSID("Channel", numDatasets, i);
                    store.setChannelID(lsid, numDatasets, i);
                    store.setLightPathEmissionFilterRef(id, numDatasets, i, 0);
                }
                filter++;
            }
        }
        core.add(new CoreMetadata());
        numDatasets++;
        laserCount = 0;
        linkedInstruments = false;
        detectorChannel = 0;
        detectors.clear();
        lasers.clear();
        nextFilter = 0;
        String name = elementName;
        if (collection != null)
            name = collection + "/" + name;
        store.setImageName(name, numDatasets);
        h = getSeriesHashtable(numDatasets);
        storeKeyValue(h, "Image name", name);
        storeSeriesHashtable(numDatasets, h);
        String instrumentID = MetadataTools.createLSID("Instrument", numDatasets);
        store.setInstrumentID(instrumentID, numDatasets);
        store.setImageInstrumentRef(instrumentID, numDatasets);
        numChannels = 0;
        extras = 1;
    } else if (qName.equals("Attachment") && level != MetadataLevel.MINIMUM) {
        if ("ContextDescription".equals(attributes.getValue("Name"))) {
            store.setImageDescription(attributes.getValue("Content"), numDatasets);
        }
    } else if (qName.equals("ChannelDescription")) {
        count++;
        numChannels++;
        lutNames.add(attributes.getValue("LUTName"));
        String bytesInc = attributes.getValue("BytesInc");
        int bytes = bytesInc == null ? 0 : Integer.parseInt(bytesInc);
        if (bytes > 0) {
            bytesPerAxis.put(new Integer(bytes), "C");
        }
    } else if (qName.equals("DimensionDescription")) {
        int len = Integer.parseInt(attributes.getValue("NumberOfElements"));
        int id = Integer.parseInt(attributes.getValue("DimID"));
        double physicalLen = Double.parseDouble(attributes.getValue("Length"));
        String unit = attributes.getValue("Unit");
        int nBytes = Integer.parseInt(attributes.getValue("BytesInc"));
        physicalLen /= len;
        if (unit.equals("Ks")) {
            physicalLen /= 1000;
        } else if (unit.equals("m")) {
            physicalLen *= 1000000;
        }
        Double physicalSize = new Double(physicalLen);
        CoreMetadata coreMeta = core.get(core.size() - 1);
        switch(id) {
            case // X axis
            1:
                coreMeta.sizeX = len;
                coreMeta.rgb = (nBytes % 3) == 0;
                if (coreMeta.rgb)
                    nBytes /= 3;
                switch(nBytes) {
                    case 1:
                        coreMeta.pixelType = FormatTools.UINT8;
                        break;
                    case 2:
                        coreMeta.pixelType = FormatTools.UINT16;
                        break;
                    case 4:
                        coreMeta.pixelType = FormatTools.FLOAT;
                        break;
                }
                physicalSizeX = physicalSize.doubleValue();
                Length sizeX = FormatTools.getPhysicalSizeX(physicalSize);
                if (sizeX != null) {
                    store.setPixelsPhysicalSizeX(sizeX, numDatasets);
                }
                break;
            case // Y axis
            2:
                if (coreMeta.sizeY != 0) {
                    if (coreMeta.sizeZ == 1) {
                        coreMeta.sizeZ = len;
                        bytesPerAxis.put(new Integer(nBytes), "Z");
                    } else if (coreMeta.sizeT == 1) {
                        coreMeta.sizeT = len;
                        bytesPerAxis.put(new Integer(nBytes), "T");
                    }
                } else {
                    coreMeta.sizeY = len;
                    physicalSizeY = physicalSize.doubleValue();
                    Length sizeY = FormatTools.getPhysicalSizeY(physicalSize);
                    if (sizeY != null) {
                        store.setPixelsPhysicalSizeY(sizeY, numDatasets);
                    }
                }
                break;
            case // Z axis
            3:
                if (coreMeta.sizeY == 0) {
                    // XZ scan - swap Y and Z
                    coreMeta.sizeY = len;
                    coreMeta.sizeZ = 1;
                    physicalSizeY = physicalSize.doubleValue();
                    Length sizeY = FormatTools.getPhysicalSizeY(physicalSize);
                    if (sizeY != null) {
                        store.setPixelsPhysicalSizeY(sizeY, numDatasets);
                    }
                    bytesPerAxis.put(new Integer(nBytes), "Y");
                } else {
                    coreMeta.sizeZ = len;
                    bytesPerAxis.put(new Integer(nBytes), "Z");
                }
                break;
            case // T axis
            4:
                if (coreMeta.sizeY == 0) {
                    // XT scan - swap Y and T
                    coreMeta.sizeY = len;
                    coreMeta.sizeT = 1;
                    physicalSizeY = physicalSize.doubleValue();
                    Length sizeY = FormatTools.getPhysicalSizeY(physicalSize);
                    if (sizeY != null) {
                        store.setPixelsPhysicalSizeY(sizeY, numDatasets);
                    }
                    bytesPerAxis.put(new Integer(nBytes), "Y");
                } else {
                    coreMeta.sizeT = len;
                    bytesPerAxis.put(new Integer(nBytes), "T");
                }
                break;
            default:
                extras *= len;
        }
        count++;
    } else if (qName.equals("ScannerSettingRecord") && level != MetadataLevel.MINIMUM) {
        String id = attributes.getValue("Identifier");
        if (id == null)
            id = "";
        if (id.equals("SystemType")) {
            store.setMicroscopeModel(value, numDatasets);
            store.setMicroscopeType(MicroscopeType.OTHER, numDatasets);
        } else if (id.equals("dblPinhole")) {
            pinhole = new Double(Double.parseDouble(value) * 1000000);
        } else if (id.equals("dblZoom")) {
            zoom = new Double(value);
        } else if (id.equals("dblStepSize")) {
            double zStep = Double.parseDouble(value) * 1000000;
            Length sizeZ = FormatTools.getPhysicalSizeZ(zStep);
            if (sizeZ != null) {
                store.setPixelsPhysicalSizeZ(sizeZ, numDatasets);
            }
        } else if (id.equals("nDelayTime_s")) {
            Double timeIncrement = new Double(value);
            if (timeIncrement != null) {
                store.setPixelsTimeIncrement(new Time(timeIncrement, UNITS.SECOND), numDatasets);
            }
        } else if (id.equals("CameraName")) {
            store.setDetectorModel(value, numDatasets, 0);
        } else if (id.indexOf("WFC") == 1) {
            int c = 0;
            try {
                c = Integer.parseInt(id.replaceAll("\\D", ""));
            } catch (NumberFormatException e) {
            }
            Channel channel = channels.get(numDatasets + "-" + c);
            if (channel == null)
                channel = new Channel();
            if (id.endsWith("ExposureTime") && c < numChannels) {
                try {
                    Double exposureTime = new Double(value);
                    if (exposureTime != null) {
                        store.setPlaneExposureTime(new Time(exposureTime, UNITS.SECOND), numDatasets, c);
                    }
                } catch (IndexOutOfBoundsException e) {
                }
            } else if (id.endsWith("Gain")) {
                channel.gain = new Double(value);
                String detectorID = MetadataTools.createLSID("Detector", numDatasets, 0);
                channel.detector = detectorID;
                store.setDetectorID(detectorID, numDatasets, 0);
                store.setDetectorType(DetectorType.CCD, numDatasets, 0);
            } else if (id.endsWith("WaveLength")) {
                Double exWave = new Double(value);
                Length ex = FormatTools.getExcitationWavelength(exWave);
                if (ex != null) {
                    channel.exWave = ex;
                }
            } else // NB: "UesrDefName" is not a typo.
            if (id.endsWith("UesrDefName") && !value.equals("None")) {
                channel.name = value;
            }
            channels.put(numDatasets + "-" + c, channel);
        }
    } else if (qName.equals("FilterSettingRecord") && level != MetadataLevel.MINIMUM) {
        String object = attributes.getValue("ObjectName");
        String attribute = attributes.getValue("Attribute");
        String objectClass = attributes.getValue("ClassName");
        String variant = attributes.getValue("Variant");
        CoreMetadata coreMeta = core.get(numDatasets);
        if (attribute.equals("NumericalAperture")) {
            store.setObjectiveLensNA(new Double(variant), numDatasets, 0);
        } else if (attribute.equals("OrderNumber")) {
            store.setObjectiveSerialNumber(variant, numDatasets, 0);
        } else if (objectClass.equals("CDetectionUnit")) {
            if (attribute.equals("State")) {
                Detector d = new Detector();
                String data = attributes.getValue("data");
                if (data == null)
                    data = attributes.getValue("Data");
                d.channel = data == null ? 0 : Integer.parseInt(data);
                d.type = "PMT";
                d.model = object;
                d.active = variant.equals("Active");
                d.zoom = zoom;
                detectors.add(d);
            } else if (attribute.equals("HighVoltage")) {
                Detector d = detectors.get(detectors.size() - 1);
                d.voltage = new Double(variant);
            } else if (attribute.equals("VideoOffset")) {
                Detector d = detectors.get(detectors.size() - 1);
                d.offset = new Double(variant);
            }
        } else if (attribute.equals("Objective")) {
            StringTokenizer tokens = new StringTokenizer(variant, " ");
            boolean foundMag = false;
            final StringBuilder model = new StringBuilder();
            while (!foundMag) {
                String token = tokens.nextToken();
                int x = token.indexOf('x');
                if (x != -1) {
                    foundMag = true;
                    Double mag = Double.parseDouble(token.substring(0, x));
                    String na = token.substring(x + 1);
                    store.setObjectiveNominalMagnification(mag, numDatasets, 0);
                    store.setObjectiveLensNA(new Double(na), numDatasets, 0);
                } else {
                    model.append(token);
                    model.append(" ");
                }
            }
            String immersion = "Other";
            if (tokens.hasMoreTokens()) {
                immersion = tokens.nextToken();
                if (immersion == null || immersion.trim().equals("")) {
                    immersion = "Other";
                }
            }
            try {
                ImmersionEnumHandler handler = new ImmersionEnumHandler();
                store.setObjectiveImmersion((Immersion) handler.getEnumeration(immersion), numDatasets, 0);
            } catch (EnumerationException e) {
            }
            String correction = "Other";
            if (tokens.hasMoreTokens()) {
                correction = tokens.nextToken();
                if (correction == null || correction.trim().equals("")) {
                    correction = "Other";
                }
            }
            try {
                CorrectionEnumHandler handler = new CorrectionEnumHandler();
                store.setObjectiveCorrection((Correction) handler.getEnumeration(correction), numDatasets, 0);
            } catch (EnumerationException e) {
            }
            store.setObjectiveModel(model.toString().trim(), numDatasets, 0);
        } else if (attribute.equals("RefractionIndex")) {
            String id = MetadataTools.createLSID("Objective", numDatasets, 0);
            store.setObjectiveID(id, numDatasets, 0);
            store.setObjectiveSettingsID(id, numDatasets);
            store.setObjectiveSettingsRefractiveIndex(new Double(variant), numDatasets);
        } else if (attribute.equals("XPos")) {
            int c = coreMeta.rgb || coreMeta.sizeC == 0 ? 1 : coreMeta.sizeC;
            int nPlanes = coreMeta.imageCount;
            final Double posXn = Double.valueOf(variant);
            final Length posXl = new Length(posXn, UNITS.REFERENCEFRAME);
            for (int image = 0; image < nPlanes; image++) {
                store.setPlanePositionX(posXl, numDatasets, image);
            }
            if (numChannels == 0)
                xPos.add(posXl);
        } else if (attribute.equals("YPos")) {
            int c = coreMeta.rgb || coreMeta.sizeC == 0 ? 1 : coreMeta.sizeC;
            int nPlanes = coreMeta.imageCount;
            final Double posYn = Double.valueOf(variant);
            final Length posYl = new Length(posYn, UNITS.REFERENCEFRAME);
            for (int image = 0; image < nPlanes; image++) {
                store.setPlanePositionY(posYl, numDatasets, image);
            }
            if (numChannels == 0)
                yPos.add(posYl);
        } else if (attribute.equals("ZPos")) {
            int c = coreMeta.rgb || coreMeta.sizeC == 0 ? 1 : coreMeta.sizeC;
            int nPlanes = coreMeta.imageCount;
            final Double posZn = Double.valueOf(variant);
            final Length posZl = new Length(posZn, UNITS.REFERENCEFRAME);
            for (int image = 0; image < nPlanes; image++) {
                store.setPlanePositionZ(posZl, numDatasets, image);
            }
            if (numChannels == 0)
                zPos.add(posZl);
        } else if (objectClass.equals("CSpectrophotometerUnit")) {
            Double v = null;
            try {
                v = Double.parseDouble(variant);
            } catch (NumberFormatException e) {
            }
            if (attributes.getValue("Description").endsWith("(left)")) {
                String id = MetadataTools.createLSID("Filter", numDatasets, nextFilter);
                store.setFilterID(id, numDatasets, nextFilter);
                store.setFilterModel(object, numDatasets, nextFilter);
                Length in = FormatTools.getCutIn(v);
                if (in != null) {
                    store.setTransmittanceRangeCutIn(in, numDatasets, nextFilter);
                }
            } else if (attributes.getValue("Description").endsWith("(right)")) {
                Length out = FormatTools.getCutOut(v);
                if (out != null) {
                    store.setTransmittanceRangeCutOut(out, numDatasets, nextFilter);
                    nextFilter++;
                }
            }
        }
    } else if (qName.equals("Detector") && level != MetadataLevel.MINIMUM) {
        String v = attributes.getValue("Gain");
        Double gain = v == null ? null : new Double(v);
        v = attributes.getValue("Offset");
        Double offset = v == null ? null : new Double(v);
        boolean active = "1".equals(attributes.getValue("IsActive"));
        if (active) {
            // find the corresponding MultiBand and Detector
            MultiBand m = null;
            Detector detector = null;
            Laser laser = lasers.isEmpty() ? null : lasers.get(lasers.size() - 1);
            String c = attributes.getValue("Channel");
            int channel = c == null ? 0 : Integer.parseInt(c);
            for (MultiBand mb : multiBands) {
                if (mb.channel == channel) {
                    m = mb;
                    break;
                }
            }
            for (Detector d : detectors) {
                if (d.channel == channel) {
                    detector = d;
                    break;
                }
            }
            String id = MetadataTools.createLSID("Detector", numDatasets, nextChannel);
            if (m != null) {
                String channelID = MetadataTools.createLSID("Channel", numDatasets, nextChannel);
                store.setChannelID(channelID, numDatasets, nextChannel);
                store.setChannelName(m.dyeName, numDatasets, nextChannel);
                String filter = MetadataTools.createLSID("Filter", numDatasets, nextFilter);
                store.setFilterID(filter, numDatasets, nextFilter);
                Length in = FormatTools.getCutIn(m.cutIn);
                Length out = FormatTools.getCutOut(m.cutOut);
                if (in != null) {
                    store.setTransmittanceRangeCutIn(in, numDatasets, nextFilter);
                }
                if (out != null) {
                    store.setTransmittanceRangeCutOut(out, numDatasets, nextFilter);
                }
                store.setLightPathEmissionFilterRef(filter, numDatasets, nextChannel, 0);
                nextFilter++;
                store.setDetectorID(id, numDatasets, nextChannel);
                store.setDetectorType(DetectorType.PMT, numDatasets, nextChannel);
                store.setDetectorSettingsGain(gain, numDatasets, nextChannel);
                store.setDetectorSettingsOffset(offset, numDatasets, nextChannel);
                store.setDetectorSettingsID(id, numDatasets, nextChannel);
            }
            store.setDetectorID(id, numDatasets, nextChannel);
            if (detector != null) {
                store.setDetectorSettingsGain(gain, numDatasets, nextChannel);
                store.setDetectorSettingsOffset(offset, numDatasets, nextChannel);
                store.setDetectorSettingsID(id, numDatasets, nextChannel);
                try {
                    DetectorTypeEnumHandler handler = new DetectorTypeEnumHandler();
                    store.setDetectorType((DetectorType) handler.getEnumeration(detector.type), numDatasets, nextChannel);
                } catch (EnumerationException e) {
                }
                store.setDetectorModel(detector.model, numDatasets, nextChannel);
                store.setDetectorZoom(detector.zoom, numDatasets, nextChannel);
                store.setDetectorOffset(detector.offset, numDatasets, nextChannel);
                store.setDetectorVoltage(new ElectricPotential(detector.voltage, UNITS.VOLT), numDatasets, nextChannel);
            }
            if (laser != null && laser.intensity < 100) {
                store.setChannelLightSourceSettingsID(laser.id, numDatasets, nextChannel);
                store.setChannelLightSourceSettingsAttenuation(new PercentFraction((float) laser.intensity / 100f), numDatasets, nextChannel);
                Length wavelength = FormatTools.getExcitationWavelength(laser.wavelength);
                if (wavelength != null) {
                    store.setChannelExcitationWavelength(wavelength, numDatasets, nextChannel);
                }
            }
            nextChannel++;
        }
    } else if (qName.equals("LaserLineSetting") && level != MetadataLevel.MINIMUM) {
        Laser l = new Laser();
        String lineIndex = attributes.getValue("LineIndex");
        String qual = attributes.getValue("Qualifier");
        l.index = lineIndex == null ? 0 : Integer.parseInt(lineIndex);
        int qualifier = qual == null ? 0 : Integer.parseInt(qual);
        l.index += (2 - (qualifier / 10));
        if (l.index < 0)
            l.index = 0;
        l.id = MetadataTools.createLSID("LightSource", numDatasets, l.index);
        l.wavelength = new Double(attributes.getValue("LaserLine"));
        while (l.index > laserCount) {
            String lsid = MetadataTools.createLSID("LightSource", numDatasets, laserCount);
            store.setLaserID(lsid, numDatasets, laserCount);
            laserCount++;
        }
        store.setLaserID(l.id, numDatasets, l.index);
        laserCount++;
        Length wavelength = FormatTools.getWavelength(l.wavelength);
        if (wavelength != null) {
            store.setLaserWavelength(wavelength, numDatasets, l.index);
        }
        store.setLaserType(LaserType.OTHER, numDatasets, l.index);
        store.setLaserLaserMedium(LaserMedium.OTHER, numDatasets, l.index);
        String intensity = attributes.getValue("IntensityDev");
        l.intensity = intensity == null ? 0d : Double.parseDouble(intensity);
        if (l.intensity > 0) {
            l.intensity = 100d - l.intensity;
            lasers.add(l);
        }
    } else if (qName.equals("TimeStamp") && numDatasets >= 0) {
        String stampHigh = attributes.getValue("HighInteger");
        String stampLow = attributes.getValue("LowInteger");
        long high = stampHigh == null ? 0 : Long.parseLong(stampHigh);
        long low = stampLow == null ? 0 : Long.parseLong(stampLow);
        long ms = DateTools.getMillisFromTicks(high, low);
        if (count == 0) {
            String date = DateTools.convertDate(ms, DateTools.COBOL);
            Timestamp timestamp = Timestamp.valueOf(date);
            if (timestamp != null && timestamp.asInstant().getMillis() < System.currentTimeMillis()) {
                store.setImageAcquisitionDate(new Timestamp(date), numDatasets);
            }
            firstStamp = ms;
            store.setPlaneDeltaT(new Time(0.0, UNITS.SECOND), numDatasets, count);
        } else if (level != MetadataLevel.MINIMUM) {
            CoreMetadata coreMeta = core.get(numDatasets);
            int nImages = coreMeta.sizeZ * coreMeta.sizeT * coreMeta.sizeC;
            if (count < nImages) {
                ms -= firstStamp;
                store.setPlaneDeltaT(new Time(ms / 1000.0, UNITS.SECOND), numDatasets, count);
            }
        }
        count++;
    } else if (qName.equals("RelTimeStamp") && level != MetadataLevel.MINIMUM) {
        CoreMetadata coreMeta = core.get(numDatasets);
        int nImages = coreMeta.sizeZ * coreMeta.sizeT * coreMeta.sizeC;
        if (count < nImages) {
            Double time = new Double(attributes.getValue("Time"));
            if (time != null) {
                store.setPlaneDeltaT(new Time(time, UNITS.SECOND), numDatasets, count++);
            }
        }
    } else if (qName.equals("Annotation") && level != MetadataLevel.MINIMUM) {
        roi = new ROI();
        String type = attributes.getValue("type");
        if (type != null)
            roi.type = Integer.parseInt(type);
        String color = attributes.getValue("color");
        if (color != null)
            roi.color = Integer.parseInt(color);
        roi.name = attributes.getValue("name");
        roi.fontName = attributes.getValue("fontName");
        roi.fontSize = attributes.getValue("fontSize");
        roi.transX = parseDouble(attributes.getValue("transTransX"));
        roi.transY = parseDouble(attributes.getValue("transTransY"));
        roi.scaleX = parseDouble(attributes.getValue("transScalingX"));
        roi.scaleY = parseDouble(attributes.getValue("transScalingY"));
        roi.rotation = parseDouble(attributes.getValue("transRotation"));
        String linewidth = attributes.getValue("linewidth");
        if (linewidth != null)
            roi.linewidth = Integer.parseInt(linewidth);
        roi.text = attributes.getValue("text");
    } else if (qName.equals("Vertex") && level != MetadataLevel.MINIMUM) {
        String x = attributes.getValue("x");
        String y = attributes.getValue("y");
        if (x != null) {
            x = x.replaceAll(",", ".");
            roi.x.add(new Double(x));
        }
        if (y != null) {
            y = y.replaceAll(",", ".");
            roi.y.add(new Double(y));
        }
    } else if (qName.equals("ROI")) {
        alternateCenter = true;
    } else if (qName.equals("MultiBand") && level != MetadataLevel.MINIMUM) {
        MultiBand m = new MultiBand();
        m.dyeName = attributes.getValue("DyeName");
        m.channel = Integer.parseInt(attributes.getValue("Channel"));
        m.cutIn = (double) Math.round(Double.parseDouble(attributes.getValue("LeftWorld")));
        m.cutOut = (double) Math.round(Double.parseDouble(attributes.getValue("RightWorld")));
        multiBands.add(m);
    } else if (qName.equals("ChannelInfo")) {
        int index = Integer.parseInt(attributes.getValue("Index"));
        channels.remove(numDatasets + "-" + index);
    } else
        count = 0;
    if (numDatasets == oldSeriesCount)
        storeSeriesHashtable(numDatasets, h);
}
Also used : Time(ome.units.quantity.Time) Timestamp(ome.xml.model.primitives.Timestamp) DetectorTypeEnumHandler(ome.xml.model.enums.handlers.DetectorTypeEnumHandler) Hashtable(java.util.Hashtable) ElectricPotential(ome.units.quantity.ElectricPotential) CoreMetadata(loci.formats.CoreMetadata) ImmersionEnumHandler(ome.xml.model.enums.handlers.ImmersionEnumHandler) StringTokenizer(java.util.StringTokenizer) Length(ome.units.quantity.Length) CorrectionEnumHandler(ome.xml.model.enums.handlers.CorrectionEnumHandler) PercentFraction(ome.xml.model.primitives.PercentFraction) EnumerationException(ome.xml.model.enums.EnumerationException)

Example 67 with Time

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

the class MIASReader method parseTemplateFile.

/**
 * Parse metadata from the Nugenesistemplate.txt file.
 */
private void parseTemplateFile(MetadataStore store) throws IOException {
    if (templateFile == null)
        return;
    Double physicalSizeX = null, physicalSizeY = null, exposure = null;
    final List<String> channelNames = new ArrayList<String>();
    String date = null;
    String data = DataTools.readFile(templateFile);
    String[] lines = data.split("\r\n");
    for (String line : lines) {
        int eq = line.indexOf('=');
        if (eq != -1) {
            String key = line.substring(0, eq);
            String value = line.substring(eq + 1);
            if (key.equals("Barcode")) {
                store.setPlateExternalIdentifier(value, 0);
            } else if (key.equals("Carrier")) {
                store.setPlateName(value, 0);
            } else if (key.equals("Pixel_X")) {
                physicalSizeX = new Double(value);
            } else if (key.equals("Pixel_Y")) {
                physicalSizeY = new Double(value);
            } else if (key.equals("Objective_ID")) {
                store.setObjectiveID(MetadataTools.createLSID("Objective", 0, 0), 0, 0);
                store.setObjectiveModel(value, 0, 0);
            } else if (key.equals("Magnification")) {
                Double mag = Double.parseDouble(value);
                store.setObjectiveNominalMagnification(mag, 0, 0);
            } else if (key.startsWith("Mode_")) {
                channelNames.add(value);
            } else if (key.equals("Date")) {
                date = value;
            } else if (key.equals("Time")) {
                date += " " + value;
            } else if (key.equals("Exposure")) {
                exposure = new Double(value);
            }
        }
    }
    for (int well = 0; well < tiffs.length; well++) {
        Length sizeX = FormatTools.getPhysicalSizeX(physicalSizeX);
        Length sizeY = FormatTools.getPhysicalSizeY(physicalSizeY);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, well);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, well);
        }
        for (int c = 0; c < channelNames.size(); c++) {
            if (c < getEffectiveSizeC()) {
                store.setChannelName(channelNames.get(c), well, c);
            }
        }
        date = DateTools.formatDate(date, "dd/MM/yyyy HH:mm:ss");
        if (date != null) {
            store.setImageAcquisitionDate(new Timestamp(date), well);
        }
        if (exposure != null) {
            for (int i = 0; i < getImageCount(); i++) {
                store.setPlaneExposureTime(new Time(exposure, UNITS.SECOND), well, i);
            }
        }
    }
}
Also used : Length(ome.units.quantity.Length) ArrayList(java.util.ArrayList) Time(ome.units.quantity.Time) Timestamp(ome.xml.model.primitives.Timestamp)

Example 68 with Time

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

the class InCellReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    // make sure that we have the .xdce (or .xml) file
    if (checkSuffix(id, PIXELS_SUFFIXES) || checkSuffix(id, "xlog")) {
        Location currentFile = new Location(id).getAbsoluteFile();
        Location parent = currentFile.getParentFile();
        String[] list = parent.list(true);
        for (String f : list) {
            if (checkSuffix(f, new String[] { "xdce", "xml" })) {
                String path = new Location(parent, f).getAbsolutePath();
                if (isThisType(path)) {
                    // make sure that the .xdce file references the current file
                    // this ensures that the correct file is chosen if multiple
                    // .xdce files are the same directory
                    String data = DataTools.readFile(path);
                    if (data.indexOf(currentFile.getName()) >= 0) {
                        id = path;
                        break;
                    }
                }
            }
        }
    }
    super.initFile(id);
    in = new RandomAccessInputStream(id);
    channelNames = new ArrayList<String>();
    emWaves = new ArrayList<Double>();
    exWaves = new ArrayList<Double>();
    channelsPerTimepoint = new ArrayList<Integer>();
    metadataFiles = new ArrayList<String>();
    // parse metadata from the .xdce or .xml file
    wellCoordinates = new HashMap<Integer, int[]>();
    posX = new HashMap<Integer, Length>();
    posY = new HashMap<Integer, Length>();
    offsetPointCounter = 0;
    byte[] b = new byte[(int) in.length()];
    in.read(b);
    CoreMetadata ms0 = core.get(0);
    ms0.dimensionOrder = "XYZCT";
    MetadataStore store = makeFilterMetadata();
    DefaultHandler handler = new MinimalInCellHandler();
    XMLTools.parseXML(b, handler);
    if (getSizeZ() == 0)
        ms0.sizeZ = 1;
    if (getSizeC() == 0)
        ms0.sizeC = 1;
    if (getSizeT() == 0)
        ms0.sizeT = 1;
    if (totalImages == 0) {
        ms0.imageCount = getSizeC() * getSizeZ() * getSizeT();
        totalImages = getImageCount() * wellRows * wellCols * fieldCount;
        Location parent = new Location(currentId).getAbsoluteFile().getParentFile();
        for (int row = 0; row < wellRows; row++) {
            for (int col = 0; col < wellCols; col++) {
                plateMap[row][col] = true;
                for (int field = 0; field < fieldCount; field++) {
                    for (int t = 0; t < getSizeT(); t++) {
                        for (int image = 0; image < getSizeC() * getSizeZ(); image++) {
                            // this could be expanded to allow for timepoint indexes
                            // in the file name, as well as allowing the filter names to
                            // be omitted
                            int channel = getZCTCoords(image)[1];
                            Image plane = new Image();
                            String filename = (char) ('A' + row) + " - " + (col + 1) + "(fld " + (field + 1) + " wv " + exFilters.get(channel) + " - " + emFilters.get(channel) + ").tif";
                            Location path = new Location(parent, filename);
                            if (path.exists()) {
                                plane.filename = path.getAbsolutePath();
                            } else {
                                LOGGER.debug("Missing file {}", filename);
                            }
                            imageFiles[row * wellCols + col][field][t][image] = plane;
                        }
                    }
                }
            }
        }
    }
    for (int t = imageFiles[0][0].length - 1; t >= 0; t--) {
        boolean allNull = true;
        for (int well = 0; well < imageFiles.length; well++) {
            for (int field = 0; field < imageFiles[well].length; field++) {
                for (int p = 0; p < imageFiles[well][field][t].length; p++) {
                    if (imageFiles[well][field][t][p] != null) {
                        allNull = false;
                        break;
                    }
                }
            }
        }
        if (allNull) {
            ms0.sizeT--;
        }
    }
    int seriesCount = 0;
    if (exclude != null) {
        for (int row = 0; row < wellRows; row++) {
            for (int col = 0; col < wellCols; col++) {
                if (!exclude[row][col]) {
                    int well = row * wellCols + col;
                    boolean hasNonNullImage = false;
                    for (int field = 0; field < imageFiles[well].length; field++) {
                        for (int t = 0; t < imageFiles[well][field].length; t++) {
                            for (int p = 0; p < imageFiles[well][field][t].length; p++) {
                                if (imageFiles[well][field][t][p] != null) {
                                    hasNonNullImage = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (hasNonNullImage) {
                        seriesCount += imageFiles[well].length;
                    }
                }
            }
        }
        int expectedSeries = totalImages / (getSizeZ() * getSizeC() * getSizeT());
        if (expectedSeries > 0) {
            seriesCount = (int) Math.min(seriesCount, expectedSeries);
        }
    } else
        seriesCount = totalImages / (getSizeZ() * getSizeC() * getSizeT());
    totalChannels = getSizeC();
    oneTimepointPerSeries = false;
    for (int i = 1; i < channelsPerTimepoint.size(); i++) {
        if (!channelsPerTimepoint.get(i).equals(channelsPerTimepoint.get(i - 1))) {
            oneTimepointPerSeries = true;
            break;
        }
    }
    if (oneTimepointPerSeries) {
        int imageCount = 0;
        for (Integer timepoint : channelsPerTimepoint) {
            imageCount += timepoint.intValue() * getSizeZ();
        }
        seriesCount = (totalImages / imageCount) * getSizeT();
    }
    int sizeT = getSizeT();
    int sizeC = getSizeC();
    int z = getSizeZ();
    int t = oneTimepointPerSeries ? 1 : getSizeT();
    core.clear();
    for (int i = 0; i < seriesCount; i++) {
        int c = oneTimepointPerSeries ? channelsPerTimepoint.get(i % sizeT).intValue() : sizeC;
        CoreMetadata ms = new CoreMetadata();
        core.add(ms);
        ms.sizeZ = z;
        ms.sizeC = c;
        ms.sizeT = t;
        ms.imageCount = z * c * t;
        ms.dimensionOrder = "XYZCT";
    }
    int wellIndex = getWellFromSeries(0);
    int fieldIndex = getFieldFromSeries(0);
    String filename = imageFiles[wellIndex][fieldIndex][0][0].filename;
    boolean isTiff = imageFiles[wellIndex][fieldIndex][0][0].isTiff;
    if (isTiff && filename != null) {
        tiffReader = new MinimalTiffReader();
        tiffReader.setId(filename);
        for (int i = 0; i < seriesCount; i++) {
            CoreMetadata ms = core.get(i);
            ms.sizeX = tiffReader.getSizeX();
            ms.sizeY = tiffReader.getSizeY();
            ms.interleaved = tiffReader.isInterleaved();
            ms.indexed = tiffReader.isIndexed();
            ms.rgb = tiffReader.isRGB();
            ms.pixelType = tiffReader.getPixelType();
            ms.littleEndian = tiffReader.isLittleEndian();
        }
    } else {
        for (int i = 0; i < seriesCount; i++) {
            CoreMetadata ms = core.get(i);
            ms.sizeX = imageWidth;
            ms.sizeY = imageHeight;
            ms.interleaved = false;
            ms.indexed = false;
            ms.rgb = false;
            ms.pixelType = FormatTools.UINT16;
            ms.littleEndian = true;
        }
    }
    MetadataTools.populatePixels(store, this, true);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        handler = new InCellHandler(store);
        XMLTools.parseXML(b, handler);
    }
    String rowNaming = Character.isDigit(rowName.charAt(0)) ? "Number" : "Letter";
    String colNaming = Character.isDigit(colName.charAt(0)) ? "Number" : "Letter";
    String plateName = currentId;
    int begin = plateName.lastIndexOf(File.separator) + 1;
    int end = plateName.lastIndexOf(".");
    plateName = plateName.substring(begin, end);
    store.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
    store.setPlateName(plateName, 0);
    store.setPlateRowNamingConvention(getNamingConvention(rowNaming), 0);
    store.setPlateColumnNamingConvention(getNamingConvention(colNaming), 0);
    store.setPlateRows(new PositiveInteger(wellRows), 0);
    store.setPlateColumns(new PositiveInteger(wellCols), 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);
    }
    // populate Image data
    String instrumentID = MetadataTools.createLSID("Instrument", 0);
    String experimentID = MetadataTools.createLSID("Experiment", 0);
    store.setInstrumentID(instrumentID, 0);
    store.setExperimentID(experimentID, 0);
    String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
    store.setObjectiveID(objectiveID, 0, 0);
    String detectorID = MetadataTools.createLSID("Detector", 0, 0);
    store.setDetectorID(detectorID, 0, 0);
    int prevWell = -1;
    for (int i = 0; i < seriesCount; i++) {
        store.setObjectiveSettingsID(objectiveID, i);
        if (refractive != null) {
            store.setObjectiveSettingsRefractiveIndex(refractive, i);
        }
        if (x != null) {
            store.setPixelsPhysicalSizeX(x, i);
        }
        if (y != null) {
            store.setPixelsPhysicalSizeY(y, i);
        }
        int well = getWellFromSeries(i);
        int field = getFieldFromSeries(i);
        int totalTimepoints = oneTimepointPerSeries ? channelsPerTimepoint.size() : 1;
        int timepoint = oneTimepointPerSeries ? (i % totalTimepoints) + 1 : -1;
        String imageID = MetadataTools.createLSID("Image", i);
        store.setImageID(imageID, i);
        store.setImageInstrumentRef(instrumentID, i);
        store.setImageExperimentRef(experimentID, i);
        int wellRow = well / wellCols;
        int wellCol = well % wellCols;
        wellIndex = i / (fieldCount * totalTimepoints);
        if (well != prevWell) {
            String wellID = MetadataTools.createLSID("Well", 0, wellIndex);
            store.setWellID(wellID, 0, wellIndex);
            store.setWellRow(new NonNegativeInteger(wellRow), 0, wellIndex);
            store.setWellColumn(new NonNegativeInteger(wellCol), 0, wellIndex);
            prevWell = well;
        }
        char rowChar = rowName.charAt(rowName.length() - 1);
        char colChar = colName.charAt(colName.length() - 1);
        String row = rowName.substring(0, rowName.length() - 1);
        String col = colName.substring(0, colName.length() - 1);
        if (Character.isDigit(rowChar)) {
            row += wellRow + Integer.parseInt(String.valueOf(rowChar));
        } else
            row += (char) (rowChar + wellRow);
        if (Character.isDigit(colChar)) {
            col += wellCol + Integer.parseInt(String.valueOf(colChar));
        } else
            col += (char) (colChar + wellCol);
        String imageName = "Well " + row + "-" + col + ", Field #" + (field + 1);
        if (timepoint >= 0) {
            imageName += ", Timepoint #" + timepoint;
        }
        store.setImageName(imageName, i);
        if (creationDate != null) {
            store.setImageAcquisitionDate(new Timestamp(creationDate), i);
        }
        timepoint--;
        if (timepoint < 0)
            timepoint = 0;
        int sampleIndex = field * totalTimepoints + timepoint;
        String wellSampleID = MetadataTools.createLSID("WellSample", 0, wellIndex, sampleIndex);
        store.setWellSampleID(wellSampleID, 0, wellIndex, sampleIndex);
        store.setWellSampleIndex(new NonNegativeInteger(i), 0, wellIndex, sampleIndex);
        store.setWellSampleImageRef(imageID, 0, wellIndex, sampleIndex);
        if (posX.containsKey(field)) {
            store.setWellSamplePositionX(posX.get(field), 0, wellIndex, sampleIndex);
        }
        if (posY.containsKey(field)) {
            store.setWellSamplePositionY(posY.get(field), 0, wellIndex, sampleIndex);
        }
        store.setPlateAcquisitionWellSampleRef(wellSampleID, 0, 0, i);
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        for (int i = 0; i < seriesCount; i++) {
            setSeries(i);
            int well = getWellFromSeries(i);
            int field = getFieldFromSeries(i);
            int timepoint = oneTimepointPerSeries ? i % channelsPerTimepoint.size() : 0;
            for (int time = 0; time < getSizeT(); time++) {
                if (!oneTimepointPerSeries)
                    timepoint = time;
                int c = channelsPerTimepoint.get(timepoint).intValue();
                for (int q = 0; q < getSizeZ() * c; q++) {
                    Image img = imageFiles[well][field][timepoint][q];
                    if (img == null)
                        continue;
                    int plane = time * getSizeZ() * c + q;
                    if (img.deltaT != null) {
                        store.setPlaneDeltaT(new Time(img.deltaT, UNITS.SECOND), i, plane);
                    }
                    if (img.exposure != null) {
                        store.setPlaneExposureTime(new Time(img.exposure, UNITS.SECOND), i, plane);
                    }
                    store.setPlanePositionX(posX.get(field), i, plane);
                    store.setPlanePositionY(posY.get(field), i, plane);
                    store.setPlanePositionZ(img.zPosition, i, plane);
                }
            }
            // populate LogicalChannel data
            for (int q = 0; q < getEffectiveSizeC(); q++) {
                if (q < channelNames.size()) {
                    store.setChannelName(channelNames.get(q), i, q);
                }
                if (q < emWaves.size()) {
                    Double wave = emWaves.get(q);
                    Length emission = FormatTools.getEmissionWavelength(wave);
                    if (emission != null) {
                        store.setChannelEmissionWavelength(emission, i, q);
                    }
                }
                if (q < exWaves.size()) {
                    Double wave = exWaves.get(q);
                    Length excitation = FormatTools.getExcitationWavelength(wave);
                    if (excitation != null) {
                        store.setChannelExcitationWavelength(excitation, i, q);
                    }
                }
                if (detectorID != null) {
                    store.setDetectorSettingsID(detectorID, i, q);
                    if (bin != null) {
                        store.setDetectorSettingsBinning(bin, i, q);
                    }
                    if (gain != null) {
                        store.setDetectorSettingsGain(gain, i, q);
                    }
                }
            }
            if (temperature != null) {
                store.setImagingEnvironmentTemperature(new Temperature(temperature, UNITS.CELSIUS), i);
            }
        }
        setSeries(0);
        // populate Plate data
        store.setPlateWellOriginX(new Length(0.5, UNITS.MICROMETER), 0);
        store.setPlateWellOriginY(new Length(0.5, UNITS.MICROMETER), 0);
    }
}
Also used : Temperature(ome.units.quantity.Temperature) 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) DefaultHandler(org.xml.sax.helpers.DefaultHandler) PositiveInteger(ome.xml.model.primitives.PositiveInteger) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) RandomAccessInputStream(loci.common.RandomAccessInputStream) Location(loci.common.Location)

Example 69 with Time

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

the class ImarisReader 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("Verifying Imaris RAW format");
    in.order(IS_LITTLE);
    long magic = in.readInt();
    if (magic != IMARIS_MAGIC_BYTES) {
        throw new FormatException("Imaris magic number not found.");
    }
    LOGGER.info("Reading header");
    int version = in.readInt();
    in.skipBytes(4);
    String imageName = in.readString(128);
    CoreMetadata m = core.get(0);
    m.sizeX = in.readShort();
    m.sizeY = in.readShort();
    m.sizeZ = in.readShort();
    in.skipBytes(2);
    m.sizeC = in.readInt();
    in.skipBytes(2);
    String date = in.readString(32);
    float dx = in.readFloat();
    float dy = in.readFloat();
    float dz = in.readFloat();
    int mag = in.readShort();
    String description = in.readString(128);
    int isSurvey = in.readInt();
    LOGGER.info("Calculating image offsets");
    m.imageCount = getSizeZ() * getSizeC();
    offsets = new int[getImageCount()];
    float[] gains = new float[getSizeC()];
    float[] detectorOffsets = new float[getSizeC()];
    float[] pinholes = new float[getSizeC()];
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        for (int i = 0; i < getSizeC(); i++) {
            addGlobalMeta("Channel #" + i + " Comment", in.readString(128));
            gains[i] = in.readFloat();
            detectorOffsets[i] = in.readFloat();
            pinholes[i] = in.readFloat();
            in.skipBytes(24);
        }
    }
    int offset = 336 + (164 * getSizeC());
    for (int i = 0; i < getSizeC(); i++) {
        for (int j = 0; j < getSizeZ(); j++) {
            offsets[i * getSizeZ() + j] = offset + (j * getSizeX() * getSizeY());
        }
        offset += getSizeX() * getSizeY() * getSizeZ();
    }
    addGlobalMeta("Version", version);
    addGlobalMeta("Image name", imageName);
    addGlobalMeta("Image comment", description);
    addGlobalMeta("Survey performed", isSurvey == 0);
    addGlobalMeta("Original date", date);
    LOGGER.info("Populating metadata");
    m.sizeT = getImageCount() / (getSizeC() * getSizeZ());
    m.dimensionOrder = "XYZCT";
    m.rgb = false;
    m.interleaved = false;
    m.littleEndian = IS_LITTLE;
    m.indexed = false;
    m.falseColor = false;
    m.metadataComplete = true;
    m.pixelType = FormatTools.UINT8;
    // The metadata store we're working with.
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    // populate Image data
    store.setImageName(imageName, 0);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        store.setImageDescription(description, 0);
        // link Instrument and Image
        String instrumentID = MetadataTools.createLSID("Instrument", 0);
        store.setInstrumentID(instrumentID, 0);
        store.setImageInstrumentRef(instrumentID, 0);
        // populate Dimensions data
        Length sizeX = FormatTools.getPhysicalSizeX((double) dx);
        Length sizeY = FormatTools.getPhysicalSizeY((double) dy);
        Length sizeZ = FormatTools.getPhysicalSizeZ((double) dz);
        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(1.0, UNITS.SECOND), 0);
        for (int i = 0; i < getSizeC(); i++) {
            if (pinholes[i] > 0) {
                store.setChannelPinholeSize(new Length(pinholes[i], UNITS.MICROMETER), 0, i);
            }
        }
        for (int i = 0; i < getSizeC(); i++) {
            if (gains[i] > 0) {
                store.setDetectorSettingsGain((double) gains[i], 0, i);
            }
            store.setDetectorSettingsOffset((double) offsets[i], i, 0);
            // link DetectorSettings to an actual Detector
            String detectorID = MetadataTools.createLSID("Detector", 0, i);
            store.setDetectorID(detectorID, 0, i);
            store.setDetectorType(getDetectorType("Other"), 0, i);
            store.setDetectorSettingsID(detectorID, 0, i);
        }
    }
}
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) FormatException(loci.formats.FormatException)

Example 70 with Time

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

the class ImprovisionTiffReader method initMetadataStore.

/* @see BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
    super.initMetadataStore();
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        Length sizeX = FormatTools.getPhysicalSizeX(pixelSizeX);
        Length sizeY = FormatTools.getPhysicalSizeY(pixelSizeY);
        Length sizeZ = FormatTools.getPhysicalSizeZ(pixelSizeZ);
        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(pixelSizeT / 1000000.0, UNITS.SECOND), 0);
        for (int i = 0; i < getEffectiveSizeC(); i++) {
            if (cNames != null && i < cNames.length) {
                store.setChannelName(cNames[i], 0, i);
            }
            int index = getIndex(0, i, 0);
            if (index < channelColors.size() && channelColors.get(index) != null) {
                store.setChannelColor(channelColors.get(index), 0, i);
            }
        }
        store.setImageDescription("", 0);
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) Time(ome.units.quantity.Time)

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