Search in sources :

Example 16 with Time

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

the class VectraReader method initMetadataStore.

/* @see loci.formats.BaseTiffReader#initMetadataStore() */
@Override
protected void initMetadataStore() throws FormatException {
    super.initMetadataStore();
    MetadataStore store = makeFilterMetadata();
    for (int i = 0; i < getSeriesCount(); i++) {
        int coreIndex = seriesToCoreIndex(i);
        store.setImageName(getImageName(coreIndex), i);
        store.setImageDescription("", i);
        int ifdIndex = getIFDIndex(coreIndex, 0);
        IFD ifd = ifds.get(ifdIndex);
        double x = ifd.getXResolution();
        double y = ifd.getYResolution();
        store.setPixelsPhysicalSizeX(FormatTools.getPhysicalSizeX(x), i);
        store.setPixelsPhysicalSizeY(FormatTools.getPhysicalSizeY(y), i);
    }
    for (int c = 0; c < getSizeC(); c++) {
        String xml = getIFDComment(c);
        try {
            Element root = XMLTools.parseDOM(xml).getDocumentElement();
            NodeList children = root.getChildNodes();
            for (int i = 0; i < children.getLength(); i++) {
                if (!(children.item(i) instanceof Element)) {
                    continue;
                }
                Element e = (Element) children.item(i);
                String name = e.getNodeName();
                String value = e.getTextContent();
                if (name.equals("ScanProfile")) {
                    try {
                        Document profileRoot = XMLTools.createDocument();
                        Node tmp = profileRoot.importNode(e, true);
                        profileRoot.appendChild(tmp);
                        profileXML = XMLTools.getXML(profileRoot);
                        // scan profile XML is usually too long to be saved
                        // when original metadata filtering is enabled, but there
                        // is an API method below to retrieve it
                        addGlobalMeta(name, profileXML);
                    } catch (Exception ex) {
                        LOGGER.debug("Could not preserve scan profile metadata", ex);
                    }
                } else {
                    addGlobalMetaList(name, value);
                }
                if (name.equals("Name")) {
                    if (hasFlattenedResolutions()) {
                        for (int series = 0; series < pyramidDepth; series++) {
                            store.setChannelName(value, series, c);
                        }
                    } else {
                        store.setChannelName(value, 0, c);
                    }
                } else if (name.equals("Color")) {
                    String[] components = value.split(",");
                    Color color = new Color(Integer.parseInt(components[0]), Integer.parseInt(components[1]), Integer.parseInt(components[2]), 255);
                    if (hasFlattenedResolutions()) {
                        for (int series = 0; series < pyramidDepth; series++) {
                            store.setChannelColor(color, series, c);
                        }
                    } else {
                        store.setChannelColor(color, 0, c);
                    }
                } else if (name.equals("Objective") && c == 0) {
                    String instrument = MetadataTools.createLSID("Instrument", 0);
                    String objective = MetadataTools.createLSID("Objective", 0, 0);
                    store.setInstrumentID(instrument, 0);
                    store.setObjectiveID(objective, 0, 0);
                    store.setObjectiveModel(value, 0, 0);
                    try {
                        String mag = value.toLowerCase().replace("x", "");
                        Double magFactor = DataTools.parseDouble(mag);
                        store.setObjectiveNominalMagnification(magFactor, 0, 0);
                    } catch (NumberFormatException ex) {
                        LOGGER.info("Could not determine magnification: {}", value);
                    }
                    for (int series = 0; series < getSeriesCount(); series++) {
                        store.setImageInstrumentRef(instrument, series);
                        store.setObjectiveSettingsID(objective, series);
                    }
                } else if (name.equals("ExposureTime")) {
                    Time exposure = new Time(DataTools.parseDouble(value), UNITS.MICROSECOND);
                    store.setPlaneExposureTime(exposure, 0, c);
                    store.setPlaneTheZ(new NonNegativeInteger(0), 0, c);
                    store.setPlaneTheT(new NonNegativeInteger(0), 0, c);
                    store.setPlaneTheC(new NonNegativeInteger(c), 0, c);
                }
            }
        } catch (ParserConfigurationException | SAXException | IOException e) {
            LOGGER.warn("Could not parse XML for channel {}", c);
            LOGGER.debug("", e);
        }
    }
}
Also used : IFD(loci.formats.tiff.IFD) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Color(ome.xml.model.primitives.Color) Time(ome.units.quantity.Time) IOException(java.io.IOException) Document(org.w3c.dom.Document) FormatException(loci.formats.FormatException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) MetadataStore(loci.formats.meta.MetadataStore) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 17 with Time

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

the class ScanrReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    if (metadataFiles.size() > 0) {
        // this dataset has already been initialized
        return;
    }
    // make sure we have the .xml file
    if (!checkSuffix(id, "xml") && isGroupFiles()) {
        Location parent = new Location(id).getAbsoluteFile().getParentFile();
        if (checkSuffix(id, "tif") && parent.getName().equalsIgnoreCase("Data")) {
            parent = parent.getParentFile();
        }
        String[] list = parent.list();
        for (String file : list) {
            if (file.equals(XML_FILE)) {
                id = new Location(parent, file).getAbsolutePath();
                super.initFile(id);
                break;
            }
        }
        if (!checkSuffix(id, "xml")) {
            throw new FormatException("Could not find " + XML_FILE + " in " + parent.getAbsolutePath());
        }
    } else if (!isGroupFiles() && checkSuffix(id, "tif")) {
        TiffReader r = new TiffReader();
        r.setMetadataStore(getMetadataStore());
        r.setId(id);
        core = new ArrayList<CoreMetadata>(r.getCoreMetadataList());
        metadataStore = r.getMetadataStore();
        final Map<String, Object> globalMetadata = r.getGlobalMetadata();
        for (final Map.Entry<String, Object> entry : globalMetadata.entrySet()) {
            addGlobalMeta(entry.getKey(), entry.getValue());
        }
        r.close();
        tiffs = new String[] { id };
        reader = new MinimalTiffReader();
        return;
    }
    Location dir = new Location(id).getAbsoluteFile().getParentFile();
    String[] list = dir.list(true);
    for (String file : list) {
        Location f = new Location(dir, file);
        if (checkSuffix(file, METADATA_SUFFIXES) && !f.isDirectory()) {
            metadataFiles.add(f.getAbsolutePath());
        }
    }
    // parse XML metadata
    String xml = DataTools.readFile(id).trim();
    if (xml.startsWith("<?")) {
        xml = xml.substring(xml.indexOf("?>") + 2);
    }
    xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + xml;
    XMLTools.parseXML(xml, new ScanrHandler());
    final List<String> uniqueRows = new ArrayList<String>();
    final List<String> uniqueColumns = new ArrayList<String>();
    if (wellRows == 0 || wellColumns == 0) {
        for (String well : wellLabels.keySet()) {
            if (!Character.isLetter(well.charAt(0)))
                continue;
            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);
            }
        }
        wellRows = uniqueRows.size();
        wellColumns = uniqueColumns.size();
        if (wellRows * wellColumns != wellCount) {
            adjustWellDimensions();
        }
    }
    int nChannels = getSizeC() == 0 ? channelNames.size() : (int) Math.min(channelNames.size(), getSizeC());
    if (nChannels == 0)
        nChannels = 1;
    int nSlices = getSizeZ() == 0 ? 1 : getSizeZ();
    int nTimepoints = getSizeT();
    int nWells = wellCount;
    int nPos = 0;
    if (foundPositions)
        nPos = fieldPositionX.length;
    else
        nPos = fieldRows * fieldColumns;
    if (nPos == 0)
        nPos = 1;
    // get list of TIFF files
    Location dataDir = new Location(dir, "data");
    list = dataDir.list(true);
    if (list == null) {
        // try to find the TIFFs in the current directory
        list = dir.list(true);
    } else
        dir = dataDir;
    if (nTimepoints == 0 || list.length < nTimepoints * nChannels * nSlices * nWells * nPos) {
        nTimepoints = list.length / (nChannels * nWells * nPos * nSlices);
        if (nTimepoints == 0)
            nTimepoints = 1;
    }
    tiffs = new String[nChannels * nWells * nPos * nTimepoints * nSlices];
    Arrays.sort(list, new Comparator<String>() {

        @Override
        public int compare(String s1, String s2) {
            int lastSeparator1 = s1.lastIndexOf(File.separator) + 1;
            int lastSeparator2 = s2.lastIndexOf(File.separator) + 1;
            String dir1 = s1.substring(0, lastSeparator1);
            String dir2 = s2.substring(0, lastSeparator2);
            if (!dir1.equals(dir2)) {
                return dir1.compareTo(dir2);
            }
            int dash1 = s1.indexOf("-", lastSeparator1);
            int dash2 = s2.indexOf("-", lastSeparator2);
            String label1 = dash1 < 0 ? "" : s1.substring(lastSeparator1, dash1);
            String label2 = dash2 < 0 ? "" : s2.substring(lastSeparator2, dash2);
            if (label1.equals(label2)) {
                String remainder1 = dash1 < 0 ? s1 : s1.substring(dash1);
                String remainder2 = dash2 < 0 ? s2 : s2.substring(dash2);
                return remainder1.compareTo(remainder2);
            }
            Integer index1 = wellLabels.get(label1);
            Integer index2 = wellLabels.get(label2);
            if (index1 == null && index2 != null) {
                return 1;
            } else if (index1 != null && index2 == null) {
                return -1;
            }
            return index1.compareTo(index2);
        }
    });
    int lastListIndex = 0;
    int next = 0;
    String[] keys = wellLabels.keySet().toArray(new String[wellLabels.size()]);
    Arrays.sort(keys, new Comparator<String>() {

        @Override
        public int compare(String s1, String s2) {
            char row1 = s1.charAt(0);
            char row2 = s2.charAt(0);
            final Integer col1 = new Integer(s1.substring(1));
            final Integer col2 = new Integer(s2.substring(1));
            if (row1 < row2) {
                return -1;
            } else if (row1 > row2) {
                return 1;
            }
            return col1.compareTo(col2);
        }
    });
    int realPosCount = 0;
    for (int well = 0; well < nWells; well++) {
        int missingWellFiles = 0;
        int wellIndex = wellNumbers.get(well);
        String wellPos = getBlock(wellIndex, "W");
        int originalIndex = next;
        for (int pos = 0; pos < nPos; pos++) {
            String posPos = getBlock(pos + 1, "P");
            int posIndex = next;
            for (int z = 0; z < nSlices; z++) {
                String zPos = getBlock(z, "Z");
                for (int t = 0; t < nTimepoints; t++) {
                    String tPos = getBlock(t, "T");
                    for (int c = 0; c < nChannels; c++) {
                        for (int i = lastListIndex; i < list.length; i++) {
                            String file = list[i];
                            if (file.indexOf(wellPos) != -1 && file.indexOf(zPos) != -1 && file.indexOf(posPos) != -1 && file.indexOf(tPos) != -1 && file.indexOf(channelNames.get(c)) != -1) {
                                tiffs[next++] = new Location(dir, file).getAbsolutePath();
                                if (c == nChannels - 1) {
                                    lastListIndex = i;
                                }
                                break;
                            }
                        }
                        if (next == originalIndex) {
                            missingWellFiles++;
                        }
                    }
                }
            }
            if (posIndex != next)
                realPosCount++;
        }
        if (next == originalIndex && well < keys.length) {
            wellLabels.remove(keys[well]);
        }
        if (next == originalIndex && missingWellFiles == nSlices * nTimepoints * nChannels * nPos) {
            wellNumbers.remove(well);
        }
    }
    nWells = wellNumbers.size();
    if (wellLabels.size() > 0 && wellLabels.size() != nWells) {
        uniqueRows.clear();
        uniqueColumns.clear();
        for (String well : wellLabels.keySet()) {
            if (!Character.isLetter(well.charAt(0)))
                continue;
            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);
            }
        }
        nWells = uniqueRows.size() * uniqueColumns.size();
        adjustWellDimensions();
    }
    if (realPosCount < nPos) {
        nPos = realPosCount;
    }
    reader = new MinimalTiffReader();
    reader.setId(tiffs[0]);
    int sizeX = reader.getSizeX();
    int sizeY = reader.getSizeY();
    int pixelType = reader.getPixelType();
    tileWidth = reader.getOptimalTileWidth();
    tileHeight = reader.getOptimalTileHeight();
    switch(pixelType) {
        case FormatTools.INT8:
            pixelType = FormatTools.UINT8;
            break;
        case FormatTools.INT16:
            pixelType = FormatTools.UINT16;
            break;
    }
    boolean rgb = reader.isRGB();
    boolean interleaved = reader.isInterleaved();
    boolean indexed = reader.isIndexed();
    boolean littleEndian = reader.isLittleEndian();
    reader.close();
    int seriesCount = nWells * nPos;
    core.clear();
    for (int i = 0; i < seriesCount; i++) {
        CoreMetadata ms = new CoreMetadata();
        core.add(ms);
        ms.sizeC = nChannels;
        ms.sizeZ = nSlices;
        ms.sizeT = nTimepoints;
        ms.sizeX = sizeX;
        ms.sizeY = sizeY;
        ms.pixelType = pixelType;
        ms.rgb = rgb;
        ms.interleaved = interleaved;
        ms.indexed = indexed;
        ms.littleEndian = littleEndian;
        ms.dimensionOrder = "XYCTZ";
        ms.imageCount = nSlices * nTimepoints * nChannels;
        ms.bitsPerPixel = 12;
    }
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this);
    store.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
    store.setPlateColumns(new PositiveInteger(wellColumns), 0);
    store.setPlateRows(new PositiveInteger(wellRows), 0);
    String plateAcqID = MetadataTools.createLSID("PlateAcquisition", 0, 0);
    store.setPlateAcquisitionID(plateAcqID, 0, 0);
    int nFields = 0;
    if (foundPositions) {
        nFields = fieldPositionX.length;
    } else {
        nFields = fieldRows * fieldColumns;
    }
    PositiveInteger fieldCount = FormatTools.getMaxFieldCount(nFields);
    if (fieldCount != null) {
        store.setPlateAcquisitionMaximumFieldCount(fieldCount, 0, 0);
    }
    for (int i = 0; i < getSeriesCount(); i++) {
        int field = i % nFields;
        int well = i / nFields;
        int index = well;
        while (wellNumbers.get(index) == null && index < wellNumbers.size()) {
            index++;
        }
        int wellIndex = wellNumbers.get(index) == null ? index : wellNumbers.get(index) - 1;
        int wellRow = wellIndex / wellColumns;
        int wellCol = wellIndex % wellColumns;
        if (field == 0) {
            store.setWellID(MetadataTools.createLSID("Well", 0, well), 0, well);
            store.setWellColumn(new NonNegativeInteger(wellCol), 0, well);
            store.setWellRow(new NonNegativeInteger(wellRow), 0, well);
        }
        String wellSample = MetadataTools.createLSID("WellSample", 0, well, field);
        store.setWellSampleID(wellSample, 0, well, field);
        store.setWellSampleIndex(new NonNegativeInteger(i), 0, well, field);
        String imageID = MetadataTools.createLSID("Image", i);
        store.setWellSampleImageRef(imageID, 0, well, field);
        store.setImageID(imageID, i);
        String name = "Well " + (well + 1) + ", Field " + (field + 1) + " (Spot " + (i + 1) + ")";
        store.setImageName(name, i);
        store.setPlateAcquisitionWellSampleRef(wellSample, 0, 0, i);
    }
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.MINIMUM) {
        for (int i = 0; i < getSeriesCount(); i++) {
            for (int c = 0; c < getSizeC(); c++) {
                store.setChannelName(channelNames.get(c), i, c);
            }
            Length x = FormatTools.getPhysicalSizeX(pixelSize);
            Length y = FormatTools.getPhysicalSizeY(pixelSize);
            if (x != null) {
                store.setPixelsPhysicalSizeX(x, i);
            }
            if (y != null) {
                store.setPixelsPhysicalSizeY(y, i);
            }
            if (fieldPositionX != null && fieldPositionY != null) {
                int field = i % nFields;
                int well = i / nFields;
                final Length posX = fieldPositionX[field];
                final Length posY = fieldPositionY[field];
                store.setWellSamplePositionX(posX, 0, well, field);
                store.setWellSamplePositionY(posY, 0, well, field);
                for (int c = 0; c < getSizeC(); c++) {
                    int image = getIndex(0, c, 0);
                    store.setPlaneTheZ(new NonNegativeInteger(0), i, image);
                    store.setPlaneTheC(new NonNegativeInteger(c), i, image);
                    store.setPlaneTheT(new NonNegativeInteger(0), i, image);
                    store.setPlanePositionX(fieldPositionX[field], i, image);
                    store.setPlanePositionY(fieldPositionY[field], i, image);
                    // exposure time is stored in milliseconds
                    // convert to seconds before populating MetadataStore
                    Double time = exposures.get(c);
                    if (time != null) {
                        time /= 1000;
                        store.setPlaneExposureTime(new Time(time, UNITS.SECOND), i, image);
                    }
                    if (deltaT != null) {
                        store.setPlaneDeltaT(new Time(deltaT, UNITS.SECOND), i, image);
                    }
                }
            }
        }
        String row = wellRows > 26 ? "Number" : "Letter";
        String col = wellRows > 26 ? "Letter" : "Number";
        store.setPlateRowNamingConvention(getNamingConvention(row), 0);
        store.setPlateColumnNamingConvention(getNamingConvention(col), 0);
        store.setPlateName(plateName, 0);
    }
}
Also used : PositiveInteger(ome.xml.model.primitives.PositiveInteger) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) ArrayList(java.util.ArrayList) Time(ome.units.quantity.Time) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException) PositiveInteger(ome.xml.model.primitives.PositiveInteger) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) HashMap(java.util.HashMap) Map(java.util.Map) Location(loci.common.Location)

Example 18 with Time

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

the class PrintTimestamps method printTimingPerPlane.

/**
 * Outputs timing details per plane.
 *
 * This information may seem redundant or unnecessary, but it is possible
 * that two image planes recorded at the same timepoint actually have
 * slightly different timestamps. Thus, OME allows for recording a separate
 * timestamp for every individual image plane.
 */
public static void printTimingPerPlane(IMetadata meta, int series) {
    System.out.println();
    System.out.println("Timing information per plane (from beginning of experiment):");
    int planeCount = meta.getPlaneCount(series);
    for (int i = 0; i < planeCount; i++) {
        Time deltaT = meta.getPlaneDeltaT(series, i);
        if (deltaT == null)
            continue;
        // convert plane ZCT coordinates into image plane index
        int z = meta.getPlaneTheZ(series, i).getValue().intValue();
        int c = meta.getPlaneTheC(series, i).getValue().intValue();
        int t = meta.getPlaneTheT(series, i).getValue().intValue();
        System.out.println("\tZ " + z + ", C " + c + ", T " + t + " = " + deltaT.value(UNITS.SECOND).doubleValue() + " s");
    }
}
Also used : Time(ome.units.quantity.Time)

Example 19 with Time

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

the class ColumbusReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
protected void initFile(String id) throws FormatException, IOException {
    Location xml = findXML(id);
    if (null == xml) {
        throw new FormatException("Could not find " + XML_FILE);
    }
    id = xml.getAbsolutePath();
    super.initFile(id);
    Location parent = new Location(currentId).getAbsoluteFile().getParentFile();
    // parse plate layout and image dimensions from the XML files
    String xmlData = DataTools.readFile(id);
    MeasurementHandler handler = new MeasurementHandler();
    XMLTools.parseXML(xmlData, handler);
    String[] parentDirectories = parent.list(true);
    Arrays.sort(parentDirectories);
    ArrayList<String> timepointDirs = new ArrayList<String>();
    for (String file : parentDirectories) {
        Location absFile = new Location(parent, file);
        if (absFile.isDirectory()) {
            timepointDirs.add(absFile.getAbsolutePath());
            for (String f : absFile.list(true)) {
                if (!checkSuffix(f, "tif")) {
                    if (!metadataFiles.contains(file + File.separator + f)) {
                        metadataFiles.add(file + File.separator + f);
                    }
                }
            }
        }
    }
    for (int i = 0; i < metadataFiles.size(); i++) {
        String metadataFile = metadataFiles.get(i);
        int end = metadataFile.indexOf(File.separator);
        String timepointPath = end < 0 ? "" : parent + File.separator + metadataFile.substring(0, end);
        Location f = new Location(parent + File.separator + metadataFile);
        if (!f.exists()) {
            metadataFile = metadataFile.substring(end + 1);
            f = new Location(parent, metadataFile);
        }
        String path = f.getAbsolutePath();
        metadataFiles.set(i, path);
        if (checkSuffix(path, "columbusidx.xml")) {
            int timepoint = timepointDirs.indexOf(timepointPath);
            if (timepointDirs.size() == 0) {
                timepoint = 0;
            }
            parseImageXML(path, timepoint);
        }
    }
    // process plane list to determine plate size
    Comparator<Plane> planeComp = new Comparator<Plane>() {

        public int compare(Plane p1, Plane p2) {
            if (p1.row != p2.row) {
                return p1.row - p2.row;
            }
            if (p1.col != p2.col) {
                return p1.col - p2.col;
            }
            if (p1.field != p2.field) {
                return p1.field - p2.field;
            }
            if (p1.timepoint != p2.timepoint) {
                return p1.timepoint - p2.timepoint;
            }
            if (p1.channel != p2.channel) {
                return p1.channel - p2.channel;
            }
            return 0;
        }
    };
    Plane[] tmpPlanes = planes.toArray(new Plane[planes.size()]);
    Arrays.sort(tmpPlanes, planeComp);
    planes.clear();
    reader = new MinimalTiffReader();
    reader.setId(tmpPlanes[0].file);
    core = reader.getCoreMetadataList();
    CoreMetadata m = core.get(0);
    m.sizeC = 0;
    m.sizeT = 0;
    ArrayList<Integer> uniqueSamples = new ArrayList<Integer>();
    ArrayList<Integer> uniqueRows = new ArrayList<Integer>();
    ArrayList<Integer> uniqueCols = new ArrayList<Integer>();
    for (Plane p : tmpPlanes) {
        planes.add(p);
        int sampleIndex = p.row * handler.getPlateColumns() + p.col;
        if (!uniqueSamples.contains(sampleIndex)) {
            uniqueSamples.add(sampleIndex);
        }
        if (!uniqueRows.contains(p.row)) {
            uniqueRows.add(p.row);
        }
        if (!uniqueCols.contains(p.col)) {
            uniqueCols.add(p.col);
        }
        // counts are assumed to be non-sparse
        if (p.field >= nFields) {
            nFields = p.field + 1;
        }
        if (p.channel >= getSizeC()) {
            m.sizeC = p.channel + 1;
        }
        if (p.timepoint >= getSizeT()) {
            m.sizeT = p.timepoint + 1;
        }
    }
    m.sizeZ = 1;
    m.imageCount = getSizeZ() * getSizeC() * getSizeT();
    m.dimensionOrder = "XYCTZ";
    m.rgb = false;
    int seriesCount = uniqueSamples.size() * nFields;
    for (int i = 1; i < seriesCount; i++) {
        core.add(m);
    }
    // populate the MetadataStore
    MetadataStore store = makeFilterMetadata();
    MetadataTools.populatePixels(store, this, true);
    store.setScreenID(MetadataTools.createLSID("Screen", 0), 0);
    store.setScreenName(handler.getScreenName(), 0);
    store.setPlateID(MetadataTools.createLSID("Plate", 0), 0);
    store.setPlateName(handler.getPlateName(), 0);
    store.setPlateRows(new PositiveInteger(handler.getPlateRows()), 0);
    store.setPlateColumns(new PositiveInteger(handler.getPlateColumns()), 0);
    String imagePrefix = handler.getPlateName() + " Well ";
    int wellSample = 0;
    int nextWell = -1;
    Timestamp date = new Timestamp(acquisitionDate);
    long timestampSeconds = date.asInstant().getMillis() / 1000;
    for (Integer row : uniqueRows) {
        for (Integer col : uniqueCols) {
            if (!uniqueSamples.contains(row * handler.getPlateColumns() + col)) {
                continue;
            }
            nextWell++;
            store.setWellID(MetadataTools.createLSID("Well", 0, nextWell), 0, nextWell);
            store.setWellRow(new NonNegativeInteger(row), 0, nextWell);
            store.setWellColumn(new NonNegativeInteger(col), 0, nextWell);
            for (int field = 0; field < nFields; field++) {
                Plane p = lookupPlane(row, col, field, 0, 0);
                String wellSampleID = MetadataTools.createLSID("WellSample", 0, nextWell, field);
                store.setWellSampleID(wellSampleID, 0, nextWell, field);
                store.setWellSampleIndex(new NonNegativeInteger(wellSample), 0, nextWell, field);
                if (p != null) {
                    store.setWellSamplePositionX(new Length(p.positionX, UNITS.REFERENCEFRAME), 0, nextWell, field);
                    store.setWellSamplePositionY(new Length(p.positionY, UNITS.REFERENCEFRAME), 0, nextWell, field);
                }
                String imageID = MetadataTools.createLSID("Image", wellSample);
                store.setImageID(imageID, wellSample);
                store.setWellSampleImageRef(imageID, 0, nextWell, field);
                store.setImageName(imagePrefix + (char) (row + 'A') + (col + 1) + " Field #" + (field + 1), wellSample);
                store.setImageAcquisitionDate(date, wellSample);
                if (p != null) {
                    p.series = wellSample;
                    store.setPixelsPhysicalSizeX(FormatTools.getPhysicalSizeX(p.sizeX), p.series);
                    store.setPixelsPhysicalSizeY(FormatTools.getPhysicalSizeY(p.sizeY), p.series);
                    for (int c = 0; c < getSizeC(); c++) {
                        p = lookupPlane(row, col, field, 0, c);
                        if (p != null) {
                            p.series = wellSample;
                            store.setChannelName(p.channelName, p.series, p.channel);
                            if ((int) p.emWavelength > 0) {
                                store.setChannelEmissionWavelength(FormatTools.getEmissionWavelength(p.emWavelength), p.series, p.channel);
                            }
                            if ((int) p.exWavelength > 0) {
                                store.setChannelExcitationWavelength(FormatTools.getExcitationWavelength(p.exWavelength), p.series, p.channel);
                            }
                            store.setChannelColor(p.channelColor, p.series, p.channel);
                        }
                        for (int t = 0; t < getSizeT(); t++) {
                            p = lookupPlane(row, col, field, t, c);
                            if (p != null) {
                                p.series = wellSample;
                                store.setPlaneDeltaT(new Time(p.deltaT - timestampSeconds, UNITS.SECOND), p.series, getIndex(0, c, t));
                            }
                        }
                    }
                }
                wellSample++;
            }
        }
    }
}
Also used : PositiveInteger(ome.xml.model.primitives.PositiveInteger) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) ArrayList(java.util.ArrayList) Time(ome.units.quantity.Time) CoreMetadata(loci.formats.CoreMetadata) Timestamp(ome.xml.model.primitives.Timestamp) FormatException(loci.formats.FormatException) Comparator(java.util.Comparator) PositiveInteger(ome.xml.model.primitives.PositiveInteger) NonNegativeInteger(ome.xml.model.primitives.NonNegativeInteger) MetadataStore(loci.formats.meta.MetadataStore) Length(ome.units.quantity.Length) Location(loci.common.Location)

Example 20 with Time

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

the class FV1000Reader method populateMetadataStore.

private void populateMetadataStore(MetadataStore store, String path) throws FormatException, IOException {
    String instrumentID = MetadataTools.createLSID("Instrument", 0);
    store.setInstrumentID(instrumentID, 0);
    for (int i = 0; i < getSeriesCount(); i++) {
        // link Instrument and Image
        store.setImageInstrumentRef(instrumentID, i);
        if (pixelSizeX != null) {
            Double sizeX = new Double(pixelSizeX);
            Length size = FormatTools.getPhysicalSizeX(sizeX);
            if (size != null) {
                store.setPixelsPhysicalSizeX(size, i);
            }
        }
        if (pixelSizeY != null) {
            Double sizeY = new Double(pixelSizeY);
            Length size = FormatTools.getPhysicalSizeY(sizeY);
            if (size != null) {
                store.setPixelsPhysicalSizeY(size, i);
            }
        }
        if (pixelSizeZ == Double.NEGATIVE_INFINITY || pixelSizeZ == Double.POSITIVE_INFINITY || getSizeZ() == 1) {
            pixelSizeZ = 1d;
        }
        if (pixelSizeT == Double.NEGATIVE_INFINITY || pixelSizeT == Double.POSITIVE_INFINITY || getSizeT() == 1) {
            pixelSizeT = 1d;
        }
        Length sizeZ = FormatTools.getPhysicalSizeZ(pixelSizeZ);
        if (sizeZ != null) {
            store.setPixelsPhysicalSizeZ(sizeZ, i);
        }
        store.setPixelsTimeIncrement(new Time(pixelSizeT, UNITS.SECOND), i);
        for (int p = 0; p < core.get(i).imageCount; p++) {
            store.setPlaneDeltaT(new Time(pixelSizeT * p, UNITS.SECOND), i, p);
        }
        for (int c = 0; c < core.get(i).sizeC; c++) {
            if (c < illuminations.size()) {
                store.setChannelIlluminationType(getIlluminationType(illuminations.get(c)), i, c);
            }
        }
    }
    int channelIndex = 0;
    for (ChannelData channel : channels) {
        if (!channel.active)
            continue;
        if (channelIndex >= getEffectiveSizeC())
            break;
        // populate Detector data
        String detectorID = MetadataTools.createLSID("Detector", 0, channelIndex);
        store.setDetectorID(detectorID, 0, channelIndex);
        store.setDetectorSettingsID(detectorID, 0, channelIndex);
        store.setDetectorGain(channel.gain, 0, channelIndex);
        ElectricPotential theVoltage = FormatTools.createElectricPotential(channel.voltage, UNITS.VOLT);
        if (theVoltage != null) {
            store.setDetectorVoltage(theVoltage, 0, channelIndex);
        }
        store.setDetectorType(getDetectorType("PMT"), 0, channelIndex);
        // populate LogicalChannel data
        store.setChannelName(channel.name, 0, channelIndex);
        String lightSourceID = MetadataTools.createLSID("LightSource", 0, channelIndex);
        store.setChannelLightSourceSettingsID(lightSourceID, 0, channelIndex);
        Length wavelength = FormatTools.getWavelength(channel.exWave);
        Length emission = FormatTools.getEmissionWavelength(channel.emWave);
        Length excitation = FormatTools.getExcitationWavelength(channel.exWave);
        if (emission != null) {
            store.setChannelEmissionWavelength(emission, 0, channelIndex);
        }
        if (excitation != null) {
            store.setChannelExcitationWavelength(excitation, 0, channelIndex);
        }
        if (wavelength != null) {
            store.setChannelLightSourceSettingsWavelength(wavelength, 0, channelIndex);
        }
        // populate Filter data
        if (channel.barrierFilter != null) {
            String filterID = MetadataTools.createLSID("Filter", 0, channelIndex);
            store.setFilterID(filterID, 0, channelIndex);
            store.setFilterModel(channel.barrierFilter, 0, channelIndex);
            if (channel.barrierFilter.indexOf('-') != -1) {
                String[] emValues = channel.barrierFilter.split("-");
                for (int i = 0; i < emValues.length; i++) {
                    emValues[i] = emValues[i].replaceAll("\\D", "");
                }
                try {
                    Double cutIn = new Double(emValues[0]);
                    Double cutOut = new Double(emValues[1]);
                    Length in = FormatTools.getCutIn(cutIn);
                    Length out = FormatTools.getCutOut(cutOut);
                    if (in != null) {
                        store.setTransmittanceRangeCutIn(in, 0, channelIndex);
                    }
                    if (out != null) {
                        store.setTransmittanceRangeCutOut(out, 0, channelIndex);
                    }
                } catch (NumberFormatException e) {
                }
            }
            store.setLightPathEmissionFilterRef(filterID, 0, channelIndex, 0);
        }
        // populate FilterSet data
        int emIndex = channelIndex * 2;
        int exIndex = channelIndex * 2 + 1;
        String emFilter = MetadataTools.createLSID("Dichroic", 0, emIndex);
        String exFilter = MetadataTools.createLSID("Dichroic", 0, exIndex);
        // populate Dichroic data
        store.setDichroicID(emFilter, 0, emIndex);
        store.setDichroicModel(channel.emissionFilter, 0, emIndex);
        store.setDichroicID(exFilter, 0, exIndex);
        store.setDichroicModel(channel.excitationFilter, 0, exIndex);
        store.setLightPathDichroicRef(exFilter, 0, channelIndex);
        // populate Laser data
        store.setLaserID(lightSourceID, 0, channelIndex);
        store.setLaserLaserMedium(getLaserMedium(channel.dyeName), 0, channelIndex);
        if (channelIndex < wavelengths.size()) {
            Length wave = FormatTools.getWavelength(wavelengths.get(channelIndex));
            if (wave != null) {
                store.setLaserWavelength(wave, 0, channelIndex);
            }
        }
        store.setLaserType(getLaserType("Other"), 0, channelIndex);
        channelIndex++;
    }
    if (lensNA != null)
        store.setObjectiveLensNA(new Double(lensNA), 0, 0);
    store.setObjectiveModel(objectiveName, 0, 0);
    if (magnification != null) {
        Double mag = Double.parseDouble(magnification);
        store.setObjectiveNominalMagnification(mag, 0, 0);
    }
    if (workingDistance != null) {
        store.setObjectiveWorkingDistance(new Length(new Double(workingDistance), UNITS.MICROMETER), 0, 0);
    }
    store.setObjectiveCorrection(getCorrection("Other"), 0, 0);
    store.setObjectiveImmersion(getImmersion("Other"), 0, 0);
    // link Objective to Image using ObjectiveSettings
    String objectiveID = MetadataTools.createLSID("Objective", 0, 0);
    store.setObjectiveID(objectiveID, 0, 0);
    store.setObjectiveSettingsID(objectiveID, 0);
    if (getMetadataOptions().getMetadataLevel() != MetadataLevel.NO_OVERLAYS) {
        int nextROI = -1;
        // populate ROI data - there is one ROI file per plane
        for (int i = 0; i < roiFilenames.size(); i++) {
            if (i >= getImageCount())
                break;
            String filename = roiFilenames.get(i);
            filename = sanitizeFile(filename, path);
            nextROI = parseROIFile(filename, store, nextROI, i);
        }
    }
    // Populate metadata for the planes
    for (int i = 0; i < planes.size(); i++) {
        PlaneData plane = planes.get(i);
        if (plane.deltaT != null) {
            store.setPlaneDeltaT(new Time(plane.deltaT, UNITS.SECOND), 0, i);
        }
        store.setPlanePositionX(plane.positionX, 0, i);
        store.setPlanePositionY(plane.positionY, 0, i);
        store.setPlanePositionZ(plane.positionZ, 0, i);
    }
}
Also used : Length(ome.units.quantity.Length) Time(ome.units.quantity.Time) ElectricPotential(ome.units.quantity.ElectricPotential)

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