Search in sources :

Example 61 with MetadataStore

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

the class BurleighReader 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());
    int version = (int) in.readFloat() - 1;
    m.sizeX = in.readShort();
    m.sizeY = in.readShort();
    double xSize = 0d, ySize = 0d, zSize = 0d;
    pixelsOffset = version == 1 ? 8 : 260;
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        double timePerPixel = 0d;
        int mode = 0, gain = 0, mag = 0;
        double sampleVolts = 0d, tunnelCurrent = 0d;
        if (version == 1) {
            in.seek(in.length() - 40);
            in.skipBytes(12);
            xSize = in.readInt();
            ySize = in.readInt();
            zSize = in.readInt();
            timePerPixel = in.readShort() * 50;
            mag = in.readShort();
            switch(mag) {
                case 3:
                    mag = 10;
                    break;
                case 4:
                    mag = 50;
                    break;
                case 5:
                    mag = 250;
                    break;
            }
            xSize /= mag;
            ySize /= mag;
            zSize /= mag;
            mode = in.readShort();
            gain = in.readShort();
            sampleVolts = in.readFloat() / 1000;
            tunnelCurrent = in.readFloat();
        } else if (version == 2) {
            in.skipBytes(14);
            xSize = in.readInt();
            ySize = in.readInt();
            zSize = in.readInt();
            mode = in.readShort();
            in.skipBytes(4);
            gain = in.readShort();
            timePerPixel = in.readShort() * 50;
            in.skipBytes(12);
            sampleVolts = in.readFloat();
            tunnelCurrent = in.readFloat();
            addGlobalMeta("Force", in.readFloat());
        }
        addGlobalMeta("Version", version);
        addGlobalMeta("Image mode", mode);
        addGlobalMeta("Z gain", gain);
        addGlobalMeta("Time per pixel (s)", timePerPixel);
        addGlobalMeta("Sample volts", sampleVolts);
        addGlobalMeta("Tunnel current", tunnelCurrent);
        addGlobalMeta("Magnification", mag);
    }
    m.pixelType = FormatTools.UINT16;
    m.sizeZ = 1;
    m.sizeC = 1;
    m.sizeT = 1;
    m.imageCount = 1;
    m.dimensionOrder = "XYZCT";
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        Length sizeX = FormatTools.getPhysicalSizeX(xSize / getSizeX());
        Length sizeY = FormatTools.getPhysicalSizeY(ySize / getSizeY());
        Length sizeZ = FormatTools.getPhysicalSizeZ(zSize / getSizeZ());
        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) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata)

Example 62 with MetadataStore

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

the class AIMReader 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());
    // check for newer version of AIM format with wider offsets
    String version = in.readString(16);
    boolean widerOffsets = version.startsWith("AIMDATA_V030");
    if (widerOffsets) {
        in.seek(96);
        m.sizeX = (int) in.readLong();
        m.sizeY = (int) in.readLong();
        m.sizeZ = (int) in.readLong();
        in.seek(280);
    } else {
        in.seek(56);
        m.sizeX = in.readInt();
        m.sizeY = in.readInt();
        m.sizeZ = in.readInt();
        in.seek(160);
    }
    m.sizeC = 1;
    m.sizeT = 1;
    m.imageCount = getSizeZ();
    m.pixelType = FormatTools.INT16;
    m.dimensionOrder = "XYZCT";
    String processingLog = in.readCString();
    pixelOffset = in.getFilePointer();
    String date = null;
    Double xSize = null, xLength = null;
    Double ySize = null, yLength = null;
    Double zSize = null, zLength = null;
    String[] lines = processingLog.split("\n");
    for (String line : lines) {
        line = line.trim();
        int split = line.indexOf("  ");
        if (split > 0) {
            String key = line.substring(0, split).trim();
            String value = line.substring(split).trim();
            addGlobalMeta(key, value);
            if (key.equals("Original Creation-Date")) {
                date = DateTools.formatDate(value, "dd-MMM-yyyy HH:mm:ss", ".");
            } else if (key.equals("Orig-ISQ-Dim-p")) {
                String[] tokens = value.split(" ");
                for (String token : tokens) {
                    token = token.trim();
                    if (token.length() > 0) {
                        if (xSize == null) {
                            xSize = new Double(token);
                        } else if (ySize == null) {
                            ySize = new Double(token);
                        } else if (zSize == null) {
                            zSize = new Double(token);
                        }
                    }
                }
            } else if (key.equals("Orig-ISQ-Dim-um")) {
                String[] tokens = value.split(" ");
                for (String token : tokens) {
                    token = token.trim();
                    if (token.length() > 0) {
                        if (xLength == null) {
                            xLength = new Double(token);
                        } else if (yLength == null) {
                            yLength = new Double(token);
                        } else if (zLength == null) {
                            zLength = new Double(token);
                        }
                    }
                }
            }
        }
    }
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    if (date != null) {
        store.setImageAcquisitionDate(new Timestamp(date), 0);
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        if (xSize != null && xLength != null) {
            Double size = xLength / xSize;
            Length physicalSize = FormatTools.getPhysicalSizeX(size);
            if (physicalSize != null) {
                store.setPixelsPhysicalSizeX(physicalSize, 0);
            }
        }
        if (ySize != null && yLength != null) {
            Double size = yLength / ySize;
            Length physicalSize = FormatTools.getPhysicalSizeY(size);
            if (physicalSize != null) {
                store.setPixelsPhysicalSizeY(physicalSize, 0);
            }
        }
        if (zSize != null && zLength != null) {
            Double size = zLength / zSize;
            Length physicalSize = FormatTools.getPhysicalSizeZ(size);
            if (physicalSize != null) {
                store.setPixelsPhysicalSizeZ(physicalSize, 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)

Example 63 with MetadataStore

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

the class ARFReader 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);
    // parse file header
    LOGGER.info("Reading file header");
    byte endian1 = in.readByte();
    byte endian2 = in.readByte();
    boolean little;
    if (endian1 == 1 && endian2 == 0)
        little = true;
    else if (endian1 == 0 && endian2 == 1)
        little = false;
    else
        throw new FormatException("Undefined endianness");
    in.order(little);
    // 'AR' signature
    in.skipBytes(2);
    int version = in.readUnsignedShort();
    int width = in.readUnsignedShort();
    int height = in.readUnsignedShort();
    int bitsPerPixel = in.readUnsignedShort();
    int numImages = version == 2 ? in.readUnsignedShort() : 1;
    // NB: The next 510 bytes are unused 'application dependent' data,
    // followed by raw image data with no padding.
    // populate core metadata
    CoreMetadata m = core.get(0);
    m.sizeX = width;
    m.sizeY = height;
    m.sizeZ = 1;
    m.sizeC = 1;
    m.sizeT = numImages;
    int bpp = bitsPerPixel / 8;
    if ((bitsPerPixel % 8) != 0)
        bpp++;
    m.pixelType = FormatTools.pixelTypeFromBytes(bpp, false, false);
    m.bitsPerPixel = bitsPerPixel;
    m.imageCount = numImages;
    m.dimensionOrder = "XYCZT";
    m.orderCertain = true;
    m.littleEndian = little;
    m.rgb = false;
    m.interleaved = false;
    m.indexed = false;
    m.metadataComplete = true;
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        // populate original metadata
        addGlobalMeta("Endianness", little ? "little" : "big");
        addGlobalMeta("Version", version);
        addGlobalMeta("Width", width);
        addGlobalMeta("Height", height);
        addGlobalMeta("Bits per pixel", bitsPerPixel);
        addGlobalMeta("Image count", numImages);
    }
    // populate OME metadata
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException)

Example 64 with MetadataStore

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

the class AliconaReader 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);
    // check that this is a valid AL3D file
    LOGGER.info("Verifying Alicona format");
    String magicString = in.readString(17);
    if (!magicString.trim().equals("AliconaImaging")) {
        throw new FormatException("Invalid magic string : " + "expected 'AliconaImaging', got " + magicString);
    }
    // now we read a series of tags
    // each one is 52 bytes - 20 byte key + 30 byte value + 2 byte CRLF
    LOGGER.info("Reading tags");
    int count = 2;
    boolean hasC = false;
    String voltage = null, magnification = null, workingDistance = null;
    String pntX = null, pntY = null;
    int depthOffset = 0;
    for (int i = 0; i < count; i++) {
        String key = in.readString(20).trim();
        String value = in.readString(30).trim();
        addGlobalMeta(key, value);
        in.skipBytes(2);
        if (key.equals("TagCount"))
            count += Integer.parseInt(value);
        else if (key.equals("Rows"))
            m.sizeY = Integer.parseInt(value);
        else if (key.equals("Cols"))
            m.sizeX = Integer.parseInt(value);
        else if (key.equals("NumberOfPlanes")) {
            m.imageCount = Integer.parseInt(value);
        } else if (key.equals("TextureImageOffset")) {
            textureOffset = Integer.parseInt(value);
        } else if (key.equals("TexturePtr") && !value.equals("7"))
            hasC = true;
        else if (key.equals("Voltage"))
            voltage = value;
        else if (key.equals("Magnification"))
            magnification = value;
        else if (key.equals("PixelSizeXMeter"))
            pntX = value;
        else if (key.equals("PixelSizeYMeter"))
            pntY = value;
        else if (key.equals("WorkingDistance"))
            workingDistance = value;
        else if (key.equals("DepthImageOffset")) {
            depthOffset = Integer.parseInt(value);
        }
    }
    LOGGER.info("Populating metadata");
    if (textureOffset != 0) {
        numBytes = (int) (in.length() - textureOffset) / (getSizeX() * getSizeY() * getImageCount());
        m.sizeC = hasC ? 3 : 1;
        m.sizeZ = 1;
        m.sizeT = getImageCount() / getSizeC();
        m.pixelType = FormatTools.pixelTypeFromBytes(numBytes, false, false);
    } else {
        textureOffset = depthOffset;
        m.pixelType = FormatTools.FLOAT;
        m.sizeC = 1;
        m.sizeZ = 1;
        m.sizeT = 1;
        m.imageCount = 1;
    }
    m.rgb = false;
    m.interleaved = false;
    m.littleEndian = true;
    m.dimensionOrder = "XYCTZ";
    m.metadataComplete = true;
    m.indexed = false;
    m.falseColor = false;
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        // link Image and Instrument
        String instrumentID = MetadataTools.createLSID("Instrument", 0);
        store.setInstrumentID(instrumentID, 0);
        store.setImageInstrumentRef(instrumentID, 0);
        // used when the dataset was acquired, i.e. detector settings.
        if (voltage != null) {
            store.setDetectorSettingsVoltage(new ElectricPotential(new Double(voltage), UNITS.VOLT), 0, 0);
            // link DetectorSettings to an actual Detector
            String detectorID = MetadataTools.createLSID("Detector", 0, 0);
            store.setDetectorID(detectorID, 0, 0);
            store.setDetectorSettingsID(detectorID, 0, 0);
            // set required Detector type
            store.setDetectorType(getDetectorType("Other"), 0, 0);
        }
        if (magnification != null) {
            store.setObjectiveCalibratedMagnification(new Double(magnification), 0, 0);
        }
        if (workingDistance != null) {
            store.setObjectiveWorkingDistance(new Length(new Double(workingDistance), UNITS.MICROMETER), 0, 0);
        }
        store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
        store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
        // link Objective to an Image using ObjectiveSettings
        String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
        store.setObjectiveID(objectiveID, 0, 0);
        store.setObjectiveSettingsID(objectiveID, 0);
        if (pntX != null && pntY != null) {
            double pixelSizeX = Double.parseDouble(pntX);
            double pixelSizeY = Double.parseDouble(pntY);
            Length sizeX = FormatTools.getPhysicalSizeX(pixelSizeX, UNITS.METER);
            Length sizeY = FormatTools.getPhysicalSizeY(pixelSizeY, UNITS.METER);
            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) ElectricPotential(ome.units.quantity.ElectricPotential) FormatException(loci.formats.FormatException)

Example 65 with MetadataStore

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

the class AnalyzeReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    // the dataset has two files - we want the one ending in '.hdr'
    if (id.endsWith(".img")) {
        LOGGER.info("Looking for header file");
        String header = id.substring(0, id.lastIndexOf(".")) + ".hdr";
        if (new Location(header).exists()) {
            setId(header);
            return;
        } else
            throw new FormatException("Header file not found.");
    }
    super.initFile(id);
    in = new RandomAccessInputStream(id);
    pixelsFilename = id.substring(0, id.lastIndexOf(".")) + ".img";
    pixelFile = new RandomAccessInputStream(pixelsFilename);
    LOGGER.info("Reading header");
    int fileSize = in.readInt();
    boolean little = fileSize != in.length();
    in.order(little);
    pixelFile.order(little);
    in.skipBytes(10);
    String imageName = in.readString(18);
    in.skipBytes(8);
    int ndims = in.readShort();
    int x = in.readShort();
    int y = in.readShort();
    int z = in.readShort();
    int t = in.readShort();
    in.skipBytes(20);
    int dataType = in.readShort();
    int nBitsPerPixel = in.readShort();
    String description = null;
    double voxelWidth = 0d, voxelHeight = 0d, sliceThickness = 0d, deltaT = 0d;
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        in.skipBytes(6);
        voxelWidth = in.readFloat();
        voxelHeight = in.readFloat();
        sliceThickness = in.readFloat();
        deltaT = in.readFloat();
        in.skipBytes(12);
        pixelOffset = (int) in.readFloat();
        in.skipBytes(12);
        float calibratedMax = in.readFloat();
        float calibratedMin = in.readFloat();
        float compressed = in.readFloat();
        float verified = in.readFloat();
        float pixelMax = in.readFloat();
        float pixelMin = in.readFloat();
        description = in.readString(80);
        String auxFile = in.readString(24);
        char orient = (char) in.readByte();
        String originator = in.readString(10);
        String generated = in.readString(10);
        String scannum = in.readString(10);
        String patientID = in.readString(10);
        String expDate = in.readString(10);
        String expTime = in.readString(10);
        in.skipBytes(3);
        int views = in.readInt();
        int volsAdded = in.readInt();
        int startField = in.readInt();
        int fieldSkip = in.readInt();
        int omax = in.readInt();
        int omin = in.readInt();
        int smax = in.readInt();
        int smin = in.readInt();
        addGlobalMeta("Database name", imageName);
        addGlobalMeta("Number of dimensions", ndims);
        addGlobalMeta("Data type", dataType);
        addGlobalMeta("Number of bits per pixel", nBitsPerPixel);
        addGlobalMeta("Voxel width", voxelWidth);
        addGlobalMeta("Voxel height", voxelHeight);
        addGlobalMeta("Slice thickness", sliceThickness);
        addGlobalMeta("Exposure time", deltaT);
        addGlobalMeta("Pixel offset", pixelOffset);
        addGlobalMeta("Calibrated maximum", calibratedMax);
        addGlobalMeta("Calibrated minimum", calibratedMin);
        addGlobalMeta("Compressed", compressed);
        addGlobalMeta("Verified", verified);
        addGlobalMeta("Pixel maximum", pixelMax);
        addGlobalMeta("Pixel minimum", pixelMin);
        addGlobalMeta("Description", description);
        addGlobalMeta("Auxiliary file", auxFile);
        addGlobalMeta("Orientation", orient);
        addGlobalMeta("Originator", originator);
        addGlobalMeta("Generated", generated);
        addGlobalMeta("Scan Number", scannum);
        addGlobalMeta("Patient ID", patientID);
        addGlobalMeta("Acquisition Date", expDate);
        addGlobalMeta("Acquisition Time", expTime);
    } else {
        in.skipBytes(34);
        pixelOffset = (int) in.readFloat();
    }
    LOGGER.info("Populating core metadata");
    CoreMetadata m = core.get(0);
    m.littleEndian = little;
    m.sizeX = x;
    m.sizeY = y;
    m.sizeZ = z;
    m.sizeT = t;
    m.sizeC = 1;
    if (getSizeZ() == 0)
        m.sizeZ = 1;
    if (getSizeT() == 0)
        m.sizeT = 1;
    m.imageCount = getSizeZ() * getSizeT();
    m.rgb = false;
    m.interleaved = false;
    m.indexed = false;
    m.dimensionOrder = "XYZTC";
    switch(dataType) {
        case 1:
        case 2:
            m.pixelType = FormatTools.UINT8;
            break;
        case 4:
            m.pixelType = FormatTools.INT16;
            break;
        case 8:
            m.pixelType = FormatTools.INT32;
            break;
        case 16:
            m.pixelType = FormatTools.FLOAT;
            break;
        case 64:
            m.pixelType = FormatTools.DOUBLE;
            break;
        case 128:
            m.pixelType = FormatTools.UINT8;
            m.sizeC = 3;
            m.rgb = true;
            m.interleaved = true;
            m.dimensionOrder = "XYCZT";
        default:
            throw new FormatException("Unsupported data type: " + dataType);
    }
    LOGGER.info("Populating MetadataStore");
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    store.setImageName(imageName, 0);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        store.setImageDescription(description, 0);
        Length sizeX = FormatTools.getPhysicalSizeX(voxelWidth, UNITS.MILLIMETER);
        Length sizeY = FormatTools.getPhysicalSizeY(voxelHeight, UNITS.MILLIMETER);
        Length sizeZ = FormatTools.getPhysicalSizeZ(sliceThickness, UNITS.MILLIMETER);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
        if (sizeZ != null) {
            store.setPixelsPhysicalSizeZ(sizeZ, 0);
        }
        store.setPixelsTimeIncrement(new Time(deltaT, UNITS.MILLISECOND), 0);
    }
}
Also used : Time(ome.units.quantity.Time) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) RandomAccessInputStream(loci.common.RandomAccessInputStream) Location(loci.common.Location)

Aggregations

MetadataStore (loci.formats.meta.MetadataStore)180 CoreMetadata (loci.formats.CoreMetadata)130 RandomAccessInputStream (loci.common.RandomAccessInputStream)97 Length (ome.units.quantity.Length)82 FormatException (loci.formats.FormatException)66 Timestamp (ome.xml.model.primitives.Timestamp)54 Location (loci.common.Location)51 Time (ome.units.quantity.Time)41 ArrayList (java.util.ArrayList)34 IFD (loci.formats.tiff.IFD)21 DependencyException (loci.common.services.DependencyException)16 IOException (java.io.IOException)15 TiffParser (loci.formats.tiff.TiffParser)15 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)15 ServiceFactory (loci.common.services.ServiceFactory)14 PositiveInteger (ome.xml.model.primitives.PositiveInteger)13 IFDList (loci.formats.tiff.IFDList)12 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)11 ServiceException (loci.common.services.ServiceException)10 Map (java.util.Map)9