Skip to content

[VIZ] Improving some visualization things; rename V1V3 to Early Visual#195

Open
36000 wants to merge 8 commits into
tractometry:mainfrom
36000:random_fixes
Open

[VIZ] Improving some visualization things; rename V1V3 to Early Visual#195
36000 wants to merge 8 commits into
tractometry:mainfrom
36000:random_fixes

Conversation

@36000
Copy link
Copy Markdown
Collaborator

@36000 36000 commented May 28, 2026

No description provided.

Copilot AI review requested due to automatic review settings May 28, 2026 22:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes several visualization-related improvements and refactors SegmentedSFT to support TRX files lazily (avoiding the eager to_sft() conversion that loaded all streamlines into memory). It also renames the user-facing bundle "V1V3" to "Early Visual" and exposes/extends a few visualization knobs (per-image trim_buffer, n_sls_viz for the fury backend).

Changes:

  • Refactor SegmentedSFT to handle TRX inputs lazily via an is_trx branch; convert bundle_idxs from a dict attribute to a method, add to_rasmm/get_lengths helpers, and update all internal callers.
  • Rename "Left/Right V1V3" → "Left/Right Early Visual" in the bundle dict and viz color map.
  • Add a configurable trim_buffer to add_img/trim/bbox and expose n_sls_viz on the fury visualize_bundles API.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
AFQ/utils/streamlines.py Adds TRX-aware SegmentedSFT path, converts bundle_idxs to a method, adds to_rasmm/get_lengths.
AFQ/tasks/segmentation.py Updates callers to use get_lengths()/to_rasmm(); reaches into new private _bundle_idxs.
AFQ/api/group.py Switches bundle_idxs[b]bundle_idxs(b) and uses to_rasmm().
AFQ/api/bundle_dict.py Renames "V1V3" subbundles to "Early Visual".
AFQ/viz/utils.py Renames V1V3 color entries, adds trim_buffer/bbox buffer, updates tract_generator for new API.
AFQ/viz/fury_backend.py Exposes n_sls_viz parameter to visualize_bundles.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread AFQ/tasks/segmentation.py Outdated
Comment thread AFQ/utils/streamlines.py Outdated
Comment thread AFQ/api/bundle_dict.py
Comment thread AFQ/utils/streamlines.py Outdated
Comment on lines +30 to +44
# Loading from TRX, we do not calculate additional information,
# To avoid loading unnecessary streamlines into memory
self.bundle_names = list(bundles.groups.keys())
self.sft = bundles

# mimic SFT attributes for compatibility
affine = np.array(self.sft.header["VOXEL_TO_RASMM"], dtype=np.float32)
dimensions = np.array(self.sft.header["DIMENSIONS"], dtype=np.uint16)
vox_sizes = np.array(voxel_sizes(affine), dtype=np.float32)
vox_order = "".join(aff2axcodes(affine))
space_attributes = (affine, dimensions, vox_sizes, vox_order)
self.sft.space_attributes = space_attributes
self.sft.space = Space.RASMM
self.sft.origin = Origin.NIFTI
self.sft.dtype_dict = self.sft.get_dtype_dict()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree that it would be great to have some tests for all this, both at the unit level, and for integration, given the intricacy of these changes, and how entangled this is with other functionality.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Our default is to use TRX, so all of the visualization code stuff it is saying is indeed already tested.

I can add a unit test for the SFT case. However, at what point do we drop support for outputting TRKs? This whole class basically just exists to allow SFTs to do what TRX already does natively, and we could remove it if we don't want that option anymore. If we decide to keep support for outputting TRKs I can keep this class and add unit tests

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Actually, I just added some tests

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Dropping trk support would be nice. I think we want to keep it in for a little while longer, though. I guess we can support trk/tck input for a longer time -- unrelated to this bit code, I guess -- but drop trk outputs pretty soon.

Copy link
Copy Markdown
Member

@arokem arokem left a comment

Choose a reason for hiding this comment

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

Integration of trx is excellent, but the added complexity would benefit from docs/testing.

Comment thread AFQ/api/bundle_dict.py
Comment thread AFQ/utils/streamlines.py Outdated
Comment on lines +30 to +44
# Loading from TRX, we do not calculate additional information,
# To avoid loading unnecessary streamlines into memory
self.bundle_names = list(bundles.groups.keys())
self.sft = bundles

# mimic SFT attributes for compatibility
affine = np.array(self.sft.header["VOXEL_TO_RASMM"], dtype=np.float32)
dimensions = np.array(self.sft.header["DIMENSIONS"], dtype=np.uint16)
vox_sizes = np.array(voxel_sizes(affine), dtype=np.float32)
vox_order = "".join(aff2axcodes(affine))
space_attributes = (affine, dimensions, vox_sizes, vox_order)
self.sft.space_attributes = space_attributes
self.sft.space = Space.RASMM
self.sft.origin = Origin.NIFTI
self.sft.dtype_dict = self.sft.get_dtype_dict()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree that it would be great to have some tests for all this, both at the unit level, and for integration, given the intricacy of these changes, and how entangled this is with other functionality.

Comment thread AFQ/utils/streamlines.py Outdated
Comment thread AFQ/utils/streamlines.py Outdated
Comment thread AFQ/viz/fury_backend.py
@arokem
Copy link
Copy Markdown
Member

arokem commented May 30, 2026

No more gifs, huh? That format does have some advantages (e.g., more portable than MP4, I believe).

@arokem
Copy link
Copy Markdown
Member

arokem commented May 30, 2026

For example, try posting an mp4 into a GitHub conversation. Does that work?

@36000 36000 changed the title [VIZ] Improving some visualization things; rename V1V3 to Early Visual [WIP/VIZ] Improving some visualization things; rename V1V3 to Early Visual May 31, 2026
@36000
Copy link
Copy Markdown
Collaborator Author

36000 commented May 31, 2026

It looks like GitHub only wants files less than 10MB currently, so I had to reduce the quality significantly. Luckily, I think it compressed well. mp4s will be much better for making things visually appealing and not stuttering. The GIF had that problem when I slowed it down, and it's just because GIFs barely compress, so we are always compromising frame rate / visual resolution / number of frames.

This is an HBN subject

test.mp4

@arokem
Copy link
Copy Markdown
Member

arokem commented May 31, 2026

This looks really good!

@36000 36000 added this to the pyAFQ 3.3 milestone Jun 4, 2026
@36000 36000 changed the title [WIP/VIZ] Improving some visualization things; rename V1V3 to Early Visual [VIZ] Improving some visualization things; rename V1V3 to Early Visual Jun 4, 2026
@arokem
Copy link
Copy Markdown
Member

arokem commented Jun 4, 2026

I think that this is probably ready to merge? I re-triggered the documentation build, which failed previously. Hopefully these changes are not adding much in terms of memory pressure or runtime, and that failure was just a glitch.

@36000
Copy link
Copy Markdown
Collaborator Author

36000 commented Jun 5, 2026

Yes, I think it is the mp4 generation that is causing problems right now, then we can merge

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.

3 participants