Skip to content

Commit

Permalink
Merge pull request #834 from 36000/nightly_fixes_1
Browse files Browse the repository at this point in the history
[FIX] update nightly tests and fix kwargs
  • Loading branch information
36000 authored May 18, 2022
2 parents 6cbd6e3 + c02969a commit 804e894
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
12 changes: 8 additions & 4 deletions AFQ/definitions/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ def image_getter(dwi, bids_info):
dwi_img.get_fdata(),
image_affine,
dwi_img.affine)
return nib.Nifti1Image(image_data, dwi_img.affine), meta
return nib.Nifti1Image(
image_data.astype(np.float32),
dwi_img.affine), meta
return image_getter

def get_image_direct(self, dwi, bids_info, b0_file, data_imap=None):
Expand Down Expand Up @@ -200,7 +202,7 @@ def get_image_getter(self, task_name):
def image_getter(dwi):
dwi_img = nib.load(dwi)
return nib.Nifti1Image(
np.ones(dwi_img.get_fdata()[..., 0].shape),
np.ones(dwi_img.get_fdata()[..., 0].shape, dtype=np.float32),
dwi_img.affine), dict(source="Entire Volume")
return image_getter

Expand Down Expand Up @@ -328,7 +330,8 @@ def image_getter_helper(b0):
mean_b0 = mean_b0_img.get_fdata()
_, image_data = median_otsu(mean_b0, **self.median_otsu_kwargs)
return nib.Nifti1Image(
image_data.astype(int), mean_b0_img.affine), dict(
image_data.astype(np.float32),
mean_b0_img.affine), dict(
source=b0,
technique="median_otsu applied to b0",
median_otsu_kwargs=self.median_otsu_kwargs)
Expand Down Expand Up @@ -645,7 +648,8 @@ def _image_getter_helper(mapping, reg_template):
scalar_data = mapping.transform_inverse(
img_data, interpolation='nearest')
return nib.Nifti1Image(
scalar_data, reg_template.affine), dict(source=self.path)
scalar_data.astype(np.float32),
reg_template.affine), dict(source=self.path)

if task_name == "mapping":
def image_getter(mapping, data_imap):
Expand Down
4 changes: 2 additions & 2 deletions AFQ/tasks/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def brain_mask(base_fname, dwi, b0,
bids_info["subject"],
bids_info["session"])
return brain_mask_definition.get_image_direct(
base_fname, bids_info, b0, data_imap=None)
dwi, bids_info, b0, data_imap=None)


@pimms.calc("bundle_dict", "reg_template")
Expand Down Expand Up @@ -586,7 +586,7 @@ def roi_scalar_to_info(roi):
bids_info["subject"],
bids_info["session"])
roi_img, _ = roi.get_image_direct(
base_fname, bids_info, b0, data_imap=None)
dwi, bids_info, b0, data_imap=None)
return roi_img
for b_name, b_info in bundle_dict._dict.items():
if "space" in b_info and b_info["space"] == "subject":
Expand Down
2 changes: 1 addition & 1 deletion AFQ/tasks/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _has_args(func):
header += f"{name}='{default}', "
else:
header += f"{name}={default}, "
content += f"{name}, "
content += f"{name}={name}, "

header = header[:-2]
content = content[:-2]
Expand Down
2 changes: 1 addition & 1 deletion AFQ/tasks/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def get_reg_subject(data_imap, bids_info, base_fname, dwi,
bids_info["subject"],
bids_info["session"])
img, _ = reg_subject_spec.get_image_direct(
base_fname, bids_info, data_imap["b0"],
dwi, bids_info, data_imap["b0"],
data_imap=data_imap)
else:
if reg_subject_spec in filename_dict:
Expand Down
22 changes: 11 additions & 11 deletions AFQ/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,15 @@ def test_AFQ_custom_tract():
'subsampled_tractography.trk'
)
)
my_afq = GroupAFQ(
myafq = GroupAFQ(
bids_path,
preproc_pipeline='vistasoft',
bundle_info=bundle_names,
import_tract={
"suffix": "tractography",
"scope": "vistasoft"
})
my_afq.export_streamlines()
myafq.export("streamlines")


@pytest.mark.nightly_basic
Expand Down Expand Up @@ -315,12 +315,12 @@ def test_AFQ_init():
match="No subjects specified in `participant_labels` "
+ " found in BIDS derivatives folders."
+ " See above warnings."):
my_afq = GroupAFQ(
myafq = GroupAFQ(
bids_path,
preproc_pipeline="synthetic",
participant_labels=participant_labels)
else:
my_afq = GroupAFQ(
myafq = GroupAFQ(
bids_path,
preproc_pipeline="synthetic",
participant_labels=participant_labels)
Expand All @@ -329,7 +329,7 @@ def test_AFQ_init():
sub = f"0{subject+1}"
if n_subjects == n_sessions:
npt.assert_equal(
len(my_afq.wf_dict[sub][sub]),
len(myafq.wf_dict[sub][sub]),
27)
else:
for session in range(n_sessions):
Expand All @@ -338,7 +338,7 @@ def test_AFQ_init():
else:
sess = f"0{session+1}"
npt.assert_equal(
len(my_afq.wf_dict[sub][sess]),
len(myafq.wf_dict[sub][sess]),
27)


Expand Down Expand Up @@ -531,7 +531,7 @@ def test_AFQ_pft():
ImageFile(suffix="CSFprobseg"))

with nbtmp.InTemporaryDirectory() as t_output_dir:
my_afq = GroupAFQ(
myafq = GroupAFQ(
bids_path,
preproc_pipeline='vistasoft',
bundle_info=bundle_names,
Expand All @@ -541,7 +541,7 @@ def test_AFQ_pft():
"stop_threshold": "CMC",
"tracker": "pft"
})
my_afq.export_streamlines()
myafq.export("streamlines")


@pytest.mark.nightly_custom
Expand All @@ -558,22 +558,22 @@ def test_AFQ_custom_subject_reg():
b0_file = GroupAFQ(
bids_path,
preproc_pipeline='vistasoft',
bundle_info=bundle_info).b0["01"]
bundle_info=bundle_info).export("b0")["01"]

# make a different temporary directly to test this custom file in
_, bids_path, sub_path = get_temp_hardi()

os.rename(b0_file, op.join(sub_path, "sub-01_ses-01_customb0.nii.gz"))

my_afq = GroupAFQ(
myafq = GroupAFQ(
bids_path,
preproc_pipeline='vistasoft',
bundle_info=bundle_info,
reg_template_spec="mni_T2",
reg_subject_spec=ImageFile(
suffix="customb0",
filters={"scope": "vistasoft"}))
my_afq.export_rois()
myafq.export("rois")


# Requires large download
Expand Down
5 changes: 2 additions & 3 deletions bin/pyAFQ
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ def parse_cli(arg_dict):
cli_parser.add_argument(
dest='config',
action="store",
help=(
"Path to config file or folder. ",
"For example, /path/to/afq_config.toml"))
help="Path to config file or folder. "
+ "For example, /path/to/afq_config.toml")

cli_parser.add_argument(
'-g',
Expand Down

0 comments on commit 804e894

Please sign in to comment.