Skip to content

ENH add types in quickflat and vertex mappers - #670

Draft
kroq-gar78 wants to merge 12 commits into
types/05-dataset-corefrom
types/06-07-mapper-quickflat-core
Draft

ENH add types in quickflat and vertex mappers#670
kroq-gar78 wants to merge 12 commits into
types/05-dataset-corefrom
types/06-07-mapper-quickflat-core

Conversation

@kroq-gar78

@kroq-gar78 kroq-gar78 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

NOTE: this is WIP. It has broken mapper changes.


This PR adds type support for the non-SVG functions in cortex.quickflat and standardizes the Mapper API.

It also improves test coverage for the many arguments of quickflat.make_figure.


Stack created with GitHub Stacks CLIGive Feedback 💬

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).
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.

1 participant