Search in sources :

Example 1 with Modulo

use of loci.formats.Modulo 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 Modulo

use of loci.formats.Modulo in project bioformats by openmicroscopy.

the class ImageInfo method readCoreMetadata.

public void readCoreMetadata() throws FormatException, IOException {
    // skip core metadata printout
    if (!doCore)
        return;
    // read basic metadata
    LOGGER.info("");
    LOGGER.info("Reading core metadata");
    LOGGER.info("{} = {}", stitch ? "File pattern" : "filename", stitch ? id : reader.getCurrentFile());
    if (map != null)
        LOGGER.info("Mapped filename = {}", map);
    if (usedFiles) {
        String[] used = reader.getUsedFiles();
        boolean usedValid = used != null && used.length > 0;
        if (usedValid) {
            for (int u = 0; u < used.length; u++) {
                if (used[u] == null) {
                    usedValid = false;
                    break;
                }
            }
        }
        if (!usedValid) {
            LOGGER.warn("************ invalid used files list ************");
        }
        if (used == null) {
            LOGGER.info("Used files = null");
        } else if (used.length == 0) {
            LOGGER.info("Used files = []");
        } else if (used.length > 1) {
            LOGGER.info("Used files:");
            for (int u = 0; u < used.length; u++) LOGGER.info("\t{}", used[u]);
        } else if (!id.equals(used[0])) {
            LOGGER.info("Used files = [{}]", used[0]);
        }
    }
    int seriesCount = reader.getSeriesCount();
    LOGGER.info("Series count = {}", seriesCount);
    MetadataStore ms = reader.getMetadataStore();
    MetadataRetrieve mr = ms instanceof MetadataRetrieve ? (MetadataRetrieve) ms : null;
    for (int j = 0; j < seriesCount; j++) {
        reader.setSeries(j);
        // read basic metadata for series #i
        int imageCount = reader.getImageCount();
        int resolutions = reader.getResolutionCount();
        boolean rgb = reader.isRGB();
        int sizeX = reader.getSizeX();
        int sizeY = reader.getSizeY();
        int sizeZ = reader.getSizeZ();
        int sizeC = reader.getSizeC();
        int sizeT = reader.getSizeT();
        int pixelType = reader.getPixelType();
        int validBits = reader.getBitsPerPixel();
        int effSizeC = reader.getEffectiveSizeC();
        int rgbChanCount = reader.getRGBChannelCount();
        boolean indexed = reader.isIndexed();
        boolean falseColor = reader.isFalseColor();
        byte[][] table8 = reader.get8BitLookupTable();
        short[][] table16 = reader.get16BitLookupTable();
        Modulo moduloZ = reader.getModuloZ();
        Modulo moduloC = reader.getModuloC();
        Modulo moduloT = reader.getModuloT();
        int thumbSizeX = reader.getThumbSizeX();
        int thumbSizeY = reader.getThumbSizeY();
        int tileSizeX = reader.getOptimalTileWidth();
        int tileSizeY = reader.getOptimalTileHeight();
        boolean little = reader.isLittleEndian();
        String dimOrder = reader.getDimensionOrder();
        boolean orderCertain = reader.isOrderCertain();
        boolean thumbnail = reader.isThumbnailSeries();
        boolean interleaved = reader.isInterleaved();
        boolean metadataComplete = reader.isMetadataComplete();
        // output basic metadata for series #i
        String seriesName = mr == null ? null : mr.getImageName(j);
        LOGGER.info("Series #{}{}{}:", new Object[] { j, seriesName == null ? " " : " -- ", seriesName == null ? "" : seriesName });
        if (flat == false && resolutions > 1) {
            LOGGER.info("\tResolutions = {}", resolutions);
            for (int i = 0; i < resolutions; i++) {
                reader.setResolution(i);
                LOGGER.info("\t\tsizeX[{}] = {}", i, reader.getSizeX());
            }
            reader.setResolution(0);
        }
        LOGGER.info("\tImage count = {}", imageCount);
        LOGGER.info("\tRGB = {} ({}) {}", new Object[] { rgb, rgbChanCount, merge ? "(merged)" : separate ? "(separated)" : "" });
        if (rgb != (rgbChanCount != 1)) {
            LOGGER.warn("\t************ RGB mismatch ************");
        }
        LOGGER.info("\tInterleaved = {}", interleaved);
        StringBuilder sb = new StringBuilder();
        sb.append("\tIndexed = ");
        sb.append(indexed);
        sb.append(" (");
        sb.append(!falseColor);
        sb.append(" color");
        if (table8 != null) {
            sb.append(", 8-bit LUT: ");
            sb.append(table8.length);
            sb.append(" x ");
            sb.append(table8[0] == null ? "null" : "" + table8[0].length);
        }
        if (table16 != null) {
            sb.append(", 16-bit LUT: ");
            sb.append(table16.length);
            sb.append(" x ");
            sb.append(table16[0] == null ? "null" : "" + table16[0].length);
        }
        sb.append(")");
        LOGGER.info(sb.toString());
        if (table8 != null && table16 != null) {
            LOGGER.warn("\t************ multiple LUTs ************");
        }
        LOGGER.info("\tWidth = {}", sizeX);
        LOGGER.info("\tHeight = {}", sizeY);
        printDimension("SizeZ", sizeZ, sizeZ, moduloZ);
        printDimension("SizeT", sizeT, sizeT, moduloT);
        printDimension("SizeC", sizeC, effSizeC, moduloC);
        if (imageCount != sizeZ * effSizeC * sizeT) {
            LOGGER.info("\t************ ZCT mismatch ************");
        }
        LOGGER.info("\tTile size = {} x {}", tileSizeX, tileSizeY);
        LOGGER.info("\tThumbnail size = {} x {}", thumbSizeX, thumbSizeY);
        LOGGER.info("\tEndianness = {}", little ? "intel (little)" : "motorola (big)");
        LOGGER.info("\tDimension order = {} ({})", dimOrder, orderCertain ? "certain" : "uncertain");
        LOGGER.info("\tPixel type = {}", FormatTools.getPixelTypeString(pixelType));
        LOGGER.info("\tValid bits per pixel = {}", validBits);
        LOGGER.info("\tMetadata complete = {}", metadataComplete);
        LOGGER.info("\tThumbnail series = {}", thumbnail);
        if (doMeta) {
            LOGGER.info("\t-----");
            int[] indices;
            if (imageCount > 6) {
                int q = imageCount / 2;
                indices = new int[] { 0, q - 2, q - 1, q, q + 1, q + 2, imageCount - 1 };
            } else if (imageCount > 2) {
                indices = new int[] { 0, imageCount / 2, imageCount - 1 };
            } else if (imageCount > 1)
                indices = new int[] { 0, 1 };
            else
                indices = new int[] { 0 };
            int[][] zct = new int[indices.length][];
            int[] indices2 = new int[indices.length];
            sb.setLength(0);
            for (int i = 0; i < indices.length; i++) {
                zct[i] = reader.getZCTCoords(indices[i]);
                indices2[i] = reader.getIndex(zct[i][0], zct[i][1], zct[i][2]);
                sb.append("\tPlane #");
                sb.append(indices[i]);
                sb.append(" <=> Z ");
                sb.append(zct[i][0]);
                sb.append(", C ");
                sb.append(zct[i][1]);
                sb.append(", T ");
                sb.append(zct[i][2]);
                if (indices[i] != indices2[i]) {
                    sb.append(" [mismatch: ");
                    sb.append(indices2[i]);
                    sb.append("]");
                    sb.append(NEWLINE);
                } else
                    sb.append(NEWLINE);
            }
            LOGGER.info(sb.toString());
        }
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Modulo(loci.formats.Modulo) MetadataRetrieve(loci.formats.meta.MetadataRetrieve)

Example 3 with Modulo

use of loci.formats.Modulo in project bioformats by openmicroscopy.

the class OMEXMLServiceImpl method getModuloAlong.

/**
 * Create a {@link loci.formats.Modulo} corresponding to the given ModuloAlong* tag.
 * @param omexml the OMEXMLMetadata from which to retrieve the ModuloAlong* tag
 * @param tag the tag name (e.g. "ModuloAlongC")
 * @param image the Image index within the OMEXMLMetadata
 * @return the corresponding Modulo object
 */
private Modulo getModuloAlong(OMEXMLMetadata omexml, String tag, int image) {
    OMEXMLMetadataRoot root = (OMEXMLMetadataRoot) omexml.getRoot();
    Image img = root.getImage(image);
    if (img == null) {
        return null;
    }
    for (int i = 0; i < img.sizeOfLinkedAnnotationList(); i++) {
        Annotation annotation = img.getLinkedAnnotation(i);
        if (!(annotation instanceof XMLAnnotation)) {
            continue;
        }
        String xml = ((XMLAnnotation) annotation).getValue();
        try {
            Document annotationRoot = XMLTools.parseDOM(xml);
            NodeList nodes = annotationRoot.getElementsByTagName(tag);
            if (nodes.getLength() > 0) {
                Element modulo = (Element) nodes.item(0);
                NamedNodeMap attrs = modulo.getAttributes();
                Modulo m = new Modulo(tag.substring(tag.length() - 1));
                Node start = attrs.getNamedItem("Start");
                Node end = attrs.getNamedItem("End");
                Node step = attrs.getNamedItem("Step");
                Node type = attrs.getNamedItem("Type");
                Node typeDescription = attrs.getNamedItem("TypeDescription");
                Node unit = attrs.getNamedItem("Unit");
                if (start != null) {
                    m.start = Double.parseDouble(start.getNodeValue());
                }
                if (end != null) {
                    m.end = Double.parseDouble(end.getNodeValue());
                }
                if (step != null) {
                    m.step = Double.parseDouble(step.getNodeValue());
                }
                if (type != null) {
                    m.type = type.getNodeValue();
                }
                if (typeDescription != null) {
                    m.typeDescription = typeDescription.getNodeValue();
                }
                if (unit != null) {
                    m.unit = unit.getNodeValue();
                }
                NodeList labels = modulo.getElementsByTagName("Label");
                if (labels != null && labels.getLength() > 0) {
                    m.labels = new String[labels.getLength()];
                    for (int q = 0; q < labels.getLength(); q++) {
                        m.labels[q] = labels.item(q).getTextContent();
                    }
                }
                return m;
            }
        } catch (ParserConfigurationException e) {
            LOGGER.debug("Failed to parse ModuloAlong", e);
        } catch (SAXException e) {
            LOGGER.debug("Failed to parse ModuloAlong", e);
        } catch (IOException e) {
            LOGGER.debug("Failed to parse ModuloAlong", e);
        }
    }
    return null;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Modulo(loci.formats.Modulo) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) IOException(java.io.IOException) Image(ome.xml.model.Image) Document(org.w3c.dom.Document) Annotation(ome.xml.model.Annotation) ModuloAnnotation(loci.formats.meta.ModuloAnnotation) OriginalMetadataAnnotation(loci.formats.meta.OriginalMetadataAnnotation) XMLAnnotation(ome.xml.model.XMLAnnotation) SAXException(org.xml.sax.SAXException) OMEXMLMetadataRoot(ome.xml.meta.OMEXMLMetadataRoot) XMLAnnotation(ome.xml.model.XMLAnnotation) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 4 with Modulo

use of loci.formats.Modulo in project bioformats by openmicroscopy.

the class DisplayHandler method displayDataBrowser.

public void displayDataBrowser(ImagePlus imp) {
    IFormatReader r = process.getReader();
    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 };
    }
    new DataBrowser(imp, null, subCTypes, subC, xmlWindow);
}
Also used : DataBrowser(loci.plugins.util.DataBrowser) IFormatReader(loci.formats.IFormatReader) Modulo(loci.formats.Modulo)

Example 5 with Modulo

use of loci.formats.Modulo in project bioformats by openmicroscopy.

the class LociFunctions method getChannelDimCount.

public void getChannelDimCount(Double[] channelDimCount) {
    Modulo moduloC = r.getModuloC();
    channelDimCount[0] = new Double(moduloC.length() > 1 ? 2 : 1);
}
Also used : Modulo(loci.formats.Modulo)

Aggregations

Modulo (loci.formats.Modulo)6 IFormatReader (loci.formats.IFormatReader)2 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)2 MetadataStore (loci.formats.meta.MetadataStore)2 OMEXMLMetadataRoot (ome.xml.meta.OMEXMLMetadataRoot)2 Image (ome.xml.model.Image)2 Timestamp (ome.xml.model.primitives.Timestamp)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Location (loci.common.Location)1 RandomAccessInputStream (loci.common.RandomAccessInputStream)1 ServiceException (loci.common.services.ServiceException)1 CoreMetadata (loci.formats.CoreMetadata)1 FormatException (loci.formats.FormatException)1