Skip to content

Commit

Permalink
Merge pull request #937 from 36000/force_seed
Browse files Browse the repository at this point in the history
[FIX] finally finish this SLR PR
  • Loading branch information
arokem authored Dec 28, 2022
2 parents 19fe6cd + 61ac04e commit e1ebde6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 67 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/nightly_slr.yml

This file was deleted.

57 changes: 22 additions & 35 deletions AFQ/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import subprocess
import gc
import random

import toml

Expand All @@ -21,16 +22,16 @@
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
import AFQ.utils.streamlines as aus
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


Expand Down Expand Up @@ -411,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)
Expand Down Expand Up @@ -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": 1, "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
Expand All @@ -500,50 +503,34 @@ def test_API_type_checking():
del myafq


@pytest.mark.nightly_slr
def test_AFQ_slr():
"""
Test if API can run using slr map
"""
np.random.seed(2022)
_, bids_path, sub_path = get_temp_hardi()
bd = BundleDict(["CST_L"])
seed = 2022
random.seed(seed)

# 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)
nib.save(
afd.read_resample_roi(
bd["CST_L"]["include"][0],
dwi_img),
seed_mask_path)
afd.read_stanford_hardi_tractography()

tracking_params = dict(
odf_model="csd",
seed_mask=ImageFile(path=seed_mask_path),
n_seeds=1000,
random_seeds=True,
rng_seed=42)
_, bids_path, sub_path = get_temp_hardi()
bd = BundleDict(["CST_L"])

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": 10,
"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"])
Expand Down

0 comments on commit e1ebde6

Please sign in to comment.