Search in sources :

Example 1 with PositiveFloat

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

the class WlzReader method initFile.

// -- Internal FormatReader API methods --
/* @see loci.formats.FormatReader#initFile(String) */
@Override
protected void initFile(String id) throws FormatException, IOException {
    super.initFile(id);
    try {
        ServiceFactory factory = new ServiceFactory();
        wlz = factory.getInstance(WlzService.class);
    } catch (DependencyException e) {
        throw new FormatException(NO_WLZ_MSG, e);
    }
    if (wlz != null) {
        wlz.open(id, "r");
        CoreMetadata md = core.get(0);
        MetadataStore store = makeFilterMetadata();
        md.rgb = wlz.isRGB();
        md.interleaved = false;
        md.indexed = false;
        md.sizeX = wlz.getSizeX();
        md.sizeY = wlz.getSizeY();
        md.sizeZ = wlz.getSizeZ();
        md.sizeC = wlz.getSizeC();
        md.sizeT = wlz.getSizeT();
        md.dimensionOrder = "XYZCT";
        md.imageCount = wlz.getSizeZ();
        md.pixelType = wlz.getPixelType();
        PositiveFloat x = new PositiveFloat(Math.abs(wlz.getVoxSzX()));
        PositiveFloat y = new PositiveFloat(Math.abs(wlz.getVoxSzY()));
        PositiveFloat z = new PositiveFloat(Math.abs(wlz.getVoxSzZ()));
        store.setPixelsPhysicalSizeX(FormatTools.createLength(x, UNITS.MICROMETER), 0);
        store.setPixelsPhysicalSizeY(FormatTools.createLength(y, UNITS.MICROMETER), 0);
        store.setPixelsPhysicalSizeZ(FormatTools.createLength(z, UNITS.MICROMETER), 0);
        store.setStageLabelName(wlz.getWlzOrgLabelName(), 0);
        store.setStageLabelX(new Length(wlz.getOrgX(), UNITS.REFERENCEFRAME), 0);
        store.setStageLabelY(new Length(wlz.getOrgY(), UNITS.REFERENCEFRAME), 0);
        store.setStageLabelZ(new Length(wlz.getOrgZ(), UNITS.REFERENCEFRAME), 0);
        MetadataTools.populatePixels(store, this);
    }
}
Also used : WlzService(loci.formats.services.WlzService) MetadataStore(loci.formats.meta.MetadataStore) ServiceFactory(loci.common.services.ServiceFactory) Length(ome.units.quantity.Length) PositiveFloat(ome.xml.model.primitives.PositiveFloat) DependencyException(loci.common.services.DependencyException) CoreMetadata(loci.formats.CoreMetadata) FormatException(loci.formats.FormatException)

Example 2 with PositiveFloat

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

the class ZeissCZIReader method translateScaling.

private void translateScaling(Element root) {
    NodeList scalings = root.getElementsByTagName("Scaling");
    if (scalings == null || scalings.getLength() == 0) {
        return;
    }
    Element scaling = (Element) scalings.item(0);
    NodeList distances = getGrandchildren(scaling, "Items", "Distance");
    if (distances != null) {
        for (int i = 0; i < distances.getLength(); i++) {
            Element distance = (Element) distances.item(i);
            String id = distance.getAttribute("Id");
            String originalValue = getFirstNodeValue(distance, "Value");
            if (originalValue == null) {
                continue;
            }
            Double value = new Double(originalValue) * 1000000;
            if (value > 0) {
                PositiveFloat size = new PositiveFloat(value);
                if (id.equals("X")) {
                    for (int series = 0; series < getSeriesCount(); series++) {
                        store.setPixelsPhysicalSizeX(FormatTools.createLength(size, UNITS.MICROMETER), series);
                    }
                } else if (id.equals("Y")) {
                    for (int series = 0; series < getSeriesCount(); series++) {
                        store.setPixelsPhysicalSizeY(FormatTools.createLength(size, UNITS.MICROMETER), series);
                    }
                } else if (id.equals("Z")) {
                    zStep = FormatTools.createLength(size, UNITS.MICROM);
                    for (int series = 0; series < getSeriesCount(); series++) {
                        store.setPixelsPhysicalSizeZ(zStep, series);
                    }
                }
            } else {
                LOGGER.debug("Expected positive value for PhysicalSize; got {}", value);
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) PositiveFloat(ome.xml.model.primitives.PositiveFloat)

Example 3 with PositiveFloat

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

the class Upgrade201006Test method validateUpgrade.

@Test
public void validateUpgrade() throws ServiceException {
    assertEquals(1, ome.sizeOfImageList());
    Image image = ome.getImage(0);
    Pixels pixels = image.getPixels();
    // Pixels physical sizes are restricted to positive values
    PositiveFloat positiveFloatValue = new PositiveFloat(10000.0);
    assertEquals(FormatTools.createLength(positiveFloatValue, UNITS.MICROMETER), pixels.getPhysicalSizeX());
    assertEquals(FormatTools.createLength(positiveFloatValue, UNITS.MICROMETER), pixels.getPhysicalSizeY());
    assertNull(pixels.getPhysicalSizeZ());
}
Also used : PositiveFloat(ome.xml.model.primitives.PositiveFloat) Image(ome.xml.model.Image) Pixels(ome.xml.model.Pixels) Test(org.testng.annotations.Test)

Example 4 with PositiveFloat

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

the class LIFReader method translateDetectors.

private void translateDetectors(Element imageNode, int image) throws FormatException {
    NodeList definitions = getNodes(imageNode, "ATLConfocalSettingDefinition");
    if (definitions == null)
        return;
    final List<String> channels = new ArrayList<String>();
    laserActive[image] = new ArrayList<Boolean>();
    int nextChannel = 0;
    for (int definition = 0; definition < definitions.getLength(); definition++) {
        Element definitionNode = (Element) definitions.item(definition);
        String parentName = definitionNode.getParentNode().getNodeName();
        boolean isMaster = parentName.endsWith("Master");
        NodeList detectors = getNodes(definitionNode, "Detector");
        if (detectors == null)
            return;
        int count = 0;
        for (int d = 0; d < detectors.getLength(); d++) {
            Element detector = (Element) detectors.item(d);
            NodeList multibands = null;
            if (!isMaster) {
                multibands = getNodes(definitionNode, "MultiBand");
            }
            String v = detector.getAttribute("Gain");
            Double gain = v == null || v.trim().isEmpty() ? null : new Double(v.trim());
            v = detector.getAttribute("Offset");
            Double offset = v == null || v.trim().isEmpty() ? null : new Double(v.trim());
            boolean active = "1".equals(detector.getAttribute("IsActive"));
            String c = detector.getAttribute("Channel");
            int channel = (c == null || c.trim().length() == 0) ? 0 : Integer.parseInt(c);
            if (active) {
                if (detectorIndexes[image] != null && detectorModels[image] != null) {
                    detectorModels[image].add(detectorIndexes[image].get(channel));
                }
                Element multiband = null;
                if (multibands != null) {
                    for (int i = 0; i < multibands.getLength(); i++) {
                        Element mb = (Element) multibands.item(i);
                        if (channel == Integer.parseInt(mb.getAttribute("Channel"))) {
                            multiband = mb;
                            break;
                        }
                    }
                }
                if (multiband != null) {
                    String dye = multiband.getAttribute("DyeName");
                    if (!channels.contains(dye)) {
                        channels.add(dye);
                    }
                    double cutIn = new Double(multiband.getAttribute("LeftWorld"));
                    double cutOut = new Double(multiband.getAttribute("RightWorld"));
                    if ((int) cutIn > 0) {
                        if (cutIns[image] == null) {
                            cutIns[image] = new ArrayList<PositiveFloat>();
                        }
                        Length in = FormatTools.getCutIn((double) Math.round(cutIn));
                        if (in != null) {
                            cutIns[image].add(in);
                        }
                    }
                    if ((int) cutOut > 0) {
                        if (cutOuts[image] == null) {
                            cutOuts[image] = new ArrayList<PositiveFloat>();
                        }
                        Length out = FormatTools.getCutOut((double) Math.round(cutOut));
                        if (out != null) {
                            cutOuts[image].add(out);
                        }
                    }
                } else {
                    channels.add("");
                }
                if (!isMaster) {
                    if (channel < nextChannel) {
                        nextChannel = 0;
                    }
                    if (nextChannel < getEffectiveSizeC()) {
                        if (gains[image] != null) {
                            gains[image][nextChannel] = gain;
                        }
                        if (detectorOffsets[image] != null) {
                            detectorOffsets[image][nextChannel] = offset;
                        }
                    }
                    nextChannel++;
                }
            } else {
                count++;
            }
            if (active && activeDetector[image] != null) {
                activeDetector[image].add(active);
            }
        }
        // Store values to check if actually it is active.
        if (!isMaster) {
            laserActive[image].add(count < detectors.getLength());
        }
    }
    if (channels != null && channelNames[image] != null) {
        for (int i = 0; i < getEffectiveSizeC(); i++) {
            int index = i + channels.size() - getEffectiveSizeC();
            if (index >= 0 && index < channels.size()) {
                if (channelNames[image][i] == null || channelNames[image][i].trim().isEmpty()) {
                    channelNames[image][i] = channels.get(index);
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Length(ome.units.quantity.Length) PositiveFloat(ome.xml.model.primitives.PositiveFloat)

Example 5 with PositiveFloat

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

the class LIFReader method translateFilterSettings.

private void translateFilterSettings(Element imageNode, int image) throws FormatException {
    NodeList filterSettings = getNodes(imageNode, "FilterSettingRecord");
    if (filterSettings == null)
        return;
    activeDetector[image] = new ArrayList<Boolean>();
    cutIns[image] = new ArrayList<PositiveFloat>();
    cutOuts[image] = new ArrayList<PositiveFloat>();
    filterModels[image] = new ArrayList<String>();
    detectorIndexes[image] = new HashMap<Integer, String>();
    int nextChannel = 0;
    for (int i = 0; i < filterSettings.getLength(); i++) {
        Element filterSetting = (Element) filterSettings.item(i);
        String object = filterSetting.getAttribute("ObjectName");
        String attribute = filterSetting.getAttribute("Attribute");
        String objectClass = filterSetting.getAttribute("ClassName");
        String variant = filterSetting.getAttribute("Variant");
        String data = filterSetting.getAttribute("Data");
        if (attribute.equals("NumericalAperture")) {
            if (variant != null && !variant.trim().isEmpty()) {
                lensNA[image] = new Double(variant.trim());
            }
        } else if (attribute.equals("OrderNumber")) {
            if (variant != null && !variant.trim().isEmpty()) {
                serialNumber[image] = variant.trim();
            }
        } else if (objectClass.equals("CDetectionUnit")) {
            if (attribute.equals("State")) {
                int channel = getChannelIndex(filterSetting);
                if (channel < 0)
                    continue;
                detectorIndexes[image].put(new Integer(data), object);
                activeDetector[image].add("Active".equals(variant.trim()));
            }
        } else if (attribute.equals("Objective")) {
            StringTokenizer tokens = new StringTokenizer(variant, " ");
            boolean foundMag = false;
            final StringBuilder model = new StringBuilder();
            while (!foundMag) {
                String token = tokens.nextToken();
                int x = token.indexOf('x');
                if (x != -1) {
                    foundMag = true;
                    String na = token.substring(x + 1);
                    if (na != null && !na.trim().isEmpty()) {
                        lensNA[image] = new Double(na.trim());
                    }
                    na = token.substring(0, x);
                    if (na != null && !na.trim().isEmpty()) {
                        magnification[image] = new Double(na.trim());
                    }
                } else {
                    model.append(token);
                    model.append(" ");
                }
            }
            String immersion = "Other";
            if (tokens.hasMoreTokens()) {
                immersion = tokens.nextToken();
                if (immersion == null || immersion.trim().isEmpty()) {
                    immersion = "Other";
                }
            }
            immersions[image] = immersion;
            String correction = "Other";
            if (tokens.hasMoreTokens()) {
                correction = tokens.nextToken();
                if (correction == null || correction.trim().isEmpty()) {
                    correction = "Other";
                }
            }
            corrections[image] = correction;
            objectiveModels[image] = model.toString().trim();
        } else if (attribute.equals("RefractionIndex")) {
            if (variant != null && !variant.trim().isEmpty()) {
                refractiveIndex[image] = new Double(variant.trim());
            }
        } else if (attribute.equals("XPos")) {
            if (variant != null && !variant.trim().isEmpty()) {
                final Double number = Double.valueOf(variant.trim());
                posX[image] = new Length(number, UNITS.REFERENCEFRAME);
            }
        } else if (attribute.equals("YPos")) {
            if (variant != null && !variant.trim().isEmpty()) {
                final Double number = Double.valueOf(variant.trim());
                posY[image] = new Length(number, UNITS.REFERENCEFRAME);
            }
        } else if (attribute.equals("ZPos")) {
            if (variant != null && !variant.trim().isEmpty()) {
                final Double number = Double.valueOf(variant.trim());
                posZ[image] = new Length(number, UNITS.REFERENCEFRAME);
            }
        } else if (objectClass.equals("CSpectrophotometerUnit")) {
            Double v = null;
            try {
                v = Double.parseDouble(variant);
            } catch (NumberFormatException e) {
            }
            String description = filterSetting.getAttribute("Description");
            if (description.endsWith("(left)")) {
                filterModels[image].add(object);
                if (v != null && v > 0) {
                    Length in = FormatTools.getCutIn(v);
                    if (in != null) {
                        cutIns[image].add(in);
                    }
                }
            } else if (description.endsWith("(right)")) {
                if (v != null && v > 0) {
                    Length out = FormatTools.getCutOut(v);
                    if (out != null) {
                        cutOuts[image].add(out);
                    }
                }
            } else if (attribute.equals("Stain")) {
                if (nextChannel < channelNames[image].length) {
                    channelNames[image][nextChannel++] = variant;
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) StringTokenizer(java.util.StringTokenizer) Length(ome.units.quantity.Length) PositiveFloat(ome.xml.model.primitives.PositiveFloat)

Aggregations

PositiveFloat (ome.xml.model.primitives.PositiveFloat)6 Length (ome.units.quantity.Length)4 Element (org.w3c.dom.Element)3 NodeList (org.w3c.dom.NodeList)3 MetadataStore (loci.formats.meta.MetadataStore)2 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 DependencyException (loci.common.services.DependencyException)1 ServiceFactory (loci.common.services.ServiceFactory)1 CoreMetadata (loci.formats.CoreMetadata)1 FormatException (loci.formats.FormatException)1 Frame (loci.formats.in.PrairieMetadata.Frame)1 PFile (loci.formats.in.PrairieMetadata.PFile)1 Sequence (loci.formats.in.PrairieMetadata.Sequence)1 WlzService (loci.formats.services.WlzService)1 Power (ome.units.quantity.Power)1 Time (ome.units.quantity.Time)1 Image (ome.xml.model.Image)1 Pixels (ome.xml.model.Pixels)1 Timestamp (ome.xml.model.primitives.Timestamp)1