Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix vector transform linearity for angular coordinate systems - #2718

Open
domfrbassett wants to merge 2 commits into
SciTools:mainfrom
domfrbassett:vector-transform-linearity
Open

Fix vector transform linearity for angular coordinate systems#2718
domfrbassett wants to merge 2 commits into
SciTools:mainfrom
domfrbassett:vector-transform-linearity

Conversation

@domfrbassett

Copy link
Copy Markdown

Rationale

CRS.transform_vectors() estimates output directions by perturbing each point in the direction of the full input vector. This can make the result non-linear in the input components. For example, in a RotatedPole -> PlateCarree transform, transforming (1, 0) + (0, 1) does not necessarily match transforming (1, 1).

This changes angular/geodetic-like source or target CRS cases to estimate the transformed local eastward and northward basis directions separately, then apply the resulting local rotation to the input vector components. The existing approximation is retained as a fallback for projected-to-projected and singular cases.

Implications

This improves vector directions for rotated latitude/longitude and near-pole cases used by quiver, barbs, and streamplot. The affected image baselines were updated.

The new path is slower because it uses two basis perturbations rather than one vector-direction perturbation. In local benchmarks it was about 1.5–1.8x slower for affected cases, but still sub-millisecond for typical quiver-sized fields.

Validation

  • Added regression tests for vector linearity and near-pole PlateCarree vectors.
  • Ran relevant CRS/vector/matplotlib tests: 65 passed.
  • Ran ruff check on changed Python files.

@CLAassistant

CLAassistant commented Aug 10, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@QuLogic

QuLogic commented Aug 27, 2026

Copy link
Copy Markdown
Member

@greglucas Does this relate to #1920?

@greglucas

Copy link
Copy Markdown
Contributor

Thanks for reminding me about those PRs @QuLogic, they had dropped off my radar. This PR is an improvement over #1920, but I still think it can be generalized even more and doesn't need the fallback/cutout. I've updated the other PRs I had addressing that as an alternative to this approach if anyone wants to take a look at those generalizations in #2725.

@domfrbassett

Copy link
Copy Markdown
Author

@greglucas I agree #2725 is the more general version of this fix. I’ll take a look there and see whether I can help with the remaining test/benchmark coverage, especially for the #2279 linearity case.

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.

4 participants