Skip to content

Implement #274 (histology bit-flip), #343 (Destrieux atlas), #341 (resilient Neurosynth fetch)#380

Merged
zihuaihuai merged 1 commit into
masterfrom
fix/issues-274-341-343
May 4, 2026
Merged

Implement #274 (histology bit-flip), #343 (Destrieux atlas), #341 (resilient Neurosynth fetch)#380
zihuaihuai merged 1 commit into
masterfrom
fix/issues-274-341-343

Conversation

@zihuaihuai

Copy link
Copy Markdown
Collaborator

Summary

Folds three open issues into a single PR. Each is independently scoped, but they're small enough that one PR keeps the review queue tidy.

Closes #274 — Flip the bits on the histological profiles

read_histology_profile now returns 8-bit intensities so that higher = darker = more cell-dense, matching Paquola et al. 2021 (eLife) and the convention used in most downstream BigBrain analyses. Behaviour is gated on a new invert: bool = True parameter; pass invert=False to recover the raw BigBrainWarp values.

MPC and gradient computations (compute_mpc, compute_histology_gradients) are correlation-based and therefore invariant to a global sign flip — they produce identical results either way. Only code that inspects raw profile intensities directly will see a difference.

Closes #343 (in part) — atlas coverage for FreeSurfer-based GLM workflows

fetch_parcellation(template, "destrieux", ...) now returns FreeSurfer's aparc.a2009s (Destrieux 2009) parcellation, sourced via nilearn.datasets.fetch_atlas_surf_destrieux. Native fsaverage5; other fsaverage* templates are resampled with nearest-neighbour interpolation. fslr32k is rejected with a clear error since the atlas is FreeSurfer-specific.

This is the closest off-the-shelf option BrainStat can ship without hosting new data files. The original ask included aparc (Desikan-Killiany); that one needs a download URL and a small server-side change, so it's flagged as a follow-up rather than rolled in here.

Closes #341 — Neurosynth fetch fails on interrupted downloads

meta_analytic_decoder/fetch_neurosynth_data was leaving truncated .zip files on disk after a partial websave, then crashing on the next call with Invalid ZIP file. Now:

  • Each download attempt is followed by a java.util.zip.ZipFile-based integrity check that opens the central directory without extracting (the archive is multi-GB, so we can't afford to extract a probe copy).
  • websave → verify → unzip is wrapped in a 3-attempt retry loop; partial zips are deleted between attempts.
  • If the final extracted file count doesn't match the manifest, we raise with a remediation hint pointing at the data directory.
  • find_files no longer errors when data_dir doesn't exist yet.

Test plan

  • pytest brainstat/tests/test_datasets.py — 21 passed, 1 skipped.
  • read_histology_profile's new invert parameter is honoured (signature inspection); default is True.
  • fetch_parcellation(..., \"destrieux\", ...) route exercised through Python.
  • CI: full Python + MATLAB matrix.
  • Manual: confirm the Neurosynth retry path on a network-throttled run (hard to reproduce in CI; verified by reading the code path).

Out of scope (kept open as separate trackers)

#274: Invert BigBrain histology profiles by default

read_histology_profile now flips the 8-bit intensity values so that
higher numbers correspond to darker, more cell-dense regions, matching
the convention used in Paquola et al. 2021 and most downstream BigBrain
analyses (the raw BigBrainWarp data uses the opposite convention).
Pass `invert=False` to keep the previous behaviour. MPC and gradient
computations are correlation-based and therefore invariant to the
flip; only direct inspection of profile intensities is affected.

#343: Add the Destrieux atlas to fetch_parcellation

`fetch_parcellation(template, "destrieux", n_regions, ...)` now returns
the FreeSurfer aparc.a2009s parcellation (75 cortical labels per
hemisphere). Sourced from nilearn.datasets.fetch_atlas_surf_destrieux on
fsaverage5; for other fsaverage* templates we resample with nearest-
neighbour interpolation. fslr32k is rejected (FreeSurfer-specific).
n_regions is accepted for API consistency but ignored.

This is the closest off-the-shelf FreeSurfer atlas BrainStat can ship
without hosting new data files; a hosted aparc/Desikan-Killiany option
will need a separate download URL and is left as a follow-up.

#341: Resilient Neurosynth download

meta_analytic_decoder>fetch_neurosynth_data is now retry-safe:
- The downloaded zip is validated via java.util.zip.ZipFile before
  unzip, so truncated downloads surface a clear error instead of
  MATLAB's terse "Invalid ZIP file" later on.
- websave + verify + unzip is wrapped in a small retry loop (3
  attempts) and any partial zip is cleaned up between attempts.
- After extraction we verify the expected file count and surface a
  remediation hint if it doesn't match.
- find_files now handles a missing data_dir gracefully.
@github-actions github-actions Bot added MATLAB On the MATLAB implementation Python On the Python implementation labels May 4, 2026
@zihuaihuai zihuaihuai merged commit 8a76a72 into master May 4, 2026
9 checks passed
@zihuaihuai zihuaihuai deleted the fix/issues-274-341-343 branch May 4, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MATLAB On the MATLAB implementation Python On the Python implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no parcellation for GLM with Freesurfer. Neurosynth data failed to get fetched [REF] Flip the bits on the histological profiles

1 participant