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

New upsampling method (PTT) for tractogram #818

Merged
merged 35 commits into from
Mar 20, 2024

Conversation

frheault
Copy link
Member

@frheault frheault commented Nov 28, 2023

Quick description

The previous version was simply adding zigzag to streamlines and was barely useful (even for data augmentation it was kind of weird). Now this version uses Parallel Transport to create new streamlines around the previous one using their real geometry. This is helpful for model creation, figures and data augmentation.

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)

image
(The input for that image for single centroids from each bundle)

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

@frheault frheault requested a review from AntoineTheb November 28, 2023 20:15
@pep8speaks
Copy link

pep8speaks commented Nov 28, 2023

Hello @frheault, Thank you for updating !

Line 396:80: E501 line too long (80 > 79 characters)

Line 21:80: E501 line too long (81 > 79 characters)

Line 65:80: E501 line too long (84 > 79 characters)
Line 67:80: E501 line too long (82 > 79 characters)
Line 68:80: E501 line too long (81 > 79 characters)
Line 73:80: E501 line too long (80 > 79 characters)
Line 74:80: E501 line too long (83 > 79 characters)
Line 80:80: E501 line too long (81 > 79 characters)
Line 81:80: E501 line too long (81 > 79 characters)

Comment last updated at 2024-03-19 17:59:20 UTC

@arnaudbore arnaudbore self-requested a review November 28, 2023 20:54
@arnaudbore
Copy link
Contributor

Build passed ! Good Job 🍻 !

Copy link
Contributor

@AntoineTheb AntoineTheb left a comment

Choose a reason for hiding this comment

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

Some minor comments, otherwise LGTM

scilpy/tractograms/tractogram_operations.py Outdated Show resolved Hide resolved
scilpy/utils/spatial_ops.py Outdated Show resolved Hide resolved
scilpy/utils/spatial_ops.py Outdated Show resolved Hide resolved
@AntoineTheb AntoineTheb self-requested a review November 30, 2023 14:59
@arnaudbore
Copy link
Contributor

Build passed ! Good Job 🍻 !

Copy link
Contributor

@AntoineTheb AntoineTheb left a comment

Choose a reason for hiding this comment

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

Small possible but not required improvement. Otherwise LGTM. Of course, pep8 problems need to be fixed and unit tests would be nice, but can be added later.

scilpy/tractograms/tractogram_operations.py Outdated Show resolved Hide resolved
@arnaudbore
Copy link
Contributor

Build passed ! Good Job 🍻 !

@arnaudbore
Copy link
Contributor

Build passed ! Good Job 🍻 !

@arnaudbore
Copy link
Contributor

@arnaudbore
Copy link
Contributor

Build passed ! Good Job 🍻 !

Copy link
Contributor

@AntoineTheb AntoineTheb left a comment

Choose a reason for hiding this comment

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

Last round of review. Couple of comments, only the args one is critical.

scripts/scil_tractogram_resample.py Outdated Show resolved Hide resolved
scripts/scil_tractogram_resample.py Outdated Show resolved Hide resolved
scilpy/utils/spatial_ops.py Outdated Show resolved Hide resolved
@arnaudbore
Copy link
Contributor

Build passed ! Good Job 🍻 !

@AntoineTheb
Copy link
Contributor

@frheault do you need help closing this PR ? It has been open for a while and I would maybe like to use this feature in some work.

@frheault
Copy link
Member Author

I just added tests so maybe just check that part? Then it would be ready to merge.

I think the tests are passing but they restarted and got stuck.

@arnaudbore
Copy link
Contributor

Build passed ! Good Job 🍻 !

@AntoineTheb
Copy link
Contributor

@frheault Tests look good to me ! Only thing remaining are pep8 errors then GTG @arnaudbore imo

@arnaudbore
Copy link
Contributor

Build passed ! Good Job 🍻 !

import numpy as np


def parallel_transport_streamline(streamline, nb_streamlines, radius, rng=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

After discussion with Arnaud, we would put this in tractogram.streamline_operations.

Can you also move the r(vec, theta) method into utils.util, and name it something like def rotation_around_vector_matrix?

Copy link
Contributor

@arnaudbore arnaudbore left a comment

Choose a reason for hiding this comment

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

A couple of comments but we are really close !

scilpy/tractograms/tractogram_operations.py Show resolved Hide resolved
scilpy/utils/spatial_ops.py Outdated Show resolved Hide resolved
scilpy/utils/spatial_ops.py Outdated Show resolved Hide resolved
scilpy/tractograms/streamline_operations.py Outdated Show resolved Hide resolved
scilpy/tractograms/streamline_operations.py Show resolved Hide resolved
scilpy/tractograms/tests/test_streamline_operations.py Outdated Show resolved Hide resolved
Copy link
Contributor

@arnaudbore arnaudbore left a comment

Choose a reason for hiding this comment

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

Small comment - almost GTG

scilpy/tractanalysis/reproducibility_measures.py Outdated Show resolved Hide resolved
scilpy/tractograms/tractogram_operations.py Show resolved Hide resolved
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.

Thanks! Much clearer than the first time I read it!


Parameters
----------
tractogram: TrkFile, TckFile, ArraySequence, list
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand, this method would work too if tractogram is a StatefulTractogram, no?

scilpy/tractograms/tractogram_operations.py Outdated Show resolved Hide resolved
scilpy/tractograms/tractogram_operations.py Show resolved Hide resolved
scripts/scil_tractogram_resample.py Outdated Show resolved Hide resolved
'points to generate new ones [%(default)s].')
upsampling_group.add_argument('--tube_radius', type=float, default=1,
help='Maximum distance to generate streamlines '
' around the original ones [%(default)s].')
Copy link
Contributor

Choose a reason for hiding this comment

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

two spaces between streamlines and around.

help='Sigma for smoothing. Use the value of '
'surrounding X,Y,Z points on the '
'streamline to blur the streamlines.\n'
'A good sigma choice would around 5.')
Copy link
Contributor

Choose a reason for hiding this comment

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

would be

(args.streamline_wise_std is not None and
args.streamline_wise_std <= 0):
parser.error('STD needs to be above 0.')
if (args.point_wise_std is not None and args.point_wise_std <= 0):
Copy link
Contributor

Choose a reason for hiding this comment

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

parenthesis not needed

parser.error('STD needs to be above 0.')
if (args.point_wise_std is not None and args.point_wise_std <= 0):
parser.error('argument --point_wise_std: must be > 0')
if (args.tube_radius is not None and args.tube_radius <= 0):
Copy link
Contributor

Choose a reason for hiding this comment

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

idem

@arnaudbore arnaudbore merged commit c584c7e into scilus:master Mar 20, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants