Skip to content

Commit 6aa529b

Browse files
authored
niscope: expand channels repeated_capability before populating channel and record info in fetched data (#1958)
* Fix fetch, read? * Fix fetch_array_measurement? * Fix fetch_measurement_stats? * fix fetch_into? * Update changelog in anticipation of fix * enable correct test cases for catching #1770 * Use subtemplate for population of channel and record info in fetched data * remove mention of niscope from changelog fix description * Remove get_channel_names TODO from tests
1 parent 63291f5 commit 6aa529b

File tree

8 files changed

+71
-46
lines changed

8 files changed

+71
-46
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ All notable changes to this project will be documented in this file.
6161
* #### Added
6262
* `get_channel_names()`
6363
* #### Changed
64+
* Fix [#1770](https://github.com/ni/nimi-python/issues/1770): fetch(), read(), and friends return wrong data when called with channel ranges on multi-instrument session.
6465
* #### Removed
6566
* ### `niswitch` (NI-SWITCH)
6667
* #### Added

generated/niscope/niscope/session.py

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,12 +2132,17 @@ def fetch(self, num_samples=None, relative_to=enums.FetchRelativeTo.PRETRIGGER,
21322132

21332133
waveform_info._populate_samples_info(wfm_info, mv, num_samples)
21342134

2135-
lwfm_i = len(wfm_info)
2136-
lrcl = len(self._repeated_capability_list)
2135+
channel_names = _converters.expand_channel_string(
2136+
self._repeated_capability,
2137+
self._all_channels_in_session
2138+
)
2139+
2140+
wfm_info_count = len(wfm_info)
2141+
channel_count = len(channel_names)
21372142
# Should this raise instead? If this asserts, is it the users fault?
2138-
assert lwfm_i % lrcl == 0, 'Number of waveforms should be evenly divisible by the number of channels: len(wfm_info) == {0}, len(self._repeated_capability_list) == {1}'.format(lwfm_i, lrcl)
2139-
actual_num_records = int(lwfm_i / lrcl)
2140-
waveform_info._populate_channel_and_record_info(wfm_info, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
2143+
assert wfm_info_count % channel_count == 0, 'Number of waveforms should be evenly divisible by the number of channels: len(wfm_info) == {0}, len(channel_names) == {1}'.format(wfm_info_count, channel_count)
2144+
actual_num_records = int(wfm_info_count / channel_count)
2145+
waveform_info._populate_channel_and_record_info(wfm_info, channel_names, range(record_number, record_number + actual_num_records))
21412146

21422147
return wfm_info
21432148

@@ -2231,11 +2236,17 @@ def fetch_array_measurement(self, array_meas_function, meas_wfm_size=None, relat
22312236
record_length = int(len(meas_wfm) / len(wfm_info))
22322237
waveform_info._populate_samples_info(wfm_info, meas_wfm, record_length)
22332238

2239+
channel_names = _converters.expand_channel_string(
2240+
self._repeated_capability,
2241+
self._all_channels_in_session
2242+
)
2243+
22342244
wfm_info_count = len(wfm_info)
2235-
channel_count = len(self._repeated_capability_list)
2236-
assert wfm_info_count % channel_count == 0, 'Number of waveforms should be evenly divisible by the number of channels: len(wfm_info) == {0}, len(self._repeated_capability_list) == {1}'.format(wfm_info_count, channel_count)
2245+
channel_count = len(channel_names)
2246+
# Should this raise instead? If this asserts, is it the users fault?
2247+
assert wfm_info_count % channel_count == 0, 'Number of waveforms should be evenly divisible by the number of channels: len(wfm_info) == {0}, len(channel_names) == {1}'.format(wfm_info_count, channel_count)
22372248
actual_num_records = int(wfm_info_count / channel_count)
2238-
waveform_info._populate_channel_and_record_info(wfm_info, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
2249+
waveform_info._populate_channel_and_record_info(wfm_info, channel_names, range(record_number, record_number + actual_num_records))
22392250

22402251
return wfm_info
22412252

@@ -2325,11 +2336,17 @@ def fetch_measurement_stats(self, scalar_meas_function, relative_to=enums.FetchR
23252336
measurement_stat = measurement_stats.MeasurementStats(result, mean, stdev, min_val, max_val, num_in_stats)
23262337
output.append(measurement_stat)
23272338

2339+
channel_names = _converters.expand_channel_string(
2340+
self._repeated_capability,
2341+
self._all_channels_in_session
2342+
)
2343+
23282344
results_count = len(results)
2329-
channel_count = len(self._repeated_capability_list)
2330-
assert results_count % channel_count == 0, 'Number of results should be evenly divisible by the number of channels: len(results) == {0}, len(self._repeated_capability_list) == {1}'.format(results_count, channel_count)
2345+
channel_count = len(channel_names)
2346+
# Should this raise instead? If this asserts, is it the users fault?
2347+
assert results_count % channel_count == 0, 'Number of results should be evenly divisible by the number of channels: len(results) == {0}, len(channel_names) == {1}'.format(results_count, channel_count)
23312348
actual_num_records = int(results_count / channel_count)
2332-
waveform_info._populate_channel_and_record_info(output, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
2349+
waveform_info._populate_channel_and_record_info(output, channel_names, range(record_number, record_number + actual_num_records))
23332350

23342351
return output
23352352

@@ -2434,12 +2451,17 @@ def read(self, num_samples=None, relative_to=enums.FetchRelativeTo.PRETRIGGER, o
24342451

24352452
waveform_info._populate_samples_info(wfm_info, mv, num_samples)
24362453

2437-
lwfm_i = len(wfm_info)
2438-
lrcl = len(self._repeated_capability_list)
2454+
channel_names = _converters.expand_channel_string(
2455+
self._repeated_capability,
2456+
self._all_channels_in_session
2457+
)
2458+
2459+
wfm_info_count = len(wfm_info)
2460+
channel_count = len(channel_names)
24392461
# Should this raise instead? If this asserts, is it the users fault?
2440-
assert lwfm_i % lrcl == 0, 'Number of waveforms should be evenly divisible by the number of channels: len(wfm_info) == {0}, len(self._repeated_capability_list) == {1}'.format(lwfm_i, lrcl)
2441-
actual_num_records = int(lwfm_i / lrcl)
2442-
waveform_info._populate_channel_and_record_info(wfm_info, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
2462+
assert wfm_info_count % channel_count == 0, 'Number of waveforms should be evenly divisible by the number of channels: len(wfm_info) == {0}, len(channel_names) == {1}'.format(wfm_info_count, channel_count)
2463+
actual_num_records = int(wfm_info_count / channel_count)
2464+
waveform_info._populate_channel_and_record_info(wfm_info, channel_names, range(record_number, record_number + actual_num_records))
24432465

24442466
return wfm_info
24452467

@@ -3147,11 +3169,17 @@ def fetch_into(self, waveform, relative_to=enums.FetchRelativeTo.PRETRIGGER, off
31473169

31483170
waveform_info._populate_samples_info(wfm_info, mv, num_samples)
31493171

3150-
lwfm_i = len(wfm_info)
3151-
lrcl = len(self._repeated_capability_list)
3152-
assert lwfm_i % lrcl == 0, 'Number of waveforms should be evenly divisible by the number of channels: len(wfm_info) == {0}, len(self._repeated_capability_list) == {1}'.format(lwfm_i, lrcl)
3153-
actual_num_records = int(lwfm_i / lrcl)
3154-
waveform_info._populate_channel_and_record_info(wfm_info, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
3172+
channel_names = _converters.expand_channel_string(
3173+
self._repeated_capability,
3174+
self._all_channels_in_session
3175+
)
3176+
3177+
wfm_info_count = len(wfm_info)
3178+
channel_count = len(channel_names)
3179+
# Should this raise instead? If this asserts, is it the users fault?
3180+
assert wfm_info_count % channel_count == 0, 'Number of waveforms should be evenly divisible by the number of channels: len(wfm_info) == {0}, len(channel_names) == {1}'.format(wfm_info_count, channel_count)
3181+
actual_num_records = int(wfm_info_count / channel_count)
3182+
waveform_info._populate_channel_and_record_info(wfm_info, channel_names, range(record_number, record_number + actual_num_records))
31553183

31563184
return wfm_info
31573185

src/niscope/system_tests/test_system_niscope.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818

1919

2020
instruments = ['FakeDevice1', 'FakeDevice2']
21-
# TODO(sbethur): Use `get_channel_names` when #1402 is fixed
2221
test_channels_1 = 'FakeDevice2/0,FakeDevice1/1'
2322
test_channels_1_expanded = test_channels_1
24-
# TODO(jfitzger): Use the commented values, once #1770 is fixed
25-
test_channels_2 = 'FakeDevice2/0' # 'FakeDevice2/0:1'
26-
test_channels_2_expanded = 'FakeDevice2/0' # 'FakeDevice2/0,FakeDevice2/1'
23+
test_channels_2 = 'FakeDevice2/0:1'
24+
test_channels_2_expanded = 'FakeDevice2/0,FakeDevice2/1'
2725

2826

2927
# There are system tests below that need either a PXI-5124 or a PXI-5142 instead of the PXIe-5164 we use everywhere else

src/niscope/templates/session.py/fancy_fetch.py.mako

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@
2828

2929
waveform_info._populate_samples_info(wfm_info, mv, num_samples)
3030

31-
lwfm_i = len(wfm_info)
32-
lrcl = len(self._repeated_capability_list)
33-
# Should this raise instead? If this asserts, is it the users fault?
34-
assert lwfm_i % lrcl == 0, 'Number of waveforms should be evenly divisible by the number of channels: len(wfm_info) == {0}, len(self._repeated_capability_list) == {1}'.format(lwfm_i, lrcl)
35-
actual_num_records = int(lwfm_i / lrcl)
36-
waveform_info._populate_channel_and_record_info(wfm_info, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
31+
<%include file="./fetch_waveform_info_population.py.mako"/>
3732

3833
return wfm_info

src/niscope/templates/session.py/fancy_fetch_array_measurement.py.mako

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
record_length = int(len(meas_wfm) / len(wfm_info))
2828
waveform_info._populate_samples_info(wfm_info, meas_wfm, record_length)
2929

30-
wfm_info_count = len(wfm_info)
31-
channel_count = len(self._repeated_capability_list)
32-
assert wfm_info_count % channel_count == 0, 'Number of waveforms should be evenly divisible by the number of channels: len(wfm_info) == {0}, len(self._repeated_capability_list) == {1}'.format(wfm_info_count, channel_count)
33-
actual_num_records = int(wfm_info_count / channel_count)
34-
waveform_info._populate_channel_and_record_info(wfm_info, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
30+
<%include file="./fetch_waveform_info_population.py.mako"/>
3531

3632
return wfm_info

src/niscope/templates/session.py/fancy_fetch_measurement_stats.py.mako

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
measurement_stat = measurement_stats.MeasurementStats(result, mean, stdev, min_val, max_val, num_in_stats)
2424
output.append(measurement_stat)
2525

26-
results_count = len(results)
27-
channel_count = len(self._repeated_capability_list)
28-
assert results_count % channel_count == 0, 'Number of results should be evenly divisible by the number of channels: len(results) == {0}, len(self._repeated_capability_list) == {1}'.format(results_count, channel_count)
29-
actual_num_records = int(results_count / channel_count)
30-
waveform_info._populate_channel_and_record_info(output, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
26+
<%include file="./fetch_waveform_info_population.py.mako" args="results_name='results', results_description='results', output_name='output'"/>
3127

3228
return output

src/niscope/templates/session.py/fetch_waveform.py.mako

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@
3636

3737
waveform_info._populate_samples_info(wfm_info, mv, num_samples)
3838

39-
lwfm_i = len(wfm_info)
40-
lrcl = len(self._repeated_capability_list)
41-
assert lwfm_i % lrcl == 0, 'Number of waveforms should be evenly divisible by the number of channels: len(wfm_info) == {0}, len(self._repeated_capability_list) == {1}'.format(lwfm_i, lrcl)
42-
actual_num_records = int(lwfm_i / lrcl)
43-
waveform_info._populate_channel_and_record_info(wfm_info, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
39+
<%include file="./fetch_waveform_info_population.py.mako"/>
4440

4541
return wfm_info
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<%page args="results_name='wfm_info', results_description='waveforms', output_name='wfm_info'"/>\
2+
<%
3+
'''Sub-template to populate channel and record info for a waveform in a fetch method.'''
4+
%>\
5+
channel_names = _converters.expand_channel_string(
6+
self._repeated_capability,
7+
self._all_channels_in_session
8+
)
9+
10+
${results_name}_count = len(${results_name})
11+
channel_count = len(channel_names)
12+
# Should this raise instead? If this asserts, is it the users fault?
13+
assert ${results_name}_count % channel_count == 0, 'Number of ${results_description} should be evenly divisible by the number of channels: len(${results_name}) == {0}, len(channel_names) == {1}'.format(${results_name}_count, channel_count)
14+
actual_num_records = int(${results_name}_count / channel_count)
15+
waveform_info._populate_channel_and_record_info(${output_name}, channel_names, range(record_number, record_number + actual_num_records))

0 commit comments

Comments
 (0)