Search in sources :

Example 31 with CoreMetadata

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

the class MRCReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
public void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    in = new RandomAccessInputStream(id);
    MetadataLevel level = getMetadataOptions().getMetadataLevel();
    CoreMetadata m = core.get(0);
    LOGGER.info("Reading header");
    // check endianness
    in.seek(ENDIANNESS_OFFSET);
    m.littleEndian = in.read() == 68;
    // read dimension information from 1024 byte header
    in.seek(0);
    in.order(isLittleEndian());
    m.sizeX = in.readInt();
    m.sizeY = in.readInt();
    m.sizeZ = in.readInt();
    // We are using BigInteger here because of the very real possiblity
    // of not just an int overflow but also a long overflow when multiplying
    // sizeX * sizeY * sizeZ.
    BigInteger v = BigInteger.valueOf(getSizeX());
    v = v.multiply(BigInteger.valueOf(getSizeY()));
    v = v.multiply(BigInteger.valueOf(getSizeZ()));
    if (getSizeX() < 0 || getSizeY() < 0 || getSizeZ() < 0 || (v.compareTo(BigInteger.valueOf(in.length())) > 0)) {
        LOGGER.debug("Detected endianness is wrong, swapping");
        m.littleEndian = !isLittleEndian();
        in.seek(0);
        in.order(isLittleEndian());
        m.sizeX = in.readInt();
        m.sizeY = in.readInt();
        m.sizeZ = in.readInt();
    }
    m.sizeC = 1;
    m.rgb = false;
    int mode = in.readInt();
    switch(mode) {
        case 0:
            in.seek(IMODSTAMP_OFFSET);
            if (in.readInt() == 1146047817) {
                m.pixelType = FormatTools.INT8;
            } else {
                m.pixelType = FormatTools.UINT8;
            }
            break;
        case 1:
            m.pixelType = FormatTools.INT16;
            break;
        case 6:
            m.pixelType = FormatTools.UINT16;
            break;
        case 2:
            m.pixelType = FormatTools.FLOAT;
            break;
        case 3:
            m.pixelType = FormatTools.UINT32;
            break;
        case 4:
            m.pixelType = FormatTools.DOUBLE;
            break;
        case 16:
            m.sizeC = 3;
            m.pixelType = FormatTools.UINT8;
            m.rgb = true;
            break;
    }
    in.seek(GRIDSIZE_OFFSET);
    // pixel size = xlen / mx
    double xSize = 0d, ySize = 0d, zSize = 0d;
    if (level != MetadataLevel.MINIMUM) {
        int mx = in.readInt();
        int my = in.readInt();
        int mz = in.readInt();
        float xlen = in.readFloat();
        float ylen = in.readFloat();
        float zlen = in.readFloat();
        // physical sizes are stored in ångströms
        xSize = (xlen / mx);
        ySize = (ylen / my);
        zSize = (zlen / mz);
        addGlobalMeta("Grid size (X)", mx);
        addGlobalMeta("Grid size (Y)", my);
        addGlobalMeta("Grid size (Z)", mz);
        addGlobalMeta("Cell size (X)", xlen);
        addGlobalMeta("Cell size (Y)", ylen);
        addGlobalMeta("Cell size (Z)", zlen);
        addGlobalMeta("Alpha angle", in.readFloat());
        addGlobalMeta("Beta angle", in.readFloat());
        addGlobalMeta("Gamma angle", in.readFloat());
        in.skipBytes(12);
    // min, max and mean pixel values
    } else
        in.skipBytes(48);
    double minValue = in.readFloat();
    double maxValue = in.readFloat();
    addGlobalMeta("Minimum pixel value", minValue);
    addGlobalMeta("Maximum pixel value", maxValue);
    addGlobalMeta("Mean pixel value", in.readFloat());
    int bytes = FormatTools.getBytesPerPixel(getPixelType());
    double range = Math.pow(2, bytes * 8) - 1;
    double pixelTypeMin = 0;
    boolean signed = FormatTools.isSigned(getPixelType());
    if (signed) {
        pixelTypeMin -= (range / 2);
    }
    double pixelTypeMax = pixelTypeMin + range;
    // See https://trac.openmicroscopy.org/ome/ticket/4619
    if (pixelTypeMax < maxValue || pixelTypeMin > minValue && signed) {
        switch(getPixelType()) {
            case FormatTools.INT16:
                m.pixelType = FormatTools.UINT16;
                break;
            case FormatTools.INT32:
                m.pixelType = FormatTools.UINT32;
                break;
        }
    }
    int ispg = in.readInt();
    addGlobalMeta("ISPG", ispg);
    addGlobalMeta("Is data cube", ispg == 1);
    extHeaderSize = in.readInt();
    if (level != MetadataLevel.MINIMUM) {
        in.skipBytes(64);
        int idtype = in.readShort();
        String type = "unknown";
        if (idtype >= 0 && idtype < TYPES.length)
            type = TYPES[idtype];
        addGlobalMeta("Series type", type);
        addGlobalMeta("Lens", in.readShort());
        addGlobalMeta("ND1", in.readShort());
        addGlobalMeta("ND2", in.readShort());
        addGlobalMeta("VD1", in.readShort());
        addGlobalMeta("VD2", in.readShort());
        for (int i = 0; i < 6; i++) {
            addGlobalMetaList("Angle", in.readFloat());
        }
        in.skipBytes(24);
        addGlobalMeta("Number of useful labels", in.readInt());
        for (int i = 0; i < 10; i++) {
            addGlobalMetaList("Label", in.readString(80));
        }
    }
    LOGGER.info("Populating metadata");
    m.sizeT = 1;
    m.dimensionOrder = isRGB() ? "XYCZT" : "XYZTC";
    m.imageCount = getSizeZ() * (isRGB() ? 1 : getSizeC());
    m.interleaved = true;
    m.indexed = false;
    m.falseColor = false;
    m.metadataComplete = true;
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    if (level != MetadataLevel.MINIMUM) {
        Length sizeX = FormatTools.getPhysicalSizeX(xSize, UNITS.ANGSTROM);
        Length sizeY = FormatTools.getPhysicalSizeY(ySize, UNITS.ANGSTROM);
        Length sizeZ = FormatTools.getPhysicalSizeZ(zSize, UNITS.ANGSTROM);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
        if (sizeZ != null) {
            store.setPixelsPhysicalSizeZ(sizeZ, 0);
        }
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) BigInteger(java.math.BigInteger) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata)

Example 32 with CoreMetadata

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

the class FluoviewReader method initStandardMetadata.

// -- Internal BaseTiffReader API methods --
/* @see loci.formats.BaseTiffReader#initStandardMetadata() */
@Override
protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();
    // First, we want to determine whether this file is a Fluoview TIFF.
    // Originally, Andor TIFF had its own reader; however, the two formats are
    // very similar, so it made more sense to merge the two formats into one
    // reader.
    short[] s = ifds.get(0).getIFDShortArray(MMHEADER);
    if (s == null) {
        initAlternateMetadata();
        return;
    }
    byte[] mmheader = shortArrayToBytes(s);
    RandomAccessInputStream ras = new RandomAccessInputStream(mmheader);
    ras.order(isLittleEndian());
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        put("Header Flag", ras.readShort());
        put("Image Type", ras.read());
        String name = ras.readString(257);
        name = name.substring(0, name.indexOf("\0"));
        put("Image name", name);
        // skip pointer to data field
        ras.skipBytes(4);
        put("Number of colors", ras.readInt());
        // skip pointer to palette field
        ras.skipBytes(4);
        // skip pointer to other palette field
        ras.skipBytes(4);
        put("Comment size", ras.readInt());
        // skip pointer to comment field
        ras.skipBytes(4);
    } else
        ras.skipBytes(284);
    // read dimension information
    String[] names = new String[10];
    int[] sizes = new int[10];
    double[] resolutions = new double[10];
    for (int i = 0; i < 10; i++) {
        names[i] = ras.readString(16);
        sizes[i] = ras.readInt();
        double origin = ras.readDouble();
        resolutions[i] = ras.readDouble();
        put("Dimension " + (i + 1) + " Name", names[i]);
        put("Dimension " + (i + 1) + " Size", sizes[i]);
        put("Dimension " + (i + 1) + " Origin", origin);
        put("Dimension " + (i + 1) + " Resolution", resolutions[i]);
        put("Dimension " + (i + 1) + " Units", ras.readString(64));
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        // skip pointer to spatial position data
        ras.skipBytes(4);
        put("Map type", ras.readShort());
        put("Map min", ras.readDouble());
        put("Map max", ras.readDouble());
        put("Min value", ras.readDouble());
        put("Max value", ras.readDouble());
        // skip pointer to map data
        ras.skipBytes(4);
        put("Gamma", ras.readDouble());
        put("Offset", ras.readDouble());
        // read gray channel data
        put("Gray Channel Name", ras.readString(16));
        put("Gray Channel Size", ras.readInt());
        put("Gray Channel Origin", ras.readDouble());
        put("Gray Channel Resolution", ras.readDouble());
        put("Gray Channel Units", ras.readString(64));
        // skip pointer to thumbnail data
        ras.skipBytes(4);
        put("Voice field", ras.readInt());
        // skip pointer to voice field
        ras.skipBytes(4);
        // now we need to read the MMSTAMP data to determine dimension order
        readStamps();
    }
    ras.close();
    // calculate the dimension order and axis sizes
    CoreMetadata m = core.get(0);
    dimensionOrder = "XY";
    int seriesCount = 1;
    m.sizeZ = m.sizeC = m.sizeT = 1;
    for (int i = 0; i < 10; i++) {
        String name = names[i];
        int size = sizes[i];
        double voxel = resolutions[i];
        if (name == null || size == 0)
            continue;
        name = name.toLowerCase().trim();
        if (name.length() == 0)
            continue;
        if (name.equals("x")) {
            voxelX = voxel;
        } else if (name.equals("y")) {
            voxelY = voxel;
        } else if (name.equals("event")) {
            m.sizeZ *= size;
            if (dimensionOrder.indexOf('Z') == -1) {
                dimensionOrder += 'Z';
            }
            if (Double.compare(voxelZ, 1) == 0) {
                voxelZ = voxel;
            }
        } else if (name.equals("z")) {
            m.sizeZ *= size;
            if (dimensionOrder.indexOf('Z') == -1) {
                dimensionOrder += 'Z';
            }
            ArrayList<Double> uniqueZ = new ArrayList<Double>();
            if (i > 1 && stamps != null) {
                zPositions = stamps[i - 2];
                if (zPositions != null) {
                    for (Double z : zPositions) {
                        BigDecimal bd = new BigDecimal(z);
                        bd = bd.setScale(10, RoundingMode.HALF_UP);
                        if (!uniqueZ.contains(bd.doubleValue()))
                            uniqueZ.add(bd.doubleValue());
                    }
                }
            }
            if (uniqueZ.size() > 1 && uniqueZ.size() == size) {
                BigDecimal lastZ = BigDecimal.valueOf(uniqueZ.get(uniqueZ.size() - 1));
                BigDecimal firstZ = BigDecimal.valueOf(uniqueZ.get(0));
                BigDecimal zRange = (lastZ.subtract(firstZ)).abs();
                BigDecimal zSize = BigDecimal.valueOf((double) (getSizeZ() - 1));
                MathContext mc = new MathContext(10, RoundingMode.HALF_UP);
                voxelZ = zRange.divide(zSize, mc).doubleValue();
                // Need to convert from millimetre to micrometre
                voxelZ *= Math.pow(10, 3);
            } else {
                voxelZ = voxel;
            }
        } else if (name.equals("ch") || name.equals("wavelength")) {
            m.sizeC *= size;
            if (dimensionOrder.indexOf('C') == -1) {
                dimensionOrder += 'C';
            }
            voxelC = voxel;
        } else if (name.equals("time") || name.equals("t") || name.equals("animation")) {
            m.sizeT *= size;
            if (dimensionOrder.indexOf('T') == -1) {
                dimensionOrder += 'T';
            }
            voxelT = voxel;
            timeIndex = i - 2;
        } else {
            if (dimensionOrder.indexOf('S') == -1)
                dimensionOrder += 'S';
            seriesCount *= size;
            if (name.equals("montage"))
                montageIndex = i - 2;
            else if (name.equals("xy"))
                fieldIndex = i - 2;
        }
    }
    if (dimensionOrder.indexOf('Z') == -1)
        dimensionOrder += 'Z';
    if (dimensionOrder.indexOf('T') == -1)
        dimensionOrder += 'T';
    if (dimensionOrder.indexOf('C') == -1)
        dimensionOrder += 'C';
    if (dimensionOrder.indexOf('S') == -1)
        dimensionOrder += 'S';
    m.imageCount = ifds.size() / seriesCount;
    if (getSizeZ() > getImageCount())
        m.sizeZ = getImageCount();
    if (getSizeT() > getImageCount())
        m.sizeT = getImageCount();
    if (getSizeZ() * getSizeC() * getSizeT() > getImageCount()) {
        int diff = getSizeZ() * getSizeC() * getSizeT() - getImageCount();
        if (diff == getSizeC()) {
            if (getSizeZ() > 1)
                m.sizeZ--;
            else if (getSizeT() > 1)
                m.sizeT--;
            else
                m.sizeC /= getSizeC();
        }
    }
    if (getImageCount() == 1 && (getSizeT() == getSizeY() || getSizeZ() == getSizeY()) && (getSizeT() > getImageCount() || getSizeZ() > getImageCount())) {
        m.sizeY = 1;
        m.imageCount = getSizeZ() * getSizeC() * getSizeT();
    }
    m.dimensionOrder = dimensionOrder.replaceAll("S", "");
    if (getPixelType() == FormatTools.UINT32) {
        m.pixelType = FormatTools.FLOAT;
    }
    if (seriesCount > 1) {
        core.clear();
        for (int i = 0; i < seriesCount; i++) {
            core.add(m);
        }
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        // cut up the comment, if necessary
        comment = ifds.get(0).getComment();
        gains = new String[getSizeC()];
        offsets = new String[getSizeC()];
        voltages = new String[getSizeC()];
        channelNames = new String[getSizeC()];
        lensNA = new String[getSizeC()];
        parsePageName();
        parseComment();
        addGlobalMeta("Comment", comment);
    }
}
Also used : ArrayList(java.util.ArrayList) CoreMetadata(loci.formats.CoreMetadata) BigDecimal(java.math.BigDecimal) MathContext(java.math.MathContext) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 33 with CoreMetadata

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

the class HitachiReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    if (!checkSuffix(id, "txt")) {
        String base = id;
        if (base.indexOf('.') >= 0) {
            base = base.substring(0, base.lastIndexOf("."));
        }
        id = base + ".txt";
        initFile(id);
        return;
    }
    super.initFile(id);
    String data = DataTools.readFile(id);
    IniParser parser = new IniParser();
    parser.setBackslashContinuesLine(false);
    IniList ini = parser.parseINI(new BufferedReader(new StringReader(data)));
    IniTable image = ini.getTable("SemImageFile");
    if (image == null) {
        throw new FormatException("Could not find 'SemImageFile' table.");
    }
    for (String key : image.keySet()) {
        addGlobalMeta(key, image.get(key));
    }
    String imageName = image.get("SampleName");
    String pixelsFile = image.get("ImageName");
    String date = image.get("Date");
    String time = image.get("Time");
    Location parent = new Location(id).getAbsoluteFile().getParentFile();
    pixelsFile = new Location(parent, pixelsFile).getAbsolutePath();
    ClassList<IFormatReader> classes = ImageReader.getDefaultReaderClasses();
    Class<? extends IFormatReader>[] classArray = classes.getClasses();
    ClassList<IFormatReader> newClasses = new ClassList<IFormatReader>(IFormatReader.class);
    for (Class<? extends IFormatReader> c : classArray) {
        if (!c.equals(HitachiReader.class)) {
            newClasses.addClass(c);
        }
    }
    helperReader = new ImageReader(newClasses);
    helperReader.setId(pixelsFile);
    core = new ArrayList<CoreMetadata>(helperReader.getCoreMetadataList());
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM);
    store.setImageName(imageName, 0);
    date = DateTools.formatDate(date + " " + time, DATE_FORMAT);
    if (date != null) {
        store.setImageAcquisitionDate(new Timestamp(date), 0);
    }
    populateOMEMetadata(image, store);
}
Also used : IniParser(loci.common.IniParser) IFormatReader(loci.formats.IFormatReader) IniList(loci.common.IniList) ClassList(loci.formats.ClassList) CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp) FormatException(loci.formats.FormatException) MetadataStore(loci.formats.meta.MetadataStore) IniTable(loci.common.IniTable) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) ImageReader(loci.formats.ImageReader) Location(loci.common.Location)

Example 34 with CoreMetadata

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

the class ImarisHDFReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    try {
        ServiceFactory factory = new ServiceFactory();
        netcdf = factory.getInstance(NetCDFService.class);
        netcdf.setFile(id);
    } catch (DependencyException e) {
        throw new MissingLibraryException(NetCDFServiceImpl.NO_NETCDF_MSG, e);
    }
    pixelSizeX = pixelSizeY = pixelSizeZ = 1;
    emWave = new ArrayList<String>();
    exWave = new ArrayList<String>();
    channelMin = new ArrayList<String>();
    channelMax = new ArrayList<String>();
    gain = new ArrayList<String>();
    pinhole = new ArrayList<String>();
    channelName = new ArrayList<String>();
    microscopyMode = new ArrayList<String>();
    colors = new ArrayList<double[]>();
    seriesCount = 0;
    // read all of the metadata key/value pairs
    parseAttributes();
    CoreMetadata ms0 = core.get(0);
    if (seriesCount > 1) {
        for (int i = 1; i < seriesCount; i++) {
            core.add(new CoreMetadata());
        }
        for (int i = 1; i < seriesCount; i++) {
            CoreMetadata ms = core.get(i);
            String groupPath = "DataSet/ResolutionLevel_" + i + "/TimePoint_0/Channel_0";
            ms.sizeX = Integer.parseInt(netcdf.getAttributeValue(groupPath + "/ImageSizeX"));
            ms.sizeY = Integer.parseInt(netcdf.getAttributeValue(groupPath + "/ImageSizeY"));
            ms.sizeZ = Integer.parseInt(netcdf.getAttributeValue(groupPath + "/ImageSizeZ"));
            ms.imageCount = ms.sizeZ * getSizeC() * getSizeT();
            ms.sizeC = getSizeC();
            ms.sizeT = getSizeT();
            ms.thumbnail = true;
            if (ms.sizeZ == ms0.sizeZ && ms.sizeC == ms0.sizeC && ms.sizeT == ms0.sizeT) {
                // do not assume that all series will have the same dimensions
                // if the Z, C or T size is different, then it cannot
                // be a subresolution
                ms0.resolutionCount++;
            }
        }
    }
    ms0.imageCount = getSizeZ() * getSizeC() * getSizeT();
    ms0.thumbnail = false;
    ms0.dimensionOrder = "XYZCT";
    // determine pixel type - this isn't stored in the metadata, so we need
    // to check the pixels themselves
    int type = -1;
    Object pix = getImageData(0, 0, 0, 1, 1);
    if (pix instanceof byte[][])
        type = FormatTools.UINT8;
    else if (pix instanceof short[][])
        type = FormatTools.UINT16;
    else if (pix instanceof int[][])
        type = FormatTools.UINT32;
    else if (pix instanceof float[][])
        type = FormatTools.FLOAT;
    else if (pix instanceof double[][])
        type = FormatTools.DOUBLE;
    else {
        throw new FormatException("Unknown pixel type: " + pix);
    }
    for (int i = 0; i < core.size(); i++) {
        CoreMetadata ms = core.get(i);
        ms.pixelType = type;
        ms.dimensionOrder = "XYZCT";
        ms.rgb = false;
        ms.thumbSizeX = 128;
        ms.thumbSizeY = 128;
        ms.orderCertain = true;
        ms.littleEndian = true;
        ms.interleaved = false;
        ms.indexed = colors.size() >= getSizeC();
    }
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    String imageName = new Location(getCurrentFile()).getName();
    for (int s = 0; s < getSeriesCount(); s++) {
        store.setImageName(imageName + " Resolution Level " + (s + 1), s);
    }
    if (getMetadataOptions().getMetadataLevel() == MetadataLevel.MINIMUM) {
        return;
    }
    int cIndex = 0;
    for (int s = 0; s < getSeriesCount(); s++) {
        setSeries(s);
        double px = pixelSizeX, py = pixelSizeY, pz = pixelSizeZ;
        if (px == 1)
            px = (maxX - minX) / getSizeX();
        if (py == 1)
            py = (maxY - minY) / getSizeY();
        if (pz == 1)
            pz = (maxZ - minZ) / getSizeZ();
        Length sizeX = FormatTools.getPhysicalSizeX(px);
        Length sizeY = FormatTools.getPhysicalSizeY(py);
        Length sizeZ = FormatTools.getPhysicalSizeZ(pz);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, s);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, s);
        }
        if (sizeZ != null) {
            store.setPixelsPhysicalSizeZ(sizeZ, s);
        }
        for (int i = 0; i < getSizeC(); i++, cIndex++) {
            Float gainValue = null;
            Integer pinholeValue = null, emWaveValue = null, exWaveValue;
            if (cIndex < gain.size()) {
                try {
                    gainValue = new Float(gain.get(cIndex));
                } catch (NumberFormatException e) {
                }
            }
            if (cIndex < pinhole.size()) {
                try {
                    pinholeValue = new Integer(pinhole.get(cIndex));
                } catch (NumberFormatException e) {
                }
            }
            if (cIndex < emWave.size()) {
                try {
                    emWaveValue = new Integer(emWave.get(cIndex));
                } catch (NumberFormatException e) {
                }
            }
            if (cIndex < exWave.size()) {
                try {
                    exWaveValue = new Integer(exWave.get(cIndex));
                } catch (NumberFormatException e) {
                }
            }
            Double minValue = null, maxValue = null;
            if (cIndex < channelMin.size()) {
                try {
                    minValue = new Double(channelMin.get(cIndex));
                } catch (NumberFormatException e) {
                }
            }
            if (cIndex < channelMax.size()) {
                try {
                    maxValue = new Double(channelMax.get(cIndex));
                } catch (NumberFormatException e) {
                }
            }
            if (i < colors.size()) {
                double[] color = colors.get(i);
                Color realColor = new Color((int) (color[0] * 255), (int) (color[1] * 255), (int) (color[2] * 255), 255);
                store.setChannelColor(realColor, s, i);
            }
        }
    }
    setSeries(0);
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) Color(ome.xml.model.primitives.Color) DependencyException(loci.common.services.DependencyException) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) MissingLibraryException(loci.formats.MissingLibraryException) NetCDFService(loci.formats.services.NetCDFService) Location(loci.common.Location)

Example 35 with CoreMetadata

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

the class ImarisHDFReader method parseAttributes.

private void parseAttributes() {
    final List<String> attributes = netcdf.getAttributeList();
    CoreMetadata ms0 = core.get(0);
    for (String attr : attributes) {
        String name = attr.substring(attr.lastIndexOf("/") + 1);
        String value = netcdf.getAttributeValue(attr);
        if (value == null)
            continue;
        value = value.trim();
        if (name.equals("X") || (attr.startsWith("DataSet/ResolutionLevel_0") && name.equals("ImageSizeX"))) {
            try {
                ms0.sizeX = Integer.parseInt(value);
            } catch (NumberFormatException e) {
                LOGGER.trace("Failed to parse '" + name + "'", e);
            }
        } else if (name.equals("Y") || (attr.startsWith("DataSet/ResolutionLevel_0") && name.equals("ImageSizeY"))) {
            try {
                ms0.sizeY = Integer.parseInt(value);
            } catch (NumberFormatException e) {
                LOGGER.trace("Failed to parse '" + name + "'", e);
            }
        } else if (name.equals("Z") || (attr.startsWith("DataSet/ResolutionLevel_0") && name.equals("ImageSizeZ"))) {
            try {
                ms0.sizeZ = Integer.parseInt(value);
            } catch (NumberFormatException e) {
                LOGGER.trace("Failed to parse '" + name + "'", e);
            }
        } else if (name.equals("FileTimePoints")) {
            ms0.sizeT = Integer.parseInt(value);
        } else if (name.equals("NumberOfChannels") && getSizeC() == 0) {
            ms0.sizeC = Integer.parseInt(value);
        } else if (name.equals("RecordingEntrySampleSpacing")) {
            pixelSizeX = Double.parseDouble(value);
        } else if (name.equals("RecordingEntryLineSpacing")) {
            pixelSizeY = Double.parseDouble(value);
        } else if (name.equals("RecordingEntryPlaneSpacing")) {
            pixelSizeZ = Double.parseDouble(value);
        } else if (name.equals("ExtMax0"))
            maxX = Double.parseDouble(value);
        else if (name.equals("ExtMax1"))
            maxY = Double.parseDouble(value);
        else if (name.equals("ExtMax2"))
            maxZ = Double.parseDouble(value);
        else if (name.equals("ExtMin0"))
            minX = Double.parseDouble(value);
        else if (name.equals("ExtMin1"))
            minY = Double.parseDouble(value);
        else if (name.equals("ExtMin2"))
            minZ = Double.parseDouble(value);
        if (attr.startsWith("DataSet/ResolutionLevel_")) {
            int slash = attr.indexOf("/", 24);
            int n = Integer.parseInt(attr.substring(24, slash == -1 ? attr.length() : slash));
            if (n >= seriesCount)
                seriesCount = n + 1;
        }
        if (attr.startsWith("DataSetInfo/Channel_")) {
            String originalValue = value;
            for (String d : DELIMITERS) {
                if (value.indexOf(d) != -1) {
                    value = value.substring(value.indexOf(d) + 1);
                }
            }
            int underscore = attr.indexOf('_') + 1;
            int cIndex = Integer.parseInt(attr.substring(underscore, attr.indexOf("/", underscore)));
            while (cIndex >= getSizeC()) ms0.sizeC++;
            if (name.equals("Gain"))
                gain.add(value);
            else if (name.equals("LSMEmissionWavelength"))
                emWave.add(value);
            else if (name.equals("LSMExcitationWavelength"))
                exWave.add(value);
            else if (name.equals("Max"))
                channelMax.add(value);
            else if (name.equals("Min"))
                channelMin.add(value);
            else if (name.equals("Pinhole"))
                pinhole.add(value);
            else if (name.equals("Name"))
                channelName.add(value);
            else if (name.equals("MicroscopyMode"))
                microscopyMode.add(value);
            else if (name.equals("Color")) {
                double[] color = new double[3];
                String[] intensity = originalValue.split(" ");
                for (int i = 0; i < intensity.length; i++) {
                    color[i] = Double.parseDouble(intensity[i]);
                }
                colors.add(color);
            }
        }
        if (value != null)
            addGlobalMeta(name, value);
    }
}
Also used : CoreMetadata(loci.formats.CoreMetadata)

Aggregations

CoreMetadata (loci.formats.CoreMetadata)211 MetadataStore (loci.formats.meta.MetadataStore)130 RandomAccessInputStream (loci.common.RandomAccessInputStream)108 FormatException (loci.formats.FormatException)87 Length (ome.units.quantity.Length)74 Location (loci.common.Location)55 ArrayList (java.util.ArrayList)50 Timestamp (ome.xml.model.primitives.Timestamp)44 IFD (loci.formats.tiff.IFD)33 Time (ome.units.quantity.Time)30 IOException (java.io.IOException)21 TiffParser (loci.formats.tiff.TiffParser)19 PhotoInterp (loci.formats.tiff.PhotoInterp)17 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)16 IFDList (loci.formats.tiff.IFDList)15 DependencyException (loci.common.services.DependencyException)14 ServiceFactory (loci.common.services.ServiceFactory)13 PositiveInteger (ome.xml.model.primitives.PositiveInteger)13 IniList (loci.common.IniList)9 HashMap (java.util.HashMap)8