-
Notifications
You must be signed in to change notification settings - Fork 7
WIP produce TRX grouped by sl len #32
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -313,3 +313,74 @@ def generate_trx(self, seeds, ref_img): | |||||||||||||
| trx_file.resize() | ||||||||||||||
|
|
||||||||||||||
| return trx_file | ||||||||||||||
|
|
||||||||||||||
| def generate_trx_grouped_by_len(self, seeds, ref_img, min_len=20, max_len=250, bin_len=10): | ||||||||||||||
| global_chunk_sz, nchunks = self._divide_chunks(seeds) | ||||||||||||||
|
|
||||||||||||||
| # Will resize by a factor of 2 if these are exceeded | ||||||||||||||
| sl_per_seed_guess = 3 | ||||||||||||||
| n_sls_guess = sl_per_seed_guess * seeds.shape[0] | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| bin_starts = np.arange(min_len, max_len + bin_len, bin_len) | ||||||||||||||
| trx_files = {} | ||||||||||||||
| offsets_idxs = {} | ||||||||||||||
| sls_data_idxs = {} | ||||||||||||||
| for bin_start in bin_starts: | ||||||||||||||
| max_steps = (bin_start + bin_len) / self.step_size | ||||||||||||||
| trx_files[bin_start] = TrxFile( | ||||||||||||||
| reference=ref_img, | ||||||||||||||
| nb_streamlines=n_sls_guess, | ||||||||||||||
| nb_vertices=n_sls_guess * max_steps, | ||||||||||||||
| ) | ||||||||||||||
|
Comment on lines
+329
to
+335
|
||||||||||||||
| trx_files[bin_start].streamlines._offsets = \ | ||||||||||||||
| trx_files[bin_start].streamlines._offsets.astype(np.uint64) | ||||||||||||||
| offsets_idxs[bin_start] = 0 | ||||||||||||||
| sls_data_idxs[bin_start] = 0 | ||||||||||||||
|
|
||||||||||||||
| with tqdm(total=seeds.shape[0]) as pbar: | ||||||||||||||
| for idx in range(int(nchunks)): | ||||||||||||||
| self.seed_propagator.propagate( | ||||||||||||||
| seeds[idx * global_chunk_sz : (idx + 1) * global_chunk_sz] | ||||||||||||||
| ) | ||||||||||||||
| bin_indices = self.seed_propagator.gen_bin_indices(bin_starts, bin_len) | ||||||||||||||
| for bin_start in bin_starts: | ||||||||||||||
| tractogram = Tractogram( | ||||||||||||||
| self.seed_propagator.as_array_sequence_group(bin_indices, bin_start), | ||||||||||||||
|
Comment on lines
+347
to
+349
|
||||||||||||||
| for bin_start in bin_starts: | |
| tractogram = Tractogram( | |
| self.seed_propagator.as_array_sequence_group(bin_indices, bin_start), | |
| for bin_idx, bin_start in enumerate(bin_starts): | |
| tractogram = Tractogram( | |
| self.seed_propagator.as_array_sequence_group(bin_indices, bin_idx), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gen_bin_indicesbuildsbin_indicesas a dict keyed by integer indices0..len(bin_starts)-1, butas_array_sequence_groupindexesbin_indicesusing thebin_startargument directly; when callers pass the physical bin start values (e.g., 20, 30, ...), this will not match the integer keys and will lead to KeyError or empty groups. The keys should be made consistent (either indices everywhere or the actualbin_startvalues), for example by keyingbin_indicesby the bin start values insidegen_bin_indicesand keepingas_array_sequence_group's interface as-is.