-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Etienne de Montalivet
committed
Dec 14, 2023
1 parent
a57f189
commit 0cf15ae
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
=================== | ||
Read TRC file data | ||
=================== | ||
Here we read a trc file recorded with a Micromed system. We access the header, the notes, | ||
the markers and the data. | ||
""" | ||
# Author: Etienne de Montalivet <[email protected]> | ||
# | ||
# License: BSD-3-Clause | ||
|
||
# %% | ||
from micromed_io.trc import MicromedTRC | ||
from pathlib import Path | ||
|
||
fname = Path("../data/sample.TRC") | ||
mmtrc = MicromedTRC(fname) | ||
# %% | ||
# To get most useful data from the header, you can use ``micromed_header`` | ||
print(mmtrc.micromed_header) | ||
hdr = mmtrc.micromed_header | ||
print( | ||
f"Participant {hdr.name}-{hdr.surname} recorded with {hdr.nb_of_channels} channels " | ||
+ f"({hdr.ch_names}) at {mmtrc.sfreq}Hz with {hdr.acq_unit}." | ||
) | ||
|
||
# %% | ||
# If this is not enough for you, you can look for what you need in the full ``_header`` | ||
mmtrc._header | ||
# %% | ||
# To extract notes from recording in the format ``{sample0 : note0, ... sampleN: noteN}`` | ||
mmtrc.get_notes() | ||
|
||
# %% | ||
# To extract markers from recording in the format ``{sample0 : marker0, ... sampleN: markerN}`` | ||
mmtrc.get_markers() | ||
|
||
# %% | ||
# If you need markers or notes times in seconds, just divide by the sampling frequency | ||
{k / mmtrc.sfreq: v for k, v in mmtrc.get_markers().items()} | ||
|
||
# %% | ||
# To get and play with the data, simply use: | ||
data = mmtrc.get_data() | ||
print(f"data shape: {data.shape}") | ||
# or, if you want the 1st channel data only: | ||
data_ch1 = mmtrc.get_data(picks=[hdr.ch_names[0]]) | ||
print(f"data_ch1 shape: {data_ch1.shape}") |