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

Fix lag application for negative lags #36

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions phys2denoise/metrics/chest_belt.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def rpv(belt_ts, window):


@due.dcite(references.POWER_2020)
def env(belt_ts, samplerate, out_samplerate, window=10, lags=(0,)):
def env(belt_ts, samplerate, out_samplerate, window=10):
"""Calculate respiratory pattern variability across a sliding window.

Parameters
Expand All @@ -69,9 +69,6 @@ def env(belt_ts, samplerate, out_samplerate, window=10, lags=(0,)):
window : :obj:`int`, optional
Size of the sliding window, in the same units as out_samplerate.
Default is 6.
lags : (Y,) :obj:`tuple` of :obj:`int`, optional
List of lags to apply to the rv estimate. In the same units as
out_samplerate.

Returns
-------
Expand Down Expand Up @@ -118,8 +115,9 @@ def rv(belt_ts, samplerate, out_samplerate, window=6, lags=(0,)):
Size of the sliding window, in the same units as out_samplerate.
Default is 6.
lags : (Y,) :obj:`tuple` of :obj:`int`, optional
List of lags to apply to the rv estimate. In the same units as
out_samplerate.
List of lags to apply to the rv estimate.
Lags can be negative, zero, and/or positive.
In seconds (like out_samplerate).

Returns
-------
Expand Down Expand Up @@ -152,7 +150,7 @@ def rv(belt_ts, samplerate, out_samplerate, window=6, lags=(0,)):
# Apply lags
n_out_samples = int((belt_ts.shape[0] / samplerate) / out_samplerate)
# convert lags from out_samplerate to samplerate
delays = [abs(int(lag * samplerate)) for lag in lags]
delays = [int(lag * samplerate) for lag in lags]
rv_with_lags = utils.apply_lags(rv_arr, lags=delays)

# Downsample to out_samplerate
Expand Down