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

Fix raw-read Function Names Spacing Issue #492

Merged
merged 7 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion generated/nidaqmx/_task_modules/in_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,12 @@ def read(self, number_of_samples_per_channel=READ_ALL_AVAILABLE):
if number_of_channels * samples_read != number_of_samples:
return numpy_array[:number_of_channels * samples_read]
return numpy_array


@deprecation.deprecated(deprecated_in="1.0.0", removed_in="1.2.0", details="Use read_all instead.")
def readall(self):
return self.read_all()

def read_all(self):
charitylxy marked this conversation as resolved.
Show resolved Hide resolved
"""
Reads all available raw samples from the task or virtual channels
you specify.
Expand Down Expand Up @@ -1137,7 +1141,11 @@ def readall(self):
"""
return self.read(number_of_samples_per_channel=READ_ALL_AVAILABLE)

@deprecation.deprecated(deprecated_in="1.0.0", removed_in="1.2.0", details="Use read_into instead.")
def readinto(self, numpy_array):
return self.read_into(numpy_array)

def read_into(self, numpy_array):
"""
Reads raw samples from the task or virtual channels you specify
into numpy_array.
Expand Down
10 changes: 9 additions & 1 deletion src/codegen/templates/_task_modules/in_stream.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,12 @@ ${property_template.script_property(attribute)}\
if number_of_channels * samples_read != number_of_samples:
return numpy_array[:number_of_channels * samples_read]
return numpy_array


@deprecation.deprecated(deprecated_in="1.0.0", removed_in="1.2.0", details="Use read_all instead.")
def readall(self):
return self.read_all()

def read_all(self):
"""
Reads all available raw samples from the task or virtual channels
you specify.
Expand Down Expand Up @@ -258,7 +262,11 @@ ${property_template.script_property(attribute)}\
"""
return self.read(number_of_samples_per_channel=READ_ALL_AVAILABLE)

@deprecation.deprecated(deprecated_in="1.0.0", removed_in="1.2.0", details="Use read_into instead.")
def readinto(self, numpy_array):
return self.read_into(numpy_array)

def read_into(self, numpy_array):
"""
Reads raw samples from the task or virtual channels you specify
into numpy_array.
Expand Down
75 changes: 71 additions & 4 deletions tests/component/_task_modules/test_in_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def test___ai_finite_task___readall___returns_valid_samples_shape_and_dtype(
rate=1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=100
)

data = ai_sine_task.in_stream.readall()
with pytest.deprecated_call():
data = ai_sine_task.in_stream.readall()

assert data.shape == (ai_sine_task.number_of_channels * 100,)
assert data.dtype == numpy.int16
Expand All @@ -83,7 +84,8 @@ def test___ai_continuous_task___readall___returns_valid_samples_shape_and_dtype(
while ai_sine_task.in_stream.avail_samp_per_chan < min_samples_per_channel:
time.sleep(10e-3)

data = ai_sine_task.in_stream.readall()
with pytest.deprecated_call():
data = ai_sine_task.in_stream.readall()

assert data.shape[0] >= ai_sine_task.number_of_channels * min_samples_per_channel
assert data.shape[0] % ai_sine_task.number_of_channels == 0
Expand All @@ -100,7 +102,8 @@ def test___valid_array___readinto___returns_valid_samples(
ai_sine_task.number_of_channels * samples_to_read, FULLSCALE_RAW_MAX, dtype=numpy.int16
)

samples_read = ai_sine_task.in_stream.readinto(data)
with pytest.deprecated_call():
samples_read = ai_sine_task.in_stream.readinto(data)

assert samples_read == samples_to_read
assert (SINE_RAW_MIN <= data).all() and (data <= SINE_RAW_MAX).all()
Expand All @@ -113,7 +116,71 @@ def test___odd_sized_array___readinto___returns_whole_samples_and_clears_padding
# Initialize the array to full-scale readings to ensure it is overwritten.
data = numpy.full(19, FULLSCALE_RAW_MIN, dtype=numpy.int16)

samples_read = task.in_stream.readinto(data)
with pytest.deprecated_call():
samples_read = task.in_stream.readinto(data)

assert samples_read == 9
assert (SINE_RAW_MIN <= data[:-1]).all() and (data[:-1] <= SINE_RAW_MAX).all()
assert data[-1] == 0 # not FULLSCALE_RAW_MIN


def test___ai_finite_task___read_all___returns_valid_samples_shape_and_dtype(
ai_sine_task: nidaqmx.Task,
) -> None:
ai_sine_task.timing.cfg_samp_clk_timing(
rate=1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=100
)

data = ai_sine_task.in_stream.read_all()

assert data.shape == (ai_sine_task.number_of_channels * 100,)
assert data.dtype == numpy.int16
assert (SINE_RAW_MIN <= data).all() and (data <= SINE_RAW_MAX).all()


def test___ai_continuous_task___read_all___returns_valid_samples_shape_and_dtype(
ai_sine_task: nidaqmx.Task,
) -> None:
ai_sine_task.timing.cfg_samp_clk_timing(
rate=1000.0, sample_mode=AcquisitionType.CONTINUOUS, samps_per_chan=1000
)
ai_sine_task.start()
# Wait until there are some samples to read.
min_samples_per_channel = 100
while ai_sine_task.in_stream.avail_samp_per_chan < min_samples_per_channel:
time.sleep(10e-3)

data = ai_sine_task.in_stream.read_all()

assert data.shape[0] >= ai_sine_task.number_of_channels * min_samples_per_channel
assert data.shape[0] % ai_sine_task.number_of_channels == 0
assert data.dtype == numpy.int16
assert (SINE_RAW_MIN <= data).all() and (data <= SINE_RAW_MAX).all()


@pytest.mark.parametrize("samples_to_read", [1, 10])
def test___valid_array___read_into___returns_valid_samples(
ai_sine_task: nidaqmx.Task, samples_to_read: int
) -> None:
# Initialize the array to full-scale readings to ensure it is overwritten.
data = numpy.full(
ai_sine_task.number_of_channels * samples_to_read, FULLSCALE_RAW_MAX, dtype=numpy.int16
)

samples_read = ai_sine_task.in_stream.read_into(data)

assert samples_read == samples_to_read
assert (SINE_RAW_MIN <= data).all() and (data <= SINE_RAW_MAX).all()


def test___odd_sized_array___read_into___returns_whole_samples_and_clears_padding(
task: nidaqmx.Task, sim_x_series_device: nidaqmx.system.Device
) -> None:
_create_ai_sine_channels(task, sim_x_series_device, number_of_channels=2)
# Initialize the array to full-scale readings to ensure it is overwritten.
data = numpy.full(19, FULLSCALE_RAW_MIN, dtype=numpy.int16)

samples_read = task.in_stream.read_into(data)

assert samples_read == 9
assert (SINE_RAW_MIN <= data[:-1]).all() and (data[:-1] <= SINE_RAW_MAX).all()
Expand Down
Loading