Skip to content

Conversation

@viktorpm
Copy link
Member

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?

To support generating the WHS SD rat atlas using the SWC female rat template as the reference image, in addition to the existing Waxholm/NITRC workflow.

What does this PR do?

  • Adds dual-mode support via swc_female_template flag:
    • SWC mode: Uses SWC female rat template, downloads individual files from GIN with hash verification
    • Waxholm/NITRC mode: Original workflow using zip archives (unchanged)
  • Refactors download functions to support both modes
  • Simplifies mesh creation by using construct_meshes_from_annotation()
  • Adds reference stack normalization for SWC template mode
  • Updates orientation to "pir" for SWC mode (not sure why it is pir, source image has to be checked)
  • Bumps version to 3

How has this PR been tested?

It was run interactively on an HPC node

Is this a breaking change?

no

Does this PR require an update to the documentation?

Likely

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality (unit & integration)
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

- SWC Female Template mode (True): Uses SWC female rat template as reference, from GIN repository
- Waxholm/NITRC mode (False): Original workflow using zip archives from NITRC
- Refactor download functions, add `download_swc_template_file()`
- Use `construct_meshes_from_annotation()`
- Add reference stack normalization for SWC template mode (uint16 scaling)
- Bump version to 3
@viktorpm viktorpm marked this pull request as ready for review December 15, 2025 09:54
@viktorpm viktorpm requested a review from adamltyson December 15, 2025 09:58
@adamltyson
Copy link
Member

Hi @viktorpm, I think it would be better for the code for this new atlas to be in it's own file. Although there's a lot of shared code with the "original" Waxholm, I think it would be easier to understand if they were seperated.

@viktorpm
Copy link
Member Author

I split the script into two separate files and had ChatGPT write the docstrings based on the code and my instructions. They both run and generate atlases.

As expected in the whs_sd_swc_female_rat atlas, the originally 50um image is upsampled to 39um during warping.

Top left: whs_sd_swc_female_rat 39um upsampled
Bottom left: original whs_sd_rat 39um
Top right: swc_female_rat 50 um
whs_swc_atlases

Do you think this is an issue @adamltyson, @alessandrofelder?

The atlases are available here: /ceph/akrami/_projects/rat_atlas/atlas/

@alessandrofelder
Copy link
Member

Do you think this is an issue @adamltyson, @alessandrofelder?

I think this is fine for the SWC template in Waxholm space (we will keep the SWC template in its own space, and 50 um (and maybe one day, at 25um) too, right?), as long as the metadata is updated accordingly.

We have a convention that the atlas generation file matches the name of the atlas created by it, so maybe the new Python file needs renaming to just whs_sd_swc_female_rat.py?

@adamltyson
Copy link
Member

I think it's fine, but ideally we would create a new 39um version in Waxholm space from a 25um version in SWC space to minimise loss of information.

Comment on lines +45 to +59
REFERENCE_URL = (
"https://gin.g-node.org/BrainGlobe/swc_rat_atlas_materials/"
"raw/master/packaging/50um/Waxholm_space/T2W_warped.nii.gz"
)
ANNOTATION_FILENAME = "WHS_SD_annotation_waxholm_space_cleaned.nii.gz"
ANNOTATION_URL = (
"https://gin.g-node.org/BrainGlobe/swc_rat_atlas_materials/"
"raw/master/packaging/50um/Waxholm_space/"
"WHS_SD_annotation_waxholm_space_cleaned.nii.gz"
)
STRUCTURES_ILF_FILENAME = "WHS_SD_rat_atlas_v4.01_labels.ilf"
STRUCTURES_ILF_URL = (
"https://gin.g-node.org/BrainGlobe/swc_rat_atlas_materials/"
"raw/master/packaging/50um/WHS_SD_rat_atlas_v4.01_labels.ilf"
)
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit confusing that these files refer to "50um", but they should be 39um right?

Comment on lines +70 to +72
ATLAS_PACKAGER = (
"Harry Carey, University of Oslo, Norway, [email protected]"
)
Copy link
Member

Choose a reason for hiding this comment

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

This one should be you @viktorpm!

@PolarBean
Copy link
Member

Hmm why 50 and not just 39, may as well align with the Waxholm. Good job with this!

@adamltyson
Copy link
Member

adamltyson commented Jan 28, 2026

Hmm why 50 and not just 39, may as well align with the Waxholm.

Just because it was created at 50, but a version has been upsampled (and warped) to match the Waxholm. A 25um version is in the works.

@PolarBean
Copy link
Member

sure, the resolutions are arbitrary, just wondering. 25um sounds good, how possible is 10um? I think it would be the first cellular resolution atlas for the Rat brain.

@adamltyson
Copy link
Member

Possible I think (@viktorpm the original data is at least 10um isotropic right?). The issue is time, as it would be 5^3 times slower than the 50um version.

@PolarBean
Copy link
Member

Which part would be so slow, the template creation or registration? the registration we could just upsample a 39um deformation field. Maybe something for down the line.

@alessandrofelder
Copy link
Member

The template creation for the 25 micron, with our current set-up (which parallelises registrations across samples) takes several weeks to a month... 10 micron is expected to take more than 8 times that.

@PolarBean
Copy link
Member

I see, that does sound a little prohibitive

@viktorpm
Copy link
Member Author

The original data is anisotropic and has a resolution below 10 µm. In theory, we could probably go up to around 7 µm. @PolarBean, the template creation would be the slow part and I’m not entirely sure whether the cluster could handle anything above 20 µm (that’s the highest resolution that’s been tested so far).

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