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

niscope: expand channels repeated_capability before populating channel and record info in fetched data #1958

Merged
merged 11 commits into from
May 9, 2023
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ All notable changes to this project will be documented in this file.
* #### Added
* `get_channel_names()`
* #### Changed
* 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.
* #### Removed
* ### `niswitch` (NI-SWITCH)
* #### Added
Expand Down
70 changes: 49 additions & 21 deletions generated/niscope/niscope/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -2132,12 +2132,17 @@ def fetch(self, num_samples=None, relative_to=enums.FetchRelativeTo.PRETRIGGER,

waveform_info._populate_samples_info(wfm_info, mv, num_samples)

lwfm_i = len(wfm_info)
lrcl = len(self._repeated_capability_list)
channel_names = _converters.expand_channel_string(
self._repeated_capability,
self._all_channels_in_session
)

wfm_info_count = len(wfm_info)
channel_count = len(channel_names)
# Should this raise instead? If this asserts, is it the users fault?
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)
actual_num_records = int(lwfm_i / lrcl)
waveform_info._populate_channel_and_record_info(wfm_info, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
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)
actual_num_records = int(wfm_info_count / channel_count)
waveform_info._populate_channel_and_record_info(wfm_info, channel_names, range(record_number, record_number + actual_num_records))

return wfm_info

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

channel_names = _converters.expand_channel_string(
self._repeated_capability,
self._all_channels_in_session
)

wfm_info_count = len(wfm_info)
channel_count = len(self._repeated_capability_list)
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)
channel_count = len(channel_names)
# Should this raise instead? If this asserts, is it the users fault?
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)
actual_num_records = int(wfm_info_count / channel_count)
waveform_info._populate_channel_and_record_info(wfm_info, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
waveform_info._populate_channel_and_record_info(wfm_info, channel_names, range(record_number, record_number + actual_num_records))

return wfm_info

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

channel_names = _converters.expand_channel_string(
self._repeated_capability,
self._all_channels_in_session
)

results_count = len(results)
channel_count = len(self._repeated_capability_list)
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)
channel_count = len(channel_names)
# Should this raise instead? If this asserts, is it the users fault?
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)
actual_num_records = int(results_count / channel_count)
waveform_info._populate_channel_and_record_info(output, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
waveform_info._populate_channel_and_record_info(output, channel_names, range(record_number, record_number + actual_num_records))

return output

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

waveform_info._populate_samples_info(wfm_info, mv, num_samples)

lwfm_i = len(wfm_info)
lrcl = len(self._repeated_capability_list)
channel_names = _converters.expand_channel_string(
self._repeated_capability,
self._all_channels_in_session
)

wfm_info_count = len(wfm_info)
channel_count = len(channel_names)
# Should this raise instead? If this asserts, is it the users fault?
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)
actual_num_records = int(lwfm_i / lrcl)
waveform_info._populate_channel_and_record_info(wfm_info, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
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)
actual_num_records = int(wfm_info_count / channel_count)
waveform_info._populate_channel_and_record_info(wfm_info, channel_names, range(record_number, record_number + actual_num_records))

return wfm_info

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

waveform_info._populate_samples_info(wfm_info, mv, num_samples)

lwfm_i = len(wfm_info)
lrcl = len(self._repeated_capability_list)
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)
actual_num_records = int(lwfm_i / lrcl)
waveform_info._populate_channel_and_record_info(wfm_info, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
channel_names = _converters.expand_channel_string(
self._repeated_capability,
self._all_channels_in_session
)

wfm_info_count = len(wfm_info)
channel_count = len(channel_names)
# Should this raise instead? If this asserts, is it the users fault?
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)
actual_num_records = int(wfm_info_count / channel_count)
waveform_info._populate_channel_and_record_info(wfm_info, channel_names, range(record_number, record_number + actual_num_records))

return wfm_info

Expand Down
6 changes: 2 additions & 4 deletions src/niscope/system_tests/test_system_niscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@


instruments = ['FakeDevice1', 'FakeDevice2']
# TODO(sbethur): Use `get_channel_names` when #1402 is fixed
test_channels_1 = 'FakeDevice2/0,FakeDevice1/1'
test_channels_1_expanded = test_channels_1
# TODO(jfitzger): Use the commented values, once #1770 is fixed
test_channels_2 = 'FakeDevice2/0' # 'FakeDevice2/0:1'
test_channels_2_expanded = 'FakeDevice2/0' # 'FakeDevice2/0,FakeDevice2/1'
test_channels_2 = 'FakeDevice2/0:1'
test_channels_2_expanded = 'FakeDevice2/0,FakeDevice2/1'


# There are system tests below that need either a PXI-5124 or a PXI-5142 instead of the PXIe-5164 we use everywhere else
Expand Down
7 changes: 1 addition & 6 deletions src/niscope/templates/session.py/fancy_fetch.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@

waveform_info._populate_samples_info(wfm_info, mv, num_samples)

lwfm_i = len(wfm_info)
lrcl = len(self._repeated_capability_list)
# Should this raise instead? If this asserts, is it the users fault?
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)
actual_num_records = int(lwfm_i / lrcl)
waveform_info._populate_channel_and_record_info(wfm_info, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
<%include file="./fetch_waveform_info_population.py.mako"/>

return wfm_info
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
record_length = int(len(meas_wfm) / len(wfm_info))
waveform_info._populate_samples_info(wfm_info, meas_wfm, record_length)

wfm_info_count = len(wfm_info)
channel_count = len(self._repeated_capability_list)
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)
actual_num_records = int(wfm_info_count / channel_count)
waveform_info._populate_channel_and_record_info(wfm_info, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
<%include file="./fetch_waveform_info_population.py.mako"/>

return wfm_info
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
measurement_stat = measurement_stats.MeasurementStats(result, mean, stdev, min_val, max_val, num_in_stats)
output.append(measurement_stat)

results_count = len(results)
channel_count = len(self._repeated_capability_list)
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)
actual_num_records = int(results_count / channel_count)
waveform_info._populate_channel_and_record_info(output, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
<%include file="./fetch_waveform_info_population.py.mako" args="results_name='results', results_description='results', output_name='output'"/>

return output
6 changes: 1 addition & 5 deletions src/niscope/templates/session.py/fetch_waveform.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@

waveform_info._populate_samples_info(wfm_info, mv, num_samples)

lwfm_i = len(wfm_info)
lrcl = len(self._repeated_capability_list)
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)
actual_num_records = int(lwfm_i / lrcl)
waveform_info._populate_channel_and_record_info(wfm_info, self._repeated_capability_list, range(record_number, record_number + actual_num_records))
<%include file="./fetch_waveform_info_population.py.mako"/>

return wfm_info
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%page args="results_name='wfm_info', results_description='waveforms', output_name='wfm_info'"/>\
<%
'''Sub-template to populate channel and record info for a waveform in a fetch method.'''
%>\
channel_names = _converters.expand_channel_string(
self._repeated_capability,
self._all_channels_in_session
)

${results_name}_count = len(${results_name})
channel_count = len(channel_names)
# Should this raise instead? If this asserts, is it the users fault?
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)
actual_num_records = int(${results_name}_count / channel_count)
waveform_info._populate_channel_and_record_info(${output_name}, channel_names, range(record_number, record_number + actual_num_records))