Skip to content

Commit

Permalink
doc: Add references around
Browse files Browse the repository at this point in the history
  • Loading branch information
smoia committed Apr 14, 2023
1 parent 73e5f86 commit 3a206a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 10 additions & 7 deletions phys2denoise/metrics/chest_belt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
from .utils import convolve_and_rescale, rms_envelope_1d


def respiratory_variance_time(belt_ts, peaks, troughs, samplerate, lags=(0, 4, 8, 12)):
@due.dcite(references.BIRN_2006)
def respiratory_variance_time(resp, peaks, troughs, samplerate, lags=(0, 4, 8, 12)):
"""
Implement the Respiratory Variance over Time (Birn et al. 2006).
Procedural choices influenced by RetroTS
Parameters
----------
belt_ts: array_like
resp: array_like
respiratory belt data - samples x 1
peaks: array_like
peaks found by peakdet algorithm
Expand All @@ -43,9 +44,9 @@ def respiratory_variance_time(belt_ts, peaks, troughs, samplerate, lags=(0, 4, 8
"""
timestep = 1 / samplerate
# respiration belt timing
time = np.arange(0, len(belt_ts) * timestep, timestep)
peak_vals = belt_ts[peaks]
trough_vals = belt_ts[troughs]
time = np.arange(0, len(resp) * timestep, timestep)
peak_vals = resp[peaks]
trough_vals = resp[troughs]
peak_time = time[peaks]
trough_time = time[troughs]
mid_peak_time = (peak_time[:-1] + peak_time[1:]) / 2
Expand Down Expand Up @@ -160,7 +161,9 @@ def env(resp, samplerate, window=10):
# Calculate RPV across a rolling window

env_arr = (
pd.Series(resp).rolling(window=window, center=True).apply(rpv, args=(window,))
pd.Series(resp)
.rolling(window=window, center=True)
.apply(respiratory_pattern_variability, args=(window,))
)
env_arr[np.isnan(env_arr)] = 0.0
return env_arr
Expand Down Expand Up @@ -210,7 +213,7 @@ def respiratory_variance(resp, samplerate, window=6):
rv_arr = afsw(resp, np.std, halfwindow_samples)

# Convolve with rrf
rv_out = convolve_and_rescale(rv_arr, rrf(samplerate), rescale='zscore')
rv_out = convolve_and_rescale(rv_arr, rrf(samplerate), rescale="zscore")

return rv_out

Expand Down
4 changes: 3 additions & 1 deletion phys2denoise/metrics/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ def _crf(t):

time_stamps = np.arange(0, time_length, 1 / samplerate)
time_stamps -= onset
crf_arr = _crf(time_stamps)
crf_arr = _crf(time_stamps)
crf_arr = crf_arr / max(abs(crf_arr))

if inverse:
return -crf_arr
else:
return crf_arr


@due.dcite(references.CHANG_CUNNINGHAM_GLOVER_2009)
@due.dcite(references.CHEN_2009)
def icrf(samplerate, time_length=32, onset=0.0):
"""
Calculate the inverse of the cardiac response function.
Expand Down

0 comments on commit 3a206a7

Please sign in to comment.