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

Modifications in the (bitbucket) tracking scripts - part 2 #511

Merged
merged 19 commits into from
Jan 5, 2022

Conversation

EmmaRenauld
Copy link
Contributor

@EmmaRenauld EmmaRenauld commented Oct 26, 2021

Bigger changes:

  • Merging the tracker and the propagator into propagator to avoid circular reference. Old file tracker.py (containing the two classes) becomes propagator.py
  • Adding a main script scil_compute_local_tracking_2.py (other names suggested?)
  • New "Tracker" class
    • Englobes the track() function that was previously alone in local_tracking.py. This will allow creating a child version in dwi_ml. File renamed tracker.py
    • Now the main script is: 1) Initialize the tracker. 2) Tracker.track().
    • So to be clear, this new "Tracker" is absolutely not the same as the old, it is one step above. See new diagram:

https://docs.google.com/presentation/d/1mvvBYjKZ-IVmkl1EYWBTQ_8T8H0R3_Y-/edit?usp=sharing&ouid=101323301275554058305&rtpof=true&sd=true

Smaller changes:

  • Encapsulating parts in the scil_compute_local_tracking that are common in scilpy.tracking.utils
    • Similiar to functions like add_processes_arg in scilpy.io.utils.
    • It makes the proof-reading a bit less natural but at least the args are the same in both scripts. Do we like that? Separated in a few sub-functions so I can use only some of them in dwi_ml. If we prefer, I can copy all of this back into each script.
  • Now the seedGenerator and DataVolume take receive the data instead of the img. In dwi_ml, we have the data and affine, not the image, it would be a little weird to create the image back just to re-divide it.
  • In the DataVolume: renaming methods as in the SFT nomenclature. Ex: using "voxmm" instead of "position", to clarify. Adding "origin" option (center or corner)
  • AbstractTrackingField created above the ODFTrackingField.

@pep8speaks
Copy link

pep8speaks commented Oct 26, 2021

Hello @EmmaRenauld, Thank you for updating !

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

Comment last updated at 2021-12-20 18:27:16 UTC

@EmmaRenauld EmmaRenauld marked this pull request as draft October 26, 2021 18:45
@scil-admin scil-admin requested a review from arnaudbore October 26, 2021 19:14
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@EmmaRenauld EmmaRenauld force-pushed the Merging_propagator_and_tracker branch from 21bfea0 to 3b56c38 Compare October 26, 2021 19:17
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

Copy link
Contributor

@CHrlS98 CHrlS98 left a comment

Choose a reason for hiding this comment

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

Cool! Some comments!

scilpy/tracking/propagator.py Outdated Show resolved Hide resolved

pool = multiprocessing.Pool(nbr_processes,
initializer=_init_sub_process,
np.save(data_file_name,
Copy link
Contributor

Choose a reason for hiding this comment

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

why don't we simply pass the dataset in arguments to all threads? memory limitations? The whole mmap_mode thingy is quite mysterious to 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.

Me too... I've left some #toDo for this, thinking we could deal with that later but if someone tells me what to do I can change it.

global data_file_info

# args[0] is the Tracker.
self.propagator.tracking_field.dataset.data = np.load(
Copy link
Contributor

Choose a reason for hiding this comment

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

dataset is reloaded inside every thread anyway so I don't understand why it is not passed as an argument.

scilpy/tracking/local_tracking.py Outdated Show resolved Hide resolved
scilpy/tracking/tracking_field.py Show resolved Hide resolved
scripts/scil_compute_local_tracking_2.py Outdated Show resolved Hide resolved
scripts/scil_compute_local_tracking_2.py Outdated Show resolved Hide resolved
scilpy/tracking/local_tracking.py Outdated Show resolved Hide resolved
scilpy/tracking/tracking_field.py Show resolved Hide resolved
scripts/scil_compute_local_tracking.py Outdated Show resolved Hide resolved
@scil-admin
Copy link

@EmmaRenauld EmmaRenauld force-pushed the Merging_propagator_and_tracker branch from 4cabe7c to 478373f Compare October 27, 2021 20:19
@scil-admin
Copy link

@scil-admin
Copy link

@EmmaRenauld EmmaRenauld force-pushed the Merging_propagator_and_tracker branch from 478373f to 5878dad Compare November 1, 2021 17:59
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

1 similar comment
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@EmmaRenauld EmmaRenauld force-pushed the Merging_propagator_and_tracker branch 2 times, most recently from 02a1e84 to 084947c Compare November 15, 2021 20:33
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

2 similar comments
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@EmmaRenauld EmmaRenauld force-pushed the Merging_propagator_and_tracker branch from 084947c to 8003c44 Compare November 16, 2021 00:00
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

1 similar comment
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@EmmaRenauld EmmaRenauld force-pushed the Merging_propagator_and_tracker branch from f3065be to d71ec83 Compare November 22, 2021 17:50
Copy link
Contributor

@CHrlS98 CHrlS98 left a comment

Choose a reason for hiding this comment

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

Ok, my last comments.

@@ -84,7 +85,7 @@ def is_voxel_in_bound(self, i, j, k):
return (0 <= i < self.dim[0] and 0 <= j < self.dim[1] and
0 <= k < self.dim[2])

def get_voxel_at_position(self, x, y, z):
def voxmm_to_idx(self, x, y, z, origin='center'):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the new origin argument useful? Why would we need this kind of flexibility? Could we not just set it to one or the other and take it into account when writing our tracking scripts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That dataset is not necessarily only associated with our traking script, though. It could eventually be used elsewhere, so I tought it was better to be thorough, like in the sft. But I won't object if others agree.

Copy link
Contributor

@CHrlS98 CHrlS98 Nov 22, 2021

Choose a reason for hiding this comment

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

Yes ok. But in this case we need to be extra careful when writing our tracking scripts, because the SeedGenerator always returns positions with origin corner. Should the SeedGenerator have an origin argument too then?

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 added one. For now it is not used-defined (self.origin='corner') but at least a bit more obvious?

scilpy/tracking/seed.py Show resolved Hide resolved
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@CHrlS98
Copy link
Contributor

CHrlS98 commented Nov 22, 2021

There is a subject that should still be discussed I think. This version works, but in the long term, I don't know if it's always going to fit with any model. I think that eventually, the tracking field should also be merged in the propagator.

Currently the tracking field: 1) gets the data (ex, fODF-sh), 2) returns the directions/maxima that are in a cone of angle theta. Then, the propagator sample from these directions.

But let's take the example of DTI. Sampling would be done direction on the tensor. I don't think we can really take a list of directions that are in a cone theta and sample on these directions, can we? So sampling should entirely be left to the propagator, and sampling should mean either, 'sampling from model' or 'sampling from a list of direction' based on the type of data. And it the case of DTI, theta is a stopping criterion, not a restreint on the tracking field.

Should we merge the tracking field and propagator? (Possibly in a 3rd PR)

Maybe we can wait for a specific situation where this refactoring is needed and do it if and when we need it, so that the new design really suits our requirements. Also I think deterministic tracking with DTI would work, because peaks are extracted on the whole sphere before selecting the direction inside a cone (if I'm not mistaken).

@EmmaRenauld
Copy link
Contributor Author

EmmaRenauld commented Nov 22, 2021

Maybe we can wait for a specific situation where this refactoring is needed and do it if and when we need it, so that the new design really suits our requirements. Also I think deterministic tracking with DTI would work, because peaks are extracted on the whole sphere before selecting the direction inside a cone (if I'm not mistaken).

Well I actually need now to decide if I will try to force dwi_ml to fit with all this or not. In our case, the tracking_field gets the inputs at current position and runs it through the model. The output from the model is not necessarily a list of directions. It could be, ex, a learned tensor, which is the same as my DTI example above.

But right now, I can still use scilpy's propagator. It's just that my "tracking_field.get_possible_next_directions" actually returns the tensor, and the propagator _sample_next_direction samples from that tensor, and I will add theta back later as a stopping critera.

@EmmaRenauld EmmaRenauld force-pushed the Merging_propagator_and_tracker branch from 7b44376 to 1f3dd74 Compare November 22, 2021 18:54
@CHrlS98
Copy link
Contributor

CHrlS98 commented Nov 22, 2021

Will dwi_ml be incorporated to scilpy (if so the changes can be done in its associated PR), or will the scilpy modules be imported in another project?

I think it would be better to keep the PR as is and merge it before making new changes, cause this is already a nice refactor that could benefit others right away.

Also shouldn't there be a test for the new script?

@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@EmmaRenauld EmmaRenauld force-pushed the Merging_propagator_and_tracker branch from 1f3dd74 to 8db4416 Compare November 22, 2021 19:00
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

2 similar comments
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@scil-admin
Copy link

Build passed ! Good Job 🍻 !

Copy link
Contributor

@mdesco mdesco left a comment

Choose a reason for hiding this comment

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

It is still crashing when I run:
scil_compute_local_tracking_dev.py sub-197348__fodf.nii.gz seeds_fa015.nii.gz seeds_fa015.nii.gz test.trk --processes 8

Data to test:
https://www.dropbox.com/s/a4s8gvkbro4pqz3/PR_511.zip?dl=0

@EmmaRenauld EmmaRenauld force-pushed the Merging_propagator_and_tracker branch from 8db4416 to dd8c66b Compare November 23, 2021 17:40
@EmmaRenauld
Copy link
Contributor Author

Sorry @mdesco

Tested and retested with your data and mine, verified origin everywhere.

@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@CHrlS98
Copy link
Contributor

CHrlS98 commented Dec 20, 2021

@EmmaRenauld @GuillaumeTh
Ok just to summarize what is left to be done :

  1. Add a test for the new script (see test_compute_local_tracking.py for example)
  2. Let's discuss this comment : Modifications in the (bitbucket) tracking scripts - part 2 #511 (comment)

Copy link
Contributor

@CHrlS98 CHrlS98 left a comment

Choose a reason for hiding this comment

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

Alright nice!

I will open a PR in the future to clarify the DataVolume, SeedGenerator coordinate system extravaganza.

@scil-admin
Copy link

Build passed ! Good Job 🍻 !

1 similar comment
@scil-admin
Copy link

Build passed ! Good Job 🍻 !

@GuillaumeTh GuillaumeTh merged commit 30b596c into scilus:master Jan 5, 2022
@EmmaRenauld EmmaRenauld deleted the Merging_propagator_and_tracker branch January 7, 2022 16:21
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.

7 participants