Skip to content

Conversation

@mvdoc
Copy link
Contributor

@mvdoc mvdoc commented Jan 26, 2026

Summary

Fixes #591

  • Pass freesurfer_subject_dir parameter to both freesurfer.get_surf() calls in cut_surface() function
  • Add regression tests to verify the fix

Problem

The cut_surface() function in cortex/segment.py accepts a freesurfer_subject_dir parameter but was not passing it to the freesurfer.get_surf() calls on lines 189-190. This caused a KeyError when the SUBJECTS_DIR environment variable was not set.

Solution

Pass the freesurfer_subject_dir parameter to both get_surf() calls:

ipt, ipoly, inrm = freesurfer.get_surf(
    fs_subject, hemi, "inflated", freesurfer_subject_dir=freesurfer_subject_dir
)
fpt, fpoly, fnrm = freesurfer.get_surf(
    fs_subject, hemi, "fiducial", freesurfer_subject_dir=freesurfer_subject_dir
)

Test plan

  • Added regression test verifying freesurfer_subject_dir is passed to get_surf() calls
  • Added test for error handling when SUBJECTS_DIR is not set
  • Added backward compatibility test when using SUBJECTS_DIR environment variable
  • All new tests pass: pytest cortex/tests/test_segment.py -v
  • Full test suite passes (except pre-existing unrelated failure)

🤖 Generated with Claude Code

The cut_surface() function accepts a freesurfer_subject_dir parameter but
was not passing it to the freesurfer.get_surf() calls for loading inflated
and fiducial surfaces. This caused a KeyError when SUBJECTS_DIR environment
variable was not set.

- Pass freesurfer_subject_dir to both get_surf() calls in cut_surface()
- Add regression tests for the fix

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 26, 2026 23:17
Copy link

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 pull request fixes issue #591 where the cut_surface() function in cortex/segment.py was not passing the freesurfer_subject_dir parameter to internal freesurfer.get_surf() calls, causing a KeyError when the SUBJECTS_DIR environment variable was not set.

Changes:

  • Fixed cut_surface() to pass freesurfer_subject_dir to both get_surf() calls for inflated and fiducial surfaces
  • Added comprehensive regression tests to verify the fix and ensure backward compatibility
  • Applied code formatting improvements throughout cortex/segment.py (quote style, line breaks, spacing)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
cortex/segment.py Fixed the bug by passing freesurfer_subject_dir to get_surf() calls on lines 205-210; also includes extensive formatting improvements throughout the entire file
cortex/tests/test_segment.py New test file with comprehensive test coverage for the fix, including regression tests, error handling tests, and backward compatibility tests

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

@mvdoc mvdoc merged commit e50b11f into main Jan 27, 2026
22 checks passed
@mvdoc mvdoc deleted the fix/591-freesurfer-subject-dir-get-surf branch January 27, 2026 01:32
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.

freesurfer_subject_dir not passed to get_surf() in segment.cut_surface()

2 participants