From b62d7be55505f77e73dc09490d0aef38ebc78dc2 Mon Sep 17 00:00:00 2001 From: 36000 Date: Thu, 18 Aug 2022 10:41:33 -0700 Subject: [PATCH 01/13] FIX: nightly broken online, but passes locally --- AFQ/tests/test_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index 03dbef331..3d776e579 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -530,7 +530,7 @@ def test_AFQ_slr(): seed_mask=ImageFile(path=seed_mask_path), n_seeds=1000, random_seeds=True, - rng_seed=42) + rng_seed=seed) myafq = GroupAFQ( bids_path=bids_path, @@ -543,7 +543,7 @@ def test_AFQ_slr(): "filter_by_endpoints": False}, bundle_info=bd, mapping_definition=SlrMap(slr_kwargs={ - "rng": np.random.RandomState(42)})) + "rng": np.random.RandomState(seed)})) seg_sft = aus.SegmentedSFT.fromfile( myafq.export("clean_bundles")["01"]) From 12fd60ce674ca456ebe0e5e1312616a7c04c19e3 Mon Sep 17 00:00:00 2001 From: 36000 Date: Thu, 18 Aug 2022 10:43:30 -0700 Subject: [PATCH 02/13] try running slr in test suite --- AFQ/tests/test_api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index 3d776e579..60f63837d 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -500,7 +500,6 @@ def test_API_type_checking(): del myafq -@pytest.mark.nightly_slr def test_AFQ_slr(): """ Test if API can run using slr map From d8fc48894d94368e6d53f15b5ab4ddb20779b7dd Mon Sep 17 00:00:00 2001 From: 36000 Date: Thu, 18 Aug 2022 12:25:25 -0700 Subject: [PATCH 03/13] maybe this will help --- AFQ/tests/test_api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index 60f63837d..e3c8766da 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -504,7 +504,9 @@ def test_AFQ_slr(): """ Test if API can run using slr map """ - np.random.seed(2022) + seed = 43 + np.random.seed(seed) + _, bids_path, sub_path = get_temp_hardi() bd = BundleDict(["CST_L"]) @@ -527,7 +529,7 @@ def test_AFQ_slr(): tracking_params = dict( odf_model="csd", seed_mask=ImageFile(path=seed_mask_path), - n_seeds=1000, + n_seeds=5000, random_seeds=True, rng_seed=seed) From 7f0dbb07495929be2ebce78e43976072c8297843 Mon Sep 17 00:00:00 2001 From: 36000 Date: Fri, 19 Aug 2022 09:39:01 -0700 Subject: [PATCH 04/13] works locally, see if it works on circleCI --- AFQ/tests/test_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index e3c8766da..d917d2843 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -504,7 +504,7 @@ def test_AFQ_slr(): """ Test if API can run using slr map """ - seed = 43 + seed = 44 np.random.seed(seed) _, bids_path, sub_path = get_temp_hardi() @@ -529,7 +529,7 @@ def test_AFQ_slr(): tracking_params = dict( odf_model="csd", seed_mask=ImageFile(path=seed_mask_path), - n_seeds=5000, + n_seeds=10000, random_seeds=True, rng_seed=seed) From 117a404615345b03696a51cffd295fd1b393bacf Mon Sep 17 00:00:00 2001 From: 36000 Date: Fri, 11 Nov 2022 09:17:31 -0800 Subject: [PATCH 05/13] force python seed --- AFQ/tests/test_api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index d917d2843..df767a548 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -4,6 +4,7 @@ import shutil import subprocess import gc +import random import toml @@ -506,6 +507,7 @@ def test_AFQ_slr(): """ seed = 44 np.random.seed(seed) + random.seed(seed) _, bids_path, sub_path = get_temp_hardi() bd = BundleDict(["CST_L"]) From 0e33f81a05d72c4fe29c08fe97398467e1985824 Mon Sep 17 00:00:00 2001 From: 36000 Date: Fri, 11 Nov 2022 09:22:09 -0800 Subject: [PATCH 06/13] try this seed --- AFQ/tests/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index df767a548..2b58f8708 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -505,7 +505,7 @@ def test_AFQ_slr(): """ Test if API can run using slr map """ - seed = 44 + seed = 1234 np.random.seed(seed) random.seed(seed) From e4408642163b919ab1af2c947f07dd1a4b076564 Mon Sep 17 00:00:00 2001 From: 36000 Date: Fri, 11 Nov 2022 09:25:56 -0800 Subject: [PATCH 07/13] remove slr, push to normal tests --- .github/workflows/nightly_slr.yml | 32 ------------------------------- AFQ/tests/test_api.py | 1 - 2 files changed, 33 deletions(-) delete mode 100644 .github/workflows/nightly_slr.yml diff --git a/.github/workflows/nightly_slr.yml b/.github/workflows/nightly_slr.yml deleted file mode 100644 index 23158040c..000000000 --- a/.github/workflows/nightly_slr.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Nightly test suite - -on: - schedule: - - cron: '0 12 * * *' # every day at 5 AM, PST - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - max-parallel: 4 - matrix: - python-version: [3.9, 3.8] - - steps: - - name: Checkout repo - uses: actions/checkout@v1 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - name: Install - run: | - python -m pip install --upgrade pip - pip install .[dev,fury,afqbrowser,plot] - - name: Lint - run: | - flake8 --ignore N802,N806,W503 --select W504 `find . -name \*.py | grep -v setup.py | grep -v version.py | grep -v __init__.py | grep -v /docs/` - - name: Test - run: | - cd && mkdir for_test && cd for_test && pytest --pyargs AFQ --cov-report term-missing --cov=AFQ -m "nightly_slr" --durations=0 diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index 2b58f8708..572440271 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -412,7 +412,6 @@ def test_AFQ_anisotropic(): 'sub-01_ses-01_dwi_model-CSD_desc-APM_dwi.nii.gz')) -@pytest.mark.nightly_slr def test_API_type_checking(): _, bids_path, _ = get_temp_hardi() np.random.seed(2022) From c62556732f0b2ac3937de2c61ea30e58e209e60e Mon Sep 17 00:00:00 2001 From: 36000 Date: Fri, 9 Dec 2022 13:47:55 -0800 Subject: [PATCH 08/13] a little more seeds here wont hurt --- AFQ/tests/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index 572440271..e247a5f9f 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -484,7 +484,7 @@ def test_API_type_checking(): affine_kwargs={ "level_iters": [1, 1], "pipeline": ["center_of_mass"]}), - tracking_params={"n_seeds": 1, "random_seeds": True}, + tracking_params={"n_seeds": 10, "random_seeds": True}, bundle_info=["ARC_L", "ARC_R"]) myafq.export("bundles") del myafq From 8346b47b7f8c94fdd22f0bb95cdd82a0aaf3e49e Mon Sep 17 00:00:00 2001 From: 36000 Date: Mon, 12 Dec 2022 13:43:54 -0800 Subject: [PATCH 09/13] increase waypoint tolerance --- AFQ/tests/test_api.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index e247a5f9f..b369cb96e 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -11,6 +11,7 @@ import numpy as np import numpy.testing as npt import pytest +from skimage.morphology import binary_dilation import pandas as pd from pandas.testing import assert_series_equal @@ -22,8 +23,8 @@ import dipy.tracking.streamline as dts from dipy.data import get_fnames from dipy.testing.decorators import xvfb_it -from AFQ.api.bundle_dict import BundleDict +from AFQ.api.bundle_dict import BundleDict from AFQ.api.group import GroupAFQ from AFQ.api.participant import ParticipantAFQ import AFQ.data.fetch as afd @@ -504,8 +505,7 @@ def test_AFQ_slr(): """ Test if API can run using slr map """ - seed = 1234 - np.random.seed(seed) + seed = 2022 random.seed(seed) _, bids_path, sub_path = get_temp_hardi() @@ -521,18 +521,18 @@ def test_AFQ_slr(): dwi_img = nib.Nifti1Image( dwi_img.get_fdata()[..., 0], affine=dwi_img.affine) - nib.save( - afd.read_resample_roi( + + rough_seed_mask = afd.read_resample_roi( bd["CST_L"]["include"][0], - dwi_img), + dwi_img) + nib.save( + rough_seed_mask, seed_mask_path) tracking_params = dict( odf_model="csd", seed_mask=ImageFile(path=seed_mask_path), - n_seeds=10000, - random_seeds=True, - rng_seed=seed) + n_seeds=3) myafq = GroupAFQ( bids_path=bids_path, @@ -541,7 +541,7 @@ def test_AFQ_slr(): reg_template_spec='hcp_atlas', tracking_params=tracking_params, segmentation_params={ - "dist_to_waypoint": 10, + "dist_to_waypoint": 50, # because of rough seed mask "filter_by_endpoints": False}, bundle_info=bd, mapping_definition=SlrMap(slr_kwargs={ From 85f4919cf8b96283b37edf7c5f284ca6b7c413f6 Mon Sep 17 00:00:00 2001 From: 36000 Date: Mon, 12 Dec 2022 14:22:00 -0800 Subject: [PATCH 10/13] try a different seed --- AFQ/tests/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index b369cb96e..98085822b 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -505,7 +505,7 @@ def test_AFQ_slr(): """ Test if API can run using slr map """ - seed = 2022 + seed = 2023 random.seed(seed) _, bids_path, sub_path = get_temp_hardi() From dc242533132af367781e65a521faf13552d70a6e Mon Sep 17 00:00:00 2001 From: 36000 Date: Mon, 12 Dec 2022 15:30:16 -0800 Subject: [PATCH 11/13] use existing tractography for SLR --- AFQ/tests/test_api.py | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index 98085822b..b8afe0b16 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -505,43 +505,26 @@ def test_AFQ_slr(): """ Test if API can run using slr map """ - seed = 2023 + seed = 2022 random.seed(seed) + afd.read_stanford_hardi_tractography() + _, bids_path, sub_path = get_temp_hardi() bd = BundleDict(["CST_L"]) - # create rough seed mask registered to subject space - # this should save time in tractography - # cannot be mapped to subject space, because mapping - # requires the tractography - # this does not matter as this is just a smoke test - seed_mask_path = f"{bids_path}/my_rough_seed_mask.nii.gz" - dwi_img = nib.load(f"{sub_path}/sub-01_ses-01_dwi.nii.gz") - dwi_img = nib.Nifti1Image( - dwi_img.get_fdata()[..., 0], - affine=dwi_img.affine) - - rough_seed_mask = afd.read_resample_roi( - bd["CST_L"]["include"][0], - dwi_img) - nib.save( - rough_seed_mask, - seed_mask_path) - - tracking_params = dict( - odf_model="csd", - seed_mask=ImageFile(path=seed_mask_path), - n_seeds=3) - myafq = GroupAFQ( bids_path=bids_path, preproc_pipeline='vistasoft', reg_subject_spec='subject_sls', reg_template_spec='hcp_atlas', - tracking_params=tracking_params, + import_tract=op.join( + op.expanduser('~'), + 'AFQ_data', + 'stanford_hardi_tractography', + 'full_segmented_cleaned_tractography.trk'), segmentation_params={ - "dist_to_waypoint": 50, # because of rough seed mask + "dist_to_waypoint": 10, "filter_by_endpoints": False}, bundle_info=bd, mapping_definition=SlrMap(slr_kwargs={ From 70794bf1a2650942c669d00ac6dba07441551b18 Mon Sep 17 00:00:00 2001 From: 36000 Date: Mon, 12 Dec 2022 15:32:48 -0800 Subject: [PATCH 12/13] cleanup --- AFQ/tests/test_api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index b8afe0b16..3486200e6 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -11,7 +11,6 @@ import numpy as np import numpy.testing as npt import pytest -from skimage.morphology import binary_dilation import pandas as pd from pandas.testing import assert_series_equal From 61ac04e9bfe4c66bc6257b73354e4ffa4a4a073a Mon Sep 17 00:00:00 2001 From: 36000 Date: Thu, 22 Dec 2022 09:04:01 -0800 Subject: [PATCH 13/13] fix and speed up test_API_type_checking --- AFQ/tests/test_api.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index 3486200e6..dff3049e5 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -31,7 +31,7 @@ import AFQ.utils.bin as afb from AFQ.definitions.image import RoiImage,\ PFTImage, ImageFile -from AFQ.definitions.mapping import SynMap, AffMap, SlrMap +from AFQ.definitions.mapping import SynMap, AffMap, SlrMap, IdentityMap from AFQ.definitions.image import TemplateImage, ImageFile, LabelledImageFile @@ -480,11 +480,14 @@ def test_API_type_checking(): myafq = GroupAFQ( bids_path, preproc_pipeline='vistasoft', - mapping_definition=AffMap( - affine_kwargs={ - "level_iters": [1, 1], - "pipeline": ["center_of_mass"]}), - tracking_params={"n_seeds": 10, "random_seeds": True}, + mapping_definition=IdentityMap(), + tracking_params={ + "n_seeds": 1, + "random_seeds": True, + "directions": "prob", + "odf_model": "CSD"}, + csd_sh_order=2, # reduce CSD fit time + csd_response=((1, 1, 1), 1), bundle_info=["ARC_L", "ARC_R"]) myafq.export("bundles") del myafq