Skip to content

examples: Speed up voltage_acq_clk_plot_wfm.py and handle multiple channels correctly#940

Open
bkeryan wants to merge 5 commits intomasterfrom
users/bkeryan/speed-up-waveform-plot
Open

examples: Speed up voltage_acq_clk_plot_wfm.py and handle multiple channels correctly#940
bkeryan wants to merge 5 commits intomasterfrom
users/bkeryan/speed-up-waveform-plot

Conversation

@bkeryan
Copy link
Collaborator

@bkeryan bkeryan commented Mar 13, 2026

  • This contribution adheres to CONTRIBUTING.md.
  • I've updated CHANGELOG.md if applicable.
  • I've added tests applicable for this pull request

What does this Pull Request accomplish?

Speed up voltage_acq_clk_plot_wfm.py by calculating the time data using np.linspace instead of waveform.timing.get_timestamps(). get_timestamps() currently creates a list of datetime objects, which is very slow for large sample counts.

Update voltage_acq_clk_plot_wfm.py to support multiple channels correctly:

  • Use the minimum start time to get the time offset for each channel. This compensates for the skew introduced by the AI Convert Clock on multiplexed devices.
  • Display the channel names in the plot legend rather than the plot title.

Why should this Pull Request be merged?

Closes #936

Demonstrates how to plot multiple waveforms.

What testing has been done?

Manual testing

Measured performance using PowerShell Measure-Command

@bkeryan
Copy link
Collaborator Author

bkeryan commented Mar 13, 2026

Example output with a floating signal:

image

@github-actions
Copy link
Contributor

github-actions bot commented Mar 13, 2026

Test Results

    48 files  ±0      48 suites  ±0   1h 16m 40s ⏱️ -30s
 3 209 tests ±0   2 556 ✅ ±0     653 💤 ±0  0 ❌ ±0 
62 228 runs  ±0  49 398 ✅ ±0  12 830 💤 ±0  0 ❌ ±0 

Results for commit 5244f7a. ± Comparison against base commit 960e35b.

♻️ This comment has been updated with latest results.

@bkeryan
Copy link
Collaborator Author

bkeryan commented Mar 13, 2026

Example output with AO loopback channels, 250 kS/s, 250k samples

image

@bkeryan
Copy link
Collaborator Author

bkeryan commented Mar 13, 2026

Example of calculated time_offset:

0.0
7.629394531e-06
2.2888183594e-05
3.8146972656e-05

Note that it currently calculates time_offset=0.0 for high AI Convert Clock rates. There is already an internal bug for this, but I also filed #941 for visibility.

@bkeryan
Copy link
Collaborator Author

bkeryan commented Mar 13, 2026

I ran PowerShell Measure-Command with the following changes, like in #936

diff --git a/examples/analog_in/voltage_acq_int_clk_plot_wfm.py b/examples/analog_in/voltage_acq_int_clk_plot_wfm.py
index bf59a795..9ff8dd90 100644
--- a/examples/analog_in/voltage_acq_int_clk_plot_wfm.py
+++ b/examples/analog_in/voltage_acq_int_clk_plot_wfm.py
@@ -29,7 +29,7 @@ def plot_analog_waveform(

 with nidaqmx.Task() as task:
     task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
-    task.timing.cfg_samp_clk_timing(1000.0, sample_mode=AcquisitionType.FINITE, samps_per_chan=50)
+    task.timing.cfg_samp_clk_timing(1e6, sample_mode=AcquisitionType.FINITE, samps_per_chan=100_000)

     waveforms = task.read_waveform(READ_ALL_AVAILABLE)
     if not isinstance(waveforms, list):
@@ -44,4 +44,4 @@ with nidaqmx.Task() as task:
     plot.legend()
     plot.grid(True)

-    plot.show()
+    plot.show(block=False)
PS D:\dev\nidaqmx-python\examples\analog_in> Measure-Command { poetry run python voltage_acq_int_clk_plot_wfm.py }


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 2
Milliseconds      : 523
Ticks             : 25239501
TotalDays         : 2.92123854166667E-05
TotalHours        : 0.00070109725
TotalMinutes      : 0.042065835
TotalSeconds      : 2.5239501
TotalMilliseconds : 2523.9501

This is about the same as voltage_acq_int_clk_plot_data.py.

@bkeryan bkeryan changed the title examples: Speed up voltage_acq_clk_plot_wfm.py and make it handle multiple channels correctly examples: Speed up voltage_acq_clk_plot_wfm.py and handle multiple channels correctly Mar 13, 2026
@bkeryan
Copy link
Collaborator Author

bkeryan commented Mar 13, 2026

Example output with a floating signal:

image

With endpoint=False, the Y-axis shows "0.05" but the data ends at 0.049.

image

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

Successfully merging this pull request may close these issues.

New example voltage_acq_int_clk_plot_wfm.py does not behave as expected.

2 participants