You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* [viewer] : Fix saving erorr when bad_segments is None.
* [doc] : Fix link to Python functions
* docstring
* docstring
* docstring
* [viewer] Refactor Viewer and Editor in a way that allows the Editor to be used as a standalone.
* [viwer] : Working directly from the BIDS folder
* [docs] More doc on the Editor and Viewer
* [docs]
* [docs]
* v0.2.4
* logo
* logo
Copy file name to clipboardExpand all lines: docs/source/notebooks/3-DetectingAndCorrectingArtefacts.ipynb
+1-1
Original file line number
Diff line number
Diff line change
@@ -1161,7 +1161,7 @@
1161
1161
"id": "dd627eb6-aa7f-4d66-a763-594d4a03611d",
1162
1162
"metadata": {},
1163
1163
"source": [
1164
-
"Because most heart rate variability metrics require continuous interval time series, we cannot simply remove the invalid intervals and concatenate everything, we have to extract valid segments and compute the HRD indices from there. Systole comes with thepy:func`systole.utils.get_valid_segments()` function that will return the valid portion of the physiological recording, sorted according to the signal length."
1164
+
"Because most heart rate variability metrics require continuous interval time series, we cannot simply remove the invalid intervals and concatenate everything, we have to extract valid segments and compute the HRD indices from there. Systole comes with the:py:func`systole.utils.get_valid_segments()` function that will return the valid portion of the physiological recording, sorted according to the signal length."
Because most heart rate variability metrics require continuous interval time series, we cannot simply remove the invalid intervals and concatenate everything, we have to extract valid segments and compute the HRD indices from there. Systole comes with thepy:func`systole.utils.get_valid_segments()` function that will return the valid portion of the physiological recording, sorted according to the signal length.
275
+
Because most heart rate variability metrics require continuous interval time series, we cannot simply remove the invalid intervals and concatenate everything, we have to extract valid segments and compute the HRD indices from there. Systole comes with the:py:func`systole.utils.get_valid_segments()` function that will return the valid portion of the physiological recording, sorted according to the signal length.
Copy file name to clipboardExpand all lines: docs/source/notebooks/6-WorkingWithBIDSFolders.md
+122-34
Original file line number
Diff line number
Diff line change
@@ -25,11 +25,11 @@ if 'google.colab' in sys.modules:
25
25
! pip install systole
26
26
```
27
27
28
-
Starting in version `0.2.3`, Systole provides tools to interact efficiently with large datasets containing physiological recordings. Most of the functionalities interface with folders structured following the [BIDS standards](https://bids-specification.readthedocs.io/en/stable/) and this is the format we recommend using if you are following this tutorial.
28
+
Starting in version `0.2.3`, Systole provides tools to interact with large datasets of physiological recordings. The functionalities interface with folders that are structured following the [BIDS standards](https://bids-specification.readthedocs.io/en/stable/) and this is the format we recommend using if you are following this tutorial.
29
29
30
-
Under BIDS standards, physiological recordings, sometimes associated with behavioural tasks or neural recordings, are stored with a filename ending with `*_physio.tsv.gz` and are always accompanied with sidecar a `*_physio.json` file containing metadata like the recording modality or the sampling frequency. Accessing both the times series and its accompanying metadata will help Systole automate the preprocessing by finding the correct parameters for peaks detection and reports.
30
+
Following the BIDS specifications, physiological recordings, sometimes associated with behavioural tasks or neural recordings, are stored with a filename ending with `*_physio.tsv.gz` and are always accompanied with sidecar a `*_physio.json` file containing metadata like the recording modality or the sampling frequency. Accessing both the times series and its accompanying metadata will help Systole automate the preprocessing by finding the correct parameters for peaks detection and reports.
31
31
32
-
Once you have organized your folder, you should have a structure resembling this one:
32
+
A valid BIDS foldershould be structured like the following:
33
33
34
34
```
35
35
└─ BIDS/
@@ -46,17 +46,22 @@ Once you have organized your folder, you should have a structure resembling this
46
46
47
47
Here, we have physiological recordings associated with a behavioural task for `n` participants in the folder.
48
48
49
+
```{tip}
50
+
We recommend using tools like [BIDS validator](https://bids-standard.github.io/bids-validator/) to ensure that your folder complies with BIDS specification before trying to preprocess your data, or to use the editor.
51
+
```
52
+
49
53
+++
50
54
51
-
## Signal preprocessing and creation of subject and group-level reports
55
+
(preprocessing)=
56
+
## Preprocessing
52
57
53
58
+++
54
59
55
60
The first step will be to preprocess the raw data and store the signal and peaks detection in a new derivative folder. During this step, we can also decide to create HTML reports for each participants, so we can visualize the signal quality and peaks detection.
56
61
57
-
### Preprocessing the physiological recording from one participant
62
+
### Preprocessing the physiological data from one participant
58
63
59
-
The py:func:`systole.reports` sub-module contains tools to directly interact with BIDS formatted folders, preprocess and save individual reports in a BIDS consistent way. Those functionalities are built on the top of thepy:func:`systole.reports.subject_level_report` function. This function will simply take a signal as input and will save as output the preprocessed signal with peaks detection (`_physio.tsv.gz` with the `_physio.json`), an `.html` reports adapted to the kind of signal that was provided, and a `features.tsv` file containing heart rate or respiratory rate variability features.
64
+
The :py:func:`systole.reports` sub-module contains tools to directly interact with BIDS formatted folders, preprocess and save individual reports in a BIDS consistent way. Those functionalities are built on the top of the:py:func:`systole.reports.subject_level_report` function. This function will simply take a signal as input and will save as output the preprocessed signal with peaks detection (`_physio.tsv.gz` with the `_physio.json`), an `.html` reports adapted to the kind of signal that was provided, and a `features.tsv` file containing heart rate or respiratory rate variability features.
60
65
61
66
For example, running the following code:
62
67
@@ -88,7 +93,7 @@ will save these four new files in the file folder.
88
93
89
94
### Preprocessing the entire BIDS folder
90
95
91
-
The previous function call can be automated for each participant and each file of a given BIDS folder and to extract the physiological features using the information provided in the `json` metadata automatically. This can be done using thepy:func:`systole.reports.wrapper` function, or directly from the command line. For example, the following command:
96
+
The previous function call can be automated for each participant and each file of a given BIDS folder and to extract the physiological features using the information provided in the `json` metadata automatically. This can be done using the:py:func:`systole.reports.wrapper` function, or directly from the command line. For example, the following command:
will preprocess the data for all participants with a physiological recording in the session `ses-session1` (default), for the behavioural modality (`beh`) and the task `mytask`. We set `n_jobs=10`, meaning that we will run 40 processes in parallel, and `overwrite=True` to overwrite previous data with the same ID in the derivative folder. Note that we also set `html_reports` to `False` as these files can be quite large, it is often preferable to only create it for the participant we want to review, or to use the {ref}`viewer`.
107
+
will preprocess the data for all participants with a physiological recording in the session `ses-session1` (default), for the behavioural modality (`beh`) and the task `mytask`. We set `n_jobs=10`, meaning that we will run 40 processes in parallel, and `overwrite=True` to overwrite previous data with the same ID in the derivative folder. Note that we also set `html_reports` to `False` as these files can be quite large, it is often preferable to only create it for the participant we want to review, or to use the {ref}`viewer`. The possible arguments are:
108
+
109
+
```{list-table} Command line arguments
110
+
:header-rows: 1
111
+
:name: label-to-reference
112
+
113
+
* - Argument
114
+
- Description
115
+
* - --bids_folder (-i)
116
+
- Path to the BIDS folder containing the physiological recordings.
117
+
* - --participant_id (-p)
118
+
- The id of the participant that should be preprocessed. If this argument is not provided, all the participants will be preprocessed.
119
+
* - --patern (-t)
120
+
- Only the files that contains the pattern string will be preprocessed. If the number of files matching is not exactly 1, the files are not processed.
121
+
* - --html_reports (-r)
122
+
- Create subject-level HTML reports if `True`.
123
+
* - --result_folder (-o)
124
+
- Path to the result folder. If not provided, the default will be ./derivatives/systole/.
125
+
* - --n_jobs (-n)
126
+
- The number of jobs to run concurrently.
127
+
* - --modality (-d)
128
+
- The modality of the recording (i.e. `"beh"`, `"func"`...).
129
+
* - --overwrite (-w)
130
+
- If `True`, overwrite preexisting files in the result folder (DOES NOT include the corrected files).
131
+
```
103
132
104
133
+++
105
134
@@ -136,59 +165,124 @@ Once the preprocessing is completed, and if you did not asked for an external re
136
165
+++
137
166
138
167
(viewer)=
139
-
## Manual edition of peaks vector and labelling bad segments using the Viewer
168
+
## Manual edition of peaks vector and bad segments labelling
140
169
141
170
While we hope that the peaks detection function used by [Systole](https://embodied-computation-group.github.io/systole/#) is sufficiently robust to extract peak vectors without errors for most of the uses cases, you might still encounter noisy or invalid recording that you will want to manually inspect and sometimes edit.
142
171
143
-
The py:func:`systole.viewer` sub-module is built on the top of Matplotlib widgets and can help for manual peaks edition or bad segments labelling. For example, running the following cells in a Jupyter notebook:
172
+
The :py:mod:`systole.interact` sub-module provides two classes (:py:class:`systole.interact.Editor` and :py:class:`systole.interact.Viewer`) built on the top of Matplotlib widgets that can help for manual edition, and interactive visualization of BIDS fodlers directly in the notebook.
173
+
174
+
### Using the Editor to inspect raw signal
175
+
176
+
The :py:mod:`systole.interact.Editor` can be use alone (apart from a BISD structured folder) to edit peaks detection from a raw ECG, PPG or respiratory signal.
Note that we are using the package [ipympl](https://matplotlib.org/ipympl/), and activating it using the magic cell `%matplotlib ipympl` so we can render Matplotlib interactive widgets in the Notebook. If you are working in another IDE, you can also render the same windows using a different backend like PyQt.
164
206
```
165
207
166
-
will create an interactive windows from which all the preprocessed recordings and peaks detection can be inspected.
208
+
This windows will automatically apply peaks detection given the `signal_type` parameter, and plot the raw signal with the instantaneous heart / respiration rate to check for artefacts. The class embed a `command_box` that can be used for edition.
* By deselecting the check box, you can mark the entire signal as **invalid**.
220
+
221
+
* Once that the signal has been edited, you can **save** the modification using the `Save modification` button, or directly use the method from the class.
169
222
170
223
+++
171
224
172
-
### Inserting / deleting peaks
225
+
This function will create a JSON file (using the path specified in the `corrected_json` parameter) with all the information about bad segments labelling, peaks deletion and peaks insertion. The JSON file contains the following entries for each modality (ECG, PPG and respiration)
226
+
227
+
*`valid` : is the recording valid or should it be discared (`True` unless otherwise stated).
228
+
*`corrected_peaks` : the peaks indexes after correction.
229
+
*`bad_segments` : a list of `start` and `end` indexed of bad segments.
173
230
174
-
Peaks can be inserted (using the local maxima of the selected range) or deleted.
231
+
+++ {"tags": []}
175
232
176
-
* Left mouse button : remove all the peaks in the selected interval.
177
-
* Right mouse button : add one new peaks where the signal local maximum is found.
233
+
### Using the Viewer to navigate preprocessed folder
The :py:mod:`systole.interact.Viewer` class wrap the Editor and allows to easily navigate and edit folder that contains large number of recoring. You can for example simply read the results generated by the command line (see {ref}`preprocessing`). Considering that the files were create in the folder `"/path/to/BIDS/folder/derivatives/systole/"` (which is the default behavior if `--result _folder is not provided`), the Viewer can be called using:
This will create an interactive windows where all the preprocessed ECG recordings from the behavioral task `my_task` can be inspected and further edited.
If the signal was previously edited, the Viewer will automatically load the edited version and display bad segment (if any).
264
+
```
180
265
181
266
+++
182
267
183
-
### Bad segments labelling
268
+
### Using the Viewer to navigate BIDS folder
269
+
270
+
Using the same logic, the :py:mod:`systole.interact.Viewer` can also work with the raw BIDS folder, instead of the derivatives, and preprocess data on the fly. This mode is more appropriate if you want to quickly inspect the data and do not want to generate subject or group level reports. The only different is that the input path should be parameter using the `bids_folder` argument, instead of `preprocessed_folder`. This will make the viewer aware that the signal are located in this folder, but that previously edited signal might also be located in `./derivatives/systole/corrected/`.
184
271
185
-
In case a whole segment of the recording contain noise and should be entirely removed from future analysis, it can be labelled by swiching the edition mode from `Correction` to `Rejection`.
pattern="task-my_task", # A string long enough to disambiguate in case of mmultiple recordings
278
+
modality="beh",
279
+
signal_type="ECG"
280
+
)
281
+
```
188
282
189
283
+++
190
284
191
-
### Working with corrected signals
285
+
### Importing signals after manual edition
192
286
193
287
After manual peaks correction and segments labelling, a new `corrected` subfolder will be appended to the systole derivatives:
194
288
@@ -218,9 +312,3 @@ After manual peaks correction and segments labelling, a new `corrected` subfolde
218
312
├─ sub-0003/
219
313
└─ ...
220
314
```
221
-
222
-
The logs of artefacts correction are located in the new `_physio.json` file and contains all information about bad segments labelling, peaks deletion and peaks insertion. The JSON file contains the following entries for each modality (ECG, PPG and respiration)
223
-
224
-
*`valid` : is the recording valid or should it be discared (`True` unless otherwise stated).
225
-
*`corrected_peaks` : the peaks indexes after correction.
226
-
*`bad_segments` : a list of `start` and `end` indexed of bad segments.
0 commit comments