Search in sources :

Example 21 with Time

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

the class BaseZeissReader method fillMetadataPass7.

/**
 * Store basic dimensions in model
 * @param store
 * @throws FormatException
 * @throws IOException
 */
protected void fillMetadataPass7(MetadataStore store) throws FormatException, IOException {
    for (int i = 0; i < getSeriesCount(); i++) {
        long firstStamp = 0;
        if (timestamps.size() > 0) {
            String timestamp = timestamps.get(0);
            store.setImageAcquisitionDate(new Timestamp(timestamp), i);
        } else if (acquisitionDate != null) {
            store.setImageAcquisitionDate(acquisitionDate, i);
        }
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        // link Instrument and Image
        String instrumentID = MetadataTools.createLSID("Instrument", 0);
        store.setInstrumentID(instrumentID, 0);
        String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
        store.setObjectiveID(objectiveID, 0, 0);
        store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
        store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
        Integer[] channelKeys = channelName.keySet().toArray(new Integer[channelName.size()]);
        Arrays.sort(channelKeys);
        // link DetectorSettings to an actual Detector
        for (int i = 0; i < getEffectiveSizeC(); i++) {
            String detectorID = MetadataTools.createLSID("Detector", 0, i);
            store.setDetectorID(detectorID, 0, i);
            store.setDetectorType(getDetectorType("Other"), 0, i);
            for (int s = 0; s < getSeriesCount(); s++) {
                int c = i;
                if (i < channelKeys.length) {
                    c = channelKeys[i];
                }
                store.setDetectorSettingsID(detectorID, s, i);
                store.setDetectorSettingsGain(detectorGain.get(c), s, i);
                store.setDetectorSettingsOffset(detectorOffset.get(c), s, i);
                store.setChannelName(channelName.get(c), s, i);
                store.setChannelEmissionWavelength(emWavelength.get(c), s, i);
                store.setChannelExcitationWavelength(exWavelength.get(c), s, i);
                if (channelColors != null && i < channelColors.length) {
                    int color = channelColors[i];
                    int red = color & 0xff;
                    int green = (color & 0xff00) >> 8;
                    int blue = (color & 0xff0000) >> 16;
                    store.setChannelColor(new Color(red, green, blue, 255), s, i);
                }
            }
        }
        for (int i = 0; i < getSeriesCount(); i++) {
            store.setImageInstrumentRef(instrumentID, i);
            store.setObjectiveSettingsID(objectiveID, i);
            if (imageDescription != null) {
                store.setImageDescription(imageDescription, i);
            }
            if (getSeriesCount() > 1) {
                store.setImageName("Tile #" + (i + 1), i);
            }
            Length sizeX = FormatTools.getPhysicalSizeX(physicalSizeX);
            Length sizeY = FormatTools.getPhysicalSizeY(physicalSizeY);
            Length sizeZ = FormatTools.getPhysicalSizeZ(physicalSizeZ);
            if (sizeX != null) {
                store.setPixelsPhysicalSizeX(sizeX, i);
            }
            if (sizeY != null) {
                store.setPixelsPhysicalSizeY(sizeY, i);
            }
            if (sizeZ != null) {
                store.setPixelsPhysicalSizeZ(sizeZ, i);
            }
            Timestamp firstStamp = null;
            if (timestamps.get(0) != null) {
                firstStamp = new Timestamp(timestamps.get(0));
            }
            for (int plane = 0; plane < getImageCount(); plane++) {
                int[] zct = getZCTCoords(plane);
                int expIndex = zct[1];
                if (channelKeys.length > 0) {
                    expIndex += channelKeys[0];
                }
                String exposure = exposureTime.get(expIndex);
                if (exposure == null && exposureTime.size() == 1) {
                    exposure = exposureTime.values().iterator().next();
                }
                Double exp = 0d;
                try {
                    exp = new Double(exposure);
                } catch (NumberFormatException e) {
                } catch (NullPointerException e) {
                }
                store.setPlaneExposureTime(new Time(exp, UNITS.SECOND), i, plane);
                int posIndex = i * getImageCount() + plane;
                if (posIndex < timestamps.size() && firstStamp != null) {
                    Timestamp timestamp = new Timestamp(timestamps.get(posIndex));
                    long difference = timestamp.asInstant().getMillis() - firstStamp.asInstant().getMillis();
                    double delta = (double) difference;
                    store.setPlaneDeltaT(new Time(delta, UNITS.MILLISECOND), i, plane);
                }
                if (stageX.get(posIndex) != null) {
                    store.setPlanePositionX(stageX.get(posIndex), i, plane);
                }
                if (stageY.get(posIndex) != null) {
                    store.setPlanePositionY(stageY.get(posIndex), i, plane);
                }
            }
        }
        for (int i = 0; i < getSeriesCount(); i++) {
            for (int roi = 0; roi < roiIDs.size(); roi++) {
                store.setImageROIRef(roiIDs.get(roi), i, roi);
            }
        }
    }
}
Also used : Color(ome.xml.model.primitives.Color) DateTime(org.joda.time.DateTime) Time(ome.units.quantity.Time) Timestamp(ome.xml.model.primitives.Timestamp) Length(ome.units.quantity.Length)

Example 22 with Time

use of ome.units.quantity.Time 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 23 with Time

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

the class AnalyzeReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    // the dataset has two files - we want the one ending in '.hdr'
    if (id.endsWith(".img")) {
        LOGGER.info("Looking for header file");
        String header = id.substring(0, id.lastIndexOf(".")) + ".hdr";
        if (new Location(header).exists()) {
            setId(header);
            return;
        } else
            throw new FormatException("Header file not found.");
    }
    super.initFile(id);
    in = new RandomAccessInputStream(id);
    pixelsFilename = id.substring(0, id.lastIndexOf(".")) + ".img";
    pixelFile = new RandomAccessInputStream(pixelsFilename);
    LOGGER.info("Reading header");
    int fileSize = in.readInt();
    boolean little = fileSize != in.length();
    in.order(little);
    pixelFile.order(little);
    in.skipBytes(10);
    String imageName = in.readString(18);
    in.skipBytes(8);
    int ndims = in.readShort();
    int x = in.readShort();
    int y = in.readShort();
    int z = in.readShort();
    int t = in.readShort();
    in.skipBytes(20);
    int dataType = in.readShort();
    int nBitsPerPixel = in.readShort();
    String description = null;
    double voxelWidth = 0d, voxelHeight = 0d, sliceThickness = 0d, deltaT = 0d;
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        in.skipBytes(6);
        voxelWidth = in.readFloat();
        voxelHeight = in.readFloat();
        sliceThickness = in.readFloat();
        deltaT = in.readFloat();
        in.skipBytes(12);
        pixelOffset = (int) in.readFloat();
        in.skipBytes(12);
        float calibratedMax = in.readFloat();
        float calibratedMin = in.readFloat();
        float compressed = in.readFloat();
        float verified = in.readFloat();
        float pixelMax = in.readFloat();
        float pixelMin = in.readFloat();
        description = in.readString(80);
        String auxFile = in.readString(24);
        char orient = (char) in.readByte();
        String originator = in.readString(10);
        String generated = in.readString(10);
        String scannum = in.readString(10);
        String patientID = in.readString(10);
        String expDate = in.readString(10);
        String expTime = in.readString(10);
        in.skipBytes(3);
        int views = in.readInt();
        int volsAdded = in.readInt();
        int startField = in.readInt();
        int fieldSkip = in.readInt();
        int omax = in.readInt();
        int omin = in.readInt();
        int smax = in.readInt();
        int smin = in.readInt();
        addGlobalMeta("Database name", imageName);
        addGlobalMeta("Number of dimensions", ndims);
        addGlobalMeta("Data type", dataType);
        addGlobalMeta("Number of bits per pixel", nBitsPerPixel);
        addGlobalMeta("Voxel width", voxelWidth);
        addGlobalMeta("Voxel height", voxelHeight);
        addGlobalMeta("Slice thickness", sliceThickness);
        addGlobalMeta("Exposure time", deltaT);
        addGlobalMeta("Pixel offset", pixelOffset);
        addGlobalMeta("Calibrated maximum", calibratedMax);
        addGlobalMeta("Calibrated minimum", calibratedMin);
        addGlobalMeta("Compressed", compressed);
        addGlobalMeta("Verified", verified);
        addGlobalMeta("Pixel maximum", pixelMax);
        addGlobalMeta("Pixel minimum", pixelMin);
        addGlobalMeta("Description", description);
        addGlobalMeta("Auxiliary file", auxFile);
        addGlobalMeta("Orientation", orient);
        addGlobalMeta("Originator", originator);
        addGlobalMeta("Generated", generated);
        addGlobalMeta("Scan Number", scannum);
        addGlobalMeta("Patient ID", patientID);
        addGlobalMeta("Acquisition Date", expDate);
        addGlobalMeta("Acquisition Time", expTime);
    } else {
        in.skipBytes(34);
        pixelOffset = (int) in.readFloat();
    }
    LOGGER.info("Populating core metadata");
    CoreMetadata m = core.get(0);
    m.littleEndian = little;
    m.sizeX = x;
    m.sizeY = y;
    m.sizeZ = z;
    m.sizeT = t;
    m.sizeC = 1;
    if (getSizeZ() == 0)
        m.sizeZ = 1;
    if (getSizeT() == 0)
        m.sizeT = 1;
    m.imageCount = getSizeZ() * getSizeT();
    m.rgb = false;
    m.interleaved = false;
    m.indexed = false;
    m.dimensionOrder = "XYZTC";
    switch(dataType) {
        case 1:
        case 2:
            m.pixelType = FormatTools.UINT8;
            break;
        case 4:
            m.pixelType = FormatTools.INT16;
            break;
        case 8:
            m.pixelType = FormatTools.INT32;
            break;
        case 16:
            m.pixelType = FormatTools.FLOAT;
            break;
        case 64:
            m.pixelType = FormatTools.DOUBLE;
            break;
        case 128:
            m.pixelType = FormatTools.UINT8;
            m.sizeC = 3;
            m.rgb = true;
            m.interleaved = true;
            m.dimensionOrder = "XYCZT";
        default:
            throw new FormatException("Unsupported data type: " + dataType);
    }
    LOGGER.info("Populating MetadataStore");
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    store.setImageName(imageName, 0);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        store.setImageDescription(description, 0);
        Length sizeX = FormatTools.getPhysicalSizeX(voxelWidth, UNITS.MILLIMETER);
        Length sizeY = FormatTools.getPhysicalSizeY(voxelHeight, UNITS.MILLIMETER);
        Length sizeZ = FormatTools.getPhysicalSizeZ(sliceThickness, UNITS.MILLIMETER);
        if (sizeX != null) {
            store.setPixelsPhysicalSizeX(sizeX, 0);
        }
        if (sizeY != null) {
            store.setPixelsPhysicalSizeY(sizeY, 0);
        }
        if (sizeZ != null) {
            store.setPixelsPhysicalSizeZ(sizeZ, 0);
        }
        store.setPixelsTimeIncrement(new Time(deltaT, UNITS.MILLISECOND), 0);
    }
}
Also used : Time(ome.units.quantity.Time) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) RandomAccessInputStream(loci.common.RandomAccessInputStream) Location(loci.common.Location)

Example 24 with Time

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

the class BDReader method initFile.

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

Example 25 with Time

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

Aggregations

Time (ome.units.quantity.Time)74 Length (ome.units.quantity.Length)46 MetadataStore (loci.formats.meta.MetadataStore)41 Timestamp (ome.xml.model.primitives.Timestamp)33 CoreMetadata (loci.formats.CoreMetadata)30 FormatException (loci.formats.FormatException)24 RandomAccessInputStream (loci.common.RandomAccessInputStream)21 Location (loci.common.Location)20 ArrayList (java.util.ArrayList)17 PositiveInteger (ome.xml.model.primitives.PositiveInteger)13 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)12 IOException (java.io.IOException)10 Temperature (ome.units.quantity.Temperature)9 IFD (loci.formats.tiff.IFD)8 ElectricPotential (ome.units.quantity.ElectricPotential)7 Color (ome.xml.model.primitives.Color)7 IMetadata (loci.formats.meta.IMetadata)6 File (java.io.File)5 DependencyException (loci.common.services.DependencyException)5 ServiceException (loci.common.services.ServiceException)5