NeuroKit: Calculating time of inspiration and expiration using RSP
Hi, I had the idea to include average inspiration and expiration times in the output of rsp_intervalrelated, but my solution right now seems a bit unpythonic (is that a word?). Any ideas for making this cleaner?
# Process it
signals, info = nk.rsp_process(rsp, sampling_rate=250)
# Get indexes of phase changes
phase_peaks = signals[signals.RSP_Phase_Completion == 1]
# Calc diff for each phase change
phase_peaks['phase_len'] = np.diff(phase_peaks.index, prepend=0)
phase_peaks['phase_time'] = phase_peaks.phase_len/250
# make df for expirations and inspirations
insp = phase_peaks[phase_peaks.RSP_Phase == 0]
exp = phase_peaks[phase_peaks.RSP_Phase == 1]
print("Mean insp_time:", insp.phase_time.mean())
print("Mean exp_time:", exp.phase_time.mean())
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 22 (22 by maintainers)
Commits related to this issue
- phase durations and i/e ratio #428 — committed to neuropsychology/NeuroKit by zen-juen 3 years ago
- rename column names in `rsp_intervalrelated()` #428 — committed to neuropsychology/NeuroKit by zen-juen 3 years ago
- minor fix #428 — committed to neuropsychology/NeuroKit by zen-juen 3 years ago
Okay I’ve made my way into where my anaconda files are and it looks like that pip command didn’t update my local nk package (which is weird because it worked the first time for the first insp/exp update). I made the changes manually and it fixed it. Sorry for the trouble!
My function is rather rudimentary, just some thresholding for rate and amplitude values that we’ve determined to be outside of what we expect to be physiologically possible. I get my signal from whole-body plethysmography in animals, which opens itself up to large changes in the signal caused by movement, not breathing.
@Mitchellb16 you can run
pip install https://github.com/neuropsychology/neurokit/zipball/dev😄