How to use the barril.units.Array function in barril

To help you get started, we’ve selected a few barril examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ESSS / barril / src / barril / units / _tests / test_array.py View on Github external
def testEquality():
    a1 = units.Array("length", values=list(range(100)), unit="m")

    assert a1 == units.Array("length", values=list(range(100)), unit="m")
    assert a1 != units.Array("temperature", values=list(range(100)), unit="degC")
    assert a1 != units.Array("length", values=[], unit="m")
    assert a1 != units.Array("length", values=list(range(100)), unit="km")
github ESSS / barril / src / barril / units / _tests / test_operations.py View on Github external
def MakeArray(values):
    """Creates a standard array used by testScalarOperations"""
    return units.Array("length", values, "m")
github ESSS / barril / src / barril / units / _tests / test_unit_database.py View on Github external
default_unit="m",
        default_value=2,
        min_value=0,
        max_value=15,
        is_min_exclusive=False,
        is_max_exclusive=False,
        caption="My Length",
    )
    import numpy

    values = numpy.array(list(range(10)), numpy.float32)
    Array("my length", values, "mm")

    values = numpy.array(list(range(20000, 20010)), numpy.float32)
    # Raise validation error
    another = Array("my length", values, "mm")
    assert not another.IsValid()
    with pytest.raises(ValueError):
        another.CheckValidity()

    # Don't raise validation error if validate = False.
    arr = Array("my length", values, "mm")
    assert not arr.IsValid()

    another = arr.CreateCopy(values=values, unit="mm")
    assert not another.IsValid()

    # Same checks on FixedArray.
    values = numpy.array(list(range(10)), numpy.float32)
    FixedArray(len(values), "my length", values, "mm")

    values = numpy.array(list(range(20000, 20010)), numpy.float32)
github ESSS / barril / src / barril / curve / _tests / test_curve.py View on Github external
def testCurveRepr(unit_database):
    q1 = ObtainQuantity("m", "length")
    q2 = ObtainQuantity("d", "time")
    curve = Curve(Array(q1, []), Array(q2, []))
    assert "Curve(m, d)[]" == repr(curve)

    curve = Curve(Array(q1, list(range(3))), Array(q2, list(range(3))))
    assert "Curve(m, d)[(0, 0) (1, 1) (2, 2)]" == repr(curve)

    curve = Curve(Array(q1, list(range(100))), Array(q2, list(range(100))))
    expected = (
        "Curve(m, d)[(0, 0) (1, 1) (2, 2) (3, 3) (4, 4) (5, 5) "
        "(6, 6) (7, 7) (8, 8) (9, 9) (10, 10) (11, 11) "
        "(12, 12) (13, 13) (14, 14) (15, 15) (16, 16) "
        "(17, 17) (18, 18) (19, 19) (20, 20)  ... ]"
    )
    assert repr(curve) == expected
github ESSS / barril / src / barril / units / _tests / test_array.py View on Github external
def test_check_empty_array(self):
        assert Array.FromScalars(scalars=[]) == Array.CreateEmptyArray()
        assert Array.FromScalars(scalars=[], unit="m") == Array([], "m")

        expected_msg = "If category and value are given, the unit must be specified too."
        with pytest.raises(AssertionError, match=expected_msg):
            Array.FromScalars(scalars=[], category="length")
github ESSS / barril / src / barril / units / _tests / test_array.py View on Github external
def testCopy():
    array = units.Array("length", values=[0, 100], unit="m")
    copy = array.Copy()
    assert copy is array

    # test copy of subclasses
    class MyArray(units.Array):
        pass

    array = MyArray("length", values=[0, 100], unit="m")
    copy = array.Copy()
    assert isinstance(copy, MyArray)
github ESSS / barril / src / barril / curve / _tests / test_curve.py View on Github external
def MakeArray(values):
        return Array(quantity, values=values)
github ESSS / barril / src / barril / units / _tests / test_array.py View on Github external
def testValues():
    array = units.Array("length", values=[100, 150, 200], unit="m")
    assert array.unit == "m"
    assert array.values == [100, 150, 200]

    array = array.CreateCopy(values=list(range(100)))
    array = array.CreateCopy(unit="km")
    assert array.values == [x / 1000.0 for x in range(100)]
    assert 3.0 / 1000.0 == array[3]

    with pytest.raises(AttributeError):
        array.values = 10
github ESSS / barril / src / barril / units / _tests / test_array.py View on Github external
def testDefaultValues(unit_database_len):
    # Not raises exception because by default validation is False on the copy operation
    array = Array("flow rate")
    assert array.values == []

    array = Array(ObtainQuantity("m"))
    assert array.values == []

    with pytest.raises(AssertionError):
        Array(ObtainQuantity("m"), unit="m")