Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task.read does not return short reads for multi-channel power #529

Open
bkeryan opened this issue Mar 5, 2024 · 0 comments
Open

Task.read does not return short reads for multi-channel power #529

bkeryan opened this issue Mar 5, 2024 · 0 comments

Comments

@bkeryan
Copy link
Collaborator

bkeryan commented Mar 5, 2024

Task.read doesn't slice the array for multi-channel power reads.

Test case (from tests/component/test_task_read_ai.py, under development):

def test___power_multi_channel_finite___read_too_many_sample___returns_valid_2d_channels_samples_truncated(
    pwr_multi_channel_task: nidaqmx.Task,
) -> None:
    samples_to_acquire = 5
    pwr_multi_channel_task.timing.cfg_samp_clk_timing(rate=1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=samples_to_acquire)
    num_channels = pwr_multi_channel_task.number_of_channels
    samples_to_read = 10

    data = pwr_multi_channel_task.read(samples_to_read)

    _assert_equal_2d(
        [[e.voltage for e in d] for d in data],
        [
            [_get_voltage_setpoint_for_chan(chan_index) for _ in range(samples_to_acquire)]
            for chan_index in range(num_channels)
        ],
        abs=POWER_EPSILON,
    )
    _assert_equal_2d(
        [[e.current for e in d] for d in data],
        [
            [_get_current_setpoint_for_chan(chan_index) for _ in range(samples_to_acquire)]
            for chan_index in range(num_channels)
        ],
        abs=POWER_EPSILON,
    )

Result:

_ test___power_multi_channel_finite___read_too_many_sample___returns_valid_2d_channels_samples_truncated[library_init_kwargs] _

pwr_multi_channel_task = Task(name=_unnamedTask<F>)

    def test___power_multi_channel_finite___read_too_many_sample___returns_valid_2d_channels_samples_truncated(
        pwr_multi_channel_task: nidaqmx.Task,
    ) -> None:
        samples_to_acquire = 5
        pwr_multi_channel_task.timing.cfg_samp_clk_timing(rate=1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=samples_to_acquire)
        num_channels = pwr_multi_channel_task.number_of_channels
        samples_to_read = 10

        data = pwr_multi_channel_task.read(samples_to_read)

>       _assert_equal_2d(
            [[e.voltage for e in d] for d in data],
            [
                [_get_voltage_setpoint_for_chan(chan_index) for _ in range(samples_to_acquire)]
                for chan_index in range(num_channels)
            ],
            abs=POWER_EPSILON,
        )

tests\component\test_task_read_ai.py:317:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

data = [[1.0, 1.0, 1.0, 1.0, 1.0, 2.0, ...], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, ...]]
expected = [[1.0, 1.0, 1.0, 1.0, 1.0], [2.0, 2.0, 2.0, 2.0, 2.0]], abs = 0.001

    def _assert_equal_2d(data: List[List[float]], expected: List[List[float]], abs: float) -> None:
        # pytest.approx() does not support nested data structures.
        assert len(data) == len(expected)
        for i in range(len(data)):
>           assert data[i] == pytest.approx(expected[i], abs=abs)
E           assert [1.0, 1.0, 1....1.0, 2.0, ...] == approx([1.0 ±....0 ± 1.0e-03])
E
E             Impossible to compare lists with different sizes.
E             Lengths: 5 and 10

tests\component\test_task_read_ai.py:152: AssertionError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant