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

Add select index to compute width #465

Merged
merged 3 commits into from
Jun 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions strax/processing/peak_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,18 @@ def compute_index_of_fraction(peak, fractions_desired, result):


@export
def compute_widths(peaks):
def compute_widths(peaks, select_peaks_indices=None):
"""Compute widths in ns at desired area fractions for peaks
Copy link
Member

Choose a reason for hiding this comment

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

could you update the dosctring to include the select_peaks_indices and what None means?

returns (n_peaks, n_widths) array
"""
if not len(peaks):
return
if select_peaks_indices is None:
select_peaks_indices = np.arange(len(peaks))
if isinstance(select_peaks_indices, list):
select_peaks_indices = np.array(select_peaks_indices, int)
if not len(select_peaks_indices):
return

desired_widths = np.linspace(0, 1, len(peaks[0]['width']))
# 0% are width is 0 by definition, and it messes up the calculation below
Expand All @@ -86,9 +92,9 @@ def compute_widths(peaks):
# We lose the 50% fraction with this operation, let's add it back
desired_fr = np.sort(np.unique(np.append(desired_fr, [0.5])))

fr_times = index_of_fraction(peaks, desired_fr)
fr_times *= peaks['dt'].reshape(-1, 1)
fr_times = index_of_fraction(peaks[select_peaks_indices], desired_fr)
fr_times *= peaks['dt'][select_peaks_indices].reshape(-1, 1)

i = len(desired_fr) // 2
peaks['width'] = fr_times[:, i:] - fr_times[:, ::-1][:, i:]
peaks['area_decile_from_midpoint'] = fr_times[:, ::2] - fr_times[:, i].reshape(-1,1)
peaks['width'][select_peaks_indices] = fr_times[:, i:] - fr_times[:, ::-1][:, i:]
peaks['area_decile_from_midpoint'][select_peaks_indices] = fr_times[:, ::2] - fr_times[:, i].reshape(-1,1)