Skip to content

Add shared polygon atlas API for strict R/Python ggseg visual parity#10

Open
mqqq333 wants to merge 2 commits into
ggsegverse:mainfrom
mqqq333:proposal/r-ggseg-polygon-interop
Open

Add shared polygon atlas API for strict R/Python ggseg visual parity#10
mqqq333 wants to merge 2 commits into
ggsegverse:mainfrom
mqqq333:proposal/r-ggseg-polygon-interop

Conversation

@mqqq333

@mqqq333 mqqq333 commented Jun 20, 2026

Copy link
Copy Markdown

Description

This PR adds a minimal polygon atlas interoperability API for rendering R ggseg-exported 2D polygon atlas tables in python-ggseg. The goal is to support strict visual parity between R ggseg and python-ggseg cortical gray-matter plots by allowing both backends to render the same atlas geometry and, when desired, the same identity colors via fill_hex.

This PR adds:

  • read_polygon_atlas(path) for loading canonical polygon atlas CSV files;
  • validate_polygon_atlas(atlas) for schema validation;
  • join_polygon_values(...) for explicit join-by-label / join-by-region behavior;
  • plot_polygons(...) for rendering shared polygon atlas tables;
  • fill_column="fill_hex" identity-color rendering for exact cross-backend color parity;
  • tests for schema validation, value joining, unmatched labels, and identity-color plotting;
  • documentation describing the R/Python visual parity workflow.

The implementation is additive and does not change existing plot_dk, plot_aseg, or plot_jhu behavior.

Related Issues

No related issue yet.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Other (describe): Cross-language visual-parity / interoperability API

Checklist

  • I have read the contributing guidelines
  • I have run devtools::check() with no errors
  • I have added tests for my changes (if applicable)
  • I have updated documentation (if applicable)
  • My code follows the tidyverse style guide

@mqqq333

mqqq333 commented Jun 21, 2026

Copy link
Copy Markdown
Author

I also tested this locally with a real DK polygon table exported from R ggseg.

The comparison image below uses:

  • the same polygon CSV as canonical geometry;
  • the same fill_hex column as identity colors;
  • Python rendering through the proposed plot_polygons(..., fill_column="fill_hex");
  • R rendering from the same polygon table.

Local smoke test using the proposed API:

read_polygon_atlas: OK
rows = 3233
labels = 70
features = 204
unique_fill_hex = 63
rendered_patches = 204

This is why the PR focuses on shared polygon geometry and optional identity-color rendering via fill_hex: exact R/Python visual parity is reliable when
both backends consume the same geometry and colors, rather than reconstructing atlas geometry independently.

FINAL_python_vs_r_shared_dk_compare

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