Skip to content

Get rid of passing directory paths and introduce data classes for these use cases - #99

Merged
PolarBean merged 82 commits into
mainfrom
interpolate-volume-refactor
Jun 8, 2026
Merged

Get rid of passing directory paths and introduce data classes for these use cases #99
PolarBean merged 82 commits into
mainfrom
interpolate-volume-refactor

Conversation

@PolarBean

@PolarBean PolarBean commented Mar 31, 2026

Copy link
Copy Markdown
Member

This PR introduces some more data classes to replace instances when we would pass directory paths to functions. some examples of how this improves things are below

Segmentation Pipeline

Before

import PyNutil as pnt

atlas    = BrainGlobeAtlas("allen_mouse_25um")
alignment = pnt.read_alignment("path/to/alignment.json")

coords = pnt.seg_to_coords(
    "path/to/segmentations/",
    alignment,
    atlas,
    pixel_id=[0, 0, 0],
    object_cutoff=0,
    segmentation_format="binary",
)

After

import PyNutil as pnt

atlas     = BrainGlobeAtlas("allen_mouse_25um")
alignment = pnt.read_alignment("path/to/alignment.json")

segs   = pnt.read_segmentation_dir("path/to/segmentations/", pixel_id=[0, 0, 0])
coords = pnt.seg_to_coords(segs, alignment, atlas, object_cutoff=0)

Volume Interpolation

Before

gv, fv, dv = pnt.interpolate_volume(
    segmentation_folder="path/to/segmentations/",
    alignment_json="path/to/alignment.json",
    colour=[0, 0, 0],
    atlas=atlas,
)

pnt.save_volume_niftis(
    output_folder="path/to/output",
    interpolated_volume=gv,
    frequency_volume=fv,
    damage_volume=dv,
    atlas_volume=atlas.volume,
    voxel_size_um=atlas.voxel_size_um,
)

After

segs    = pnt.read_segmentation_dir("path/to/segmentations/", pixel_id=[0, 0, 0])
volumes = pnt.interpolate_volume(
    image_series=segs,
    registration=alignment,
    atlas=atlas,
)

pnt.save_volumes(output_folder="path/to/output", volumes=volumes, atlas=atlas)

Seperating these steps also makes it easier for users to pass arrays directly to construct segmentation objects. at the moment doing this would be a bit hacky but at least possible without writing to disk.

Im hoping that long term these data classes become useful enough as a standardised way of interacting with segmentation outputs from different tools.

PolarBean and others added 13 commits March 31, 2026 18:04
…Atlas

- resolve_atlas() now captures voxel_size_um from BrainGlobeAtlas
- interpolate_volume() calls resolve_atlas() internally (like batch_processor)
  so that atlas_volume is always in PyNutil's transposed coordinate system
- test_helpers.load_atlas_from_settings wraps BrainGlobeAtlas with resolve_atlas
  so pipeline helpers consistently return AtlasData
- Update tests to use atlas.volume.shape and atlas.voxel_size_um (AtlasData API)
- Revert incorrectly-updated NIfTI fixtures (they were generated from wrong coords)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- test_return_orientation: replace removed load_atlas_data with BrainGlobeAtlas
- test_build_volume_from_sections: resolve leftover conflict marker from
  remove-nonlinear cherry-pick

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The test previously passed return_orientation="lpi" (which was removed
as part of stripping the non_linear/damage_mask opt-out). The default
return_orientation is "asr", which reorients the volume and produces
shape (80, 48, 69) rather than (69, 80, 48). Regenerate the fixtures
to match the current default behaviour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@PolarBean

Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

Copilot AI and others added 2 commits April 23, 2026 15:48
Co-authored-by: PolarBean <38996929+PolarBean@users.noreply.github.com>
@PolarBean
PolarBean changed the base branch from simplify-api to main April 23, 2026 15:53

Copilot AI commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Done — I merged simplify-api into this branch and resolved all merge conflicts, then pushed the follow-up fixes in 5107f06 (merge commit: 36fe540).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • gin.g-node.org
    • Triggering command: /usr/bin/python python -m unittest tests.core.test_interpolate_volume_value_modes tests.core.test_return_orientation tests.regression.test_build_volume_from_sections tests.regression.test_damage_volume_interpolation tests.nutil_comparison.test_validator_nutil_comparison (dns block)
    • Triggering command: /usr/bin/python python -m unittest tests.core.test_interpolate_volume_value_modes tests.regression.test_build_volume_from_sections tests.regression.test_damage_volume_interpolation tests.nutil_comparison.test_validator_nutil_comparison gn/gh-gpgsign-linux-x86_64 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@PolarBean
PolarBean changed the base branch from main to simplify-api April 23, 2026 16:17
Comment thread .github/workflows/tests.yml Outdated
Comment thread demos/modified_alignment.json Outdated
Comment thread PyNutil/io/volume_nifti.py
@PolarBean
PolarBean marked this pull request as ready for review May 8, 2026 17:06
sharoncy and others added 3 commits May 15, 2026 09:35
…ents

write docstrings that are compatible with our docs with examples
…ng-improvements

Revert "write docstrings that are compatible with our docs with examples"

@IgorTatarnikov IgorTatarnikov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good! Just a few comments, none are blocking.

Comment thread .github/workflows/tests.yml Outdated
Comment thread demos/basic_example_custom_atlas.py Outdated
Comment thread PyNutil/io/volume_nifti.py Outdated
Comment thread PyNutil/processing/atlas_map.py Outdated
Comment thread PyNutil/processing/pipeline/batch_processor.py
Comment thread PyNutil/processing/pipeline/batch_processor.py Outdated
Comment thread PyNutil/context.py Outdated
Comment thread PyNutil/image_series.py Outdated
Comment thread PyNutil/io/volume_nifti.py Outdated
@PolarBean
PolarBean merged commit a2db2e2 into main Jun 8, 2026
4 checks passed
@PolarBean
PolarBean deleted the interpolate-volume-refactor branch June 8, 2026 17:14
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.

5 participants