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

Alter tractogram (trim, cut, replace, subsample, transform) #992

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

frheault
Copy link
Member

@frheault frheault commented May 16, 2024

Quick description

New script to simulate alteration of tractogram (should be used for bundle, so maybe I will rename)
The operation are describe in the docstring of the script:

This script is used to alter a bundle to reach specific minimum dice
coefficient from the original bundle. The script will subsample, trim, cut,
replace or transform the streamlines until the minimum dice is reached.
(cannot be combined in one run, use the script multiple times if needed)

All operation use a dichotomic search to find the parameter that gets as close
as possible to the specified minimum dice coefficient (with an epsilon for
convergence).

The subsample operation will remove streamlines until the minimum dice is
reached. This affect the whole bundle.

The trim operation will used the lowest density voxels (starting at 1) to
remove points from the streamlines until the minimum dice is reached.
This typically affect the edge of the bundle.

The cut operation will remove points from the start (or end) streamlines until
the minimum dice is reached. This affect one end of the bundle.

The replace operation will upsample the tractogram (generate new streamlines
with noise) and then subsample the tractogram. This effectively replace
streamlines with similar ones until the minimum dice is reached.
This affect the whole bundle.

The transform operation will apply random transformations to the streamlines
until the minimum dice is reached. This affect the whole bundle.

...

Type of change

Check the relevant options.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Provide data, screenshots, command line to test (if relevant)

...

Checklist

  • My code follows the style guidelines of this project (run autopep8)
  • I added relevant citations to scripts, modules and functions docstrings and descriptions
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I moved all functions from the script file (except the argparser and main) to scilpy modules
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@pep8speaks
Copy link

pep8speaks commented May 16, 2024

Hello @frheault, Thank you for updating !

Line 990:80: E501 line too long (80 > 79 characters)
Line 1003:80: E501 line too long (81 > 79 characters)
Line 1038:80: E501 line too long (80 > 79 characters)
Line 1060:80: E501 line too long (80 > 79 characters)
Line 1142:80: E501 line too long (80 > 79 characters)
Line 1237:80: E501 line too long (80 > 79 characters)
Line 1249:80: E501 line too long (80 > 79 characters)

Line 49:80: E501 line too long (83 > 79 characters)
Line 50:80: E501 line too long (81 > 79 characters)
Line 51:80: E501 line too long (83 > 79 characters)

Comment last updated at 2024-06-18 14:03:36 UTC

Copy link

codecov bot commented May 16, 2024

Codecov Report

Attention: Patch coverage is 17.05426% with 214 lines in your changes missing coverage. Please review.

Project coverage is 67.63%. Comparing base (3191a0b) to head (9eb4594).
Report is 25 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #992      +/-   ##
==========================================
- Coverage   68.14%   67.63%   -0.51%     
==========================================
  Files         419      420       +1     
  Lines       21369    21662     +293     
  Branches     3216     3243      +27     
==========================================
+ Hits        14561    14651      +90     
- Misses       5533     5746     +213     
+ Partials     1275     1265      -10     
Components Coverage Δ
Scripts 69.15% <71.98%> (+0.01%) ⬆️
Library 65.48% <43.57%> (-1.19%) ⬇️

Copy link
Contributor

@EmmaRenauld EmmaRenauld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 1 of comments. I didn't really read the code yet, only the descriptions.

Pep8 also needs to be addressed.

input tractogram.
"""
# Import in function to avoid circular import error
from scilpy.tractanalysis.reproducibility_measures import compute_dice_voxel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that our management is not perfect yet.

tractanalysis.reproducibility_measures.compute_dice_voxel seems to be usable with any map. So it is not necessarily a tractanalysis method. Maybe it could go in image.volume_operations (or in volume_math if we also want to offer this option in scil_volume_math). Or in stats.something but I don't like it as much.

#!/usr/bin/env python
# -*- coding: utf-8 -*-


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would indeed rename. But not just bundle: the goal of this script is not simply to alter. I would imagine that a scil_tractogram_alter.py would ask user how to alter. Here it decides alone (if no option is provided). Can we put a longer, but more significative name? scil_bundle_alter_to_dice?

Also, I see that in your new methods (ex, subsample_streamlines_alter), you have an option baseline_sft=None that is never used in your script. Can you add an option --reference_bundle in your script?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what you mean by "Here it decides alone (if no option is provided)."

I agree that the name scil_bundle_alter.py does not mean much
Here are a few more suggestions:

  • scil_bundle_alter_preserve_overlap.py
  • scil_bundle_alter_optimize_overlap.py
  • scil_bundle_alter_to_target_dice.py

(alter could be replaced by adjust, vary, adapt, modify, but I like alter because of the definition: change or cause to change in character or composition, typically in a comparatively small but significant way)

baseline_sft: It is used in another function (replace)


"""
This script is used to alter a bundle to reach specific minimum dice
coefficient from the original bundle. The script will subsample, trim, cut,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a little while to understand the goal of the script. Maybe something like this for the first sentence?

This script is used to alter a bundle while keeping it similar enough to the original version (keeping the dice coefficient above a given threshold).

This script is used to alter a bundle to reach specific minimum dice
coefficient from the original bundle. The script will subsample, trim, cut,
replace or transform the streamlines until the minimum dice is reached.
(cannot be combined in one run, use the script multiple times if needed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not clear for me. What cannot be combined? Do you mean Cannot be used on multiple bundles in one run? Or the various operations choices cannot be combined?

Copy link
Member Author

@frheault frheault Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

various operations choices cannot be combined

replace or transform the streamlines until the minimum dice is reached.
(cannot be combined in one run, use the script multiple times if needed)

All operation use a dichotomic search to find the parameter that gets as close
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

operations.

"""
Shuffle the orientation of the streamlines. The streamlines are not
reversed, only the orientation of the points within the streamlines is
shuffled.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I understand the difference.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes its unclear, it is not a blanket reverse all streamlines, it is a shuffle head/tail of random streamlines

def replace_streamlines_alter(sft, min_dice=0.90, epsilon=0.01):
"""
Replace streamlines based on a dice similarity metric.
The function will upsamples the streamlines (with parallel transport),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upsample



def trim_streamlines_alter(sft, min_dice=0.90, epsilon=0.01):
# Import in function to avoid circular import error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring

This affect the whole bundle.

The transform operation will apply random transformations to the streamlines
until the minimum dice is reached. This affect the whole bundle.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the description of the method, you only mention rotations. Here, you say any transformation. Can you be more precise?

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def test_help_option(script_runner):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More tests required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants