Example #1
0
def test_point_variable_step_size():
    dims = Dims(ndim=3)
    assert dims.point == (0, ) * 3

    desired_range = ((0, 6, 0.5), (0, 6, 1), (0, 6, 2))
    dims.set_range(range(3), desired_range)
    assert dims.range == desired_range

    # set point updates current_step indirectly
    dims.set_point([0, 1, 2], (2.9, 2.9, 2.9))
    assert dims.current_step == (6, 3, 1)
    # point is a property computed on demand from current_step
    assert dims.point == (3, 3, 2)

    # can set step directly as well
    # note that out of range values get clipped
    dims.set_current_step((0, 1, 2), (1, -3, 5))
    assert dims.current_step == (1, 0, 2)
    assert dims.point == (0.5, 0, 4)

    dims.set_current_step(0, -1)
    assert dims.current_step == (0, 0, 2)
    assert dims.point == (0, 0, 4)

    # mismatched len(axis) vs. len(value)
    with pytest.raises(ValueError):
        dims.set_point((0, 1), (0, 0, 0))

    with pytest.raises(ValueError):
        dims.set_current_step((0, 1), (0, 0, 0))
Example #2
0
def test_point():
    """
    Tests point setting
    """
    dims = Dims(4)
    dims.set_point(3, 2.5)

    assert dims.ndim == 4
    assert dims.point[0] == 0.0
    assert dims.point[1] == 0.0
    assert dims.point[2] == 0.0
    assert dims.point[3] == 2.5
Example #3
0
def test_point():
    """
    Test point setting.
    """
    dims = Dims(4)
    assert dims.point == [0] * 4

    dims.set_point(3, 4)
    assert dims.point == [0, 0, 0, 4]

    dims.set_point(2, 1)
    assert dims.point == [0, 0, 1, 4]
Example #4
0
def test_axis_labels():
    dims = Dims(ndim=4)
    assert dims.axis_labels == ('0', '1', '2', '3')

    dims.set_axis_label(0, 't')
    assert dims.axis_labels == ('t', '1', '2', '3')

    dims.set_axis_label((0, 1, 3), ('t', 'c', 'last'))
    assert dims.axis_labels == ('t', 'c', '2', 'last')

    # mismatched len(axis) vs. len(value)
    with pytest.raises(ValueError):
        dims.set_point((0, 1), ('x', 'y', 'z'))
Example #5
0
def test_point():
    """
    Test point setting.
    """
    dims = Dims(ndim=4)
    assert dims.point == (0, ) * 4

    dims.set_range(3, (0, 5, 1))
    dims.set_point(3, 4)
    assert dims.point == (0, 0, 0, 4)

    dims.set_range(2, (0, 5, 1))
    dims.set_point(2, 1)
    assert dims.point == (0, 0, 1, 4)
Example #6
0
def test_order_when_changing_ndim():
    """
    Test order of the dims when changing the number of dimensions.
    """
    dims = Dims(4)
    dims.set_point(0, 2)

    dims.ndim = 5
    # Test that new dims get appended to the beginning of lists
    assert dims.point == [0, 2, 0, 0, 0]

    dims.set_point(2, 3)
    dims.ndim = 3
    # Test that dims get removed from the beginning of lists
    assert dims.point == [3, 0, 0]
Example #7
0
def test_indices():
    """
    Test indices values.
    """
    dims = Dims(4)
    # On instantiation no dims are displayed and the indices default to 0
    assert dims.indices == (0, ) * 4

    dims._set_2d_viewing()
    # On 2D viewing the last two dims are now set to sliced mode
    assert dims.indices == (0, ) * 2 + (slice(None, None, None), ) * 2

    dims.set_point(0, 2)
    dims.set_point(1, 3)
    # Set the values of the first two dims in point mode
    assert dims.indices == (2, 3) + (slice(None, None, None), ) * 2
Example #8
0
def test_slice_labels(qtbot):
    ndim = 4
    dims = Dims(ndim=ndim)
    dims.set_range(0, (0, 20, 1))
    view = QtDims(dims)
    qtbot.addWidget(view)

    # make sure the totslice_label is showing the correct number
    assert int(view.slider_widgets[0].totslice_label.text()) == 19

    # make sure setting the dims.point updates the slice label
    label_edit = view.slider_widgets[0].curslice_label
    dims.set_point(0, 15)
    assert int(label_edit.text()) == 15

    # make sure setting the current slice label updates the model
    label_edit.setText(str(8))
    label_edit.editingFinished.emit()
    assert dims.point[0] == 8
Example #9
0
def test_order_when_changing_ndim():
    """
    Test order of the dims when changing the number of dimensions.
    """
    dims = Dims(4)
    dims.set_point(0, 2)

    dims.ndim = 5
    # Test that new dims get appended to the beginning of lists
    assert dims.point == [0, 2, 0, 0, 0]
    assert dims.order == [0, 1, 2, 3, 4]
    assert dims.axis_labels == ['0', '1', '2', '3', '4']

    dims.set_point(2, 3)
    dims.ndim = 3
    # Test that dims get removed from the beginning of lists
    assert dims.point == [3, 0, 0]
    assert dims.order == [0, 1, 2]
    assert dims.axis_labels == ['2', '3', '4']
Example #10
0
def test_indices():
    """
    Test indices values.
    """
    dims = Dims(4)
    # On instantiation the last two dims are set to sliced mode
    assert dims.indices == (0, ) * 2 + (slice(None, None, None), ) * 2

    # Set the values of the first two dims in point mode outside of range
    dims.set_point(0, 2)
    dims.set_point(1, 3)
    assert dims.indices == (1, 1) + (slice(None, None, None), ) * 2

    # Increase range and then set points again
    # Note changing the step size changes the indices for the same point value
    dims.set_range(0, (0, 4, 2))
    dims.set_range(1, (0, 4, 2))
    dims.set_point(0, 2)
    dims.set_point(1, 3)
    assert dims.indices == (1, 2) + (slice(None, None, None), ) * 2
Example #11
0
def test_order_when_changing_ndim():
    """
    Test order of the dims when changing the number of dimensions.
    """
    dims = Dims(ndim=4)
    dims.set_range(0, (0, 4, 1))
    dims.set_point(0, 2)

    dims.ndim = 5
    # Test that new dims get appended to the beginning of lists
    assert dims.point == (0, 2, 0, 0, 0)
    assert dims.order == (0, 1, 2, 3, 4)
    assert dims.axis_labels == ('0', '1', '2', '3', '4')

    dims.set_range(2, (0, 4, 1))
    dims.set_point(2, 3)
    dims.ndim = 3
    # Test that dims get removed from the beginning of lists
    assert dims.point == (3, 0, 0)
    assert dims.order == (0, 1, 2)
    assert dims.axis_labels == ('2', '3', '4')
Example #12
0
def test_point():
    """
    Test point setting.
    """
    dims = Dims(ndim=4)
    assert dims.point == (0, ) * 4

    dims.set_range(range(dims.ndim), ((0, 5, 1), ) * dims.ndim)
    dims.set_point(3, 4)
    assert dims.point == (0, 0, 0, 4)

    dims.set_point(2, 1)
    assert dims.point == (0, 0, 1, 4)

    dims.set_point((0, 1, 2), (2.1, 2.6, 0.0))
    assert dims.point == (2, 3, 0, 4)