From a872bca3b4076c60669b1423d3451abbf9f757f6 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Mon, 28 Jun 2021 11:26:40 -0400 Subject: [PATCH 1/6] Improve docstrings. --- phys2denoise/metrics/chest_belt.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/phys2denoise/metrics/chest_belt.py b/phys2denoise/metrics/chest_belt.py index 7c5ae1c..888e8b7 100644 --- a/phys2denoise/metrics/chest_belt.py +++ b/phys2denoise/metrics/chest_belt.py @@ -70,8 +70,9 @@ def env(belt_ts, samplerate, out_samplerate, window=10, 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 env estimate. + Lags can be negative, zero, and/or positive. + In seconds (like out_samplerate). Returns ------- @@ -118,8 +119,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 ------- From a1648daf0e24308ebac4b3f7fe786b44aa6131f3 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Mon, 28 Jun 2021 11:33:49 -0400 Subject: [PATCH 2/6] Remove unused argument from env. --- phys2denoise/metrics/chest_belt.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/phys2denoise/metrics/chest_belt.py b/phys2denoise/metrics/chest_belt.py index 888e8b7..09feeb2 100644 --- a/phys2denoise/metrics/chest_belt.py +++ b/phys2denoise/metrics/chest_belt.py @@ -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 @@ -69,10 +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 env estimate. - Lags can be negative, zero, and/or positive. - In seconds (like out_samplerate). Returns ------- From b5611e32f9a6a64fda624e4e3f2d060c7dbe28c7 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Mon, 28 Jun 2021 11:33:57 -0400 Subject: [PATCH 3/6] Support negative lags in rv. --- phys2denoise/metrics/chest_belt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phys2denoise/metrics/chest_belt.py b/phys2denoise/metrics/chest_belt.py index 09feeb2..89745c6 100644 --- a/phys2denoise/metrics/chest_belt.py +++ b/phys2denoise/metrics/chest_belt.py @@ -150,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 From 827e081e9b55983e2688321d7402d4525ec77b49 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Wed, 15 Mar 2023 11:13:59 -0400 Subject: [PATCH 4/6] Remove lags from rv. --- phys2denoise/metrics/chest_belt.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/phys2denoise/metrics/chest_belt.py b/phys2denoise/metrics/chest_belt.py index 5a2244a..f0803e8 100644 --- a/phys2denoise/metrics/chest_belt.py +++ b/phys2denoise/metrics/chest_belt.py @@ -162,7 +162,7 @@ def env(resp, samplerate, window=10): @due.dcite(references.CHANG_GLOVER_2009) -def rv(resp, samplerate, window=6, lags=(0,)): +def rv(resp, samplerate, window=6): """Calculate respiratory variance. Parameters @@ -174,10 +174,6 @@ def rv(resp, samplerate, window=6, lags=(0,)): window : :obj:`int`, optional Size of the sliding window, in seconds. Default is 6. - lags : (Y,) :obj:`tuple` of :obj:`int`, optional - List of lags to apply to the rv estimate. - Lags can be negative, zero, and/or positive. - In seconds (like out_samplerate). Returns ------- @@ -209,15 +205,6 @@ def rv(resp, samplerate, window=6, lags=(0,)): rv_arr = pd.Series(resp).rolling(window=window, center=True).std() rv_arr[np.isnan(rv_arr)] = 0.0 - # Apply lags - n_out_samples = int((resp.shape[0] / samplerate) / out_samplerate) - # convert lags from out_samplerate to samplerate - delays = [int(lag * samplerate) for lag in lags] - rv_with_lags = utils.apply_lags(rv_arr, lags=delays) - - # Downsample to out_samplerate - rv_with_lags = resample(rv_with_lags, num=n_out_samples, axis=0) - # Convolve with rrf rrf_arr = rrf(samplerate, oversampling=1) rv_convolved = convolve1d(rv_arr, rrf_arr, axis=0) From 8e467e6c884818893350e547845b4756dac97026 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Wed, 15 Mar 2023 11:17:29 -0400 Subject: [PATCH 5/6] Fix lag implementation. --- phys2denoise/metrics/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phys2denoise/metrics/utils.py b/phys2denoise/metrics/utils.py index 7426a5c..9d41e77 100644 --- a/phys2denoise/metrics/utils.py +++ b/phys2denoise/metrics/utils.py @@ -116,9 +116,9 @@ def apply_lags(arr1d, lags): arr_with_lags = np.zeros((arr1d.shape[0], len(lags))) for i_lag, lag in enumerate(lags): if lag < 0: - arr_delayed = np.hstack((arr1d[lag:], np.zeros(lag))) + arr_delayed = np.hstack((arr1d[abs(lag):], np.zeros(abs(lag)))) elif lag > 0: - arr_delayed = np.hstack((np.zeros(lag), arr1d[lag:])) + arr_delayed = np.hstack((np.zeros(lag), arr1d[:-lag])) else: arr_delayed = arr1d.copy() arr_with_lags[:, i_lag] = arr_delayed From f7c85b195d1cf00d6d1de99127334560a29a2b43 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Wed, 15 Mar 2023 11:23:50 -0400 Subject: [PATCH 6/6] Use int instead of numpy.int (deprecated). --- phys2denoise/metrics/cardiac.py | 2 +- phys2denoise/metrics/chest_belt.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phys2denoise/metrics/cardiac.py b/phys2denoise/metrics/cardiac.py index f52d7b2..b8b2dcc 100644 --- a/phys2denoise/metrics/cardiac.py +++ b/phys2denoise/metrics/cardiac.py @@ -53,7 +53,7 @@ def _crf(t): dt = tr / oversampling time_stamps = np.linspace( - 0, time_length, np.rint(float(time_length) / dt).astype(np.int) + 0, time_length, np.rint(float(time_length) / dt).astype(int) ) time_stamps -= onset crf_arr = _crf(time_stamps) diff --git a/phys2denoise/metrics/chest_belt.py b/phys2denoise/metrics/chest_belt.py index f0803e8..9417e67 100644 --- a/phys2denoise/metrics/chest_belt.py +++ b/phys2denoise/metrics/chest_belt.py @@ -260,7 +260,7 @@ def _rrf(t): dt = tr / oversampling time_stamps = np.linspace( - 0, time_length, np.rint(float(time_length) / dt).astype(np.int) + 0, time_length, np.rint(float(time_length) / dt).astype(int) ) time_stamps -= onset rrf_arr = _rrf(time_stamps)