`stream_readers` array shape validation is incompatible with `READ_ALL_AVAILABLE`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 592
- Forks
- 199
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 10
Description
If you use stream_readers to read into a preallocated NumPy array with number_of_samples_per_channel=READ_ALL_AVAILABLE, the stream reader validates the NumPy array shape against the available samples per channel, which is not a predictable number.
Steps to reproduce
Install an X Series or M Series as Dev1 and run this code:
import pprint
import time
import nidaqmx
import numpy
from nidaqmx.constants import AcquisitionType
from nidaqmx.stream_readers import AnalogMultiChannelReader
pp = pprint.PrettyPrinter(indent=4)
with nidaqmx.Task() as task:
task.ai_channels.add_ai_voltage_chan("Dev1/ai0:1")
task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.CONTINUOUS)
task.start()
time.sleep(100e-3)
reader = AnalogMultiChannelReader(task.in_stream)
data = numpy.zeros((2, 1000), dtype=numpy.double)
reader.read_many_sample(data, timeout=0.0)
pp.pprint(data)
Expected output
Prints array data
Actual output
The required number of samples varies from run to run but is around 100 to 110.
Traceback (most recent call last):
File "D:\dev\nidaqmx-python\examples\ai_raw.py", line 19, in <module>
reader.read_many_sample(data, timeout=0.0)
File "D:\dev\nidaqmx-python\generated\nidaqmx\stream_readers.py", line 322, in read_many_sample
self._verify_array(data, number_of_samples_per_channel, True, True)
File "D:\dev\nidaqmx-python\generated\nidaqmx\stream_readers.py", line 83, in _verify_array
raise DaqError(
nidaqmx.errors.DaqError: Read cannot be performed because the NumPy array passed into this function is not shaped correctly. You must pass in a NumPy array of the correct shape based on the number of channels in task and the number of samples per channel requested.
Shape of NumPy Array provided: (2, 1000)
Shape of NumPy Array required: (2, 105)
Task Name: _unnamedTask<0>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with generated/nidaqmx/stream_readers.py, especially read_many_sample and _verify_array, then reproduce the example using AnalogMultiChannelReader and READ_ALL_AVAILABLE. Done means a preallocated (2, 1000) NumPy array is accepted when the available sample count varies, and the example prints array data without the shape-validation error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100