Skip to content

Commit

Permalink
Merge branch 'master' into read-spike
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano Moia committed Nov 22, 2021
2 parents 65289d2 + 7369827 commit a54e85c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Unittest_task:
populate_script:
- source activate $PWD/conda-env
Running_unit_tests_script:
- apt-get install -y make curl
- apt-get update
- apt-get install -y build-essential curl
- source activate $PWD/conda-env
- make unittest
- bash <(curl -s https://codecov.io/bash)
Expand All @@ -62,7 +63,8 @@ Integration_task:
populate_script:
- source activate $PWD/conda-env
Running_integration_tests_script:
- apt-get install -y make curl tree tar
- apt-get update
- apt-get install -y build-essential curl tree tar
- source activate $PWD/conda-env
- PATH=/home/test_user/.local/bin:$PATH
- make integration
Expand All @@ -84,7 +86,8 @@ Style_check_task:
populate_script:
- source activate $PWD/conda-env
Lintin_script:
- apt-get install -y make
- apt-get update
- apt-get install -y build-essential
- source activate $PWD/conda-env
- make lint

Expand All @@ -101,7 +104,8 @@ Build_docs_task:
populate_script:
- source activate $PWD/conda-env
Build_documentation_script:
- apt-get install -y make tar
- apt-get update
- apt-get install -y build-essential tar
- source activate $PWD/conda-env
- make -C docs html
docs_artifacts:
Expand All @@ -121,6 +125,7 @@ Bids_validate_task:
populate_script:
- source activate $PWD/conda-env
Generate_enviroment_script:
- apt-get update
- apt-get install -yqq wget curl tree
- curl -sL https://deb.nodesource.com/setup_15.x | bash -
- apt-get install -yqq nodejs
Expand Down
4 changes: 2 additions & 2 deletions docs/howto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Now the output says:
Tip: Time 0 is the time of first trigger
------------------------------------------------
``phys2bids`` has an automatic way of finding the right threshold, in order to find the correct number of timepoints, by using the mean and standard deviation of the trigger channel. If "Found just the right amount of timepoints!" appears everything should be working properly!
``phys2bids`` has an automatic way of finding the right threshold, in order to find the correct number of timepoints, by using the mean of the trigger channel. If "Found just the right amount of timepoints!" appears everything should be working properly!

Alright, so now we have some outputs that make sense! We have 158 timepoints expected (as inputted with ``-ntp``) and found. The output also tells us that the fMRI sampling started around 0.25 seconds later than the start of this physiological sampling.

Expand All @@ -231,7 +231,7 @@ If for some reason ``-ntp`` and the number of timepoints found by ``phys2bids``
3. The file doesn't have all the trigger pulses you expect because the recording started later than the MRI recording (e.g. by mistake).

.. note::
``phys2bids`` was created to deal with little sampling errors - such as distracted researchers that started sampling a bit too late than expected. For this reason, if it finds less trigger pulses than the amount specified, it will assume that the missing ones are at the beginning and anticipate the starting time consequently.
``phys2bids`` was created to deal with little sampling errors - such as distracted researchers that started sampling a bit too late than expected. For this reason, if it finds fewer trigger pulses than the amount specified, it will assume that the missing ones are at the beginning and anticipate the starting time consequently.


Let's go through an example where the number of timepoints automatically found is not correct. For that, will we use tutorial_file_v2.txt (in the same location as tutorial_file.txt):
Expand Down
9 changes: 7 additions & 2 deletions phys2bids/physio_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ def check_trigger_amount(self, thr=None, num_timepoints_expected=0, tr=0):
Outcome:
self.thr: float
Threshold used by the function to detect trigger points.
If no threshold is provided, value is the mean of the trigger channel.
self.num_timepoints_found: int
Property of the `BlueprintInput` class.
Contains the number of timepoints found
Expand All @@ -477,10 +478,14 @@ def check_trigger_amount(self, thr=None, num_timepoints_expected=0, tr=0):
'of time to find the starting time.')
time = np.linspace(time[0], time[-1], len(trigger))

# Check if thr was given, if not "guess" it.
flag = 0
if thr is None:
thr = np.mean(trigger) + 2 * np.std(trigger)
# If trigger channels are binary
# (i.e., "on" is a higher value and "off" is a lower value)
# and each "on" and "off" are each always approzimately the same value
# then any value above the mean is "on" and every value below the mean
# is "off".
thr = np.mean(trigger)
flag = 1
timepoints = trigger > thr
num_timepoints_found = len([is_true for is_true, _ in groupby(timepoints,
Expand Down

0 comments on commit a54e85c

Please sign in to comment.