Search in sources :

Example 31 with Timestamp

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

the class BioRadSCNReader 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);
    String line = in.readLine();
    String currentBoundary = "";
    String currentType = "";
    int currentLength = 0;
    ArrayList<String> xml = new ArrayList<String>();
    while (in.getFilePointer() < in.length() && line != null) {
        line = line.trim();
        if (line.startsWith("Content-Type")) {
            currentType = line.substring(line.indexOf(' ') + 1);
            int boundary = currentType.indexOf("boundary");
            if (boundary > 0) {
                currentBoundary = currentType.substring(boundary + 10, currentType.length() - 1);
            }
            if (currentType.indexOf(';') > 0) {
                currentType = currentType.substring(0, currentType.indexOf(';'));
            }
        } else if (line.equals("--" + currentBoundary)) {
            currentLength = 0;
        } else if (line.startsWith("Content-Length")) {
            currentLength = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
        } else if (line.length() == 0) {
            if (currentType.equals("application/octet-stream")) {
                pixelsOffset = in.getFilePointer();
                in.skipBytes(currentLength);
            } else if (currentType.equals("text/xml")) {
                String xmlBlock = in.readString(currentLength);
                xml.add(xmlBlock);
            }
        }
        line = in.readLine();
    }
    SCNHandler handler = new SCNHandler();
    for (String block : xml) {
        XMLTools.parseXML(block, handler);
    }
    m.sizeZ = 1;
    m.sizeT = 1;
    m.imageCount = 1;
    m.dimensionOrder = "XYCZT";
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, exposureTime != null);
    store.setInstrumentID(MetadataTools.createLSID("Instrument", 0), 0);
    if (serialNumber != null) {
        store.setMicroscopeSerialNumber(serialNumber, 0);
    }
    if (model != null) {
        store.setMicroscopeModel(model, 0);
    }
    if (imageName != null) {
        store.setImageName(imageName, 0);
    }
    if (acquisitionDate != null) {
        store.setImageAcquisitionDate(new Timestamp(acquisitionDate), 0);
    }
    if (gain != null || binning != null) {
        String detector = MetadataTools.createLSID("Detector", 0, 0);
        store.setDetectorID(detector, 0, 0);
        store.setDetectorSettingsID(detector, 0, 0);
    }
    if (gain != null) {
        store.setDetectorSettingsGain(gain, 0, 0);
    }
    if (binning != null) {
        store.setDetectorSettingsBinning(getBinning(binning), 0, 0);
    }
    if (exposureTime != null) {
        store.setPlaneExposureTime(new Time(exposureTime, UNITS.SECOND), 0, 0);
    }
    if (physicalSizeX != null) {
        store.setPixelsPhysicalSizeX(FormatTools.createLength(physicalSizeX, UNITS.MICROMETER), 0);
    }
    if (physicalSizeY != null) {
        store.setPixelsPhysicalSizeY(FormatTools.createLength(physicalSizeY, UNITS.MICROMETER), 0);
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) ArrayList(java.util.ArrayList) Time(ome.units.quantity.Time) RandomAccessInputStream(loci.common.RandomAccessInputStream) CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp)

Example 32 with Timestamp

use of ome.xml.model.primitives.Timestamp 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 33 with Timestamp

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

the class BDReader method getTimestamp.

private long getTimestamp(String file) throws FormatException, IOException {
    RandomAccessInputStream s = new RandomAccessInputStream(file, 16);
    TiffParser parser = new TiffParser(s);
    parser.setDoCaching(false);
    IFD firstIFD = parser.getFirstIFD();
    if (firstIFD != null) {
        TiffIFDEntry timestamp = (TiffIFDEntry) firstIFD.get(IFD.DATE_TIME);
        if (timestamp != null) {
            String stamp = parser.getIFDValue(timestamp).toString();
            s.close();
            stamp = DateTools.formatDate(stamp, BaseTiffReader.DATE_FORMATS, ".");
            Timestamp t = Timestamp.valueOf(stamp);
            // NPE if invalid input.
            return t.asInstant().getMillis();
        }
    }
    s.close();
    return new Location(file).lastModified();
}
Also used : TiffIFDEntry(loci.formats.tiff.TiffIFDEntry) IFD(loci.formats.tiff.IFD) TiffParser(loci.formats.tiff.TiffParser) RandomAccessInputStream(loci.common.RandomAccessInputStream) Timestamp(ome.xml.model.primitives.Timestamp) Location(loci.common.Location)

Example 34 with Timestamp

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

the class FormatTools method getFilename.

public static String getFilename(int series, int image, MetadataRetrieve retrieve, String pattern, boolean padded) throws FormatException, IOException {
    String sPlaces = "%d";
    if (padded) {
        sPlaces = "%0" + String.valueOf(retrieve.getImageCount()).length() + "d";
    }
    String filename = pattern.replaceAll(SERIES_NUM, String.format(sPlaces, series));
    String imageName = retrieve.getImageName(series);
    if (imageName == null)
        imageName = "Series" + series;
    imageName = imageName.replaceAll("/", "_");
    imageName = imageName.replaceAll("\\\\", "_");
    filename = filename.replaceAll(SERIES_NAME, imageName);
    DimensionOrder order = retrieve.getPixelsDimensionOrder(series);
    int sizeC = retrieve.getChannelCount(series);
    int sizeT = retrieve.getPixelsSizeT(series).getValue();
    int sizeZ = retrieve.getPixelsSizeZ(series).getValue();
    int[] coordinates = FormatTools.getZCTCoords(order.getValue(), sizeZ, sizeC, sizeT, sizeZ * sizeC * sizeT, image);
    String zPlaces = "%d";
    String tPlaces = "%d";
    String cPlaces = "%d";
    if (padded) {
        zPlaces = "%0" + String.valueOf(sizeZ).length() + "d";
        tPlaces = "%0" + String.valueOf(sizeT).length() + "d";
        cPlaces = "%0" + String.valueOf(sizeC).length() + "d";
    }
    filename = filename.replaceAll(Z_NUM, String.format(zPlaces, coordinates[0]));
    filename = filename.replaceAll(T_NUM, String.format(tPlaces, coordinates[2]));
    filename = filename.replaceAll(CHANNEL_NUM, String.format(cPlaces, coordinates[1]));
    String channelName = retrieve.getChannelName(series, coordinates[1]);
    if (channelName == null)
        channelName = String.valueOf(coordinates[1]);
    channelName = channelName.replaceAll("/", "_");
    channelName = channelName.replaceAll("\\\\", "_");
    filename = filename.replaceAll(CHANNEL_NAME, channelName);
    Timestamp timestamp = retrieve.getImageAcquisitionDate(series);
    long stamp = 0;
    String date = null;
    if (timestamp != null) {
        date = timestamp.getValue();
        if (retrieve.getPlaneCount(series) > image) {
            Time deltaT = retrieve.getPlaneDeltaT(series, image);
            if (deltaT != null) {
                stamp = (long) (deltaT.value(UNITS.SECOND).doubleValue() * 1000);
            }
        }
        stamp += DateTools.getTime(date, DateTools.ISO8601_FORMAT);
    } else {
        stamp = System.currentTimeMillis();
    }
    date = DateTools.convertDate(stamp, (int) DateTools.UNIX_EPOCH);
    filename = filename.replaceAll(TIMESTAMP, date);
    return filename;
}
Also used : UnitsTime(ome.xml.model.enums.UnitsTime) Time(ome.units.quantity.Time) DimensionOrder(ome.xml.model.enums.DimensionOrder) Timestamp(ome.xml.model.primitives.Timestamp)

Example 35 with Timestamp

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

the class MicromanagerReader method populateMetadata.

private void populateMetadata() throws FormatException, IOException {
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, true);
    String instrumentID = MetadataTools.createLSID("Instrument", 0);
    store.setInstrumentID(instrumentID, 0);
    for (int i = 0; i < positions.size(); i++) {
        Position p = positions.get(i);
        if (p.time != null) {
            String date = DateTools.formatDate(p.time, DATE_FORMAT);
            if (date != null) {
                store.setImageAcquisitionDate(new Timestamp(date), i);
            }
        }
        if (positions.size() > 1) {
            Location parent = new Location(p.metadataFile).getParentFile();
            store.setImageName(parent.getName(), i);
        }
        if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
            store.setImageDescription(p.comment, i);
            // link Instrument and Image
            store.setImageInstrumentRef(instrumentID, i);
            for (int c = 0; c < p.channels.length; c++) {
                store.setChannelName(p.channels[c], i, c);
            }
            Length sizeX = FormatTools.getPhysicalSizeX(p.pixelSize);
            Length sizeY = FormatTools.getPhysicalSizeY(p.pixelSize);
            Length sizeZ = FormatTools.getPhysicalSizeZ(p.sliceThickness);
            if (sizeX != null) {
                store.setPixelsPhysicalSizeX(sizeX, i);
            }
            if (sizeY != null) {
                store.setPixelsPhysicalSizeY(sizeY, i);
            }
            if (sizeZ != null) {
                store.setPixelsPhysicalSizeZ(sizeZ, i);
            }
            int nextStamp = 0;
            for (int q = 0; q < getImageCount(); q++) {
                store.setPlaneExposureTime(p.exposureTime, i, q);
                String tiff = positions.get(getSeries()).getFile(q);
                if (tiff != null && new Location(tiff).exists() && nextStamp < p.timestamps.length && p.timestamps[nextStamp] != null) {
                    store.setPlaneDeltaT(new Time(p.timestamps[nextStamp++], UNITS.MILLISECOND), i, q);
                }
                if (p.positions != null && q < p.positions.length) {
                    if (p.positions[q][0] != null) {
                        store.setPlanePositionX(new Length(p.positions[q][0], UNITS.MICROMETER), i, q);
                    }
                    if (p.positions[q][1] != null) {
                        store.setPlanePositionY(new Length(p.positions[q][1], UNITS.MICROMETER), i, q);
                    }
                    if (p.positions[q][2] != null) {
                        store.setPlanePositionZ(new Length(p.positions[q][2], UNITS.MICROMETER), i, q);
                    }
                }
            }
            String serialNumber = p.detectorID;
            p.detectorID = MetadataTools.createLSID("Detector", 0, i);
            for (int c = 0; c < p.channels.length; c++) {
                store.setDetectorSettingsBinning(getBinning(p.binning), i, c);
                store.setDetectorSettingsGain(new Double(p.gain), i, c);
                if (c < p.voltage.size()) {
                    store.setDetectorSettingsVoltage(new ElectricPotential(p.voltage.get(c), UNITS.VOLT), i, c);
                }
                store.setDetectorSettingsID(p.detectorID, i, c);
            }
            store.setDetectorID(p.detectorID, 0, i);
            if (p.detectorModel != null) {
                store.setDetectorModel(p.detectorModel, 0, i);
            }
            if (serialNumber != null) {
                store.setDetectorSerialNumber(serialNumber, 0, i);
            }
            if (p.detectorManufacturer != null) {
                store.setDetectorManufacturer(p.detectorManufacturer, 0, i);
            }
            if (p.cameraMode == null)
                p.cameraMode = "Other";
            store.setDetectorType(getDetectorType(p.cameraMode), 0, i);
            store.setImagingEnvironmentTemperature(new Temperature(p.temperature, UNITS.CELSIUS), i);
        }
    }
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) Temperature(ome.units.quantity.Temperature) Length(ome.units.quantity.Length) Time(ome.units.quantity.Time) Timestamp(ome.xml.model.primitives.Timestamp) ElectricPotential(ome.units.quantity.ElectricPotential) Location(loci.common.Location)

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