Search in sources :

Example 46 with Length

use of ome.units.quantity.Length in project bioformats by openmicroscopy.

the class BioRadReader method parseNotes.

private boolean parseNotes(MetadataStore store) throws FormatException {
    boolean multipleFiles = false;
    int nextDetector = 0, nLasers = 0;
    for (Note n : noteStrings) {
        if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
            switch(n.type) {
                case NOTE_TYPE_USER:
                    // TODO : this should be an overlay
                    addGlobalMetaList("Note", n.toString());
                    break;
                case NOTE_TYPE_SCALEBAR:
                    // TODO : this should be an overlay
                    // the format of the text is:
                    // SCALEBAR = <length> <angle>
                    // where <length> is the length of the scalebar in microns,
                    // and <angle> is the angle in degrees
                    addGlobalMetaList("Note", n.toString());
                    break;
                case NOTE_TYPE_ARROW:
                    // TODO : this should be an overlay
                    // the format of the text is:
                    // ARROW = <lx> <ly> <angle> <fill>
                    // where <lx> and <ly> define the arrow's bounding box,
                    // <angle> is the angle in degrees and <fill> is either "Fill" or
                    // "Outline"
                    addGlobalMetaList("Note", n.toString());
                    break;
                case NOTE_TYPE_VARIABLE:
                    if (n.p.indexOf('=') >= 0) {
                        String key = n.p.substring(0, n.p.indexOf('=')).trim();
                        String value = n.p.substring(n.p.indexOf('=') + 1).trim();
                        addGlobalMeta(key, value);
                        if (key.equals("INFO_OBJECTIVE_NAME")) {
                            store.setObjectiveModel(value, 0, 0);
                        } else if (key.equals("INFO_OBJECTIVE_MAGNIFICATION")) {
                            Double mag = Double.parseDouble(value);
                            store.setObjectiveNominalMagnification(mag, 0, 0);
                        } else if (key.equals("LENS_MAGNIFICATION")) {
                            Double magnification = Double.parseDouble(value);
                            store.setObjectiveNominalMagnification(magnification, 0, 0);
                        } else if (key.startsWith("SETTING")) {
                            if (key.indexOf("_DET_") != -1) {
                                int index = key.indexOf("_DET_") + 5;
                                if (key.lastIndexOf("_") > index) {
                                    String detectorID = MetadataTools.createLSID("Detector", 0, nextDetector);
                                    store.setDetectorID(detectorID, 0, nextDetector);
                                    store.setDetectorType(getDetectorType("Other"), 0, nextDetector);
                                    if (key.endsWith("OFFSET")) {
                                        if (nextDetector < offset.size()) {
                                            offset.set(nextDetector, Double.parseDouble(value));
                                        } else {
                                            while (nextDetector > offset.size()) {
                                                offset.add(null);
                                            }
                                            offset.add(new Double(value));
                                        }
                                    } else if (key.endsWith("GAIN")) {
                                        if (nextDetector < gain.size()) {
                                            gain.set(nextDetector, Double.parseDouble(value));
                                        } else {
                                            while (nextDetector > gain.size()) {
                                                gain.add(null);
                                            }
                                            gain.add(new Double(value));
                                        }
                                    }
                                    nextDetector++;
                                }
                            }
                        } else {
                            String[] values = value.split(" ");
                            if (values.length > 1) {
                                try {
                                    int type = Integer.parseInt(values[0]);
                                    if (type == 257 && values.length >= 3) {
                                        // found length of axis in um
                                        Double pixelSize = new Double(values[2]);
                                        if (key.equals("AXIS_2")) {
                                            Length size = FormatTools.getPhysicalSizeX(pixelSize);
                                            if (size != null) {
                                                store.setPixelsPhysicalSizeX(size, 0);
                                            }
                                        } else if (key.equals("AXIS_3")) {
                                            Length size = FormatTools.getPhysicalSizeY(pixelSize);
                                            if (size != null) {
                                                store.setPixelsPhysicalSizeY(size, 0);
                                            }
                                        }
                                    }
                                } catch (NumberFormatException e) {
                                }
                            }
                        }
                    } else if (n.p.startsWith("AXIS_2")) {
                        String[] values = n.p.split(" ");
                        Double pixelSize = new Double(values[3]);
                        Length size = FormatTools.getPhysicalSizeX(pixelSize);
                        if (size != null) {
                            store.setPixelsPhysicalSizeX(size, 0);
                        }
                    } else if (n.p.startsWith("AXIS_3")) {
                        String[] values = n.p.split(" ");
                        Double pixelSize = new Double(values[3]);
                        Length size = FormatTools.getPhysicalSizeY(pixelSize);
                        if (size != null) {
                            store.setPixelsPhysicalSizeY(size, 0);
                        }
                    } else {
                        addGlobalMetaList("Note", n.toString());
                    }
                    break;
                case NOTE_TYPE_STRUCTURE:
                    int structureType = (n.x & 0xff00) >> 8;
                    int version = (n.x & 0xff);
                    String[] values = n.p.split(" ");
                    if (structureType == 1) {
                        switch(n.y) {
                            case 1:
                                for (int i = 0; i < STRUCTURE_LABELS_1.length; i++) {
                                    addGlobalMeta(STRUCTURE_LABELS_1[i], values[i]);
                                }
                                Double mag = Double.parseDouble(values[11]);
                                store.setObjectiveNominalMagnification(mag, 0, 0);
                                Double sizeZ = new Double(values[14]);
                                Length size = FormatTools.getPhysicalSizeZ(sizeZ);
                                if (size != null) {
                                    store.setPixelsPhysicalSizeZ(size, 0);
                                }
                                break;
                            case 2:
                                for (int i = 0; i < STRUCTURE_LABELS_2.length; i++) {
                                    addGlobalMeta(STRUCTURE_LABELS_2[i], values[i]);
                                }
                                double x1 = Double.parseDouble(values[2]);
                                double x2 = Double.parseDouble(values[4]);
                                double width = x2 - x1;
                                width /= getSizeX();
                                double y1 = Double.parseDouble(values[3]);
                                double y2 = Double.parseDouble(values[5]);
                                double height = y2 - y1;
                                height /= getSizeY();
                                Length sizeX = FormatTools.getPhysicalSizeX(width);
                                Length sizeY = FormatTools.getPhysicalSizeY(height);
                                if (sizeX != null) {
                                    store.setPixelsPhysicalSizeX(sizeX, 0);
                                }
                                if (sizeY != null) {
                                    store.setPixelsPhysicalSizeY(sizeY, 0);
                                }
                                break;
                            case 3:
                                for (int i = 0; i < 3; i++) {
                                    for (int j = 0; j < STRUCTURE_LABELS_3.length; j++) {
                                        String v = j == STRUCTURE_LABELS_3.length - 1 ? values[12 + i] : values[i * 4 + j];
                                        addGlobalMetaList(STRUCTURE_LABELS_3[j], v);
                                    }
                                }
                                break;
                            case 4:
                                nLasers = Integer.parseInt(values[0]);
                                addGlobalMeta("Number of lasers", values[0]);
                                addGlobalMeta("Number of transmission detectors", values[1]);
                                addGlobalMeta("Number of PMTs", values[2]);
                                for (int i = 1; i <= 3; i++) {
                                    int idx = (i + 1) * 3;
                                    addGlobalMetaList("Shutter present for laser", values[i + 2]);
                                    addGlobalMetaList("Neutral density filter for laser", values[idx]);
                                    addGlobalMetaList("Excitation filter for laser", values[idx + 1]);
                                    addGlobalMetaList("Use laser", values[idx + 2]);
                                }
                                for (int i = 0; i < nLasers; i++) {
                                    addGlobalMetaList("Neutral density filter name - laser", values[15 + i]);
                                }
                                break;
                            case 5:
                                String prefix = "Excitation filter name - laser";
                                for (int i = 0; i < nLasers; i++) {
                                    addGlobalMetaList(prefix, values[i]);
                                }
                                break;
                            case 6:
                                prefix = "Emission filter name - laser";
                                for (int i = 0; i < nLasers; i++) {
                                    addGlobalMeta(prefix, values[i]);
                                }
                                break;
                            case 7:
                                for (int i = 0; i < 2; i++) {
                                    prefix = "Mixer " + i + " - ";
                                    for (int j = 0; j < STRUCTURE_LABELS_4.length; j++) {
                                        addGlobalMeta(prefix + STRUCTURE_LABELS_4[j], values[i * 7 + j]);
                                    }
                                }
                                addGlobalMeta("Mixer 0 - low signal on", values[14]);
                                addGlobalMeta("Mixer 1 - low signal on", values[15]);
                                break;
                            case 8:
                            case 9:
                            case 10:
                                addGlobalMeta("Laser name - laser " + (n.y - 7), values[0]);
                                break;
                            case 11:
                                for (int i = 0; i < 3; i++) {
                                    prefix = "Transmission detector " + (i + 1) + " - ";
                                    addGlobalMeta(prefix + "offset", values[i * 3]);
                                    addGlobalMeta(prefix + "gain", values[i * 3 + 1]);
                                    addGlobalMeta(prefix + "black level", values[i * 3 + 2]);
                                    String detectorID = MetadataTools.createLSID("Detector", 0, i);
                                    store.setDetectorID(detectorID, 0, i);
                                    store.setDetectorOffset(new Double(values[i * 3]), 0, i);
                                    store.setDetectorGain(new Double(values[i * 3 + 1]), 0, i);
                                    store.setDetectorType(getDetectorType("Other"), 0, i);
                                }
                                break;
                            case 12:
                                for (int i = 0; i < 2; i++) {
                                    prefix = "Part number for ";
                                    for (int j = 0; j < STRUCTURE_LABELS_5.length; j++) {
                                        addGlobalMetaList(prefix + STRUCTURE_LABELS_5[j], values[i * 4 + j]);
                                    }
                                }
                                break;
                            case 13:
                                for (int i = 0; i < STRUCTURE_LABELS_6.length; i++) {
                                    addGlobalMeta(STRUCTURE_LABELS_6[i], values[i]);
                                }
                                break;
                            case 14:
                                prefix = "Filter Block Name - filter block ";
                                addGlobalMetaList(prefix, values[0]);
                                addGlobalMetaList(prefix, values[1]);
                                break;
                            case 15:
                                for (int i = 0; i < 5; i++) {
                                    addGlobalMetaList("Image bands status - band", values[i * 3]);
                                    addGlobalMetaList("Image bands min - band", values[i * 3 + 1]);
                                    addGlobalMetaList("Image bands max - band", values[i * 3 + 2]);
                                    if (store instanceof IMinMaxStore) {
                                        ((IMinMaxStore) store).setChannelGlobalMinMax(i, Double.parseDouble(values[i * 3 + 1]), Double.parseDouble(values[i * 3 + 2]), 0);
                                    }
                                }
                                break;
                            case 17:
                                int year = Integer.parseInt(values[5]) + 1900;
                                for (int i = 0; i < 5; i++) {
                                    if (values[i].length() == 1)
                                        values[i] = "0" + values[i];
                                }
                                // date is in yyyy-MM-dd'T'HH:mm:ss
                                String date = year + "-" + values[4] + "-" + values[3] + "T" + values[2] + ":" + values[1] + ":" + values[0];
                                addGlobalMeta("Acquisition date", date);
                                try {
                                    store.setImageAcquisitionDate(new Timestamp(date), 0);
                                } catch (Exception e) {
                                    LOGGER.debug("Failed to parse acquisition date", e);
                                }
                                break;
                            case 18:
                                addGlobalMeta("Mixer 3 - enhanced", values[0]);
                                for (int i = 1; i <= 3; i++) {
                                    addGlobalMetaList("Mixer 3 - PMT percentage", values[i]);
                                    addGlobalMetaList("Mixer 3 - Transmission percentage", values[i + 3]);
                                    addGlobalMetaList("Mixer 3 - photon counting", values[i + 7]);
                                }
                                addGlobalMeta("Mixer 3 - low signal on", values[7]);
                                addGlobalMeta("Mixer 3 - mode", values[11]);
                                break;
                            case 19:
                                for (int i = 1; i <= 2; i++) {
                                    prefix = "Mixer " + i + " - ";
                                    String photon = prefix + "photon counting ";
                                    addGlobalMetaList(photon, values[i * 4 - 4]);
                                    addGlobalMetaList(photon, values[i * 4 - 3]);
                                    addGlobalMetaList(photon, values[i * 4 - 2]);
                                    addGlobalMeta(prefix + "mode", values[i * 4 - 1]);
                                }
                                break;
                            case 20:
                                addGlobalMeta("Display mode", values[0]);
                                addGlobalMeta("Course", values[1]);
                                addGlobalMeta("Time Course - experiment type", values[2]);
                                addGlobalMeta("Time Course - kd factor", values[3]);
                                String experimentID = MetadataTools.createLSID("Experiment", 0);
                                store.setExperimentID(experimentID, 0);
                                store.setExperimentType(getExperimentType(values[2]), 0);
                                break;
                            case 21:
                                addGlobalMeta("Time Course - ion name", values[0]);
                                break;
                            case 22:
                                addGlobalMeta("PIC file generated on Isoscan (lite)", values[0]);
                                for (int i = 1; i <= 3; i++) {
                                    addGlobalMetaList("Photon counting used - PMT", values[i]);
                                    addGlobalMetaList("Hot spot filter used - PMT", values[i + 3]);
                                    addGlobalMetaList("Tx Selector used - TX", values[i + 6]);
                                }
                                break;
                        }
                    }
                    break;
                default:
                    // notes for display only
                    addGlobalMetaList("Note", n.toString());
            }
        }
        if (n.p.indexOf("AXIS") != -1) {
            n.p = n.p.replaceAll("=", "");
            final List<String> v = new ArrayList<String>();
            StringTokenizer tokens = new StringTokenizer(n.p, " ");
            while (tokens.hasMoreTokens()) {
                String token = tokens.nextToken().trim();
                if (token.length() > 0)
                    v.add(token);
            }
            String[] values = v.toArray(new String[v.size()]);
            String key = values[0];
            String noteType = values[1];
            int axisType = Integer.parseInt(noteType);
            if (axisType == 11 && values.length > 2) {
                addGlobalMeta(key + " RGB type (X)", values[2]);
                addGlobalMeta(key + " RGB type (Y)", values[3]);
                CoreMetadata m = core.get(0);
                if (key.equals("AXIS_4")) {
                    // this is a single section multi-channel dataset
                    m.sizeC = getImageCount();
                    m.sizeZ = 1;
                    m.sizeT = 1;
                } else if (key.equals("AXIS_9")) {
                    multipleFiles = true;
                    m.sizeC = (int) Double.parseDouble(values[3]);
                }
            }
            if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM && values.length > 2) {
                switch(axisType) {
                    case 1:
                        addGlobalMeta(key + " distance (X) in microns", values[2]);
                        addGlobalMeta(key + " distance (Y) in microns", values[3]);
                        break;
                    case 3:
                        addGlobalMeta(key + " angle (X) in degrees", values[2]);
                        addGlobalMeta(key + " angle (Y) in degrees", values[3]);
                        break;
                    case 4:
                        addGlobalMeta(key + " intensity (X)", values[2]);
                        addGlobalMeta(key + " intensity (Y)", values[3]);
                        break;
                    case 6:
                        addGlobalMeta(key + " ratio (X)", values[2]);
                        addGlobalMeta(key + " ratio (Y)", values[3]);
                        break;
                    case 7:
                        addGlobalMeta(key + " log ratio (X)", values[2]);
                        addGlobalMeta(key + " log ratio (Y)", values[3]);
                        break;
                    case 9:
                        addGlobalMeta(key + " noncalibrated intensity min", values[2]);
                        addGlobalMeta(key + " noncalibrated intensity max", values[3]);
                        addGlobalMeta(key + " calibrated intensity min", values[4]);
                        addGlobalMeta(key + " calibrated intensity max", values[5]);
                        break;
                    case 14:
                        addGlobalMeta(key + " time course type (X)", values[2]);
                        addGlobalMeta(key + " time course type (Y)", values[3]);
                        break;
                    case 15:
                        String prefix = " inverse sigmoid calibrated intensity ";
                        addGlobalMeta(key + prefix + "(min)", values[2]);
                        addGlobalMeta(key + prefix + "(max)", values[3]);
                        addGlobalMeta(key + prefix + "(beta)", values[4]);
                        addGlobalMeta(key + prefix + "(Kd)", values[5]);
                        break;
                    case 16:
                        prefix = " log inverse sigmoid calibrated intensity ";
                        addGlobalMeta(key + prefix + "(min)", values[2]);
                        addGlobalMeta(key + prefix + "(max)", values[3]);
                        addGlobalMeta(key + prefix + "(beta)", values[4]);
                        addGlobalMeta(key + prefix + "(Kd)", values[5]);
                        break;
                }
            }
        }
    }
    return multipleFiles;
}
Also used : ArrayList(java.util.ArrayList) Timestamp(ome.xml.model.primitives.Timestamp) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException) IOException(java.io.IOException) StringTokenizer(java.util.StringTokenizer) Length(ome.units.quantity.Length) IMinMaxStore(loci.formats.meta.IMinMaxStore)

Example 47 with Length

use of ome.units.quantity.Length 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 48 with Length

use of ome.units.quantity.Length 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 49 with Length

use of ome.units.quantity.Length 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 50 with Length

use of ome.units.quantity.Length 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

Length (ome.units.quantity.Length)154 MetadataStore (loci.formats.meta.MetadataStore)82 CoreMetadata (loci.formats.CoreMetadata)74 Timestamp (ome.xml.model.primitives.Timestamp)52 RandomAccessInputStream (loci.common.RandomAccessInputStream)48 Time (ome.units.quantity.Time)46 FormatException (loci.formats.FormatException)39 Location (loci.common.Location)34 ArrayList (java.util.ArrayList)29 IMetadata (loci.formats.meta.IMetadata)13 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)13 ServiceFactory (loci.common.services.ServiceFactory)12 IOException (java.io.IOException)11 DependencyException (loci.common.services.DependencyException)11 PositiveInteger (ome.xml.model.primitives.PositiveInteger)11 MetadataRetrieve (loci.formats.meta.MetadataRetrieve)10 ElectricPotential (ome.units.quantity.ElectricPotential)9 Test (org.testng.annotations.Test)9 Element (org.w3c.dom.Element)9 NodeList (org.w3c.dom.NodeList)9