Search in sources :

Example 91 with CoreMetadata

use of loci.formats.CoreMetadata 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 92 with CoreMetadata

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

Example 93 with CoreMetadata

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

the class AmiraReader method initFile.

/* (non-Javadoc)
   * @see loci.formats.FormatReader#initFile(java.lang.String)
   */
@Override
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    in = new RandomAccessInputStream(id);
    AmiraParameters parameters = new AmiraParameters(in);
    offsetOfFirstStream = in.getFilePointer();
    LOGGER.info("Populating metadata hashtable");
    addGlobalMeta("Image width", parameters.width);
    addGlobalMeta("Image height", parameters.height);
    addGlobalMeta("Number of planes", parameters.depth);
    addGlobalMeta("Bits per pixel", 8);
    LOGGER.info("Populating core metadata");
    int channelIndex = 1;
    while (parameters.getStreams().get("@" + channelIndex) != null) {
        channelIndex++;
    }
    CoreMetadata m = core.get(0);
    m.sizeX = parameters.width;
    m.sizeY = parameters.height;
    m.sizeZ = parameters.depth;
    m.sizeT = 1;
    m.sizeC = channelIndex - 1;
    m.imageCount = getSizeZ() * getSizeC();
    m.littleEndian = parameters.littleEndian;
    m.dimensionOrder = "XYZCT";
    String streamType = parameters.streamTypes[0].toLowerCase();
    if (streamType.equals("byte")) {
        m.pixelType = FormatTools.UINT8;
    } else if (streamType.equals("short")) {
        m.pixelType = FormatTools.INT16;
        addGlobalMeta("Bits per pixel", 16);
    } else if (streamType.equals("ushort")) {
        m.pixelType = FormatTools.UINT16;
        addGlobalMeta("Bits per pixel", 16);
    } else if (streamType.equals("int")) {
        m.pixelType = FormatTools.INT32;
        addGlobalMeta("Bits per pixel", 32);
    } else if (streamType.equals("float")) {
        m.pixelType = FormatTools.FLOAT;
        addGlobalMeta("Bits per pixel", 32);
    } else {
        LOGGER.warn("Assuming data type is byte");
        m.pixelType = FormatTools.UINT8;
    }
    LOGGER.info("Populating metadata store");
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    // The bounding box is the range of the centre of the voxels
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        double pixelWidth = (double) (parameters.x1 - parameters.x0) / (parameters.width - 1);
        double pixelHeight = (double) (parameters.y1 - parameters.y0) / (parameters.height - 1);
        // TODO - what is correct setting if single slice?
        double pixelDepth = (double) (parameters.z1 - parameters.z0) / (parameters.depth - 1);
        // Amira does not have a standard form for encoding units, so we just
        // have to assume microns for microscopy data
        addGlobalMeta("Pixels per meter (X)", 1e6 / pixelWidth);
        addGlobalMeta("Pixels per meter (Y)", 1e6 / pixelHeight);
        addGlobalMeta("Pixels per meter (Z)", 1e6 / pixelDepth);
        Length sizeX = FormatTools.getPhysicalSizeX(pixelWidth);
        Length sizeY = FormatTools.getPhysicalSizeY(pixelHeight);
        Length sizeZ = FormatTools.getPhysicalSizeZ(pixelDepth);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
        if (sizeZ != null) {
            store.setPixelsPhysicalSizeZ(sizeZ, 0);
        }
    }
    ascii = parameters.ascii;
    ArrayList streamData = (ArrayList) parameters.getStreams().get("@1");
    if (streamData.size() > 2) {
        compression = (String) streamData.get(2);
    }
    initPlaneReader();
    hasPlaneReader = planeReader != null;
    addGlobalMeta("Compression", compression);
    Map params = (Map) parameters.getMap().get("Parameters");
    if (params != null) {
        Map materials = (Map) params.get("Materials");
        if (materials != null) {
            lut = getLookupTable(materials);
            m.indexed = true;
        }
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) ArrayList(java.util.ArrayList) AmiraParameters(loci.formats.tools.AmiraParameters) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata) Map(java.util.Map)

Example 94 with CoreMetadata

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

the class BDReader method readMetaData.

private IniList readMetaData(String id) throws IOException {
    IniParser parser = new IniParser();
    RandomAccessInputStream idStream = new RandomAccessInputStream(id);
    IniList exp = parser.parseINI(new BufferedReader(new InputStreamReader(idStream, Constants.ENCODING)));
    IniList plate = null;
    IniList xyz = null;
    // Read Plate File
    for (String filename : metadataFiles) {
        if (checkSuffix(filename, "plt")) {
            RandomAccessInputStream stream = new RandomAccessInputStream(filename);
            plate = parser.parseINI(new BufferedReader(new InputStreamReader(stream, Constants.ENCODING)));
            stream.close();
        } else if (checkSuffix(filename, "xyz")) {
            RandomAccessInputStream stream = new RandomAccessInputStream(filename);
            xyz = parser.parseINI(new BufferedReader(new InputStreamReader(stream, Constants.ENCODING)));
            stream.close();
        } else if (filename.endsWith("RoiSummary.txt")) {
            roiFile = filename;
            if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
                RandomAccessInputStream s = new RandomAccessInputStream(filename);
                String line = s.readLine().trim();
                while (!line.endsWith(".adf\"")) {
                    line = s.readLine().trim();
                }
                plateName = line.substring(line.indexOf(':')).trim();
                plateName = plateName.replace('/', File.separatorChar);
                plateName = plateName.replace('\\', File.separatorChar);
                for (int i = 0; i < 3; i++) {
                    plateName = plateName.substring(0, plateName.lastIndexOf(File.separator));
                }
                plateName = plateName.substring(plateName.lastIndexOf(File.separator) + 1);
                s.close();
            }
        }
    }
    if (plate == null)
        throw new IOException("No Plate File");
    IniTable plateType = plate.getTable("PlateType");
    if (plateName == null) {
        plateName = plateType.get("Brand");
    }
    plateDescription = plateType.get("Brand") + " " + plateType.get("Description");
    int nWells = Integer.parseInt(plateType.get("Wells"));
    if (nWells == 96) {
        wellRows = 8;
        wellCols = 12;
    } else if (nWells == 384) {
        wellRows = 16;
        wellCols = 24;
    }
    for (String filename : rootList) {
        String name = new Location(filename).getName();
        if (name.startsWith("Well ")) {
            wellLabels.add(name.split("\\s|\\.")[1]);
        }
    }
    IniTable imageTable = exp.getTable("Image");
    boolean montage = imageTable.get("Montaged").equals("1");
    if (montage) {
        fieldRows = Integer.parseInt(imageTable.get("TilesY"));
        fieldCols = Integer.parseInt(imageTable.get("TilesX"));
    } else {
        fieldRows = 1;
        fieldCols = 1;
    }
    core.clear();
    int coresize = wellLabels.size() * fieldRows * fieldCols;
    CoreMetadata ms0 = new CoreMetadata();
    core.add(ms0);
    for (int i = 1; i < coresize; i++) {
        core.add(new CoreMetadata());
    }
    ms0.sizeC = Integer.parseInt(exp.getTable("General").get("Dyes"));
    ms0.bitsPerPixel = Integer.parseInt(exp.getTable("Camera").get("BitdepthUsed"));
    IniTable dyeTable = exp.getTable("Dyes");
    for (int i = 1; i <= getSizeC(); i++) {
        channelNames.add(dyeTable.get(Integer.toString(i)));
    }
    if (xyz != null) {
        IniTable zTable = xyz.getTable("Z1Axis");
        boolean zEnabled = "1".equals(zTable.get("Z1AxisEnabled")) && "1".equals(zTable.get("Z1AxisMode"));
        if (zEnabled) {
            ms0.sizeZ = (int) Double.parseDouble(zTable.get("Z1AxisValue")) + 1;
        } else {
            ms0.sizeZ = 1;
        }
    } else {
        ms0.sizeZ = 1;
    }
    // Count Images
    ms0.sizeT = 0;
    for (String channelName : channelNames) {
        int images = 0;
        for (String filename : wellList.get(1)) {
            if (filename.startsWith(channelName) && filename.endsWith(".tif")) {
                images++;
            }
        }
        if (images > getImageCount()) {
            ms0.sizeT = images / getSizeZ();
            ms0.imageCount = getSizeZ() * getSizeT() * channelNames.size();
        }
    }
    idStream.close();
    return exp;
}
Also used : IniParser(loci.common.IniParser) InputStreamReader(java.io.InputStreamReader) IniList(loci.common.IniList) IniTable(loci.common.IniTable) BufferedReader(java.io.BufferedReader) RandomAccessInputStream(loci.common.RandomAccessInputStream) IOException(java.io.IOException) CoreMetadata(loci.formats.CoreMetadata) Location(loci.common.Location)

Example 95 with CoreMetadata

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

the class BDReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    // make sure we have the experiment file
    id = locateExperimentFile(id);
    super.initFile(id);
    Location dir = new Location(id).getAbsoluteFile().getParentFile();
    rootList = dir.list(true);
    Arrays.sort(rootList);
    for (int i = 0; i < rootList.length; i++) {
        String file = rootList[i];
        Location f = new Location(dir, file);
        rootList[i] = f.getAbsolutePath();
        if (!f.isDirectory()) {
            if (checkSuffix(file, META_EXT) && !f.isDirectory()) {
                metadataFiles.add(f.getAbsolutePath());
            }
        } else {
            String[] wells = f.list(true);
            Arrays.sort(wells);
            wellList.add(wells);
            for (String well : wells) {
                Location wellFile = new Location(f, well);
                if (!wellFile.isDirectory()) {
                    if (checkSuffix(well, META_EXT)) {
                        metadataFiles.add(wellFile.getAbsolutePath());
                    }
                }
            }
        }
    }
    // parse Experiment metadata
    IniList experiment = readMetaData(id);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        objective = experiment.getTable("Geometry").get("Name");
        IniTable camera = experiment.getTable("Camera");
        binning = camera.get("BinX") + "x" + camera.get("BinY");
        parseChannelData(dir);
        addGlobalMeta("Objective", objective);
        addGlobalMeta("Camera binning", binning);
    }
    final List<String> uniqueRows = new ArrayList<String>();
    final List<String> uniqueColumns = new ArrayList<String>();
    for (String well : wellLabels) {
        String row = well.substring(0, 1).trim();
        String column = well.substring(1).trim();
        if (!uniqueRows.contains(row) && row.length() > 0)
            uniqueRows.add(row);
        if (!uniqueColumns.contains(column) && column.length() > 0) {
            uniqueColumns.add(column);
        }
    }
    int nSlices = getSizeZ() == 0 ? 1 : getSizeZ();
    int nTimepoints = getSizeT();
    int nWells = wellLabels.size();
    int nChannels = getSizeC() == 0 ? channelNames.size() : getSizeC();
    if (nChannels == 0)
        nChannels = 1;
    tiffs = getTiffs();
    reader = new MinimalTiffReader();
    reader.setId(tiffs[0][0]);
    int sizeX = reader.getSizeX();
    int sizeY = reader.getSizeY();
    int pixelType = reader.getPixelType();
    boolean rgb = reader.isRGB();
    boolean interleaved = reader.isInterleaved();
    boolean indexed = reader.isIndexed();
    boolean littleEndian = reader.isLittleEndian();
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        IniParser parser = new IniParser();
        for (String metadataFile : metadataFiles) {
            String filename = new Location(metadataFile).getName();
            if (!checkSuffix(metadataFile, new String[] { "txt", "bmp", "adf", "roi" })) {
                String data = DataTools.readFile(metadataFile);
                IniList ini = parser.parseINI(new BufferedReader(new StringReader(data)));
                HashMap<String, String> h = ini.flattenIntoHashMap();
                for (String key : h.keySet()) {
                    addGlobalMeta(filename + " " + key, h.get(key));
                }
            }
        }
    }
    int coresize = core.size();
    core.clear();
    for (int i = 0; i < coresize; i++) {
        CoreMetadata ms = new CoreMetadata();
        core.add(ms);
        ms.sizeC = nChannels;
        ms.sizeZ = nSlices;
        ms.sizeT = nTimepoints;
        ms.sizeX = sizeX / fieldCols;
        ms.sizeY = sizeY / fieldRows;
        ms.pixelType = pixelType;
        ms.rgb = rgb;
        ms.interleaved = interleaved;
        ms.indexed = indexed;
        ms.littleEndian = littleEndian;
        ms.dimensionOrder = "XYZTC";
        ms.imageCount = nSlices * nTimepoints * nChannels;
    }
    MetadataStore store = makeFilterMetadata();
    boolean populatePlanes = getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM;
    MetadataTools.populatePixels(store, this, populatePlanes);
    String plateAcqID = MetadataTools.createLSID("PlateAcquisition", 0, 0);
    store.setPlateAcquisitionID(plateAcqID, 0, 0);
    PositiveInteger fieldCount = FormatTools.getMaxFieldCount(fieldRows * fieldCols);
    if (fieldCount != null) {
        store.setPlateAcquisitionMaximumFieldCount(fieldCount, 0, 0);
    }
    for (int row = 0; row < wellRows; row++) {
        for (int col = 0; col < wellCols; col++) {
            int index = row * wellCols + col;
            store.setWellID(MetadataTools.createLSID("Well", 0, index), 0, index);
            store.setWellRow(new NonNegativeInteger(row), 0, index);
            store.setWellColumn(new NonNegativeInteger(col), 0, index);
        }
    }
    for (int i = 0; i < getSeriesCount(); i++) {
        int well = i / (fieldRows * fieldCols);
        int field = i % (fieldRows * fieldCols);
        MetadataTools.setDefaultCreationDate(store, tiffs[well][0], i);
        String name = wellLabels.get(well);
        String row = name.substring(0, 1);
        Integer col = Integer.parseInt(name.substring(1));
        int index = (row.charAt(0) - 'A') * wellCols + col - 1;
        String wellSampleID = MetadataTools.createLSID("WellSample", 0, index, field);
        store.setWellSampleID(wellSampleID, 0, index, field);
        store.setWellSampleIndex(new NonNegativeInteger(i), 0, index, field);
        String imageID = MetadataTools.createLSID("Image", i);
        store.setWellSampleImageRef(imageID, 0, index, field);
        store.setImageID(imageID, i);
        store.setImageName(name + " Field #" + (field + 1), i);
        store.setPlateAcquisitionWellSampleRef(wellSampleID, 0, 0, i);
    }
    MetadataLevel level = getMetadataOptions().getMetadataLevel();
    if (level != MetadataLevel.MINIMUM) {
        String instrumentID = MetadataTools.createLSID("Instrument", 0);
        store.setInstrumentID(instrumentID, 0);
        String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
        store.setObjectiveID(objectiveID, 0, 0);
        if (objective != null) {
            String[] tokens = objective.split(" ");
            String mag = tokens[0].replaceAll("[xX]", "");
            String na = null;
            int naIndex = 0;
            for (int i = 0; i < tokens.length; i++) {
                if (tokens[i].equals("NA")) {
                    naIndex = i + 1;
                    na = tokens[naIndex];
                    break;
                }
            }
            Double magnification = new Double(mag);
            store.setObjectiveNominalMagnification(magnification, 0, 0);
            if (na != null) {
                na = na.substring(0, 1) + "." + na.substring(1);
                store.setObjectiveLensNA(new Double(na), 0, 0);
            }
            if (naIndex + 1 < tokens.length) {
                store.setObjectiveManufacturer(tokens[naIndex + 1], 0, 0);
            }
        }
        // populate LogicalChannel data
        for (int i = 0; i < getSeriesCount(); i++) {
            store.setImageInstrumentRef(instrumentID, i);
            store.setObjectiveSettingsID(objectiveID, i);
            for (int c = 0; c < getSizeC(); c++) {
                store.setChannelName(channelNames.get(c), i, c);
                Length emission = FormatTools.getEmissionWavelength(emWave[c]);
                Length excitation = FormatTools.getExcitationWavelength(exWave[c]);
                if (emission != null) {
                    store.setChannelEmissionWavelength(emission, i, c);
                }
                if (excitation != null) {
                    store.setChannelExcitationWavelength(excitation, i, c);
                }
                String detectorID = MetadataTools.createLSID("Detector", 0, c);
                store.setDetectorID(detectorID, 0, c);
                store.setDetectorSettingsID(detectorID, i, c);
                store.setDetectorSettingsGain(gain[c], i, c);
                store.setDetectorSettingsOffset(offset[c], i, c);
                store.setDetectorSettingsBinning(getBinning(binning), i, c);
            }
            long firstPlane = 0;
            for (int p = 0; p < getImageCount(); p++) {
                int[] zct = getZCTCoords(p);
                store.setPlaneExposureTime(new Time(exposure[zct[1]], UNITS.SECOND), i, p);
                String file = getFilename(i, p);
                if (file != null) {
                    long plane = getTimestamp(file);
                    if (p == 0) {
                        firstPlane = plane;
                    }
                    double timestamp = (plane - firstPlane) / 1000.0;
                    store.setPlaneDeltaT(new Time(timestamp, UNITS.SECOND), i, p);
                }
            }
        }
        store.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
        store.setPlateRowNamingConvention(getNamingConvention("Letter"), 0);
        store.setPlateColumnNamingConvention(getNamingConvention("Number"), 0);
        store.setPlateName(plateName, 0);
        store.setPlateDescription(plateDescription, 0);
        if (level != MetadataLevel.NO_OVERLAYS) {
            parseROIs(store);
        }
    }
}
Also used : IniParser(loci.common.IniParser) IniList(loci.common.IniList) ArrayList(java.util.ArrayList) Time(ome.units.quantity.Time) StringReader(java.io.StringReader) PositiveInteger(ome.xml.model.primitives.PositiveInteger) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) CoreMetadata(loci.formats.CoreMetadata) MetadataStore(loci.formats.meta.MetadataStore) PositiveInteger(ome.xml.model.primitives.PositiveInteger) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) Length(ome.units.quantity.Length) IniTable(loci.common.IniTable) BufferedReader(java.io.BufferedReader) Location(loci.common.Location)

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