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

Fill pulse traces with NaN/-1 if data is too short #245

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

philsmt
Copy link
Collaborator

@philsmt philsmt commented Sep 26, 2024

When using the pulse separation feature in the AdqRawChannel component, currently an exception is thrown if the underlying train trace is too short for all pulses. This is not very useful however, as there's little way for users to fix that in any way, e.g. only get data for those pulses that fit, or reduce the pattern asked for.

Rather than throwing an exception, this PR instead fills the missing samples with NaN (for floating types, most likely) or -1 (in case of integer types, only with non-default settings). This maintains the information which data is missing, and the returned array can easily be truncated if desired.

Copy link

codecov bot commented Sep 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.87%. Comparing base (049efdf) to head (8c63960).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #245   +/-   ##
=======================================
  Coverage   73.87%   73.87%           
=======================================
  Files          23       23           
  Lines        2989     2989           
=======================================
  Hits         2208     2208           
  Misses        781      781           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@philsmt philsmt force-pushed the fix/adq-too-short-pulse-traces branch from 87fd49e to 8c63960 Compare September 26, 2024 15:56
Comment on lines +47 to +59
# The end of this pulse is beyond the trace length, try to
# copy what remains and fill with placeholder as needed.

if start < trace_len:
# There is still some data to copy into this pulse.
memcpy(&out[i, 0], &traces[j, start],
(trace_len - start) * sizeof(traces[0, 0]))

# Fill in the rest of this pulse with the placeholder value.
for k in range(max(trace_len - start, 0), samples_per_pulse):
out[i, k] = placeholder_val
else:
memcpy(&out[i, 0], &traces[j, start], bytes_per_pulse)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks it possible to make a bit simple:

Suggested change
# The end of this pulse is beyond the trace length, try to
# copy what remains and fill with placeholder as needed.
if start < trace_len:
# There is still some data to copy into this pulse.
memcpy(&out[i, 0], &traces[j, start],
(trace_len - start) * sizeof(traces[0, 0]))
# Fill in the rest of this pulse with the placeholder value.
for k in range(max(trace_len - start, 0), samples_per_pulse):
out[i, k] = placeholder_val
else:
memcpy(&out[i, 0], &traces[j, start], bytes_per_pulse)
# The end of this pulse is beyond the trace length, try to
# copy what remains and fill with placeholder as needed.
samples_to_copy = min(max(trace_len - start, 0), samples_per_pulse)
# copy if data available
memcpy(&out[i, 0], &traces[j, start], samples_to_copy * sizeof(traces[0, 0]))
# Fill in the rest of this pulse with the placeholder value.
for k in range(samples_to_copy, samples_per_pulse):
out[i, k] = placeholder_val

Comment on lines 44 to 46
end = start + samples_per_pulse

if end > trace_len:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
end = start + samples_per_pulse
if end > trace_len:

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.

2 participants