How to use the barril.units.FixedArray 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_fixedarray.py View on Github external
def testCopy(unit_database_start_units):
    point = units.FixedArray(3, "length", [100, 150, 200], "m")
    assert point.Copy() == point

    #         other = units.FixedArray(3, 'length', [1, 2, 3], 'km')
    other = point.CreateCopy()
    assert other == point

    # test copy with subclasses
    class MyFixedArray(units.FixedArray):
        pass

    point = MyFixedArray(3, "length", [100, 150, 200], "m")
    assert isinstance(point.Copy(), MyFixedArray)

    point = units.FixedArray(3, "length", [100, 150, 200], "m")
github ESSS / barril / src / barril / units / _tests / test_unit_database.py View on Github external
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)
    # Raise validation error
    another = FixedArray(len(values), "my length", values, "mm")
    assert not another.IsValid()

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

    another = arr.CreateCopy(values=values, unit="mm")
    assert not another.IsValid()
github ESSS / barril / src / barril / units / _tests / test_fixedarray.py View on Github external
def testDefaultValues(unit_database_start_units):
    # Not raises exception because by default validation is False on the copy operation
    array = units.FixedArray(3, "length")
    assert array.values == [0.0, 0.0, 0.0]

    array = units.FixedArray(3, ObtainQuantity("m"))
    assert array.values == [0.0, 0.0, 0.0]

    with pytest.raises(AssertionError):
        units.FixedArray(3, ObtainQuantity("m"), unit="m")
github ESSS / barril / src / barril / units / _tests / test_fixedarray.py View on Github external
def testCreateWithQuantity(unit_database_start_units):
    units.FixedArray.CreateWithQuantity(
        Quantity.CreateDerived(OrderedDict()), [100, 150, 200], dimension=3
    )

    quantity = ObtainQuantity("m", "length")
    a1 = units.FixedArray(3, quantity, values=[1, 2, 3])
    a2 = units.FixedArray(3, quantity, values=[1, 2, 3])

    assert a1.GetValues("km") == [0.001, 0.002, 0.003]
    assert a2.GetValues() == [1, 2, 3]
github ESSS / barril / src / barril / units / _tests / test_fixedarray.py View on Github external
def testReadOnlyQuantity(unit_database_start_units):
    quantity = ObtainQuantity("m", "length")
    array = units.FixedArray(3, quantity, values=[1, 2, 3])
    assert approx(array.GetValues("km")) == [0.001, 0.002, 0.003]
github ESSS / barril / src / barril / units / _tests / test_fixedarray.py View on Github external
def testFixedArrayChangingIndex():
    fixed_array = units.FixedArray(3, [1, 2, 3], "m")
    assert fixed_array.ChangingIndex(0, 5) == units.FixedArray(3, [5, 2, 3], "m")
    assert fixed_array.ChangingIndex(0, units.Scalar(5, "m")) == units.FixedArray(3, [5, 2, 3], "m")
    assert fixed_array.ChangingIndex(0, (5,)) == units.FixedArray(3, [5, 2, 3], "m")

    # Different unit
    assert fixed_array.ChangingIndex(0, (5, "cm")) == units.FixedArray(3, [5, 200, 300], "cm")
    assert fixed_array.ChangingIndex(0, units.Scalar(5, "cm")) == units.FixedArray(
        3, [5, 200, 300], "cm"
    )

    # Keeping fixed array unit
    assert fixed_array.ChangingIndex(
        0, units.Scalar(5, "cm"), use_value_unit=False
    ) == units.FixedArray(3, [0.05, 2, 3], "m")

    # Other indexes
github ESSS / barril / src / barril / units / _tests / test_fixedarray.py View on Github external
# Different unit
    assert fixed_array.ChangingIndex(0, (5, "cm")) == units.FixedArray(3, [5, 200, 300], "cm")
    assert fixed_array.ChangingIndex(0, units.Scalar(5, "cm")) == units.FixedArray(
        3, [5, 200, 300], "cm"
    )

    # Keeping fixed array unit
    assert fixed_array.ChangingIndex(
        0, units.Scalar(5, "cm"), use_value_unit=False
    ) == units.FixedArray(3, [0.05, 2, 3], "m")

    # Other indexes
    assert fixed_array.ChangingIndex(1, units.Scalar(5, "cm")) == units.FixedArray(
        3, [100, 5, 300], "cm"
    )
    assert fixed_array.ChangingIndex(2, units.Scalar(5, "cm")) == units.FixedArray(
        3, [100, 200, 5], "cm"
    )
github ESSS / barril / src / barril / units / _tests / test_fixedarray.py View on Github external
def testFixedArrayIndexAsScalar():
    from barril.units import Scalar

    fixed_array = units.FixedArray(3, "length of path", [1, 2, 3], "m")
    assert fixed_array.IndexAsScalar(0).GetCategory() == "length of path"
    assert fixed_array.IndexAsScalar(0) == Scalar("length of path", 1, "m")
    assert fixed_array.IndexAsScalar(1) == Scalar("length of path", 2, "m")