Exemplo n.º 1
0
# coding: utf-8

r"""Force conversions"""

from corelib.units.base import create_code

forces = {"N": 1., "newton": 1., "newtons": 1.,
          "kgf": 9.81, "kilogram_force": 9.81, "kilograms_force": 9.81}

for k in forces.keys():
    exec(create_code("forces", k), globals())


def convert(value, to_unit, from_unit):
    r"""Convenience function for cases where the to_unit and the from_unit
    are in string form

    Parameters
    ----------
    value : float or int
    to_unit : str
        The desired unit
    from_unit : str
        The input unit

    """
    return globals()[to_unit](**{from_unit: value})
Exemplo n.º 2
0
# coding: utf-8
r"""Torque conversions"""

from corelib.units.base import create_code

torques = {
    "Nm": 1.,
    "newton_metre": 1.,
    "newton_metres": 1.,
    "newton_meter": 1.,
    "newton_meters": 1.
}

for k in torques.keys():
    exec(create_code("torques", k), globals())


def convert(value, to_unit, from_unit):
    r"""Convenience function for cases where the to_unit and the from_unit
    are in string form

    Parameters
    ----------
    value : float or int
    to_unit : str
        The desired unit
    from_unit : str
        The input unit

    """
    return globals()[to_unit](**{from_unit: value})
Exemplo n.º 3
0
# coding: utf-8

r"""Speed conversions"""

from corelib.units.base import create_code

speeds = {"ms": 1., "mps": 1., "meter_per_second": 1., "meters_per_second": 1.,
          "kmh": 1000./3600., "kilometer_per_hour": 1000./3600., "kilometers_per_hour": 1000./3600.,
          "kt": 1852./3600., "knt": 1852./3600., "knts": 1852./3600., "knot": 1852./3600., "knots": 1852./3600.}

for k in speeds.keys():
    exec(create_code("speeds", k), globals())


def convert(value, to_unit, from_unit):
    r"""Convenience function for cases where the to_unit and the from_unit
    are in string form

    Parameters
    ----------
    value : float or int
    to_unit : str
        The desired unit
    from_unit : str
        The input unit

    """
    return globals()[to_unit](**{from_unit: value})
Exemplo n.º 4
0
    "mi": 1609.344,
    "mile": 1609.344,
    "miles": 1609.344,
    "ftm": 1.8288,
    "fathom": 1.8288,
    "fathoms": 1.8288,
    "nm": 1852.,
    "nautical_mile": 1852.,
    "nautical_miles": 1852.
}

for k in distances.keys():
    # code = fs_units.base.create_code("distances", k)
    # exec code in module.__dict__
    # g = globals()
    exec(create_code("distances", k), globals())


def convert(value, to_unit, from_unit):
    r"""Convenience function for cases where the to_unit and the from_unit are
    in string form

    Parameters
    ----------
    value : float or int
    to_unit : str
        The desired unit
    from_unit : str
        The input unit

    """
Exemplo n.º 5
0
from corelib.units.base import create_code

areas = {
    "m2": 1.,
    "square_meter": 1.,
    "square_meters": 1.,
    "cm2": 1e-4,
    "square_centimeter": 1e-4,
    "square_centimeters": 1e-4,
    "mm2": 1e-6,
    "square_millimeter": 1e-6,
    "square_millimeters": 1e-6
}

for k in areas.keys():
    exec(create_code("areas", k), globals())


def convert(value, to_unit, from_unit):
    r"""Convenience function for cases where the to_unit and the from_unit are
    in string form

    Parameters
    ----------
    value : float or int
    to_unit : str
        The desired unit
    from_unit : str
        The input unit

    """
Exemplo n.º 6
0
# coding: utf-8

r"""Pressure conversions"""

from corelib.units.base import create_code

pressures = {"Pa": 1., "pascal": 1., "pascals": 1.,
             "hPa": 100., "hectopascal": 100., "hectopascals": 100.,
             "bar": 1e5, "bars": 1e5,
             "millibar": 100., "millibars": 100.,
             "mmHg": 133.322387415, "millimeter_of_mercury": 133.322387415, "millimeters_of_mercury": 133.322387415}

for k in pressures.keys():
    exec(create_code("pressures", k), globals())


def convert(value, to_unit, from_unit):
    r"""Convenience function for cases where the to_unit and the from_unit
    are in string form

    Parameters
    ----------
    value : float or int
    to_unit : str
        The desired unit
    from_unit : str
        The input unit

    """
    return globals()[to_unit](**{from_unit: value})
Exemplo n.º 7
0
# coding: utf-8

r"""Mass conversions"""

from corelib.units.base import create_code

masses = {"kg": 1., "kilogram": 1., "kilograms": 1.,
          "g": 1e-3, "gram": 1e-3, "grams": 1e-3,
          "t": 1000., "ton": 1000., "tons": 1000.,
          "oz": 28.349523125 * 1e-3, "ounce": 28.349523125 * 1e-3, "ounces": 28.349523125 * 1e-3,
          "lb": 0.45359237, "pound": 0.45359237, "pounds": 0.45359237,
          "st": 6.35029318, "stone": 6.35029318, "stones": 6.35029318}

for k in masses.keys():
    exec(create_code("masses", k), globals())


def convert(value, to_unit, from_unit):
    r"""Convenience function for cases where the to_unit and the from_unit
    are in string form

    Parameters
    ----------
    value : float or int
    to_unit : str
        The desired unit
    from_unit : str
        The input unit

    """
    return globals()[to_unit](**{from_unit: value})
Exemplo n.º 8
0
r"""Volume conversions"""

from corelib.units.base import create_code


volumes = {"m3": 1., "cubic_meter": 1., "cubic_meters": 1.,
           "l": 0.001, "litre": 0.001, "liter": 0.001, "litres": 0.001, "liters": 0.001,
           "cm3": 1e-6, "centimeter_cube": 1e-6, "centimeters_cube": 1e-6,
           "ml": 1e-6, "millilitre": 1e-6, "millilitres": 1e-6, "milliliter": 1e-6, "milliliters": 1e-6,
           "mm3": 1e-9, "millimeter_cube": 1e-9, "millimeters_cube": 1e-9,
           "pt": 568.26125 * 1e-6, "pint": 568.26125 * 1e-6, "pints": 568.26125 * 1e-6,
           "qt": 1136.5225 * 1e-6, "quart": 1136.5225 * 1e-6, "quarts": 1136.5225 * 1e-6,
           "gal": 4546.09 * 1e-6, "gallon": 4546.09 * 1e-6, "gallons": 4546.09 * 1e-6}

for k in volumes.keys():
    exec(create_code("volumes", k), globals())


def convert(value, to_unit, from_unit):
    r"""Convenience function for cases where the to_unit and the from_unit
    are in string form

    Parameters
    ----------
    value : float or int
    to_unit : str
        The desired unit
    from_unit : str
        The input unit

    """