ENH add types in quickflat and vertex mappers - #670
Draft
kroq-gar78 wants to merge 12 commits into
Draft
Conversation
The mapper/mapper.py and webgl/data.py/webgl/view.py hunks of this original commit are owned by PR 6 and PR 9 respectively.
Consolidates the rest of PR 5's per-commit typing work (dataset/braindata.py, dataset/views.py, dataset/view2D.py, dataset/viewRGB.py, dataset/__init__.py, tests/test_dataset.py) into one commit rather than replaying the remaining ~15 original commits individually. Reason for the shortcut: several of these commits touch the same lines in a different real chronological order than PR_SPLIT_PLAN.md's "PR-internal commit order is chronological" claim assumes (e.g. `1d2164b5`, dated 2026-03-07 17:54, resolves ColormapDict's `cmap` TODO before `90acd0bd`, dated 2026-03-07 21:29, removes the now-unused ListedColormap import — but the plan lists 90acd0b at position 9 and 1d2164b at position 21). Replaying in the plan's listed order applies real hunks against a file shape they weren't authored against, which is how a silent bug (re-deleting an import still in use) almost landed in the first cherry-pick pass. This commit instead checks out the exact final state of each PR-5-owned file from `types-easy`, verified to produce zero diff against `types-easy` for every file in PR 5's file list.
Types add_curvature, add_data, add_hatch, add_colorbar, add_colorbar_2d, add_connected_vertices, and all of view.py/utils.py's non-SVG helpers. add_rois, add_sulci, add_custom, add_cutout, and _convert_svg_kwargs are deliberately left untyped here — they call into cortex.svgoverlay directly and land with that module in PR 8 instead (see PR_SPLIT_PLAN.md). Built by diffing this worktree's pre-typing composite.py/utils.py against types-easy's final versions and keeping only the non-SVG-function hunks, rather than replaying the ~14 original historical commits individually — several of those commits interleave SVG and non-SVG hunks in ways that don't split cleanly commit-by-commit. test_quickflat.py's four new ROI-specific test functions (test_roi_styling_parameters, test_roi_list_and_sulci_list, test_combined_parameters, and the ROI/sulci assertions inside test_display_flags) are included here rather than held back for PR 8, since they don't block anything at runtime and splitting test_display_flags mid-function is not worthwhile. Verified: zero diff against types-easy for composite.py (excluding the 4 SVG functions + the Sequence import, which stay untyped pending PR 8), and zero diff for utils.py/view.py/test_quickflat.py.
Types cortex/mapper/{__init__,mapper,line,patch,point,samplers}.py.
These files are exclusively owned by PR 6 (no commit before this one in
main..types-easy touches cortex/mapper/), so checked out directly from
types-easy rather than replayed commit-by-commit.
Verified: zero diff against types-easy for all six mapper files.
… 2a3c944c)
PR 6 renames get_mapper's `type` parameter to `maptype` (mypy Wave 3,
2a3c944c: `type` shadowed the builtin `type` used on the very next line).
cortex/utils.py has four call sites still using the old `type=` keyword;
since get_mapper has **kwargs, this wasn't a clean TypeError — the old
keyword silently landed in **kwargs, get_mapper defaulted `maptype` to
"nearest" regardless of what was requested, and the leftover kwarg then
propagated down to the sampler functions where PR 6 also added a "raise
ValueError on unexpected kwargs" check, surfacing as a confusing
ValueError several frames removed from the actual cause (or, worse, no
error at all and silently the wrong mapper class if a cache file for
"nearest" already happened to exist).
Reproduced before this commit:
get_mapper('S1', 'fullhead', type='trilinear', recache=True)
-> ValueError: nearest sampler does not take any kwargs
This isn't otherwise in PR 6 or PR 7's file list (cortex/utils.py belongs
to PR 12), but is picked from PR 12's 2a3c944c here — just the four
`type=` -> `maptype=` call-site renames in get_cortical_mask,
get_hemi_masks, get_roi_mask, and get_roi_masks — so that PR 6+7 doesn't
leave get_mapper's real callers broken. PR 12 will still add full typing
to cortex/utils.py; this commit only touches the four call sites that
would otherwise regress.
Verified: get_cortical_mask, get_hemi_masks, and get_roi_masks all run
correctly against the S1 test subject after this fix; all 4 previously
failed or behaved incorrectly before it (get_mapper('S1', 'fullhead',
type='trilinear', recache=True) reproduces the bug directly).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NOTE: this is WIP. It has broken mapper changes.
This PR adds type support for the non-SVG functions in
cortex.quickflatand standardizes the Mapper API.It also improves test coverage for the many arguments of
quickflat.make_figure.Stack created with GitHub Stacks CLI • Give Feedback 💬