Skip to content

Commit

Permalink
Merge pull request #134 from ErikHogenbirk/patch-1
Browse files Browse the repository at this point in the history
Several bugfixes in peak processing
  • Loading branch information
JelleAalbers committed Feb 1, 2019
2 parents ab9a461 + 6099381 commit 3bba629
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 6 additions & 1 deletion strax/processing/peak_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,18 @@ def sum_waveform(peaks, records, adc_to_pe, n_channels=248):
# we've seen all overlapping records
break

if n_r <= s:
# Only the zero-padded part of the record coincidentally
# overlaps with the peak, so this is not part of it
continue

# Range of record that contributes to peak
r_start = max(0, s)
r_end = min(n_r, s + n_p)
assert r_end > r_start

max_in_record = r['data'][r_start:r_end].max()
p['saturated_channel'][ch] = int(max_in_record < r['baseline'])
p['saturated_channel'][ch] = int(max_in_record >= r['baseline'])

# TODO Do we need .astype(np.int32).sum() ??
p['area_per_channel'][ch] += r['data'][r_start:r_end].sum()
Expand Down
2 changes: 1 addition & 1 deletion strax/processing/peak_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ def compute_widths(peaks):
fr_times *= peaks['dt'].reshape(-1, 1)

i = len(desired_fr) // 2
peaks['width'][:, 1:] = fr_times[:, i:] - fr_times[:, :i]
peaks['width'][:, 1:] = fr_times[:, i:] - fr_times[:, ::-1][:, i:]
12 changes: 12 additions & 0 deletions strax/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,15 @@ def formatted_exception():
# There was no relevant exception to record
return ''
return traceback.format_exc()

def print_entry(d, n=0, show_data=False):
""" Print entry number n in human-readable format.
Default behavior is to skip the entry 'data' since it clutters output.
"""
# Check what number of spaces required for nice alignment
max_len = np.max([len(key) for key in d.dtype.names])
el = d[n]
for key in d.dtype.names:
if (show_data or key != 'data'):
print(("{:<%d}: " % max_len).format(key), el[key])
return

0 comments on commit 3bba629

Please sign in to comment.