Search in sources :

Example 56 with CoreMetadata

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

the class SEQReader method initStandardMetadata.

// -- Internal BaseTiffReader API methods --
/* @see BaseTiffReader#initStandardMetadata() */
@Override
protected void initStandardMetadata() throws FormatException, IOException {
    super.initStandardMetadata();
    CoreMetadata m = core.get(0);
    m.sizeZ = 0;
    m.sizeT = 0;
    MetadataLevel level = getMetadataOptions().getMetadataLevel();
    for (IFD ifd : ifds) {
        if (level != MetadataLevel.MINIMUM) {
            short[] tag1 = (short[]) ifd.getIFDValue(IMAGE_PRO_TAG_1);
            if (tag1 != null) {
                StringBuilder seqId = new StringBuilder();
                for (int i = 0; i < tag1.length; i++) {
                    seqId.append(tag1[i]);
                }
                addGlobalMeta("Image-Pro SEQ ID", seqId.toString());
            }
        }
        int tag2 = ifds.get(0).getIFDIntValue(IMAGE_PRO_TAG_2);
        if (tag2 != -1) {
            // should be one of these for every image plane
            m.sizeZ++;
            addGlobalMeta("Frame Rate", tag2);
        }
        addGlobalMeta("Number of images", getSizeZ());
    }
    if (getSizeZ() == 0)
        m.sizeZ = 1;
    if (getSizeT() == 0)
        m.sizeT = 1;
    if (getSizeZ() == 1 && getSizeT() == 1) {
        m.sizeZ = ifds.size();
    }
    // default values
    addGlobalMeta("frames", getSizeZ());
    addGlobalMeta("channels", super.getSizeC());
    addGlobalMeta("slices", getSizeT());
    // parse the description to get channels, slices and times where applicable
    String descr = ifds.get(0).getComment();
    metadata.remove("Comment");
    if (descr != null) {
        String[] lines = descr.split("\n");
        for (String token : lines) {
            token = token.trim();
            int eq = token.indexOf('=');
            if (eq == -1)
                eq = token.indexOf(':');
            if (eq != -1) {
                String label = token.substring(0, eq);
                String data = token.substring(eq + 1);
                addGlobalMeta(label, data);
                if (label.equals("channels"))
                    m.sizeC = Integer.parseInt(data);
                else if (label.equals("frames")) {
                    m.sizeT = Integer.parseInt(data);
                } else if (label.equals("slices")) {
                    m.sizeZ = Integer.parseInt(data);
                }
            }
        }
    }
    if (isRGB() && getSizeC() != 3)
        m.sizeC *= 3;
    m.dimensionOrder = "XY";
    int maxNdx = 0, max = 0;
    int[] dims = { getSizeZ(), getSizeC(), getSizeT() };
    String[] axes = { "Z", "C", "T" };
    for (int i = 0; i < dims.length; i++) {
        if (dims[i] > max) {
            max = dims[i];
            maxNdx = i;
        }
    }
    m.dimensionOrder += axes[maxNdx];
    if (maxNdx != 1) {
        if (getSizeC() > 1) {
            m.dimensionOrder += 'C';
            m.dimensionOrder += (maxNdx == 0 ? axes[2] : axes[0]);
        } else
            m.dimensionOrder += (maxNdx == 0 ? axes[2] : axes[0]) + "C";
    } else {
        if (getSizeZ() > getSizeT())
            m.dimensionOrder += "ZT";
        else
            m.dimensionOrder += "TZ";
    }
}
Also used : IFD(loci.formats.tiff.IFD) CoreMetadata(loci.formats.CoreMetadata)

Example 57 with CoreMetadata

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

the class FilePatternReader method getCoreMetadataList.

@Override
public List<CoreMetadata> getCoreMetadataList() {
    // Only used for determining the object type.
    List<CoreMetadata> oldcore = helper.getCoreMetadataList();
    List<CoreMetadata> newcore = new ArrayList<CoreMetadata>();
    for (int s = 0; s < oldcore.size(); s++) {
        CoreMetadata newMeta = oldcore.get(s).clone(this, s);
        newMeta.resolutionCount = oldcore.get(s).resolutionCount;
        newcore.add(newMeta);
    }
    return newcore;
}
Also used : ArrayList(java.util.ArrayList) CoreMetadata(loci.formats.CoreMetadata)

Example 58 with CoreMetadata

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

the class EPSReader 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);
    CoreMetadata m = core.get(0);
    LOGGER.info("Verifying EPS format");
    String line = readLine();
    if (!line.trim().startsWith("%!PS")) {
        // read the TIFF preview
        isTiff = true;
        in.order(true);
        in.seek(20);
        int offset = in.readInt();
        int len = in.readInt();
        byte[] b = new byte[len];
        in.seek(offset);
        in.read(b);
        in = new RandomAccessInputStream(b);
        TiffParser tp = new TiffParser(in);
        ifds = tp.getIFDs();
        IFD firstIFD = ifds.get(0);
        map = tp.getColorMap(firstIFD);
        m.sizeX = (int) firstIFD.getImageWidth();
        m.sizeY = (int) firstIFD.getImageLength();
        m.sizeZ = 1;
        m.sizeT = 1;
        m.sizeC = firstIFD.getSamplesPerPixel();
        if (map != null && getSizeC() == 1) {
            m.sizeC = 3;
        }
        if (getSizeC() == 2)
            m.sizeC = 4;
        m.littleEndian = firstIFD.isLittleEndian();
        m.interleaved = true;
        m.rgb = getSizeC() > 1;
        m.pixelType = firstIFD.getPixelType();
        m.imageCount = 1;
        m.dimensionOrder = "XYCZT";
        m.metadataComplete = true;
        m.indexed = false;
        m.falseColor = false;
        MetadataStore store = makeFilterMetadata();
        MetadataTools.populatePixels(store, this);
        return;
    }
    LOGGER.info("Finding image data");
    binary = false;
    String image = "image";
    int lineNum = 1;
    line = readLine().trim();
    while (line != null && !line.equals("%%EOF")) {
        if (line.endsWith(image)) {
            if (!line.startsWith(image)) {
                if (line.indexOf("colorimage") != -1)
                    m.sizeC = 3;
                String[] t = line.split(" ");
                try {
                    int newX = Integer.parseInt(t[0]);
                    int newY = Integer.parseInt(t[1]);
                    if (t.length > 2 && Integer.parseInt(t[2]) >= 8) {
                        m.sizeX = newX;
                        m.sizeY = newY;
                        start = lineNum;
                    }
                } catch (NumberFormatException exc) {
                    LOGGER.debug("Could not parse image dimensions", exc);
                    if (t.length > 3) {
                        m.sizeC = Integer.parseInt(t[3]);
                    }
                }
            }
            break;
        } else if (line.startsWith("%%")) {
            if (line.startsWith("%%BoundingBox:")) {
                line = line.substring(14).trim();
                String[] t = line.split(" ");
                try {
                    int originX = Integer.parseInt(t[0].trim());
                    int originY = Integer.parseInt(t[1].trim());
                    m.sizeX = Integer.parseInt(t[2].trim()) - originX;
                    m.sizeY = Integer.parseInt(t[3].trim()) - originY;
                    addGlobalMeta("X-coordinate of origin", originX);
                    addGlobalMeta("Y-coordinate of origin", originY);
                } catch (NumberFormatException e) {
                    throw new FormatException("Files without image data are not supported.");
                }
            } else if (line.startsWith("%%BeginBinary")) {
                binary = true;
            } else {
                // parse key/value pairs
                int ndx = line.indexOf(':');
                if (ndx != -1) {
                    String key = line.substring(0, ndx);
                    String value = line.substring(ndx + 1);
                    addGlobalMeta(key, value);
                }
            }
        } else if (line.startsWith("%ImageData:")) {
            line = line.substring(11);
            String[] t = line.split(" ");
            m.sizeX = Integer.parseInt(t[0]);
            m.sizeY = Integer.parseInt(t[1]);
            m.sizeC = Integer.parseInt(t[3]);
            for (int i = 4; i < t.length; i++) {
                image = t[i].trim();
                if (image.length() > 1) {
                    image = image.substring(1, image.length() - 1);
                }
            }
        }
        lineNum++;
        line = readLine().trim();
    }
    LOGGER.info("Populating metadata");
    if (getSizeC() == 0)
        m.sizeC = 1;
    m.sizeZ = 1;
    m.sizeT = 1;
    m.dimensionOrder = "XYCZT";
    m.pixelType = FormatTools.UINT8;
    m.rgb = getSizeC() == 3;
    m.interleaved = true;
    m.littleEndian = true;
    m.imageCount = 1;
    // Populate metadata store
    // The metadata store we're working with.
    MetadataStore store = getMetadataStore();
    MetadataTools.populatePixels(store, this);
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException)

Example 59 with CoreMetadata

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

the class VolocityReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    if (!checkSuffix(id, "mvd2")) {
        Location file = new Location(id).getAbsoluteFile();
        Location parent = file.getParentFile().getParentFile();
        String[] files = parent.list(true);
        for (String f : files) {
            if (checkSuffix(f, "mvd2")) {
                id = new Location(parent, f).getAbsolutePath();
                break;
            }
        }
    }
    super.initFile(id);
    stacks = new ArrayList<Stack>();
    extraFiles = new ArrayList<String>();
    Location file = new Location(id).getAbsoluteFile();
    extraFiles.add(file.getAbsolutePath());
    Location parentDir = file.getParentFile();
    dir = new Location(parentDir, DATA_DIR);
    if (dir.exists()) {
        String[] files = dir.list(true);
        for (String f : files) {
            if (!checkSuffix(f, "aisf") && !checkSuffix(f, "atsf")) {
                extraFiles.add(new Location(dir, f).getAbsolutePath());
            }
        }
    }
    try {
        ServiceFactory factory = new ServiceFactory();
        MetakitService reader = factory.getInstance(MetakitService.class);
        reader.initialize(id);
        sampleTable = reader.getTableData(1);
        stringTable = reader.getTableData(2);
        reader.close();
    } catch (DependencyException e) {
        throw new MissingLibraryException("Could not find Metakit library", e);
    }
    ArrayList<String> stackNames = new ArrayList<String>();
    ArrayList<Integer> parentIDs = new ArrayList<Integer>();
    for (int i = 0; i < sampleTable.length; i++) {
        Integer stringID = (Integer) sampleTable[i][11];
        String name = getString(stringID);
        int channelIndex = getChildIndex((Integer) sampleTable[i][0], "Channels");
        if (i > 0 && (Integer) sampleTable[i][2] == 1 && (channelIndex >= 0 || (sampleTable[i][14] != null && !sampleTable[i][14].equals(0)) || ((byte[]) sampleTable[i][13]).length > 21)) {
            if (channelIndex < 0) {
                RandomAccessInputStream s = getStream(i);
                s.seek(0);
                if (s.read() != 'I') {
                    s.order(false);
                }
                s.seek(22);
                int x = s.readInt();
                int y = s.readInt();
                int z = s.readInt();
                if (x * y * z > 0 && x * y * z < (s.length() * 3)) {
                    stackNames.add(name);
                    parentIDs.add((Integer) sampleTable[i][0]);
                }
                s.close();
            } else {
                stackNames.add(name);
                parentIDs.add((Integer) sampleTable[i][0]);
            }
        }
    }
    for (int i = 0; i < parentIDs.size(); i++) {
        Stack stack = new Stack();
        stack.core = new CoreMetadata();
        Integer parent = parentIDs.get(i);
        int channelIndex = getChildIndex(parent, "Channels");
        if (channelIndex >= 0) {
            Integer[] channels = getAllChildren((Integer) sampleTable[channelIndex][0]);
            stack.core.sizeC = channels.length;
            stack.pixelsFiles = new String[stack.core.sizeC];
            stack.channelNames = new String[channels.length];
            for (int c = 0; c < channels.length; c++) {
                stack.channelNames[c] = getString((Integer) sampleTable[channels[c]][11]);
                RandomAccessInputStream data = getStream(channels[c]);
                if (data.length() > 22) {
                    data.seek(22);
                    int stackID = data.readInt();
                    Location f = new Location(dir, stackID + ".aisf");
                    if (!f.exists()) {
                        f = new Location(dir, DataTools.swap(stackID) + ".aisf");
                    }
                    stack.pixelsFiles[c] = f.getAbsolutePath();
                } else {
                    Integer child = getAllChildren((Integer) sampleTable[channels[c]][0])[0];
                    stack.pixelsFiles[c] = getFile((Integer) sampleTable[child][0], dir);
                }
                data.close();
            }
        } else {
            stack.pixelsFiles = new String[1];
            stack.pixelsFiles[0] = getFile(parent, dir);
            if (stack.pixelsFiles[0] == null || !new Location(stack.pixelsFiles[0]).exists()) {
                int row = -1;
                for (int r = 0; r < sampleTable.length; r++) {
                    if (sampleTable[r][0].equals(parent)) {
                        row = r;
                        break;
                    }
                }
                stack.pixelsFiles[0] = EMBEDDED_STREAM;
                IRandomAccess data = new ByteArrayHandle((byte[]) sampleTable[row][13]);
                Location.mapFile(stack.pixelsFiles[0], data);
            }
        }
        RandomAccessInputStream data = null;
        int timestampIndex = getChildIndex(parent, "Timepoint times stream");
        if (timestampIndex >= 0) {
            data = getStream(timestampIndex);
            data.seek(22);
            int timestampID = data.readInt();
            Location f = new Location(dir, timestampID + ".atsf");
            if (!f.exists()) {
                f = new Location(dir, DataTools.swap(timestampID) + ".atsf");
            }
            stack.timestampFile = f.getAbsolutePath();
            data.close();
        }
        int xIndex = getChildIndex(parent, "um/pixel (X)");
        if (xIndex >= 0) {
            data = getStream(xIndex);
            data.seek(SIGNATURE_SIZE);
            stack.physicalX = data.readDouble();
            data.close();
        }
        int yIndex = getChildIndex(parent, "um/pixel (Y)");
        if (yIndex >= 0) {
            data = getStream(yIndex);
            data.seek(SIGNATURE_SIZE);
            stack.physicalY = data.readDouble();
            data.close();
        }
        int zIndex = getChildIndex(parent, "um/pixel (Z)");
        if (zIndex >= 0) {
            data = getStream(zIndex);
            data.seek(SIGNATURE_SIZE);
            stack.physicalZ = data.readDouble();
            data.close();
        }
        timestampIndex = getChildIndex(parent, "TimepointTimes");
        if (timestampIndex >= 0) {
            data = getStream(timestampIndex);
            data.seek(SIGNATURE_SIZE);
            data.close();
        }
        int objectiveIndex = getChildIndex(parent, "Microscope Objective");
        if (objectiveIndex >= 0) {
            data = getStream(objectiveIndex);
            data.seek(SIGNATURE_SIZE);
            stack.magnification = data.readDouble();
            data.close();
        }
        int detectorIndex = getChildIndex(parent, "Camera/Detector");
        if (detectorIndex >= 0) {
            data = getStream(detectorIndex);
            data.seek(SIGNATURE_SIZE);
            int len = data.readInt();
            stack.detector = data.readString(len);
            data.close();
        }
        int descriptionIndex = getChildIndex(parent, "Experiment Description");
        if (descriptionIndex >= 0) {
            data = getStream(descriptionIndex);
            data.seek(SIGNATURE_SIZE);
            int len = data.readInt();
            stack.description = data.readString(len);
            data.close();
        }
        int xLocationIndex = getChildIndex(parent, "X Location");
        if (xLocationIndex >= 0) {
            data = getStream(xLocationIndex);
            data.seek(SIGNATURE_SIZE);
            stack.xLocation = data.readDouble();
            data.close();
        }
        int yLocationIndex = getChildIndex(parent, "Y Location");
        if (yLocationIndex >= 0) {
            data = getStream(yLocationIndex);
            data.seek(SIGNATURE_SIZE);
            stack.yLocation = data.readDouble();
            data.close();
        }
        int zLocationIndex = getChildIndex(parent, "Z Location");
        if (zLocationIndex >= 0) {
            data = getStream(zLocationIndex);
            data.seek(SIGNATURE_SIZE);
            stack.zLocation = data.readDouble();
            data.close();
        }
        stacks.add(stack);
    }
    for (int i = 0; i < stacks.size(); i++) {
        Stack stack = stacks.get(i);
        if (!new Location(stack.pixelsFiles[0]).exists()) {
            stacks.remove(i);
            i--;
            continue;
        }
        RandomAccessInputStream base = new RandomAccessInputStream(stack.pixelsFiles[0]);
        long baseLength = base.length();
        base.close();
        for (int q = 1; q < stack.pixelsFiles.length; q++) {
            if (!new Location(stack.pixelsFiles[q]).exists()) {
                continue;
            }
            base = new RandomAccessInputStream(stack.pixelsFiles[q]);
            long length = base.length();
            base.close();
            if (length > baseLength) {
                // split the stack
                Stack newStack = new Stack();
                newStack.timestampFile = stack.timestampFile;
                newStack.core = new CoreMetadata();
                newStack.physicalX = stack.physicalX;
                newStack.physicalY = stack.physicalY;
                newStack.physicalZ = stack.physicalZ;
                newStack.magnification = stack.magnification;
                newStack.detector = stack.detector;
                newStack.description = stack.description;
                newStack.xLocation = stack.xLocation;
                newStack.yLocation = stack.yLocation;
                newStack.zLocation = stack.zLocation;
                String[] pixels = stack.pixelsFiles;
                newStack.pixelsFiles = new String[pixels.length - q];
                System.arraycopy(pixels, q, newStack.pixelsFiles, 0, newStack.pixelsFiles.length);
                stack.pixelsFiles = new String[q];
                System.arraycopy(pixels, 0, stack.pixelsFiles, 0, q);
                String[] channels = stack.channelNames;
                newStack.channelNames = new String[channels.length - q];
                System.arraycopy(channels, q, newStack.channelNames, 0, newStack.channelNames.length);
                stack.channelNames = new String[q];
                System.arraycopy(channels, 0, stack.channelNames, 0, q);
                newStack.core.sizeC = newStack.channelNames.length;
                stack.core.sizeC = stack.channelNames.length;
                stacks.add(i + 1, newStack);
                stackNames.add(i + 1, stackNames.get(i));
            }
        }
    }
    int seriesCount = stacks.size();
    core.clear();
    for (int i = 0; i < seriesCount; i++) {
        Stack stack = stacks.get(i);
        CoreMetadata ms = stack.core;
        core.add(ms);
        setSeries(i);
        ms.littleEndian = true;
        if (stack.timestampFile != null) {
            RandomAccessInputStream s = new RandomAccessInputStream(stack.timestampFile);
            s.seek(0);
            if (s.read() != 'I') {
                ms.littleEndian = false;
            }
            s.seek(17);
            s.order(isLittleEndian());
            ms.sizeT = s.readInt();
            Double firstStamp = null;
            Double[] stamps = new Double[ms.sizeT];
            for (int t = 0; t < ms.sizeT; t++) {
                // timestamps are stored in microseconds
                double timestamp = s.readLong() / 1000000.0;
                if (firstStamp == null) {
                    firstStamp = timestamp;
                }
                stamps[t] = timestamp - firstStamp;
            }
            timestamps.add(stamps);
            s.close();
        } else {
            ms.sizeT = 1;
        }
        ms.rgb = false;
        ms.interleaved = true;
        ms.dimensionOrder = "XYCZT";
        RandomAccessInputStream s = new RandomAccessInputStream(stack.pixelsFiles[0]);
        s.order(isLittleEndian());
        if (checkSuffix(stack.pixelsFiles[0], "aisf")) {
            s.seek(18);
            stack.blockSize = s.readShort() * 256;
            s.skipBytes(5);
            int x = s.readInt();
            int y = s.readInt();
            int zStart = s.readInt();
            int w = s.readInt();
            int h = s.readInt();
            if (w - x < 0 || h - y < 0 || (w - x) * (h - y) < 0) {
                ms.littleEndian = !isLittleEndian();
                s.order(isLittleEndian());
                s.seek(s.getFilePointer() - 20);
                x = s.readInt();
                y = s.readInt();
                zStart = s.readInt();
                w = s.readInt();
                h = s.readInt();
            }
            ms.sizeX = w - x;
            ms.sizeY = h - y;
            ms.sizeZ = s.readInt() - zStart;
            ms.imageCount = getSizeZ() * getSizeC() * getSizeT();
            ms.pixelType = FormatTools.INT8;
            int planesPerFile = getSizeZ() * getSizeT();
            int planeSize = FormatTools.getPlaneSize(this);
            int bytesPerPlane = (int) ((s.length() - stack.blockSize) / planesPerFile);
            int bytesPerPixel = 0;
            while (bytesPerPlane >= planeSize) {
                bytesPerPixel++;
                bytesPerPlane -= planeSize;
            }
            if ((bytesPerPixel % 3) == 0) {
                ms.sizeC *= 3;
                ms.rgb = true;
                bytesPerPixel /= 3;
            }
            ms.pixelType = FormatTools.pixelTypeFromBytes(bytesPerPixel, false, bytesPerPixel > 2);
            // full timepoints are padded to have a multiple of 256 bytes
            int timepoint = FormatTools.getPlaneSize(this) * getSizeZ();
            stack.planePadding = stack.blockSize - (timepoint % stack.blockSize);
            if (stack.planePadding == stack.blockSize) {
                stack.planePadding = 0;
            }
        } else {
            boolean embedded = Location.getMappedFile(EMBEDDED_STREAM) != null;
            s.seek(0);
            if (s.read() != 'I') {
                ms.littleEndian = false;
                s.order(false);
            }
            s.seek(22);
            ms.sizeX = s.readInt();
            ms.sizeY = s.readInt();
            ms.sizeZ = s.readInt();
            ms.sizeC = embedded ? 1 : 4;
            ms.imageCount = getSizeZ() * getSizeT();
            ms.rgb = ms.sizeC > 1;
            ms.pixelType = FormatTools.UINT8;
            stack.blockSize = embedded ? (int) s.getFilePointer() : 99;
            stack.planePadding = 0;
            if (s.length() > ms.sizeX * ms.sizeY * ms.sizeZ * 6) {
                ms.pixelType = FormatTools.UINT16;
                ms.sizeC = 3;
                ms.rgb = true;
            }
            if (s.length() < (ms.sizeX * ms.sizeY * ms.sizeZ * ms.sizeC)) {
                ms.rgb = false;
                ms.sizeC = 1;
                long pixels = ms.sizeX * ms.sizeY * ms.sizeZ;
                double approximateBytes = (double) s.length() / pixels;
                int bytes = (int) Math.ceil(approximateBytes);
                if (bytes == 0) {
                    bytes = 1;
                } else if (bytes == 3) {
                    bytes = 2;
                }
                ms.pixelType = FormatTools.pixelTypeFromBytes(bytes, false, false);
                s.seek(70);
                stack.blockSize = s.readInt();
                stack.clippingData = true;
            }
        }
        s.close();
    }
    setSeries(0);
    for (int i = 0; i < getSeriesCount(); i++) {
        setSeries(i);
        Stack stack = stacks.get(i);
        addSeriesMeta("Name", stackNames.get(i));
        addSeriesMeta("Pixel width (in microns)", stack.physicalX);
        addSeriesMeta("Pixel height (in microns)", stack.physicalY);
        addSeriesMeta("Z step (in microns)", stack.physicalZ);
        addSeriesMeta("Objective magnification", stack.magnification);
        addSeriesMeta("Camera/Detector", stack.detector);
        addSeriesMeta("Description", stack.description);
        addSeriesMeta("X Location", stack.xLocation);
        addSeriesMeta("Y Location", stack.yLocation);
        addSeriesMeta("Z Location", stack.zLocation);
        if (stack.channelNames != null) {
            for (int c = 0; c < stack.channelNames.length; c++) {
                addSeriesMetaList("Channel", stack.channelNames[c]);
            }
        }
    }
    setSeries(0);
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, true);
    String instrument = MetadataTools.createLSID("Instrument", 0);
    store.setInstrumentID(instrument, 0);
    for (int i = 0; i < getSeriesCount(); i++) {
        store.setImageInstrumentRef(instrument, i);
        setSeries(i);
        Stack stack = stacks.get(i);
        store.setImageName(stackNames.get(i), i);
        store.setImageDescription(stack.description, i);
        if (stack.channelNames != null) {
            for (int c = 0; c < getEffectiveSizeC(); c++) {
                store.setChannelName(stack.channelNames[c], i, c);
            }
        }
        Length sizeX = FormatTools.getPhysicalSizeX(stack.physicalX);
        Length sizeY = FormatTools.getPhysicalSizeY(stack.physicalY);
        Length sizeZ = FormatTools.getPhysicalSizeZ(stack.physicalZ);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, i);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, i);
        }
        if (sizeZ != null) {
            store.setPixelsPhysicalSizeZ(sizeZ, i);
        }
        String objective = MetadataTools.createLSID("Objective", 0, i);
        store.setObjectiveID(objective, 0, i);
        store.setObjectiveNominalMagnification(stack.magnification, 0, i);
        store.setObjectiveCorrection(getCorrection("Other"), 0, i);
        store.setObjectiveImmersion(getImmersion("Other"), 0, i);
        store.setObjectiveSettingsID(objective, i);
        String detectorID = MetadataTools.createLSID("Detector", 0, i);
        store.setDetectorID(detectorID, 0, i);
        store.setDetectorModel(stack.detector, 0, i);
        for (int c = 0; c < getEffectiveSizeC(); c++) {
            store.setDetectorSettingsID(detectorID, i, c);
        }
        for (int img = 0; img < getImageCount(); img++) {
            int[] coords = getZCTCoords(img);
            int z = coords[0];
            final Length xLoc = new Length(stack.xLocation, UNITS.REFERENCEFRAME);
            final Length yLoc = new Length(stack.yLocation, UNITS.REFERENCEFRAME);
            store.setPlanePositionX(xLoc, i, img);
            store.setPlanePositionY(yLoc, i, img);
            if (stack.physicalZ != null) {
                final double zLocNumber = stack.zLocation + z * stack.physicalZ;
                final Length zLoc = new Length(zLocNumber, UNITS.REFERENCEFRAME);
                store.setPlanePositionZ(zLoc, i, img);
            }
            if (i < timestamps.size() && coords[2] < timestamps.get(i).length && timestamps.get(i)[coords[2]] != null) {
                store.setPlaneDeltaT(new Time(timestamps.get(i)[coords[2]], UNITS.SECOND), i, img);
            }
        }
    }
    setSeries(0);
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) ArrayList(java.util.ArrayList) Time(ome.units.quantity.Time) IRandomAccess(loci.common.IRandomAccess) DependencyException(loci.common.services.DependencyException) CoreMetadata(loci.formats.CoreMetadata) MetadataStore(loci.formats.meta.MetadataStore) MetakitService(loci.formats.services.MetakitService) Length(ome.units.quantity.Length) MissingLibraryException(loci.formats.MissingLibraryException) RandomAccessInputStream(loci.common.RandomAccessInputStream) ByteArrayHandle(loci.common.ByteArrayHandle) Location(loci.common.Location)

Example 60 with CoreMetadata

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

the class WATOPReader 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);
    CoreMetadata m = core.get(0);
    m.littleEndian = true;
    in.order(isLittleEndian());
    String comment = null;
    MetadataLevel level = getMetadataOptions().getMetadataLevel();
    if (level != MetadataLevel.MINIMUM) {
        in.seek(49);
        comment = in.readString(33);
    }
    in.seek(211);
    int year = in.readInt();
    int month = in.readInt();
    int day = in.readInt();
    int hour = in.readInt();
    int min = in.readInt();
    String date = year + "-" + month + "-" + day + "T" + hour + ":" + min;
    date = DateTools.formatDate(date, "yyyy-MM-dd'T'HH:mm");
    in.skipBytes(8);
    double xSize = in.readInt() / 100d;
    double ySize = in.readInt() / 100d;
    double zSize = in.readInt() / 100d;
    m.sizeX = in.readInt();
    m.sizeY = in.readInt();
    if (level != MetadataLevel.MINIMUM) {
        double tunnelCurrent = in.readInt() / 1000d;
        double sampleVolts = in.readInt() / 1000d;
        in.skipBytes(180);
        int originalZMax = in.readInt();
        int originalZMin = in.readInt();
        int zMax = in.readInt();
        int zMin = in.readInt();
        addGlobalMeta("Comment", comment);
        addGlobalMeta("X size (in um)", xSize);
        addGlobalMeta("Y size (in um)", ySize);
        addGlobalMeta("Z size (in um)", zSize);
        addGlobalMeta("Tunnel current (in amps)", tunnelCurrent);
        addGlobalMeta("Sample volts", sampleVolts);
        addGlobalMeta("Acquisition date", date);
    }
    m.pixelType = FormatTools.INT16;
    m.sizeC = 1;
    m.sizeZ = 1;
    m.sizeT = 1;
    m.imageCount = 1;
    m.dimensionOrder = "XYZCT";
    m.rgb = false;
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    if (date != null) {
        store.setImageAcquisitionDate(new Timestamp(date), 0);
    }
    if (level != MetadataLevel.MINIMUM) {
        store.setImageDescription(comment, 0);
        Length sizeX = FormatTools.getPhysicalSizeX((double) xSize / getSizeX());
        Length sizeY = FormatTools.getPhysicalSizeY((double) ySize / getSizeY());
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp)

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