From bd5c7ce4131b0370eb42cd11232b093f26625d70 Mon Sep 17 00:00:00 2001 From: charitylxy Date: Wed, 7 Feb 2024 23:43:12 -0600 Subject: [PATCH 1/7] fix name spacing issue --- generated/nidaqmx/_task_modules/in_stream.py | 4 ++-- .../templates/_task_modules/in_stream.py.mako | 4 ++-- tests/component/_task_modules/test_in_stream.py | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/generated/nidaqmx/_task_modules/in_stream.py b/generated/nidaqmx/_task_modules/in_stream.py index f03c5bac..40b0af50 100644 --- a/generated/nidaqmx/_task_modules/in_stream.py +++ b/generated/nidaqmx/_task_modules/in_stream.py @@ -1087,7 +1087,7 @@ def read(self, number_of_samples_per_channel=READ_ALL_AVAILABLE): return numpy_array[:number_of_channels * samples_read] return numpy_array - def readall(self): + def read_all(self): """ Reads all available raw samples from the task or virtual channels you specify. @@ -1137,7 +1137,7 @@ def readall(self): """ return self.read(number_of_samples_per_channel=READ_ALL_AVAILABLE) - def readinto(self, numpy_array): + def read_into(self, numpy_array): """ Reads raw samples from the task or virtual channels you specify into numpy_array. diff --git a/src/codegen/templates/_task_modules/in_stream.py.mako b/src/codegen/templates/_task_modules/in_stream.py.mako index 09e3cd89..c8c026d7 100644 --- a/src/codegen/templates/_task_modules/in_stream.py.mako +++ b/src/codegen/templates/_task_modules/in_stream.py.mako @@ -208,7 +208,7 @@ ${property_template.script_property(attribute)}\ return numpy_array[:number_of_channels * samples_read] return numpy_array - def readall(self): + def read_all(self): """ Reads all available raw samples from the task or virtual channels you specify. @@ -258,7 +258,7 @@ ${property_template.script_property(attribute)}\ """ return self.read(number_of_samples_per_channel=READ_ALL_AVAILABLE) - def readinto(self, numpy_array): + def read_into(self, numpy_array): """ Reads raw samples from the task or virtual channels you specify into numpy_array. diff --git a/tests/component/_task_modules/test_in_stream.py b/tests/component/_task_modules/test_in_stream.py index e18584e0..0ae1c46d 100644 --- a/tests/component/_task_modules/test_in_stream.py +++ b/tests/component/_task_modules/test_in_stream.py @@ -64,14 +64,14 @@ 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() + 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___readall___returns_valid_samples_shape_and_dtype( +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( @@ -83,7 +83,7 @@ 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() + 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 @@ -92,7 +92,7 @@ def test___ai_continuous_task___readall___returns_valid_samples_shape_and_dtype( @pytest.mark.parametrize("samples_to_read", [1, 10]) -def test___valid_array___readinto___returns_valid_samples( +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. @@ -100,20 +100,20 @@ 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) + 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___readinto___returns_whole_samples_and_clears_padding( +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.readinto(data) + 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() From 35e504bb65ec6de24dc86f1ce053d9ba79bda31c Mon Sep 17 00:00:00 2001 From: charitylxy Date: Thu, 8 Feb 2024 00:08:48 -0600 Subject: [PATCH 2/7] minor edit --- tests/component/_task_modules/test_in_stream.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/component/_task_modules/test_in_stream.py b/tests/component/_task_modules/test_in_stream.py index 0ae1c46d..1fb7876c 100644 --- a/tests/component/_task_modules/test_in_stream.py +++ b/tests/component/_task_modules/test_in_stream.py @@ -57,7 +57,7 @@ def test___ai_task___read___returns_valid_samples_shape_and_dtype( assert (SINE_RAW_MIN <= data).all() and (data <= SINE_RAW_MAX).all() -def test___ai_finite_task___readall___returns_valid_samples_shape_and_dtype( +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( From 4a0c7694e0b7e7b1fb282fafa8a2174abd114a80 Mon Sep 17 00:00:00 2001 From: charitylxy Date: Thu, 8 Feb 2024 19:55:21 -0600 Subject: [PATCH 3/7] Address comment --- generated/nidaqmx/_task_modules/in_stream.py | 8 ++++++++ src/codegen/templates/_task_modules/in_stream.py.mako | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/generated/nidaqmx/_task_modules/in_stream.py b/generated/nidaqmx/_task_modules/in_stream.py index 40b0af50..488c898c 100644 --- a/generated/nidaqmx/_task_modules/in_stream.py +++ b/generated/nidaqmx/_task_modules/in_stream.py @@ -1086,6 +1086,10 @@ 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.2.0", details="Use read_all instead.") + def readall(self): + return self.read_all() def read_all(self): """ @@ -1137,6 +1141,10 @@ def read_all(self): """ return self.read(number_of_samples_per_channel=READ_ALL_AVAILABLE) + @deprecation.deprecated(deprecated_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 diff --git a/src/codegen/templates/_task_modules/in_stream.py.mako b/src/codegen/templates/_task_modules/in_stream.py.mako index c8c026d7..ad94df28 100644 --- a/src/codegen/templates/_task_modules/in_stream.py.mako +++ b/src/codegen/templates/_task_modules/in_stream.py.mako @@ -207,6 +207,10 @@ ${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.2.0", details="Use read_all instead.") + def readall(self): + return self.read_all() def read_all(self): """ @@ -258,6 +262,10 @@ ${property_template.script_property(attribute)}\ """ return self.read(number_of_samples_per_channel=READ_ALL_AVAILABLE) + @deprecation.deprecated(deprecated_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 From d55d5336e7eb8e967651b2852edb5a6db87a6a2e Mon Sep 17 00:00:00 2001 From: charitylxy Date: Thu, 8 Feb 2024 19:55:51 -0600 Subject: [PATCH 4/7] Add test for deprecated functions --- .../component/_task_modules/test_in_stream.py | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/component/_task_modules/test_in_stream.py b/tests/component/_task_modules/test_in_stream.py index 1fb7876c..4b2a39ce 100644 --- a/tests/component/_task_modules/test_in_stream.py +++ b/tests/component/_task_modules/test_in_stream.py @@ -56,6 +56,71 @@ def test___ai_task___read___returns_valid_samples_shape_and_dtype( assert data.dtype == numpy.int16 assert (SINE_RAW_MIN <= data).all() and (data <= SINE_RAW_MAX).all() +def test___ai_finite_task___readall___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 + ) + + 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 + assert (SINE_RAW_MIN <= data).all() and (data <= SINE_RAW_MAX).all() + +def test___ai_continuous_task___readall___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) + + 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 + 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___readinto___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 + ) + + 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() + + +def test___odd_sized_array___readinto___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) + + 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, From bd04c0f79d4c16b4cf4e860168b89bfa2d43836e Mon Sep 17 00:00:00 2001 From: charitylxy Date: Thu, 8 Feb 2024 20:03:38 -0600 Subject: [PATCH 5/7] fix lint error --- tests/component/_task_modules/test_in_stream.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/component/_task_modules/test_in_stream.py b/tests/component/_task_modules/test_in_stream.py index 4b2a39ce..86de9a3c 100644 --- a/tests/component/_task_modules/test_in_stream.py +++ b/tests/component/_task_modules/test_in_stream.py @@ -56,6 +56,7 @@ def test___ai_task___read___returns_valid_samples_shape_and_dtype( assert data.dtype == numpy.int16 assert (SINE_RAW_MIN <= data).all() and (data <= SINE_RAW_MAX).all() + def test___ai_finite_task___readall___returns_valid_samples_shape_and_dtype( ai_sine_task: nidaqmx.Task, ) -> None: @@ -70,6 +71,7 @@ def test___ai_finite_task___readall___returns_valid_samples_shape_and_dtype( assert data.dtype == numpy.int16 assert (SINE_RAW_MIN <= data).all() and (data <= SINE_RAW_MAX).all() + def test___ai_continuous_task___readall___returns_valid_samples_shape_and_dtype( ai_sine_task: nidaqmx.Task, ) -> None: @@ -113,7 +115,7 @@ def test___odd_sized_array___readinto___returns_whole_samples_and_clears_padding _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) - + with pytest.deprecated_call(): samples_read = task.in_stream.readinto(data) From f61805f3948e8ac3241d80513f2192ccf681d518 Mon Sep 17 00:00:00 2001 From: charitylxy Date: Wed, 14 Feb 2024 02:16:48 -0600 Subject: [PATCH 6/7] address comments --- generated/nidaqmx/_task_modules/in_stream.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generated/nidaqmx/_task_modules/in_stream.py b/generated/nidaqmx/_task_modules/in_stream.py index 488c898c..f5e38905 100644 --- a/generated/nidaqmx/_task_modules/in_stream.py +++ b/generated/nidaqmx/_task_modules/in_stream.py @@ -1087,7 +1087,7 @@ def read(self, number_of_samples_per_channel=READ_ALL_AVAILABLE): return numpy_array[:number_of_channels * samples_read] return numpy_array - @deprecation.deprecated(deprecated_in="1.2.0", details="Use read_all instead.") + @deprecation.deprecated(deprecated_in="1.0.0", removed_in="1.2.0", details="Use read_all instead.") def readall(self): return self.read_all() @@ -1141,7 +1141,7 @@ def read_all(self): """ return self.read(number_of_samples_per_channel=READ_ALL_AVAILABLE) - @deprecation.deprecated(deprecated_in="1.2.0", details="Use read_into instead.") + @deprecation.deprecated(deprecated_in="1.2.0", removed_in="1.2.0", details="Use read_into instead.") def readinto(self, numpy_array): return self.read_into(numpy_array) From 05d992af53ee761f0f5d714640eba7523546604a Mon Sep 17 00:00:00 2001 From: charitylxy Date: Wed, 14 Feb 2024 02:23:04 -0600 Subject: [PATCH 7/7] Minor edit --- generated/nidaqmx/_task_modules/in_stream.py | 2 +- src/codegen/templates/_task_modules/in_stream.py.mako | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/generated/nidaqmx/_task_modules/in_stream.py b/generated/nidaqmx/_task_modules/in_stream.py index f5e38905..bd17b656 100644 --- a/generated/nidaqmx/_task_modules/in_stream.py +++ b/generated/nidaqmx/_task_modules/in_stream.py @@ -1141,7 +1141,7 @@ def read_all(self): """ return self.read(number_of_samples_per_channel=READ_ALL_AVAILABLE) - @deprecation.deprecated(deprecated_in="1.2.0", removed_in="1.2.0", details="Use read_into instead.") + @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) diff --git a/src/codegen/templates/_task_modules/in_stream.py.mako b/src/codegen/templates/_task_modules/in_stream.py.mako index ad94df28..280c1821 100644 --- a/src/codegen/templates/_task_modules/in_stream.py.mako +++ b/src/codegen/templates/_task_modules/in_stream.py.mako @@ -208,7 +208,7 @@ ${property_template.script_property(attribute)}\ return numpy_array[:number_of_channels * samples_read] return numpy_array - @deprecation.deprecated(deprecated_in="1.2.0", details="Use read_all instead.") + @deprecation.deprecated(deprecated_in="1.0.0", removed_in="1.2.0", details="Use read_all instead.") def readall(self): return self.read_all() @@ -262,7 +262,7 @@ ${property_template.script_property(attribute)}\ """ return self.read(number_of_samples_per_channel=READ_ALL_AVAILABLE) - @deprecation.deprecated(deprecated_in="1.2.0", details="Use read_into instead.") + @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)