From 245e936e199dc44c1a3e41394e512371ff0c28d0 Mon Sep 17 00:00:00 2001 From: Katie Bottenhorn Date: Mon, 11 Jan 2021 15:07:05 -0500 Subject: [PATCH 01/15] update trigger guesstimate calculation --- phys2bids/physio_obj.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/phys2bids/physio_obj.py b/phys2bids/physio_obj.py index 3466aa626..94fb5ed5b 100644 --- a/phys2bids/physio_obj.py +++ b/phys2bids/physio_obj.py @@ -467,11 +467,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) - flag = 1 + thr = np.mean(trigger) + 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, lambda x: x != 0) if is_true]) From 16bcef52a77b4045c026a0d403ac6c53ecd9fbc3 Mon Sep 17 00:00:00 2001 From: Katie Bottenhorn Date: Mon, 11 Jan 2021 15:11:54 -0500 Subject: [PATCH 02/15] update check_trigger_amount() documentation to reflect changes --- phys2bids/physio_obj.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phys2bids/physio_obj.py b/phys2bids/physio_obj.py index 94fb5ed5b..0e8fbd803 100644 --- a/phys2bids/physio_obj.py +++ b/phys2bids/physio_obj.py @@ -444,7 +444,8 @@ 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. + 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 From 1ceaabcc4fdc5c0c52594322ca21be1e6c06c8c0 Mon Sep 17 00:00:00 2001 From: Katie Bottenhorn Date: Mon, 11 Jan 2021 22:13:40 -0500 Subject: [PATCH 03/15] Update physio_obj.py accidentally deleted flag initial assignment, fixed now! --- phys2bids/physio_obj.py | 1 + 1 file changed, 1 insertion(+) diff --git a/phys2bids/physio_obj.py b/phys2bids/physio_obj.py index 0e8fbd803..154618a86 100644 --- a/phys2bids/physio_obj.py +++ b/phys2bids/physio_obj.py @@ -468,6 +468,7 @@ 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)) + flag = 0 if thr is None: thr = np.mean(trigger) + np.std(trigger) # If trigger channels are binary # (i.e., "on" is a higher value and "off" is a lower value) From ae7deeaa4e0c78e0167a2f78d46f0c1d16f70139 Mon Sep 17 00:00:00 2001 From: Katie Bottenhorn Date: Tue, 12 Jan 2021 10:47:00 -0500 Subject: [PATCH 04/15] fixed linting errors --- phys2bids/physio_obj.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/phys2bids/physio_obj.py b/phys2bids/physio_obj.py index 0e8fbd803..4113ed0a4 100644 --- a/phys2bids/physio_obj.py +++ b/phys2bids/physio_obj.py @@ -444,7 +444,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. + 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. @@ -469,13 +469,14 @@ def check_trigger_amount(self, thr=None, num_timepoints_expected=0, tr=0): time = np.linspace(time[0], time[-1], len(trigger)) if thr is None: - thr = np.mean(trigger) + np.std(trigger) # If trigger channels are binary + thr = np.mean(trigger) + 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". + # is "off". thr = np.mean(trigger) - flag = 1 + flag = 1 timepoints = trigger > thr num_timepoints_found = len([is_true for is_true, _ in groupby(timepoints, lambda x: x != 0) if is_true]) From fa6467a7f7c7c435b35d9758e9e2027fcc7f6813 Mon Sep 17 00:00:00 2001 From: Katie Bottenhorn Date: Tue, 12 Jan 2021 10:50:32 -0500 Subject: [PATCH 05/15] fix duplicate thr typo, updated docs --- docs/howto.rst | 2 +- phys2bids/physio_obj.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/howto.rst b/docs/howto.rst index 81a5a26d5..ddf6a5274 100644 --- a/docs/howto.rst +++ b/docs/howto.rst @@ -202,7 +202,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. diff --git a/phys2bids/physio_obj.py b/phys2bids/physio_obj.py index 7b6397231..7c1ac6959 100644 --- a/phys2bids/physio_obj.py +++ b/phys2bids/physio_obj.py @@ -469,8 +469,7 @@ def check_trigger_amount(self, thr=None, num_timepoints_expected=0, tr=0): time = np.linspace(time[0], time[-1], len(trigger)) flag = 0 - if thr is None: - thr = np.mean(trigger) + np.std(trigger) + if thr is None: # 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 From 3c54b5223f307395f200717a6868cef0389136c0 Mon Sep 17 00:00:00 2001 From: Katie Bottenhorn Date: Tue, 12 Jan 2021 10:53:05 -0500 Subject: [PATCH 06/15] fix typo in howto docs --- docs/howto.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/howto.rst b/docs/howto.rst index ddf6a5274..f7c099393 100644 --- a/docs/howto.rst +++ b/docs/howto.rst @@ -225,7 +225,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): From 6fda3f6183da42e872d147d7d1e80232c2086976 Mon Sep 17 00:00:00 2001 From: Katie Bottenhorn Date: Tue, 12 Jan 2021 10:59:40 -0500 Subject: [PATCH 07/15] fix linting issues --- phys2bids/physio_obj.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phys2bids/physio_obj.py b/phys2bids/physio_obj.py index 7c1ac6959..a1845e6eb 100644 --- a/phys2bids/physio_obj.py +++ b/phys2bids/physio_obj.py @@ -469,14 +469,14 @@ def check_trigger_amount(self, thr=None, num_timepoints_expected=0, tr=0): time = np.linspace(time[0], time[-1], len(trigger)) flag = 0 - if thr is None: + if thr is None: # 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 + flag = 1 timepoints = trigger > thr num_timepoints_found = len([is_true for is_true, _ in groupby(timepoints, lambda x: x != 0) if is_true]) From b8dbbeaba9a70bfbeb6e30e5597ffb9f0b6084fb Mon Sep 17 00:00:00 2001 From: vinferrer Date: Fri, 25 Jun 2021 10:45:25 +0200 Subject: [PATCH 08/15] add python 3.10 testing --- .cirrus.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.cirrus.yml b/.cirrus.yml index 7b64acd79..f62e98568 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -10,6 +10,7 @@ makeenv_task: PYTHON: 3.7 PYTHON: 3.8 PYTHON: 3.9 + PYTHON: 3.10 environment_cache: folder: conda-env fingerprint_script: @@ -30,6 +31,7 @@ Unittest_task: PYTHON: 3.7 PYTHON: 3.8 PYTHON: 3.9 + PYTHON: 3.10 CODECOV_TOKEN: eb5758aa-6d0c-4981-a22a-16c663e2aaa9 environment_cache: folder: conda-env @@ -53,6 +55,7 @@ Integration_task: PYTHON: 3.7 PYTHON: 3.8 PYTHON: 3.9 + PYTHON: 3.10 CODECOV_TOKEN: eb5758aa-6d0c-4981-a22a-16c663e2aaa9 environment_cache: folder: conda-env @@ -76,6 +79,7 @@ Style_check_task: - makeenv env: PYTHON: 3.9 + PYTHON: 3.10 environment_cache: folder: conda-env fingerprint_script: @@ -93,6 +97,7 @@ Build_docs_task: - makeenv env: PYTHON: 3.9 + PYTHON: 3.10 environment_cache: folder: conda-env fingerprint_script: @@ -113,6 +118,7 @@ Bids_validate_task: - makeenv env: PYTHON: 3.9 + PYTHON: 3.10 environment_cache: folder: conda-env fingerprint_script: @@ -145,6 +151,7 @@ Integration_windows_task: env: matrix: PYTHON: 3.9 + PYTHON: 3.10 PYTHON: 3.8 PYTHON: 3.7 PYTHON: 3.6 @@ -165,6 +172,7 @@ Unittest_windows_task: env: matrix: PYTHON: 3.9 + PYTHON: 3.10 PYTHON: 3.8 PYTHON: 3.7 PYTHON: 3.6 From 5d8f622a759660d1f1335ddbb9771f88c4d917cc Mon Sep 17 00:00:00 2001 From: vinferrer Date: Tue, 26 Oct 2021 14:50:19 +0200 Subject: [PATCH 09/15] empty commit to trigger tests From 816ec2085fd035bd37074c41ffec74583e29c04c Mon Sep 17 00:00:00 2001 From: vinferrer Date: Tue, 26 Oct 2021 14:56:40 +0200 Subject: [PATCH 10/15] eliminate python 3.10 build --- .cirrus.yml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index f62e98568..0acfdf45b 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -10,7 +10,6 @@ makeenv_task: PYTHON: 3.7 PYTHON: 3.8 PYTHON: 3.9 - PYTHON: 3.10 environment_cache: folder: conda-env fingerprint_script: @@ -31,7 +30,6 @@ Unittest_task: PYTHON: 3.7 PYTHON: 3.8 PYTHON: 3.9 - PYTHON: 3.10 CODECOV_TOKEN: eb5758aa-6d0c-4981-a22a-16c663e2aaa9 environment_cache: folder: conda-env @@ -55,7 +53,6 @@ Integration_task: PYTHON: 3.7 PYTHON: 3.8 PYTHON: 3.9 - PYTHON: 3.10 CODECOV_TOKEN: eb5758aa-6d0c-4981-a22a-16c663e2aaa9 environment_cache: folder: conda-env @@ -78,8 +75,7 @@ Style_check_task: depends_on: - makeenv env: - PYTHON: 3.9 - PYTHON: 3.10 + PYTHON: 3. environment_cache: folder: conda-env fingerprint_script: @@ -96,8 +92,7 @@ Build_docs_task: depends_on: - makeenv env: - PYTHON: 3.9 - PYTHON: 3.10 + PYTHON: 3. environment_cache: folder: conda-env fingerprint_script: @@ -117,8 +112,7 @@ Bids_validate_task: depends_on: - makeenv env: - PYTHON: 3.9 - PYTHON: 3.10 + PYTHON: 3. environment_cache: folder: conda-env fingerprint_script: @@ -151,7 +145,6 @@ Integration_windows_task: env: matrix: PYTHON: 3.9 - PYTHON: 3.10 PYTHON: 3.8 PYTHON: 3.7 PYTHON: 3.6 @@ -172,7 +165,6 @@ Unittest_windows_task: env: matrix: PYTHON: 3.9 - PYTHON: 3.10 PYTHON: 3.8 PYTHON: 3.7 PYTHON: 3.6 From 67413326f95efdf168a2ea7948920126b12cab8b Mon Sep 17 00:00:00 2001 From: vinferrer Date: Tue, 26 Oct 2021 15:05:41 +0200 Subject: [PATCH 11/15] try with build esentials --- .cirrus.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 0acfdf45b..ac069b022 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -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) @@ -62,7 +63,7 @@ Integration_task: populate_script: - source activate $PWD/conda-env Running_integration_tests_script: - - apt-get install -y make curl tree tar + - apt-get install -y build-essential curl tree tar - source activate $PWD/conda-env - PATH=/home/test_user/.local/bin:$PATH - make integration From 579a64741a77657776aa18f9ed599ecbb30ad8a9 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Tue, 26 Oct 2021 15:09:19 +0200 Subject: [PATCH 12/15] add apt-get update to intregration scripts --- .cirrus.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.cirrus.yml b/.cirrus.yml index ac069b022..cc26785a6 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -63,6 +63,7 @@ Integration_task: populate_script: - source activate $PWD/conda-env Running_integration_tests_script: + - apt-get update - apt-get install -y build-essential curl tree tar - source activate $PWD/conda-env - PATH=/home/test_user/.local/bin:$PATH From 156b3f754ebfddde7fedc24617d91b091c5063d3 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Tue, 26 Oct 2021 15:13:06 +0200 Subject: [PATCH 13/15] correct error in style, bids validation and other tests --- .cirrus.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index cc26785a6..3502ff7a6 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -77,7 +77,7 @@ Style_check_task: depends_on: - makeenv env: - PYTHON: 3. + PYTHON: 3.9 environment_cache: folder: conda-env fingerprint_script: @@ -94,7 +94,7 @@ Build_docs_task: depends_on: - makeenv env: - PYTHON: 3. + PYTHON: 3.9 environment_cache: folder: conda-env fingerprint_script: @@ -114,7 +114,7 @@ Bids_validate_task: depends_on: - makeenv env: - PYTHON: 3. + PYTHON: 3.9 environment_cache: folder: conda-env fingerprint_script: From d7f0f2fec9ee4ce43c46193eda9c240584b498ce Mon Sep 17 00:00:00 2001 From: vinferrer Date: Tue, 26 Oct 2021 15:17:03 +0200 Subject: [PATCH 14/15] use build-essential in the style test --- .cirrus.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 3502ff7a6..6bfb0c82b 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -86,7 +86,7 @@ Style_check_task: populate_script: - source activate $PWD/conda-env Lintin_script: - - apt-get install -y make + - apt-get install -y build-essential - source activate $PWD/conda-env - make lint @@ -103,7 +103,7 @@ Build_docs_task: populate_script: - source activate $PWD/conda-env Build_documentation_script: - - apt-get install -y make tar + - apt-get install -y build-essential tar - source activate $PWD/conda-env - make -C docs html docs_artifacts: From fcabaf1ac0c4446e20ebf9b9589c1dc586187614 Mon Sep 17 00:00:00 2001 From: vinferrer Date: Tue, 26 Oct 2021 15:26:22 +0200 Subject: [PATCH 15/15] add apt-get update to the style test --- .cirrus.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.cirrus.yml b/.cirrus.yml index 6bfb0c82b..9a64032a8 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -86,6 +86,7 @@ Style_check_task: populate_script: - source activate $PWD/conda-env Lintin_script: + - apt-get update - apt-get install -y build-essential - source activate $PWD/conda-env - make lint @@ -103,6 +104,7 @@ Build_docs_task: populate_script: - source activate $PWD/conda-env Build_documentation_script: + - apt-get update - apt-get install -y build-essential tar - source activate $PWD/conda-env - make -C docs html @@ -123,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