Search in sources :

Example 1 with DummyMetadata

use of loci.formats.meta.DummyMetadata in project bioformats by openmicroscopy.

the class ImagePlusReader method constructSliceLabel.

private String constructSliceLabel(int ndx, IFormatReader r, IMetadata meta, int series, int zCount, int cCount, int tCount) {
    r.setSeries(series);
    String sliceLabelPattern = LociPrefs.getSliceLabelPattern();
    String order = r.getDimensionOrder();
    int sizeC = r.getEffectiveSizeC();
    int sizeT = r.getSizeT();
    int sizeZ = r.getSizeZ();
    int seriesCount = r.getImageCount();
    int indexBase = LociPrefs.getSliceLabelBaseIndex();
    int[] coordinates = FormatTools.getZCTCoords(order, sizeZ, sizeC, sizeT, sizeZ * sizeC * sizeT, ndx);
    MetadataStore store = r.getMetadataStore();
    MetadataRetrieve retrieve = store instanceof MetadataRetrieve ? (MetadataRetrieve) store : new DummyMetadata();
    String filename = sliceLabelPattern.replaceAll(FormatTools.SERIES_NUM, String.format("%d", series));
    String imageName = retrieve.getImageName(series);
    if (imageName == null)
        imageName = "Series" + series;
    filename = sliceLabelPattern;
    filename = filename.replaceAll(FormatTools.SERIES_NUM, String.format("%d", series));
    filename = filename.replaceAll(FormatTools.SERIES_NAME, imageName);
    if (sizeC > 1) {
        int[] subC;
        String[] subCTypes;
        Modulo moduloC = r.getModuloC();
        if (moduloC.length() > 1) {
            subC = new int[] { r.getSizeC() / moduloC.length(), moduloC.length() };
            subCTypes = new String[] { moduloC.parentType, moduloC.type };
        } else {
            subC = new int[] { r.getSizeC() };
            subCTypes = new String[] { FormatTools.CHANNEL };
        }
        int[] subCPos = FormatTools.rasterToPosition(subC, coordinates[1]);
        StringBuffer channelString = new StringBuffer();
        for (int i = 0; i < subC.length; i++) {
            boolean ch = subCTypes[i] == null || FormatTools.CHANNEL.equals(subCTypes[i]);
            channelString.append(ch ? "c" : subCTypes[i]);
            channelString.append(":");
            channelString.append(subCPos[i] + 1);
            channelString.append("/");
            channelString.append(subC[i]);
            if (i < subC.length - 1)
                channelString.append(", ");
        }
        filename = filename.replaceAll(FormatTools.CHANNEL_NUM, channelString.toString() + " ");
        int channelCount = retrieve.getChannelCount(series);
        if (coordinates[1] < channelCount) {
            String channelName = retrieve.getChannelName(series, coordinates[1]);
            if (channelName == null)
                channelName = String.valueOf(coordinates[1]);
            filename = filename.replaceAll(FormatTools.CHANNEL_NAME, channelName);
        } else {
            filename = filename.replaceAll(FormatTools.CHANNEL_NAME, String.valueOf(coordinates[1]));
        }
    } else {
        filename = filename.replaceAll(FormatTools.CHANNEL_NUM, "");
        filename = filename.replaceAll(FormatTools.CHANNEL_NAME, "");
    }
    if (sizeZ > 1) {
        filename = filename.replaceAll(FormatTools.Z_NUM, "z:" + String.format("%d", coordinates[0] + 1) + "/" + String.format("%d", sizeZ) + " ");
    } else {
        filename = filename.replaceAll(FormatTools.Z_NUM, "");
    }
    if (sizeT > 1) {
        filename = filename.replaceAll(FormatTools.T_NUM, "t:" + String.format("%d", coordinates[2] + 1) + "/" + String.format("%d", sizeT) + " ");
    } else {
        filename = filename.replaceAll(FormatTools.T_NUM, "");
    }
    Timestamp timestamp = retrieve.getImageAcquisitionDate(series);
    long stamp = 0;
    String date = null;
    if (timestamp != null) {
        date = timestamp.getValue();
        if (retrieve.getPlaneCount(series) > ndx) {
            Time deltaT = retrieve.getPlaneDeltaT(series, ndx);
            if (deltaT != null) {
                stamp = (long) (deltaT.value(UNITS.SECOND).doubleValue() * 1000);
            }
        }
        stamp += DateTools.getTime(date, DateTools.ISO8601_FORMAT);
    } else {
        stamp = System.currentTimeMillis();
    }
    date = DateTools.convertDate(stamp, (int) DateTools.UNIX_EPOCH);
    filename = filename.replaceAll(FormatTools.TIMESTAMP, date);
    return filename;
}
Also used : Modulo(loci.formats.Modulo) Time(ome.units.quantity.Time) Timestamp(ome.xml.model.primitives.Timestamp) MetadataStore(loci.formats.meta.MetadataStore) DummyMetadata(loci.formats.meta.DummyMetadata) MetadataRetrieve(loci.formats.meta.MetadataRetrieve)

Example 2 with DummyMetadata

use of loci.formats.meta.DummyMetadata in project bioformats by openmicroscopy.

the class ZeissZVIReader method fillMetadataPass1.

/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void fillMetadataPass1(MetadataStore store) throws FormatException, IOException {
    super.fillMetadataPass1(store);
    // parse each embedded file
    for (String name : files) {
        String relPath = name.substring(name.lastIndexOf(File.separator) + 1);
        if (!relPath.toUpperCase().equals("CONTENTS"))
            continue;
        String dirName = name.substring(0, name.lastIndexOf(File.separator));
        if (dirName.indexOf(File.separator) != -1) {
            dirName = dirName.substring(dirName.lastIndexOf(File.separator) + 1);
        }
        if (name.indexOf("Scaling") == -1 && dirName.equals("Tags")) {
            int imageNum = getImageNumber(name, -1);
            if (imageNum == -1) {
                parseTags(imageNum, name, new DummyMetadata());
            } else
                tagsToParse.add(name);
        } else if (dirName.equals("Shapes") && name.indexOf("Item") != -1) {
            int imageNum = getImageNumber(name, -1);
            if (imageNum != -1) {
                try {
                    parseROIs(imageNum, name, store);
                } catch (IOException e) {
                    LOGGER.debug("Could not parse all ROIs.", e);
                }
            }
        } else if (dirName.equals("Image") || dirName.toUpperCase().indexOf("ITEM") != -1) {
            int imageNum = getImageNumber(dirName, getImageCount() == 1 ? 0 : -1);
            if (imageNum == -1)
                continue;
            // found a valid image stream
            RandomAccessInputStream s = poi.getDocumentStream(name);
            s.order(true);
            if (s.length() <= 1024) {
                s.close();
                continue;
            }
            for (int q = 0; q < 11; q++) {
                getNextTag(s);
            }
            s.skipBytes(2);
            int len = s.readInt() - 20;
            s.skipBytes(8);
            int zidx = s.readInt();
            int cidx = s.readInt();
            int tidx = s.readInt();
            s.skipBytes(4);
            int tileIndex = s.readInt();
            zIndices.add(zidx);
            timepointIndices.add(tidx);
            channelIndices.add(cidx);
            tileIndices.add(tileIndex);
            s.skipBytes(len - 8);
            for (int q = 0; q < 5; q++) {
                getNextTag(s);
            }
            s.skipBytes(4);
            core.get(0).sizeX = s.readInt();
            core.get(0).sizeY = s.readInt();
            s.skipBytes(4);
            if (bpp == 0) {
                bpp = s.readInt();
            } else
                s.skipBytes(4);
            s.skipBytes(4);
            int valid = s.readInt();
            String check = s.readString(4).trim();
            isZlib = (valid == 0 || valid == 1) && check.equals("WZL");
            isJPEG = (valid == 0 || valid == 1) && !isZlib;
            // save the offset to the pixel data
            offsets[imageNum] = (int) s.getFilePointer() - 4;
            if (isZlib)
                offsets[imageNum] += 8;
            coordinates[imageNum][0] = zidx;
            coordinates[imageNum][1] = cidx;
            coordinates[imageNum][2] = tidx;
            coordinates[imageNum][3] = tileIndex;
            LOGGER.trace("imageNum = {}, coordinate = {}", imageNum, coordinates[imageNum]);
            imageFiles[imageNum] = name;
            s.close();
        }
    }
}
Also used : DummyMetadata(loci.formats.meta.DummyMetadata) IOException(java.io.IOException) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 3 with DummyMetadata

use of loci.formats.meta.DummyMetadata in project bioformats by openmicroscopy.

the class FormatTools method getFilename.

/**
 * @throws FormatException Never actually thrown.
 * @throws IOException Never actually thrown.
 */
public static String getFilename(int series, int image, IFormatReader r, String pattern, boolean padded) throws FormatException, IOException {
    MetadataStore store = r.getMetadataStore();
    MetadataRetrieve retrieve = store instanceof MetadataRetrieve ? (MetadataRetrieve) store : new DummyMetadata();
    return getFilename(series, image, retrieve, pattern, padded);
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) DummyMetadata(loci.formats.meta.DummyMetadata) MetadataRetrieve(loci.formats.meta.MetadataRetrieve)

Example 4 with DummyMetadata

use of loci.formats.meta.DummyMetadata in project bioformats by openmicroscopy.

the class BaseZeissReader method parseMainTags.

// -- Internal FormatReader API methods --
void parseMainTags(int image, MetadataStore store, ArrayList<Tag> tags) throws FormatException, IOException {
    int effectiveSizeC = 0;
    try {
        effectiveSizeC = getEffectiveSizeC();
    } catch (ArithmeticException e) {
    }
    for (Tag t : tags) {
        String key = t.getKey();
        String value = t.getValue();
        try {
            if (key.equals("Image Channel Index")) {
                cIndex = Integer.parseInt(value);
                addGlobalMetaList(key, cIndex);
                continue;
            } else if (key.equals("ImageWidth")) {
                int v = Integer.parseInt(value);
                if (getSizeX() == 0 || v < getSizeX()) {
                    core.get(0).sizeX = v;
                }
                if (realWidth == 0 && v > realWidth)
                    realWidth = v;
            } else if (key.equals("ImageHeight")) {
                int v = Integer.parseInt(value);
                if (getSizeY() == 0 || v < getSizeY())
                    core.get(0).sizeY = v;
                if (realHeight == 0 || v > realHeight)
                    realHeight = v;
            }
            if (cIndex != -1)
                key += " " + cIndex;
            if (!key.startsWith("Camera Acquisition Time") && !key.startsWith("ImageRelativeTime")) {
                String metavalue = value;
                if (key.endsWith("Date")) {
                    try {
                        metavalue = DateTools.convertDate(parseTimestamp(value), DateTools.UNIX, DateTools.ISO8601_FORMAT_MS);
                    } catch (Exception e) {
                    }
                }
                addGlobalMeta(key, metavalue);
            }
            if (key.startsWith("ImageTile") && !(store instanceof DummyMetadata)) {
                if (!tiles.containsKey(new Integer(value))) {
                    tiles.put(Integer.valueOf(value), 1);
                } else {
                    int v = tiles.get(new Integer(value)).intValue() + 1;
                    tiles.put(new Integer(value), new Integer(v));
                }
            }
            if (key.startsWith("MultiChannel Color")) {
                if (cIndex >= 0 && cIndex < effectiveSizeC) {
                    if (channelColors == null || effectiveSizeC > channelColors.length) {
                        channelColors = new int[effectiveSizeC];
                    }
                    if (channelColors[cIndex] == 0) {
                        channelColors[cIndex] = Integer.parseInt(value);
                    }
                } else if (cIndex == effectiveSizeC && channelColors != null && channelColors[0] == 0) {
                    System.arraycopy(channelColors, 1, channelColors, 0, channelColors.length - 1);
                    channelColors[cIndex - 1] = Integer.parseInt(value);
                } else if (channelColors != null && channelColors[0] > 0 && channelColors.length > 1) {
                    int c = 1;
                    while (c < channelColors.length - 1 && channelColors[c] != 0) {
                        c++;
                    }
                    if (channelColors[c] == 0) {
                        channelColors[c] = Integer.parseInt(value);
                    }
                }
            } else if (key.startsWith("Scale Factor for X") && physicalSizeX == null) {
                physicalSizeX = Double.parseDouble(value);
            } else if (key.startsWith("Scale Factor for Y") && physicalSizeY == null) {
                physicalSizeY = Double.parseDouble(value);
            } else if (key.startsWith("Scale Factor for Z") && physicalSizeZ == null) {
                physicalSizeZ = Double.parseDouble(value);
            } else if (key.startsWith("Number Rows") && rowCount == 0) {
                rowCount = parseInt(value);
            } else if (key.startsWith("Number Columns") && colCount == 0) {
                colCount = parseInt(value);
            } else if (key.startsWith("NumberOfRawImages") && rawCount == 0) {
                rawCount = parseInt(value);
            } else if (key.startsWith("Emission Wavelength")) {
                if (cIndex != -1) {
                    Double wave = new Double(value);
                    Length emission = FormatTools.getEmissionWavelength(wave);
                    if (emission != null) {
                        emWavelength.put(cIndex, emission);
                    }
                }
            } else if (key.startsWith("Excitation Wavelength")) {
                if (cIndex != -1) {
                    Double wave = new Double(Double.parseDouble(value));
                    Length excitation = FormatTools.getExcitationWavelength(wave);
                    if (excitation != null) {
                        exWavelength.put(cIndex, excitation);
                    }
                }
            } else if (key.startsWith("Channel Name")) {
                if (cIndex != -1) {
                    channelName.put(cIndex, value);
                }
            } else if (key.startsWith("Exposure Time [ms]")) {
                if (exposureTime.get(new Integer(cIndex)) == null) {
                    double exp = Double.parseDouble(value) / 1000;
                    exposureTime.put(new Integer(cIndex), String.valueOf(exp));
                }
            } else if (key.startsWith("User Name")) {
                String[] username = value.split(" ");
                if (username.length >= 2) {
                    String id = MetadataTools.createLSID("Experimenter", 0);
                    store.setExperimenterID(id, 0);
                    store.setExperimenterFirstName(username[0], 0);
                    store.setExperimenterLastName(username[username.length - 1], 0);
                }
            } else if (key.equals("User company")) {
                String id = MetadataTools.createLSID("Experimenter", 0);
                store.setExperimenterID(id, 0);
                store.setExperimenterInstitution(value, 0);
            } else if (key.startsWith("Objective Magnification")) {
                Double magnification = Double.parseDouble(value);
                store.setObjectiveNominalMagnification(magnification, 0, 0);
            } else if (key.startsWith("Objective ID")) {
                store.setObjectiveID("Objective:" + value, 0, 0);
                store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
                store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
            } else if (key.startsWith("Objective N.A.")) {
                store.setObjectiveLensNA(new Double(value), 0, 0);
            } else if (key.startsWith("Objective Name")) {
                String[] tokens = value.split(" ");
                for (int q = 0; q < tokens.length; q++) {
                    int slash = tokens[q].indexOf('/');
                    if (slash != -1 && slash - q > 0) {
                        Double mag = Double.parseDouble(tokens[q].substring(0, slash - q));
                        String na = tokens[q].substring(slash + 1);
                        store.setObjectiveNominalMagnification(mag, 0, 0);
                        store.setObjectiveLensNA(new Double(na), 0, 0);
                        store.setObjectiveCorrection(getCorrection(tokens[q - 1]), 0, 0);
                        break;
                    }
                }
            } else if (key.startsWith("Objective Working Distance")) {
                store.setObjectiveWorkingDistance(new Length(new Double(value), UNITS.MICROMETER), 0, 0);
            } else if (key.startsWith("Objective Immersion Type")) {
                String immersion = "Other";
                switch(Integer.parseInt(value)) {
                    // case 1: no immersion
                    case 2:
                        immersion = "Oil";
                        break;
                    case 3:
                        immersion = "Water";
                        break;
                }
                store.setObjectiveImmersion(getImmersion(immersion), 0, 0);
            } else if (key.startsWith("Stage Position X")) {
                final Double number = Double.valueOf(value);
                stageX.put(image, new Length(number, UNITS.REFERENCEFRAME));
                addGlobalMetaList("X position for position", value);
            } else if (key.startsWith("Stage Position Y")) {
                final Double number = Double.valueOf(value);
                stageY.put(image, new Length(number, UNITS.REFERENCEFRAME));
                addGlobalMetaList("Y position for position", value);
            } else if (key.startsWith("Orca Analog Gain")) {
                detectorGain.put(cIndex, new Double(value));
            } else if (key.startsWith("Orca Analog Offset")) {
                detectorOffset.put(cIndex, new Double(value));
            } else if (key.startsWith("Comments")) {
                imageDescription = value;
            } else if (key.startsWith("Acquisition Date")) {
                acquisitionDate = new Timestamp(DateTools.convertDate(parseTimestamp(value), DateTools.UNIX, DateTools.ISO8601_FORMAT_MS));
            } else if (image >= 0 && key.startsWith("Camera Acquisition Time")) {
                // Note Double variant for TIFF XML.
                String date = DateTools.convertDate(parseTimestamp(value), DateTools.UNIX, DateTools.ISO8601_FORMAT_MS);
                addSeriesMetaList(key, date);
                if (timepoint != 0) {
                    // First timepoint is duplicated for some reason.
                    timestamps.put(timepoint - 1, date);
                } else {
                    timestamps.put(timepoint, date);
                }
                timepoint++;
            } else if (image >= 0 && key.startsWith("ImageRelativeTime")) {
                Time time = new Time(Double.parseDouble(value), UNITS.DAY);
                String timestr = time.value().toString() + " " + time.unit().getSymbol();
                addSeriesMetaList(key, timestr);
            }
        } catch (NumberFormatException e) {
        }
    }
}
Also used : DateTime(org.joda.time.DateTime) Time(ome.units.quantity.Time) Timestamp(ome.xml.model.primitives.Timestamp) FormatException(loci.formats.FormatException) IOException(java.io.IOException) DummyMetadata(loci.formats.meta.DummyMetadata) Length(ome.units.quantity.Length)

Aggregations

DummyMetadata (loci.formats.meta.DummyMetadata)4 IOException (java.io.IOException)2 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)2 MetadataStore (loci.formats.meta.MetadataStore)2 Time (ome.units.quantity.Time)2 Timestamp (ome.xml.model.primitives.Timestamp)2 RandomAccessInputStream (loci.common.RandomAccessInputStream)1 FormatException (loci.formats.FormatException)1 Modulo (loci.formats.Modulo)1 Length (ome.units.quantity.Length)1 DateTime (org.joda.time.DateTime)1