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] Add mrds scripts part 3 #1046

Merged
merged 14 commits into from
Nov 13, 2024

Conversation

arnaudbore
Copy link
Contributor

@arnaudbore arnaudbore commented Nov 4, 2024

Quick description

Script to get MRDS metrics along a bundle - fixel based metric.

...

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 Nov 4, 2024

Hello @arnaudbore, Thank you for updating !

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

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

Comment last updated at 2024-11-12 16:11:54 UTC

@arnaudbore arnaudbore changed the title [ENH] Add mrds scripts part 2 [ENH] Add mrds scripts part 3 Nov 4, 2024
Copy link

codecov bot commented Nov 4, 2024

Codecov Report

Attention: Patch coverage is 28.86598% with 69 lines in your changes missing coverage. Please review.

Project coverage is 68.77%. Comparing base (546f1a9) to head (bf9140c).
Report is 27 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1046      +/-   ##
==========================================
- Coverage   68.89%   68.77%   -0.13%     
==========================================
  Files         434      436       +2     
  Lines       22646    22754     +108     
  Branches     3078     3094      +16     
==========================================
+ Hits        15603    15649      +46     
- Misses       5727     5793      +66     
+ Partials     1316     1312       -4     
Components Coverage Δ
Scripts 69.59% <47.05%> (-0.03%) ⬇️
Library 67.62% <8.69%> (-0.28%) ⬇️

scilpy/tractanalysis/mrds_along_streamlines.py Outdated Show resolved Hide resolved

all_metric = mrds_sum[0]
for curr_metric in mrds_sum[1:]:
all_metric += curr_metric
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. Isn't it just all_metric= np.sum(curr_metric, axis=0)?

But it's only used for non-zero. Is there a possibility that the metrics will cancel each-other?
Something like that could be safer?:

non_zeros = np.sum(np.non_zeros(curr_metric), axis=0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just add a absolute value so it does not cancel each-other, also this method mimics afd_along_streamlines.py.

from scilpy.tractanalysis.grid_intersections import grid_intersections


def mrds_metrics_along_streamlines(sft, mrds_pdds,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that this method is not mrds-related. It's just dividing data.

It could be, in the main script:

 mrds_sum, weights = \
        mrds_metric_sums_along_streamlines(sft, mrds_pdds,
                                           metrics, max_theta,
                                           length_weighting)
weighte_mrds = weight_values(mrds_sum, weights)

Where weight values is function that divides by the weight where non-zero, somewhere in volume tools or something.

StatefulTractogram containing the streamlines needed.
mrds_pdds : ndarray (X, Y, Z, 3*N_TENSORS)
MRDS principal diffusion directions (PDDs) of the tensors
metrics : list of ndarray (X, Y, Z, N_TENSORS)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think metrics should be metric

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I aggree it's "a" list but reading it I feel like metrics make sense here.

weight_map = np.zeros(metrics[0].shape[:-1])
min_cos_theta = np.cos(np.radians(max_theta))

all_crossed_indices = grid_intersections(sft.streamlines)
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 pretty sure that our "uncompress" method should be used somewhere here. @frheault probably knows this better than me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe, this version is copy paste (kinda) of afd_along_streamlinespy

scripts/scil_bundle_mean_fixel_mrds_metric.py Show resolved Hide resolved
scripts/scil_bundle_mean_fixel_mrds_metric.py Outdated Show resolved Hide resolved
scripts/scil_bundle_mean_fixel_mrds_metric.py Show resolved Hide resolved
@arnaudbore arnaudbore merged commit 307280b into scilus:master Nov 13, 2024
2 checks passed
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.

4 participants