Search in sources :

Example 1 with UnitsLength

use of ome.xml.model.enums.UnitsLength in project bioformats by openmicroscopy.

the class FormatTools method getPhysicalSize.

public static Length getPhysicalSize(Double value, String unit) {
    if (value != null && value != 0 && value < Double.POSITIVE_INFINITY) {
        if (unit != null) {
            try {
                UnitsLength ul = UnitsLength.fromString(unit);
                int ordinal = ul.ordinal();
                Length returnLength = UnitsLength.create(value, ul);
                if (returnLength.value().doubleValue() > Constants.EPSILON && returnLength.value().doubleValue() < Double.POSITIVE_INFINITY) {
                    return returnLength;
                }
                // Using UnitsLength.values().length - 2 as a boundary so as not to include Pixel and Reference Frame as convertible units
                while (returnLength.value().doubleValue() < Constants.EPSILON && ordinal < (UnitsLength.values().length - 3)) {
                    ordinal++;
                    ul = UnitsLength.values()[ordinal];
                    Length tempLength = UnitsLength.create(0, ul);
                    returnLength = UnitsLength.create(returnLength.value(tempLength.unit()), ul);
                }
                if (returnLength.value().doubleValue() > Constants.EPSILON && returnLength.value().doubleValue() < Double.POSITIVE_INFINITY) {
                    return returnLength;
                } else {
                    LOGGER.debug("Expected positive value for PhysicalSize; got {}", value);
                    return null;
                }
            } catch (EnumerationException e) {
            }
        }
        return new Length(value, UNITS.MICROMETER);
    }
    LOGGER.debug("Expected positive value for PhysicalSize; got {}", value);
    return null;
}
Also used : UnitsLength(ome.xml.model.enums.UnitsLength) UnitsLength(ome.xml.model.enums.UnitsLength) Length(ome.units.quantity.Length) EnumerationException(ome.xml.model.enums.EnumerationException)

Example 2 with UnitsLength

use of ome.xml.model.enums.UnitsLength in project bioformats by openmicroscopy.

the class Configuration method getPhysicalSizeX.

public Length getPhysicalSizeX() {
    String physicalSize = currentTable.get(PHYSICAL_SIZE_X);
    String sizeXUnits = currentTable.get(PHYSICAL_SIZE_X_UNIT);
    try {
        UnitsLength xUnits = sizeXUnits == null ? UnitsLength.MICROMETER : UnitsLength.fromString(sizeXUnits);
        return physicalSize == null ? null : UnitsLength.create(new Double(physicalSize), xUnits);
    } catch (NumberFormatException e) {
    } catch (EnumerationException e) {
    }
    return null;
}
Also used : UnitsLength(ome.xml.model.enums.UnitsLength) EnumerationException(ome.xml.model.enums.EnumerationException)

Example 3 with UnitsLength

use of ome.xml.model.enums.UnitsLength in project bioformats by openmicroscopy.

the class FakeReader method parsePosition.

private Length parsePosition(String axis, int s, int index, IniTable table) {
    String position = table.get("Position" + axis + "_" + index);
    String positionUnit = table.get("Position" + axis + "Unit_" + index);
    if (position != null) {
        try {
            Double v = Double.valueOf(position);
            Length size = new Length(v, UNITS.MICROM);
            if (positionUnit != null) {
                try {
                    UnitsLength ul = UnitsLength.fromString(positionUnit);
                    size = UnitsLength.create(v, ul);
                } catch (EnumerationException e) {
                    LOGGER.trace("Could not parse Position" + axis + "Unit for series #" + s + " plane #" + index, e);
                }
            }
            return size;
        } catch (NumberFormatException e) {
            LOGGER.trace("Could not parse Position" + axis + " for series #" + s + " plane #" + index, e);
        }
    }
    return null;
}
Also used : UnitsLength(ome.xml.model.enums.UnitsLength) UnitsLength(ome.xml.model.enums.UnitsLength) Length(ome.units.quantity.Length) EnumerationException(ome.xml.model.enums.EnumerationException)

Example 4 with UnitsLength

use of ome.xml.model.enums.UnitsLength in project bioformats by openmicroscopy.

the class Configuration method getPhysicalSizeY.

public Length getPhysicalSizeY() {
    String physicalSize = currentTable.get(PHYSICAL_SIZE_Y);
    String sizeYUnits = currentTable.get(PHYSICAL_SIZE_Y_UNIT);
    try {
        UnitsLength yUnits = sizeYUnits == null ? UnitsLength.MICROMETER : UnitsLength.fromString(sizeYUnits);
        return physicalSize == null ? null : UnitsLength.create(new Double(physicalSize), yUnits);
    } catch (NumberFormatException e) {
    } catch (EnumerationException e) {
    }
    return null;
}
Also used : UnitsLength(ome.xml.model.enums.UnitsLength) EnumerationException(ome.xml.model.enums.EnumerationException)

Example 5 with UnitsLength

use of ome.xml.model.enums.UnitsLength in project bioformats by openmicroscopy.

the class Configuration method getPhysicalSizeZ.

public Length getPhysicalSizeZ() {
    String physicalSize = currentTable.get(PHYSICAL_SIZE_Z);
    String sizeZUnits = currentTable.get(PHYSICAL_SIZE_Z_UNIT);
    try {
        UnitsLength zUnits = sizeZUnits == null ? UnitsLength.MICROMETER : UnitsLength.fromString(sizeZUnits);
        return physicalSize == null ? null : UnitsLength.create(new Double(physicalSize), zUnits);
    } catch (NumberFormatException e) {
    } catch (EnumerationException e) {
    }
    return null;
}
Also used : UnitsLength(ome.xml.model.enums.UnitsLength) EnumerationException(ome.xml.model.enums.EnumerationException)

Aggregations

EnumerationException (ome.xml.model.enums.EnumerationException)5 UnitsLength (ome.xml.model.enums.UnitsLength)5 Length (ome.units.quantity.Length)2