Search in sources :

Example 96 with IFD

use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.

the class FlexReader method groupFiles.

private void groupFiles(String[] fileList, MetadataStore store) throws FormatException, IOException {
    LOGGER.info("Grouping together files in the same dataset");
    HashMap<String, ArrayList<String>> v = new HashMap<String, ArrayList<String>>();
    Boolean firstCompressed = null;
    int firstIFDCount = 0;
    for (String file : fileList) {
        LOGGER.warn("parsing {}", file);
        RandomAccessInputStream s = new RandomAccessInputStream(file, 16);
        TiffParser parser = new TiffParser(s);
        IFD firstIFD = parser.getFirstIFD();
        int ifdCount = parser.getIFDOffsets().length;
        s.close();
        boolean compressed = firstIFD.getCompression() != TiffCompression.UNCOMPRESSED;
        if (firstCompressed == null) {
            firstCompressed = compressed;
            firstIFDCount = ifdCount;
        }
        if (compressed == firstCompressed && ifdCount == firstIFDCount) {
            int[] well = getWell(file);
            int field = getField(file);
            if (well[0] > nRows)
                nRows = well[0];
            if (well[1] > nCols)
                nCols = well[1];
            if (fileList.length == 1) {
                well[0] = 0;
                well[1] = 0;
            }
            ArrayList<String> files = v.get(well[0] + "," + well[1]);
            if (files == null) {
                files = new ArrayList<String>();
            }
            files.add(file);
            v.put(well[0] + "," + well[1], files);
        } else {
            v.clear();
            ArrayList<String> files = new ArrayList<String>();
            files.add(currentId);
            v.put("0,0", files);
            fileList = new String[] { currentId };
            break;
        }
    }
    nRows++;
    nCols++;
    if (fileList.length == 1) {
        nRows = 1;
        nCols = 1;
    }
    LOGGER.debug("Determined that there are {} rows and {} columns of wells.", nRows, nCols);
    flexFiles = new ArrayList<FlexFile>();
    wellCount = v.size();
    wellNumber = new int[wellCount][2];
    RandomAccessInputStream s = null;
    boolean firstFile = true;
    boolean compressed = false;
    int nOffsets = 1;
    int currentWell = 0;
    for (int row = 0; row < nRows; row++) {
        for (int col = 0; col < nCols; col++) {
            ArrayList<String> files = v.get(row + "," + col);
            if (files == null) {
                continue;
            }
            nFiles = files.size();
            String[] sortedFiles = files.toArray(new String[files.size()]);
            Arrays.sort(sortedFiles);
            files.clear();
            for (String f : sortedFiles) {
                files.add(f);
            }
            for (int field = 0; field < nFiles; field++) {
                FlexFile file = new FlexFile();
                file.row = row;
                file.column = col;
                file.field = field;
                file.file = files.get(field);
                if (file.file == null) {
                    continue;
                }
                wellNumber[currentWell][0] = row;
                wellNumber[currentWell][1] = col;
                s = new RandomAccessInputStream(getFileHandle(file.file));
                TiffParser tp = new TiffParser(s);
                if (compressed || firstFile) {
                    LOGGER.info("Parsing IFDs for well {}{}", (char) (row + 'A'), col + 1);
                    IFD firstIFD = tp.getFirstIFD();
                    compressed = firstIFD.getCompression() != TiffCompression.UNCOMPRESSED;
                    if (compressed || firstIFD.getStripOffsets()[0] == 16 || firstIFD.getStripOffsets().length == 1) {
                        tp.setDoCaching(false);
                        file.ifds = tp.getIFDs();
                        file.ifds.set(0, firstIFD);
                        if (firstIFD.getStripOffsets().length == 1) {
                            // used to ensure that image offsets are read, not calculated
                            compressed = true;
                        }
                    } else {
                        // if the pixel data is uncompressed and the IFD is stored
                        // before the image, we can assume that
                        // the pixel data for image #0 is located immediately before
                        // IFD #1; as a result, we only need to parse the first IFD
                        file.offsets = tp.getIFDOffsets();
                        nOffsets = file.offsets.length;
                        file.ifds = new IFDList();
                        file.ifds.add(firstIFD);
                    }
                } else {
                    // retrieve the offsets to each IFD, instead of parsing
                    // all of the IFDs
                    LOGGER.info("Retrieving IFD offsets for well {}{}", (char) (row + 'A'), col + 1);
                    file.offsets = new long[nOffsets];
                    // Assume that all IFDs after the first are evenly spaced.
                    // TiffParser.getIFDOffsets() could be used instead, but is
                    // substantially slower.
                    file.offsets[0] = tp.getFirstOffset();
                    if (file.offsets.length > 1) {
                        s.seek(file.offsets[0]);
                        s.skipBytes(s.readShort() * TiffConstants.BYTES_PER_ENTRY);
                        file.offsets[1] = s.readInt();
                        int size = FormatTools.getPlaneSize(this) + 174;
                        for (int i = 2; i < file.offsets.length; i++) {
                            file.offsets[i] = file.offsets[i - 1] + size;
                        }
                    }
                }
                flexFiles.add(file);
                // setting a negative field index indicates that the field count
                // should be taken from the XML
                parseFlexFile(currentWell, row, col, nFiles == 1 ? -1 : field, firstFile, store);
                s.close();
                if (firstFile)
                    firstFile = false;
            }
            currentWell++;
        }
    }
}
Also used : HashMap(java.util.HashMap) IFD(loci.formats.tiff.IFD) ArrayList(java.util.ArrayList) IFDList(loci.formats.tiff.IFDList) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream)

Example 97 with IFD

use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.

the class FluoviewReader method isThisType.

// -- IFormatReader API methods --
/* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */
@Override
public boolean isThisType(RandomAccessInputStream stream) throws IOException {
    TiffParser tp = new TiffParser(stream);
    IFD ifd = tp.getFirstIFD();
    if (ifd == null)
        return false;
    String com = ifd.getComment();
    if (com == null)
        com = "";
    return (com.indexOf(FLUOVIEW_MAGIC_STRING) != -1 && ifd.containsKey(new Integer(MMHEADER)) || ifd.containsKey(new Integer(MMSTAMP))) || com.startsWith(ANDOR_MAGIC_STRING);
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser)

Example 98 with IFD

use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.

the class FluoviewReader method initAlternateMetadata.

// -- Helper methods --
private void initAlternateMetadata() throws FormatException, IOException {
    IFD firstIFD = ifds.get(0);
    temperature = (Float) firstIFD.getIFDValue(TEMPERATURE);
    exposureTime = (Float) firstIFD.getIFDValue(EXPOSURE_TIME);
    Float kineticCycleTime = (Float) firstIFD.getIFDValue(KINETIC_CYCLE_TIME);
    Double nAccumulations = (Double) firstIFD.getIFDValue(N_ACCUMULATIONS);
    Float acquisitionCycleTime = (Float) firstIFD.getIFDValue(ACQUISITION_CYCLE_TIME);
    readoutTime = (Float) firstIFD.getIFDValue(READOUT_TIME);
    Double emDAC = (Double) firstIFD.getIFDValue(EM_DAC);
    Double nFrames = (Double) firstIFD.getIFDValue(N_FRAMES);
    Double horizontalFlip = (Double) firstIFD.getIFDValue(HORIZONTAL_FLIP);
    Double verticalFlip = (Double) firstIFD.getIFDValue(VERTICAL_FLIP);
    Double clockwise = (Double) firstIFD.getIFDValue(CLOCKWISE);
    Double counterClockwise = (Double) firstIFD.getIFDValue(COUNTER_CLOCKWISE);
    Double verticalClockVoltage = (Double) firstIFD.getIFDValue(VERTICAL_CLOCK_VOLTAGE);
    Float verticalShiftSpeed = (Float) firstIFD.getIFDValue(VERTICAL_SHIFT_SPEED);
    Float preamp = (Float) firstIFD.getIFDValue(PRE_AMP_SETTING);
    Double serialSetting = (Double) firstIFD.getIFDValue(CAMERA_SERIAL_SETTING);
    Float actualTemperature = (Float) firstIFD.getIFDValue(ACTUAL_TEMPERATURE);
    Double baselineClamp = (Double) firstIFD.getIFDValue(BASELINE_CLAMP);
    Double prescans = (Double) firstIFD.getIFDValue(PRESCANS);
    model = firstIFD.getIFDTextValue(MODEL);
    Double chipSizeX = (Double) firstIFD.getIFDValue(CHIP_SIZE_X);
    Double chipSizeY = (Double) firstIFD.getIFDValue(CHIP_SIZE_Y);
    Double baselineOffset = (Double) firstIFD.getIFDValue(BASELINE_OFFSET);
    addGlobalMeta("Temperature", temperature);
    addGlobalMeta("Exposure time (in seconds)", exposureTime);
    addGlobalMeta("Kinetic cycle time", kineticCycleTime);
    addGlobalMeta("Number of accumulations", nAccumulations);
    addGlobalMeta("Acquisition cycle time", acquisitionCycleTime);
    addGlobalMeta("Readout time", readoutTime);
    addGlobalMeta("EM DAC", emDAC);
    addGlobalMeta("Number of frames", nFrames);
    addGlobalMeta("Horizontal flip", horizontalFlip);
    addGlobalMeta("Vertical flip", verticalFlip);
    addGlobalMeta("Clockwise rotation", clockwise);
    addGlobalMeta("Counter-clockwise rotation", counterClockwise);
    addGlobalMeta("Vertical clock voltage", verticalClockVoltage);
    addGlobalMeta("Vertical shift speed", verticalShiftSpeed);
    addGlobalMeta("Pre-amp", preamp);
    addGlobalMeta("Camera serial setting", serialSetting);
    addGlobalMeta("Actual temperature", actualTemperature);
    addGlobalMeta("Baseline clamp", baselineClamp);
    addGlobalMeta("Prescans", prescans);
    addGlobalMeta("Camera model", model);
    addGlobalMeta("Chip size X", chipSizeX);
    addGlobalMeta("Chip size Y", chipSizeY);
    addGlobalMeta("Baseline offset", baselineOffset);
}
Also used : IFD(loci.formats.tiff.IFD)

Example 99 with IFD

use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.

the class GelReader method initMetadata.

// -- Internal BaseTiffReader API methods --
/* @see BaseTiffReader#initMetadata() */
@Override
protected void initMetadata() throws FormatException, IOException {
    ifds = tiffParser.getIFDs();
    if (ifds.size() > 1) {
        IFDList tmpIFDs = ifds;
        ifds = new IFDList();
        for (int i = 0; i < tmpIFDs.size() / 2; i++) {
            IFD ifd = new IFD();
            ifds.add(ifd);
            ifd.putAll(tmpIFDs.get(i * 2 + 1));
            ifd.putAll(tmpIFDs.get(i * 2));
            tiffParser.fillInIFD(ifd);
        }
    }
    IFD firstIFD = ifds.get(0);
    tiffParser.fillInIFD(firstIFD);
    super.initStandardMetadata();
    fmt = firstIFD.getIFDLongValue(MD_FILETAG, LINEAR);
    if (fmt == SQUARE_ROOT)
        core.get(0).pixelType = FormatTools.FLOAT;
    TiffRational scale = (TiffRational) firstIFD.getIFDValue(MD_SCALE_PIXEL);
    if (scale == null)
        scale = new TiffRational(1, 1);
    core.get(0).imageCount = ifds.size();
    core.get(0).sizeT = getImageCount();
    // ignore MD_COLOR_TABLE
    String info = firstIFD.getIFDStringValue(MD_SAMPLE_INFO);
    String prepDate = firstIFD.getIFDStringValue(MD_PREP_DATE);
    String prepTime = firstIFD.getIFDStringValue(MD_PREP_TIME);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        String units = firstIFD.getIFDStringValue(MD_FILE_UNITS);
        String lab = firstIFD.getIFDStringValue(MD_LAB_NAME);
        addGlobalMeta("Scale factor", scale);
        addGlobalMeta("Lab name", lab);
        addGlobalMeta("Sample info", info);
        addGlobalMeta("Date prepared", prepDate);
        addGlobalMeta("Time prepared", prepTime);
        addGlobalMeta("File units", units);
        addGlobalMeta("Data format", fmt == SQUARE_ROOT ? "square root" : "linear");
    }
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    String parsedDate = DateTools.formatDate(prepDate, FORMATS);
    String parsedTime = DateTools.formatDate(prepTime, FORMATS);
    if (parsedDate != null) {
        store.setImageAcquisitionDate(new Timestamp(parsedDate), 0);
    } else if (parsedTime != null) {
        store.setImageAcquisitionDate(new Timestamp(parsedTime), 0);
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        Double pixelSize = new Double(scale.doubleValue());
        Length sizeX = FormatTools.getPhysicalSizeX(pixelSize);
        Length sizeY = FormatTools.getPhysicalSizeY(pixelSize);
        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) IFD(loci.formats.tiff.IFD) IFDList(loci.formats.tiff.IFDList) TiffRational(loci.formats.tiff.TiffRational) Timestamp(ome.xml.model.primitives.Timestamp)

Example 100 with IFD

use of loci.formats.tiff.IFD in project bioformats by openmicroscopy.

the class GelReader method isThisType.

// -- IFormatReader API methods --
/* @see loci.formats.IFormatReader#isThisType(RandomAccessInputStream) */
@Override
public boolean isThisType(RandomAccessInputStream stream) throws IOException {
    TiffParser parser = new TiffParser(stream);
    parser.setDoCaching(false);
    IFD ifd = parser.getFirstIFD();
    if (ifd == null)
        return false;
    return ifd.containsKey(MD_FILETAG);
}
Also used : IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser)

Aggregations

IFD (loci.formats.tiff.IFD)121 TiffParser (loci.formats.tiff.TiffParser)74 RandomAccessInputStream (loci.common.RandomAccessInputStream)51 CoreMetadata (loci.formats.CoreMetadata)33 FormatException (loci.formats.FormatException)32 MetadataStore (loci.formats.meta.MetadataStore)21 IFDList (loci.formats.tiff.IFDList)21 PhotoInterp (loci.formats.tiff.PhotoInterp)18 IOException (java.io.IOException)17 Location (loci.common.Location)15 ArrayList (java.util.ArrayList)14 Timestamp (ome.xml.model.primitives.Timestamp)11 Length (ome.units.quantity.Length)10 Time (ome.units.quantity.Time)8 TiffIFDEntry (loci.formats.tiff.TiffIFDEntry)7 TiffRational (loci.formats.tiff.TiffRational)6 File (java.io.File)5 TiffReader (loci.formats.in.TiffReader)5 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)5 PositiveInteger (ome.xml.model.primitives.PositiveInteger)5