Skip to content

Commit

Permalink
Merge pull request #191 from vinferrer/doc_trig
Browse files Browse the repository at this point in the history
Update trigger detection tutorial
  • Loading branch information
vinferrer authored Apr 3, 2020
2 parents 19251e0 + f3e06ef commit c37bb87
Show file tree
Hide file tree
Showing 7 changed files with 189,136 additions and 102 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/heuristic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Once you modified your heuristic file or created a new one, you can save it anyw

.. code-block:: shell
phys2bids -in tutorial_file.txt -chtrig 1 -outdir /home/arthurdent/physio_bids -ntp 158 -tr 1.2 -thr 0.735 -heur /home/arthurdent/git/phys2bids/phys2bids/heuristics/heur_tutorial.py -sub 006 -ses 01
phys2bids -in tutorial_file.txt -indir /home/arthurdent/git/phys2bids/phys2bids/tests/data/ -chtrig 1 -ntp 158 -tr 1.2 -outdir /home/arthurdent/physio -heur /home/arthurdent/git/phys2bids/phys2bids/heuristics/heur_tutorial.py -sub 006 -ses 01
Remember to **specify the full path** to the heuristic file. A copy of the heuristic file will be saved in the site folder.

Expand Down
213 changes: 116 additions & 97 deletions docs/howto.rst

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions phys2bids/phys2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ def phys2bids(filename, info=False, indir='.', outdir='.', heur_file=None,
viz.plot_trigger(phys_in.timeseries[0], phys_in.timeseries[chtrig],
plot_path, tr, phys_in.thr, num_timepoints_expected, filename)
else:
LGR.info('Not plotting trigger. If you want the trigger to be'
' plotted enter -tr or -ntp, preferably both.')
LGR.warning('Skipping trigger pulse count. If you want to run it, '
'call phys2bids using "-ntp" and "-tr" arguments')

# The next few lines remove the undesired channels from phys_in.
if chsel:
Expand Down
10 changes: 8 additions & 2 deletions phys2bids/physio_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,19 @@ def check_trigger_amount(self, chtrig=1, thr=None, num_timepoints_expected=0, tr
# Use the trigger channel to find the TRs,
# comparing it to a given threshold.
trigger = self.timeseries[chtrig]
flag = 0
if thr is None:
thr = np.mean(trigger) + 2 * np.std(trigger)
flag = 1
timepoints = trigger > thr
num_timepoints_found = len([is_true for is_true, _ in groupby(timepoints,
lambda x: x != 0) if is_true])
LGR.info(f'The number of timepoints according to the std_thr method '
f'is {num_timepoints_found}. The computed threshold is {thr}')
if flag == 1:
LGR.info(f'The number of timepoints according to the std_thr method '
f'is {num_timepoints_found}. The computed threshold is {thr}')
else:
LGR.info(f'The number of timepoints found with the manual threshold of {thr} '
f'is {num_timepoints_found}')
time_offset = self.timeseries[0][timepoints.argmax()]

if num_timepoints_expected:
Expand Down
File renamed without changes.
Loading

0 comments on commit c37bb87

Please sign in to comment.