Search in sources :

Example 71 with Timestamp

use of ome.xml.model.primitives.Timestamp in project bioformats by openmicroscopy.

the class InCellReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    // make sure that we have the .xdce (or .xml) file
    if (checkSuffix(id, PIXELS_SUFFIXES) || checkSuffix(id, "xlog")) {
        Location currentFile = new Location(id).getAbsoluteFile();
        Location parent = currentFile.getParentFile();
        String[] list = parent.list(true);
        for (String f : list) {
            if (checkSuffix(f, new String[] { "xdce", "xml" })) {
                String path = new Location(parent, f).getAbsolutePath();
                if (isThisType(path)) {
                    // make sure that the .xdce file references the current file
                    // this ensures that the correct file is chosen if multiple
                    // .xdce files are the same directory
                    String data = DataTools.readFile(path);
                    if (data.indexOf(currentFile.getName()) >= 0) {
                        id = path;
                        break;
                    }
                }
            }
        }
    }
    super.initFile(id);
    in = new RandomAccessInputStream(id);
    channelNames = new ArrayList<String>();
    emWaves = new ArrayList<Double>();
    exWaves = new ArrayList<Double>();
    channelsPerTimepoint = new ArrayList<Integer>();
    metadataFiles = new ArrayList<String>();
    // parse metadata from the .xdce or .xml file
    wellCoordinates = new HashMap<Integer, int[]>();
    posX = new HashMap<Integer, Length>();
    posY = new HashMap<Integer, Length>();
    offsetPointCounter = 0;
    byte[] b = new byte[(int) in.length()];
    in.read(b);
    CoreMetadata ms0 = core.get(0);
    ms0.dimensionOrder = "XYZCT";
    MetadataStore store = makeFilterMetadata();
    DefaultHandler handler = new MinimalInCellHandler();
    XMLTools.parseXML(b, handler);
    if (getSizeZ() == 0)
        ms0.sizeZ = 1;
    if (getSizeC() == 0)
        ms0.sizeC = 1;
    if (getSizeT() == 0)
        ms0.sizeT = 1;
    if (totalImages == 0) {
        ms0.imageCount = getSizeC() * getSizeZ() * getSizeT();
        totalImages = getImageCount() * wellRows * wellCols * fieldCount;
        Location parent = new Location(currentId).getAbsoluteFile().getParentFile();
        for (int row = 0; row < wellRows; row++) {
            for (int col = 0; col < wellCols; col++) {
                plateMap[row][col] = true;
                for (int field = 0; field < fieldCount; field++) {
                    for (int t = 0; t < getSizeT(); t++) {
                        for (int image = 0; image < getSizeC() * getSizeZ(); image++) {
                            // this could be expanded to allow for timepoint indexes
                            // in the file name, as well as allowing the filter names to
                            // be omitted
                            int channel = getZCTCoords(image)[1];
                            Image plane = new Image();
                            String filename = (char) ('A' + row) + " - " + (col + 1) + "(fld " + (field + 1) + " wv " + exFilters.get(channel) + " - " + emFilters.get(channel) + ").tif";
                            Location path = new Location(parent, filename);
                            if (path.exists()) {
                                plane.filename = path.getAbsolutePath();
                            } else {
                                LOGGER.debug("Missing file {}", filename);
                            }
                            imageFiles[row * wellCols + col][field][t][image] = plane;
                        }
                    }
                }
            }
        }
    }
    for (int t = imageFiles[0][0].length - 1; t >= 0; t--) {
        boolean allNull = true;
        for (int well = 0; well < imageFiles.length; well++) {
            for (int field = 0; field < imageFiles[well].length; field++) {
                for (int p = 0; p < imageFiles[well][field][t].length; p++) {
                    if (imageFiles[well][field][t][p] != null) {
                        allNull = false;
                        break;
                    }
                }
            }
        }
        if (allNull) {
            ms0.sizeT--;
        }
    }
    int seriesCount = 0;
    if (exclude != null) {
        for (int row = 0; row < wellRows; row++) {
            for (int col = 0; col < wellCols; col++) {
                if (!exclude[row][col]) {
                    int well = row * wellCols + col;
                    boolean hasNonNullImage = false;
                    for (int field = 0; field < imageFiles[well].length; field++) {
                        for (int t = 0; t < imageFiles[well][field].length; t++) {
                            for (int p = 0; p < imageFiles[well][field][t].length; p++) {
                                if (imageFiles[well][field][t][p] != null) {
                                    hasNonNullImage = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (hasNonNullImage) {
                        seriesCount += imageFiles[well].length;
                    }
                }
            }
        }
        int expectedSeries = totalImages / (getSizeZ() * getSizeC() * getSizeT());
        if (expectedSeries > 0) {
            seriesCount = (int) Math.min(seriesCount, expectedSeries);
        }
    } else
        seriesCount = totalImages / (getSizeZ() * getSizeC() * getSizeT());
    totalChannels = getSizeC();
    oneTimepointPerSeries = false;
    for (int i = 1; i < channelsPerTimepoint.size(); i++) {
        if (!channelsPerTimepoint.get(i).equals(channelsPerTimepoint.get(i - 1))) {
            oneTimepointPerSeries = true;
            break;
        }
    }
    if (oneTimepointPerSeries) {
        int imageCount = 0;
        for (Integer timepoint : channelsPerTimepoint) {
            imageCount += timepoint.intValue() * getSizeZ();
        }
        seriesCount = (totalImages / imageCount) * getSizeT();
    }
    int sizeT = getSizeT();
    int sizeC = getSizeC();
    int z = getSizeZ();
    int t = oneTimepointPerSeries ? 1 : getSizeT();
    core.clear();
    for (int i = 0; i < seriesCount; i++) {
        int c = oneTimepointPerSeries ? channelsPerTimepoint.get(i % sizeT).intValue() : sizeC;
        CoreMetadata ms = new CoreMetadata();
        core.add(ms);
        ms.sizeZ = z;
        ms.sizeC = c;
        ms.sizeT = t;
        ms.imageCount = z * c * t;
        ms.dimensionOrder = "XYZCT";
    }
    int wellIndex = getWellFromSeries(0);
    int fieldIndex = getFieldFromSeries(0);
    String filename = imageFiles[wellIndex][fieldIndex][0][0].filename;
    boolean isTiff = imageFiles[wellIndex][fieldIndex][0][0].isTiff;
    if (isTiff && filename != null) {
        tiffReader = new MinimalTiffReader();
        tiffReader.setId(filename);
        for (int i = 0; i < seriesCount; i++) {
            CoreMetadata ms = core.get(i);
            ms.sizeX = tiffReader.getSizeX();
            ms.sizeY = tiffReader.getSizeY();
            ms.interleaved = tiffReader.isInterleaved();
            ms.indexed = tiffReader.isIndexed();
            ms.rgb = tiffReader.isRGB();
            ms.pixelType = tiffReader.getPixelType();
            ms.littleEndian = tiffReader.isLittleEndian();
        }
    } else {
        for (int i = 0; i < seriesCount; i++) {
            CoreMetadata ms = core.get(i);
            ms.sizeX = imageWidth;
            ms.sizeY = imageHeight;
            ms.interleaved = false;
            ms.indexed = false;
            ms.rgb = false;
            ms.pixelType = FormatTools.UINT16;
            ms.littleEndian = true;
        }
    }
    MetadataTools.populatePixels(store, this, true);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        handler = new InCellHandler(store);
        XMLTools.parseXML(b, handler);
    }
    String rowNaming = Character.isDigit(rowName.charAt(0)) ? "Number" : "Letter";
    String colNaming = Character.isDigit(colName.charAt(0)) ? "Number" : "Letter";
    String plateName = currentId;
    int begin = plateName.lastIndexOf(File.separator) + 1;
    int end = plateName.lastIndexOf(".");
    plateName = plateName.substring(begin, end);
    store.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
    store.setPlateName(plateName, 0);
    store.setPlateRowNamingConvention(getNamingConvention(rowNaming), 0);
    store.setPlateColumnNamingConvention(getNamingConvention(colNaming), 0);
    store.setPlateRows(new PositiveInteger(wellRows), 0);
    store.setPlateColumns(new PositiveInteger(wellCols), 0);
    String plateAcqID = MetadataTools.createLSID("PlateAcquisition", 0, 0);
    store.setPlateAcquisitionID(plateAcqID, 0, 0);
    PositiveInteger maxFieldCount = FormatTools.getMaxFieldCount(fieldCount);
    if (maxFieldCount != null) {
        store.setPlateAcquisitionMaximumFieldCount(maxFieldCount, 0, 0);
    }
    // populate Image data
    String instrumentID = MetadataTools.createLSID("Instrument", 0);
    String experimentID = MetadataTools.createLSID("Experiment", 0);
    store.setInstrumentID(instrumentID, 0);
    store.setExperimentID(experimentID, 0);
    String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
    store.setObjectiveID(objectiveID, 0, 0);
    String detectorID = MetadataTools.createLSID("Detector", 0, 0);
    store.setDetectorID(detectorID, 0, 0);
    int prevWell = -1;
    for (int i = 0; i < seriesCount; i++) {
        store.setObjectiveSettingsID(objectiveID, i);
        if (refractive != null) {
            store.setObjectiveSettingsRefractiveIndex(refractive, i);
        }
        if (x != null) {
            store.setPixelsPhysicalSizeX(x, i);
        }
        if (y != null) {
            store.setPixelsPhysicalSizeY(y, i);
        }
        int well = getWellFromSeries(i);
        int field = getFieldFromSeries(i);
        int totalTimepoints = oneTimepointPerSeries ? channelsPerTimepoint.size() : 1;
        int timepoint = oneTimepointPerSeries ? (i % totalTimepoints) + 1 : -1;
        String imageID = MetadataTools.createLSID("Image", i);
        store.setImageID(imageID, i);
        store.setImageInstrumentRef(instrumentID, i);
        store.setImageExperimentRef(experimentID, i);
        int wellRow = well / wellCols;
        int wellCol = well % wellCols;
        wellIndex = i / (fieldCount * totalTimepoints);
        if (well != prevWell) {
            String wellID = MetadataTools.createLSID("Well", 0, wellIndex);
            store.setWellID(wellID, 0, wellIndex);
            store.setWellRow(new NonNegativeInteger(wellRow), 0, wellIndex);
            store.setWellColumn(new NonNegativeInteger(wellCol), 0, wellIndex);
            prevWell = well;
        }
        char rowChar = rowName.charAt(rowName.length() - 1);
        char colChar = colName.charAt(colName.length() - 1);
        String row = rowName.substring(0, rowName.length() - 1);
        String col = colName.substring(0, colName.length() - 1);
        if (Character.isDigit(rowChar)) {
            row += wellRow + Integer.parseInt(String.valueOf(rowChar));
        } else
            row += (char) (rowChar + wellRow);
        if (Character.isDigit(colChar)) {
            col += wellCol + Integer.parseInt(String.valueOf(colChar));
        } else
            col += (char) (colChar + wellCol);
        String imageName = "Well " + row + "-" + col + ", Field #" + (field + 1);
        if (timepoint >= 0) {
            imageName += ", Timepoint #" + timepoint;
        }
        store.setImageName(imageName, i);
        if (creationDate != null) {
            store.setImageAcquisitionDate(new Timestamp(creationDate), i);
        }
        timepoint--;
        if (timepoint < 0)
            timepoint = 0;
        int sampleIndex = field * totalTimepoints + timepoint;
        String wellSampleID = MetadataTools.createLSID("WellSample", 0, wellIndex, sampleIndex);
        store.setWellSampleID(wellSampleID, 0, wellIndex, sampleIndex);
        store.setWellSampleIndex(new NonNegativeInteger(i), 0, wellIndex, sampleIndex);
        store.setWellSampleImageRef(imageID, 0, wellIndex, sampleIndex);
        if (posX.containsKey(field)) {
            store.setWellSamplePositionX(posX.get(field), 0, wellIndex, sampleIndex);
        }
        if (posY.containsKey(field)) {
            store.setWellSamplePositionY(posY.get(field), 0, wellIndex, sampleIndex);
        }
        store.setPlateAcquisitionWellSampleRef(wellSampleID, 0, 0, i);
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        for (int i = 0; i < seriesCount; i++) {
            setSeries(i);
            int well = getWellFromSeries(i);
            int field = getFieldFromSeries(i);
            int timepoint = oneTimepointPerSeries ? i % channelsPerTimepoint.size() : 0;
            for (int time = 0; time < getSizeT(); time++) {
                if (!oneTimepointPerSeries)
                    timepoint = time;
                int c = channelsPerTimepoint.get(timepoint).intValue();
                for (int q = 0; q < getSizeZ() * c; q++) {
                    Image img = imageFiles[well][field][timepoint][q];
                    if (img == null)
                        continue;
                    int plane = time * getSizeZ() * c + q;
                    if (img.deltaT != null) {
                        store.setPlaneDeltaT(new Time(img.deltaT, UNITS.SECOND), i, plane);
                    }
                    if (img.exposure != null) {
                        store.setPlaneExposureTime(new Time(img.exposure, UNITS.SECOND), i, plane);
                    }
                    store.setPlanePositionX(posX.get(field), i, plane);
                    store.setPlanePositionY(posY.get(field), i, plane);
                    store.setPlanePositionZ(img.zPosition, i, plane);
                }
            }
            // populate LogicalChannel data
            for (int q = 0; q < getEffectiveSizeC(); q++) {
                if (q < channelNames.size()) {
                    store.setChannelName(channelNames.get(q), i, q);
                }
                if (q < emWaves.size()) {
                    Double wave = emWaves.get(q);
                    Length emission = FormatTools.getEmissionWavelength(wave);
                    if (emission != null) {
                        store.setChannelEmissionWavelength(emission, i, q);
                    }
                }
                if (q < exWaves.size()) {
                    Double wave = exWaves.get(q);
                    Length excitation = FormatTools.getExcitationWavelength(wave);
                    if (excitation != null) {
                        store.setChannelExcitationWavelength(excitation, i, q);
                    }
                }
                if (detectorID != null) {
                    store.setDetectorSettingsID(detectorID, i, q);
                    if (bin != null) {
                        store.setDetectorSettingsBinning(bin, i, q);
                    }
                    if (gain != null) {
                        store.setDetectorSettingsGain(gain, i, q);
                    }
                }
            }
            if (temperature != null) {
                store.setImagingEnvironmentTemperature(new Temperature(temperature, UNITS.CELSIUS), i);
            }
        }
        setSeries(0);
        // populate Plate data
        store.setPlateWellOriginX(new Length(0.5, UNITS.MICROMETER), 0);
        store.setPlateWellOriginY(new Length(0.5, UNITS.MICROMETER), 0);
    }
}
Also used : Temperature(ome.units.quantity.Temperature) Time(ome.units.quantity.Time) Timestamp(ome.xml.model.primitives.Timestamp) PositiveInteger(ome.xml.model.primitives.PositiveInteger) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) CoreMetadata(loci.formats.CoreMetadata) DefaultHandler(org.xml.sax.helpers.DefaultHandler) PositiveInteger(ome.xml.model.primitives.PositiveInteger) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) RandomAccessInputStream(loci.common.RandomAccessInputStream) Location(loci.common.Location)

Example 72 with Timestamp

use of ome.xml.model.primitives.Timestamp in project bioformats by openmicroscopy.

the class IPWReader 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);
    initPOIService();
    imageFiles = new HashMap<Integer, String>();
    Vector<String> fileList = poi.getDocumentList();
    String description = null, creationDate = null;
    CoreMetadata m = core.get(0);
    for (String name : fileList) {
        String relativePath = name.substring(name.lastIndexOf(File.separator) + 1);
        if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
            if (relativePath.equals("CONTENTS")) {
                addGlobalMeta("Version", new String(poi.getDocumentBytes(name), Constants.ENCODING).trim());
            } else if (relativePath.equals("FrameRate")) {
                byte[] b = poi.getDocumentBytes(name, 4);
                addGlobalMeta("Frame Rate", DataTools.bytesToInt(b, true));
            } else if (relativePath.equals("FrameInfo")) {
                RandomAccessInputStream s = poi.getDocumentStream(name);
                s.order(true);
                for (int q = 0; q < s.length() / 2; q++) {
                    addGlobalMetaList("FrameInfo", s.readShort());
                }
                s.close();
            }
        }
        if (relativePath.equals("ImageInfo")) {
            description = new String(poi.getDocumentBytes(name), Constants.ENCODING).trim();
            addGlobalMeta("Image Description", description);
            String timestamp = null;
            // basically the same as in SEQReader
            if (description != null) {
                String[] tokens = description.split("\n");
                for (String token : tokens) {
                    String label = "Timestamp";
                    String data = token.trim();
                    if (token.indexOf('=') != -1) {
                        label = token.substring(0, token.indexOf('=')).trim();
                        data = token.substring(token.indexOf('=') + 1).trim();
                    }
                    addGlobalMeta(label, data);
                    if (label.equals("frames"))
                        m.sizeT = Integer.parseInt(data);
                    else if (label.equals("slices")) {
                        m.sizeZ = Integer.parseInt(data);
                    } else if (label.equals("channels")) {
                        m.sizeC = Integer.parseInt(data);
                    } else if (label.equals("Timestamp"))
                        timestamp = data;
                }
            }
            if (timestamp != null) {
                if (timestamp.length() > 26) {
                    timestamp = timestamp.substring(timestamp.length() - 26);
                }
                creationDate = DateTools.formatDate(timestamp, "MM/dd/yyyy HH:mm:ss aa", ".");
            }
        } else if (relativePath.equals("ImageTIFF")) {
            // pixel data
            String idx = "0";
            if (!name.substring(0, name.lastIndexOf(File.separator)).equals("Root Entry")) {
                idx = name.substring(21, name.indexOf(File.separator, 22));
            }
            imageFiles.put(new Integer(idx), name);
        }
    }
    LOGGER.info("Populating metadata");
    m.imageCount = imageFiles.size();
    RandomAccessInputStream stream = poi.getDocumentStream(imageFiles.get(0));
    TiffParser tp = new TiffParser(stream);
    IFD firstIFD = tp.getFirstIFD();
    stream.close();
    m.rgb = firstIFD.getSamplesPerPixel() > 1;
    if (!isRGB()) {
        m.indexed = firstIFD.getPhotometricInterpretation() == PhotoInterp.RGB_PALETTE;
    }
    if (isIndexed()) {
        m.sizeC = 1;
        m.rgb = false;
    }
    m.littleEndian = firstIFD.isLittleEndian();
    // retrieve axis sizes
    addGlobalMeta("slices", "1");
    addGlobalMeta("channels", "1");
    addGlobalMeta("frames", getImageCount());
    m.sizeX = (int) firstIFD.getImageWidth();
    m.sizeY = (int) firstIFD.getImageLength();
    m.dimensionOrder = isRGB() ? "XYCZT" : "XYZCT";
    if (getSizeZ() == 0)
        m.sizeZ = 1;
    if (getSizeC() == 0)
        m.sizeC = 1;
    if (getSizeT() == 0)
        m.sizeT = 1;
    if (getSizeZ() * getSizeC() * getSizeT() == 1 && getImageCount() != 1) {
        m.sizeZ = getImageCount();
    }
    if (isRGB())
        m.sizeC *= 3;
    int bitsPerSample = firstIFD.getBitsPerSample()[0];
    m.pixelType = firstIFD.getPixelType();
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    store.setImageDescription(description, 0);
    if (creationDate != null) {
        store.setImageAcquisitionDate(new Timestamp(creationDate), 0);
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp)

Example 73 with Timestamp

use of ome.xml.model.primitives.Timestamp in project bioformats by openmicroscopy.

the class QuesantReader 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());
    while (in.getFilePointer() < MAX_HEADER_SIZE) {
        readVariable();
    }
    in.seek(pixelsOffset);
    m.sizeX = in.readShort();
    pixelsOffset += 2;
    m.sizeY = getSizeX();
    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 (date != null) {
        // Insert fake separator between seconds and milliseconds to use
        // DateTools.formatDate()
        int separator = date.lastIndexOf(":");
        if (separator > 0 && date.length() > (separator + 5)) {
            date = date.substring(0, separator + 3) + "." + date.substring(separator + 3);
        }
        date = DateTools.formatDate(date, "MMM dd yyyy HH:mm:ss", ".");
        if (date != null) {
            store.setImageAcquisitionDate(new Timestamp(date), 0);
        }
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        store.setImageDescription(comment, 0);
        Length sizeX = FormatTools.getPhysicalSizeX((double) xSize / getSizeX());
        Length sizeY = FormatTools.getPhysicalSizeY((double) xSize / getSizeY());
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp)

Example 74 with Timestamp

use of ome.xml.model.primitives.Timestamp in project bioformats by openmicroscopy.

the class SISReader method initMetadataStore.

/* @see BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
    super.initMetadataStore();
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    store.setImageName(imageName, 0);
    if (acquisitionDate != null) {
        store.setImageAcquisitionDate(new Timestamp(acquisitionDate), 0);
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        String instrument = MetadataTools.createLSID("Instrument", 0);
        store.setInstrumentID(instrument, 0);
        store.setImageInstrumentRef(instrument, 0);
        String objective = MetadataTools.createLSID("Objective", 0, 0);
        store.setObjectiveID(objective, 0, 0);
        store.setObjectiveNominalMagnification(magnification, 0, 0);
        store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
        store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
        store.setObjectiveSettingsID(objective, 0);
        String detector = MetadataTools.createLSID("Detector", 0, 0);
        store.setDetectorID(detector, 0, 0);
        store.setDetectorModel(cameraName, 0, 0);
        store.setDetectorType(getDetectorType("Other"), 0, 0);
        store.setDetectorSettingsID(detector, 0, 0);
        physicalSizeX /= 1000;
        physicalSizeY /= 1000;
        Length sizeX = FormatTools.getPhysicalSizeX(physicalSizeX);
        Length sizeY = FormatTools.getPhysicalSizeY(physicalSizeY);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
        store.setChannelName(channelName, 0, 0);
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) Timestamp(ome.xml.model.primitives.Timestamp)

Example 75 with Timestamp

use of ome.xml.model.primitives.Timestamp in project bioformats by openmicroscopy.

the class FormatReaderTest method testSaneOMEXML.

@Test(groups = { "all", "xml", "automated" })
public void testSaneOMEXML() {
    String testName = "testSaneOMEXML";
    if (!initFile())
        result(testName, false, "initFile");
    if (!config.hasValidXML()) {
        LOGGER.debug("Skipping valid XML test");
        result(testName, true);
        return;
    }
    String msg = null;
    try {
        MetadataRetrieve retrieve = (MetadataRetrieve) reader.getMetadataStore();
        boolean success = omexmlService.isOMEXMLMetadata(retrieve);
        if (!success)
            msg = TestTools.shortClassName(retrieve);
        for (int i = 0; i < reader.getSeriesCount() && msg == null; i++) {
            // total number of ChannelComponents should match SizeC
            int sizeC = retrieve.getPixelsSizeC(i).getValue().intValue();
            int nChannelComponents = retrieve.getChannelCount(i);
            int samplesPerPixel = retrieve.getChannelSamplesPerPixel(i, 0).getValue();
            if (sizeC != nChannelComponents * samplesPerPixel) {
                msg = "ChannelComponent";
            }
            // Z, C and T indices should be populated if PlaneTiming is present
            Time deltaT = null;
            Time exposure = null;
            Integer z = null, c = null, t = null;
            if (retrieve.getPlaneCount(i) > 0) {
                deltaT = retrieve.getPlaneDeltaT(i, 0);
                exposure = retrieve.getPlaneExposureTime(i, 0);
                z = retrieve.getPlaneTheZ(i, 0).getValue();
                c = retrieve.getPlaneTheC(i, 0).getValue();
                t = retrieve.getPlaneTheT(i, 0).getValue();
            }
            if ((deltaT != null || exposure != null) && (z == null || c == null || t == null)) {
                msg = "PlaneTiming";
            }
            // if CreationDate is before 1990, it's probably invalid
            String date = null;
            if (retrieve.getImageAcquisitionDate(i) != null) {
                date = retrieve.getImageAcquisitionDate(i).getValue();
            }
            config.setSeries(i);
            String configDate = config.getDate();
            if (date != null && !date.equals(configDate)) {
                date = date.trim();
                long acquiredDate = new Timestamp(date).asInstant().getMillis();
                long saneDate = new Timestamp("1990-01-01T00:00:00").asInstant().getMillis();
                long fileDate = new Location(reader.getCurrentFile()).getAbsoluteFile().lastModified();
                if (acquiredDate < saneDate && fileDate >= saneDate) {
                    msg = "CreationDate (date=" + date + " acquiredDate=" + acquiredDate + " fileDate=" + fileDate + " saneDate=" + saneDate + ")";
                }
            }
        }
    } catch (Throwable t) {
        LOGGER.info("", t);
        msg = t.getMessage();
    }
    result(testName, msg == null, msg);
}
Also used : PositiveInteger(ome.xml.model.primitives.PositiveInteger) Time(ome.units.quantity.Time) MetadataRetrieve(loci.formats.meta.MetadataRetrieve) Timestamp(ome.xml.model.primitives.Timestamp) Location(loci.common.Location) Test(org.testng.annotations.Test)

Aggregations

Timestamp (ome.xml.model.primitives.Timestamp)76 MetadataStore (loci.formats.meta.MetadataStore)54 Length (ome.units.quantity.Length)52 CoreMetadata (loci.formats.CoreMetadata)44 Time (ome.units.quantity.Time)33 Location (loci.common.Location)28 RandomAccessInputStream (loci.common.RandomAccessInputStream)28 FormatException (loci.formats.FormatException)23 ArrayList (java.util.ArrayList)20 IFD (loci.formats.tiff.IFD)11 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)10 TiffParser (loci.formats.tiff.TiffParser)9 IOException (java.io.IOException)8 IFDList (loci.formats.tiff.IFDList)8 PositiveInteger (ome.xml.model.primitives.PositiveInteger)8 Temperature (ome.units.quantity.Temperature)7 Hashtable (java.util.Hashtable)4 StringTokenizer (java.util.StringTokenizer)4 Frequency (ome.units.quantity.Frequency)4 File (java.io.File)3