Skip to content

feat: port lps2sph/sph2lps coordinate transforms from MATLAB#476

Open
AmitSubhash wants to merge 1 commit into
OpenwaterHealth:mainfrom
AmitSubhash:add-lps-spherical-transforms
Open

feat: port lps2sph/sph2lps coordinate transforms from MATLAB#476
AmitSubhash wants to merge 1 commit into
OpenwaterHealth:mainfrom
AmitSubhash:add-lps-spherical-transforms

Conversation

@AmitSubhash

Copy link
Copy Markdown

Closes #463

Ports fus.seg.lps2sph and sph2lps from openwater-neuromod-software into
openlifu.geo.transforms, right next to the existing cartesian/spherical
converters. Scalar versions plus vectorized ones for arrays.

The main thing here was matching the MATLAB convention exactly: angles in
degrees, the +90 azimuth offset (0 is the anterior/nose line, increasing
toward patient-left), and phi as an elevation angle rather than the polar
angle off z. Return order follows the MATLAB ([th, phi, r] and [l, p, s]).

These are deterministic transforms with no captured fixtures, so I tested
them analytically like you suggested in the issue:

  • round-trip identity across all 8 octants, both directions
  • known values hand-derived from the MATLAB (pure-left, pure-superior, a
    45 degree case, a 3-4-5 case)
  • edge cases: r=0, on-axis points, negative coords

I also checked the outputs against Octave's cart2sph/sph2cart to be sure the
convention lines up. pytest passes locally.

Happy to move the functions if you'd rather they live somewhere else.

Port fus.seg.lps2sph and fus.seg.sph2lps from the legacy MATLAB toolbox
(opw_neuromod_sw) into openlifu.geo.transforms, with scalar and vectorized
variants matching the existing cartesian/spherical converters. Faithfully
preserves the MATLAB convention (degrees, azimuth+90 offset, elevation angle).
Adds golden-value, round-trip, edge-case (r=0), and vectorized-consistency
tests to test_geo.py.

Refs OpenwaterHealth#463
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.

Port one MATLAB calibration utility to Python (good first issue)

1 participant