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

debug cross co example in doc of cardio respi synchro and improve doc of other examples (remove typos) #38

Merged
merged 5 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 17 additions & 18 deletions examples/example_01_getting_started.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@

##############################################################################
#
# Analyse respiration
# Analyze respiration
# -------------------
#
# :py:func:`~physio.compute_respiration` is an easy function to:
#
# * preprocess the respiration signal
# * compute cycle
# * compute cycle features
# * preprocess the respiratory signal (resp)
# * compute cycle features (resp_cycles)


resp, resp_cycles = physio.compute_respiration(raw_resp, srate)
Expand All @@ -61,11 +60,11 @@

##############################################################################
#
# repiration cycles and features
# Respiration cycles and features
# ------------------------------
#
# resp_cycles is a dataframe containing all respiration cycles as rows and columns.
# It contains features like duration, amplitudes, durations
# resp_cycles is a dataframe containing all respiratory cycles as rows.
# Columns contain features like duration, amplitudes, volumes.
#

print(resp_cycles.shape)
Expand Down Expand Up @@ -98,8 +97,8 @@
#
# :py:func:`~physio.compute_ecg` is an easy function to:
#
# * Preprocess the ECG signal output, which is normalized by default
# * Detect R peaks
# * Preprocess the ECG signal output, which is normalized by default (ecg)
# * Detect R peaks (ecg_peaks)


ecg, ecg_peaks = physio.compute_ecg(raw_ecg, srate)
Expand All @@ -122,10 +121,10 @@
# ECG metrics
# -----------
#
# :py:func:`~physio.compute_ecg_metrics` is a simple function to compute temporal based metrics around ECG
# :py:func:`~physio.compute_ecg_metrics` is a simple function to compute time-domain Heart Rate Variability (HRV) metrics.
#
# We can visualize theses metrics and the RR interval distribution.
# We can visualize these metrics and the RR interval distribution.


ecg_metrics = physio.compute_ecg_metrics(ecg_peaks)
Expand All @@ -150,21 +149,21 @@
# to a cycle template by stretching with linear resampling to a fixed number of
# points per cycle.
#
# This is helpfull to check if a signal is driven by a cyclic event like respiration.
# This is helpful to explore if features of a signal are driven by a cyclic phenomenon like respiration.
# Here, we deform the signal trace by "itself" : the respiration cycle.
# This leads to an average respiration template.
# Here, we deform the signal trace by "itself" : the respiratory cycle.
# This leads to an average respiratory template.
#
# Importantly, this can be done using one or several segment inside the cycle.

# here we have 3 time per cycle so 2 segments
# here we have 3 times per cycle so 2 segments
cycle_times = resp_cycles[['inspi_time', 'expi_time', 'next_inspi_time']].values
deformed_resp_1seg = physio.deform_traces_to_cycle_template(resp, times, cycle_times,
points_per_cycle=40, segment_ratios=0.4,
output_mode='stacked')
print(deformed_resp_1seg.shape, cycle_times.shape)

# here we have 2 time per cycle so 1 segment
# here we have 2 times per cycle so 1 segment
cycle_times = resp_cycles[['inspi_time', 'next_inspi_time']].values
deformed_resp_2seg = physio.deform_traces_to_cycle_template(resp, times, cycle_times,
points_per_cycle=40, segment_ratios=None,
Expand All @@ -183,7 +182,7 @@
# Cyclic deformation on ECG
# -------------------------
Lets use the same for ECG trace
Let's use the same for ECG trace
# We can also use a simple vector in this case it is converted a a 1 segment case.

Expand All @@ -196,7 +195,7 @@

fig, ax = plt.subplots()
physio.plot_cyclic_deformation(deformed_ecg, two_cycles=True, ax=ax)
ax.set_title('two ECG cycle avaerage')
ax.set_title('Two ECG cycle averaged')

##############################################################################
#
Expand Down
23 changes: 16 additions & 7 deletions examples/example_02_respiration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# ------------------------------------------
#
# The fastest way is to use compute_respiration() using a predefined
# parameter presetset. Here is a simple example.
# parameter preset. Here is a simple example.


# read data
Expand All @@ -46,22 +46,31 @@

ax.set_xlim(110, 170)

##############################################################################
# Cycle detection: Default parameters
# -----------------------------------
# Here are the default parameters : those aiming to process a human airflow signal.
# It is possible to get default parameters dictionnary by calling it with the :py:func:`~physio.get_respiration_parameters` function.

# this is a nested dict of parameters of every processing step
parameters = physio.get_respiration_parameters('human_airflow')
pprint(parameters)

##############################################################################
# Cycle detection: Parameters tuning
# -----------------------------------
Here is a simple recipe to change some predefined parameters.
We change here the length of the smoothing parameter.
If necessary, it is possible to change the predefined parameters.
For example, we change here the length of the smoothing parameter.

# get paramseters set
# this is a nested dict of parameter of every step
parameters = physio.get_respiration_parameters('human_airflow')
# lets change on parameter in the structure
# let's change on parameter in the structure ...
parameters['smooth']['sigma_ms'] = 100.
pprint(parameters)

# ... and use them by providing it to "parameters"
resp, resp_cycles = physio.compute_respiration(raw_resp, srate, parameters=parameters)


Expand Down
18 changes: 9 additions & 9 deletions examples/example_03_ecg.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
# Detect ECG R peaks: Parameters tuning
# -------------------------------------
# Here is a simple recipe to change some predefined parameters.
# We change here some filtering parameters.
# Here is a simple recipe to change the default parameters.
# We change here some filtering parameters (frequency band, filter type, order of the filter).

# get paramseters predefined set for 'human_ecg'
# this is a nested dict of parameter of every step
Expand All @@ -74,7 +74,7 @@

##############################################################################
#
# ECG: compute metrics
# ECG: compute time-domain heart rate variability (HRV) metrics
# --------------------
#

Expand All @@ -87,13 +87,13 @@
# ECG : compute instantaneous rate
# --------------------------------
#
# The RR-interval (aka rri) time series is a common tool to analyse the heart rate variability (hrv).
# This is equivalent to computing the instantaneous heart rate.
# The RR-interval (aka rri) time series is a common tool to analyse the heart rate variability (HRV).
# This is equivalent to compute the instantaneous heart rate.
# Heart rate [bpm] = 1 / rri * 60
#
# Most people use rri in ms, we feel that use heart rate in bpm is more intuitive.
# With bpm an increase in the curve = heart acceleration.
# With ms an increase in the curve = heart decceleration.
# Most people use rri in ms, we feel that the use of heart rate in bpm is more intuitive.
# With bpm unit, an increase in the curve means heart rate acceleration.
# With ms unit, an increase in the curve means heart rate deceleration.
#
# Feel free to use the units you prefer (bpm or ms)

Expand Down Expand Up @@ -125,7 +125,7 @@

##############################################################################
#
# ECG: compute hrv spectrum
# ECG: compute frequency-domain heart rate variability (HRV) metrics
# -------------------------
#
Expand Down
2 changes: 1 addition & 1 deletion examples/example_05_rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
# This is done with one unique function that returns:
#
# * One dataframe with all RSA features
# * The cyclic deformed cardiac rate
# * The cyclically deformed cardiac rate

points_per_cycle = 50

Expand Down
4 changes: 1 addition & 3 deletions examples/example_06_cardio_respiratory_synchronization.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,4 @@
ax.legend()


plt.show()

ax.set_xlim(-0.01, 1.01)
plt.show()
Loading