Skip to content

feat(shape): add e<->g ellipticity converters#69

Merged
cailmdaley merged 3 commits into
developfrom
feature/cs_util-shape
Jul 1, 2026
Merged

feat(shape): add e<->g ellipticity converters#69
cailmdaley merged 3 commits into
developfrom
feature/cs_util-shape

Conversation

@cailmdaley

@cailmdaley cailmdaley commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

What

Adds cs_util.shape, a small module parallel to cs_util.size, as the single home for the distortion (e-type) ↔ reduced-shear (g-type) ellipticity conversion used across the UNIONS / ShapePipe stack:

g = e / (1 + sqrt(1 - e^2))      # e_to_g
e = 2 g / (1 + g^2)              # g_to_e

Both functions are component-wise (the WL-native two-component form): the two ellipticity components are scaled by the magnitude ratio, so orientation is preserved. Round objects map to round objects; the small-ellipticity limit reduces to e ≈ 2g.

No version bump. Downstream (shapepipe) will track cs_util @ develop rather than pinning a release, so new helpers like this are available without shipping a new version each time.

Why

ShapePipe's HSM moments store the distortion e while ngmix stores the reduced shear g; downstream (sp_validation) sometimes needs one given the other. Centralising the conversion here means producers and consumers import a single source of truth rather than re-deriving the factors locally — the same move that motivated cs_util.size.

This closes the converter half of Sacha Guerrini's review point on CosmoStat/shapepipe#761 (HSM is e-type, ngmix g-type — name consistently and add a converter).

Tests

cs_util/tests/test_shape.py — known q=1/3 pair (|e|=0.8 ↔ |g|=0.5), axis-ratio closed forms, component-wise round-trips, orientation preservation, zero handling, small-ellipticity limit, array shapes. All pass.

— Claude on behalf of Cail


Closes #73 — the e↔g converter single-source-of-truth (a sub-issue of the ngmix v2.0 epic CosmoStat/shapepipe#762). Linked here via the Development sidebar so the issue tracks this PR and closes when it merges.

New cs_util.shape module, parallel to cs_util.size, as the single home
for the distortion (e-type) <-> reduced-shear (g-type) conversion used
across the UNIONS / ShapePipe stack:

  g = e / (1 + sqrt(1 - e^2))      (e_to_g)
  e = 2 g / (1 + g^2)              (g_to_e)

Component-wise (the WL-native two-component form): both ellipticity
components are scaled by the magnitude ratio, preserving orientation.
Producers (ShapePipe HSM e-type vs ngmix g-type) and consumers
(sp_validation) import from here rather than re-deriving the factors.

No version bump: downstream (shapepipe) tracks cs_util @ develop rather
than pinning a release, so new helpers are available without a ship.

Closes the converter half of Sacha Guerrini's review point on
CosmoStat/shapepipe#761.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BXY93SBtDvLLrxWX8Vh4KW
@sachaguer

Copy link
Copy Markdown
Collaborator

Apparently I do not have write access to the repo. I have a commit related to this PR. @martinkilbinger can you check if I do have write access and I made a mistake when pushing and if not could you add me?

@cailmdaley

Copy link
Copy Markdown
Collaborator Author

gave you maintainer access @sachaguer

@sachaguer

Copy link
Copy Markdown
Collaborator

Thanks, the PR meets its goals. As for me, it can be merged if all the CD/CI's pass

@cailmdaley cailmdaley merged commit 8593be6 into develop Jul 1, 2026
5 checks passed
@cailmdaley cailmdaley deleted the feature/cs_util-shape branch July 1, 2026 10:53
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.

Single source of truth for e↔g ellipticity converters (cs_util.shape)

2 participants