Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Make the cleaning easier to interact with #1100

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion AFQ/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def __init__(self,
presegment_kwargs={},
filter_by_endpoints=True,
dist_to_atlas=4,
save_intermediates=None):
save_intermediates=None,
cleaning_params={}):
"""
Segment streamlines into bundles.

Expand Down Expand Up @@ -260,6 +261,11 @@ def __init__(self,
save_intermediates : str, optional
The full path to a folder into which intermediate products
are saved. Default: None, means no saving of intermediates.
cleaning_params : dict, optional
Cleaning params to pass to seg.clean_bundle. This will
override the default parameters of that method. However, this
can be overriden by setting the cleaning parameters in the
bundle_dict. Default: {}.

References
----------
Expand Down Expand Up @@ -297,6 +303,7 @@ def __init__(self,
self.filter_by_endpoints = filter_by_endpoints
self.dist_to_atlas = dist_to_atlas
self.parallel_segmentation = parallel_segmentation
self.cleaning_params = cleaning_params

if (save_intermediates is not None) and \
(not op.exists(save_intermediates)):
Expand Down Expand Up @@ -774,6 +781,9 @@ def segment_afq(self, tg=None):
if b_sls:
accept_idx = b_sls.initiate_selection("Mahalanobis")
clean_params = bundle_def.get("mahal", {})
clean_params = {
**self.cleaning_params,
**clean_params}
clean_params["return_idx"] = True
cut = self.clip_edges or ("bundlesection" in bundle_def)
_, cleaned_idx = clean_bundle(
Expand Down
17 changes: 12 additions & 5 deletions AFQ/tasks/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,20 @@ def segment(data_imap, mapping_imap,
else:
tgram, meta = seg_sft.get_sft_and_sidecar()

segmentation_params_out = {
arg_name: value if isinstance(value, (int, float, bool, str)) or (
value is None) else str(value)
for arg_name, value in segmentation_params.items()}
seg_params_out = {}
for arg_name, value in segmentation_params.items():
if isinstance(value, (int, float, bool, str)):
seg_params_out[arg_name] = value
elif isinstance(value, (list, tuple)):
seg_params_out[arg_name] = [str(v) for v in value]
elif isinstance(value, dict):
for k, v in value.items():
seg_params_out[k] = str(v)
else:
seg_params_out[arg_name] = str(value)

meta["source"] = streamlines
meta["Recognition Parameters"] = segmentation_params_out
meta["Recognition Parameters"] = seg_params_out
meta["Timing"] = time() - start_time
return tgram, meta

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ dev =
sphinx-autoapi
rapidfuzz
xvfbwrapper==0.2.9
moto>=3.0.0
moto>=3.0.0,<5.0.0
pip-conflict-checker>=0.6.0
pydata-sphinx-theme
sphinx-design
Expand Down
Loading