Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update quaternions to prevent sign flipping #623

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ release.
- Fixed incorrect distortion look up in Orex camera when working with PolyCam images [#583](https://github.com/DOI-USGS/ale/pull/583)
- Brought timing in line with ISIS for the KaguyaMiIsisLabelNaifSpiceDriver [#599](https://github.com/DOI-USGS/ale/pull/599)
- Brought timing in line with ISIS for the MroMarciIsisLabelNaifSpiceDriver [#600](https://github.com/DOI-USGS/ale/pull/600)
- Fixed a bug in which quaternions would flip sign in a way that caused interpolation errors [#603](https://github.com/DOI-USGS/ale/issues/603)

## [0.10.0] - 2024-01-08

Expand Down
22 changes: 21 additions & 1 deletion ale/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,27 @@ def quats(self):
the destination reference frame. The quaternions are in scalar
last format (x, y, z, w).
"""
return self._rots.as_quat()
quats = self._rots.as_quat()

# First find the largest magnitude quaternion coefficient and its coordinate
num_quats = len(quats)
max_q = 0.0
max_j = 0
for i in range(num_quats):
for j in range(4):
if abs(quats[i][j]) > abs(max_q):
max_q = quats[i][j]
max_j = j

# Ensure the signs are consistent
qcnt = 0
for i in range(num_quats):
if quats[i][max_j] * max_q < 0:
qcnt = qcnt + 1
for j in range(4):
quats[i][j] *= -1.0

return quats

@quats.setter
def quats(self, new_quats):
Expand Down
8 changes: 4 additions & 4 deletions tests/pytests/data/isds/dawnvir_isd.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@
],
"quaternions": [
[
-0.08339426680875163,
0.2825790922154143,
-0.2899354389711647,
0.9105667982826637
0.08339426680875163,
-0.2825790922154143,
0.2899354389711647,
-0.9105667982826637
],
[
-0.05753008804150366,
Expand Down
Loading