Skip to content

Commit

Permalink
🎨 Replace rotation matrix variables by a numpy array
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed May 16, 2024
1 parent 8a4952c commit b85d55a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extend-select = ["E", "W", "YTT", "ASYNC", "BLE", "B", "A",
"PTH", "TD", "ERA", "PL", "PERF", "RUF", "ARG",
"ANN", "D"
]
ignore = ["ISC001", "ANN101", "D203", "D213", "D100", "D105", "PLR0913"]
ignore = ["ISC001", "ANN101", "D203", "D213", "D100", "D105"]

[tool.ruff.lint.pydocstyle]
convention = "numpy"
Expand Down
33 changes: 10 additions & 23 deletions src/ipyaladin/region_converter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import math

import numpy as np

try:
from regions import (
RectangleSkyRegion,
Expand Down Expand Up @@ -37,25 +39,9 @@ class RefToLocalRotMatrix:

def __init__(
self,
r11: float,
r12: float,
r13: float,
r21: float,
r22: float,
r23: float,
r31: float,
r32: float,
r33: float,
rotation_matrix: np.ndarray,
) -> None:
self.r11 = r11
self.r12 = r12
self.r13 = r13
self.r21 = r21
self.r22 = r22
self.r23 = r23
self.r31 = r31
self.r32 = r32
self.r33 = r33
self.rotation_matrix = rotation_matrix

@classmethod
def from_center(cls: any, lon: float, lat: float) -> "RefToLocalRotMatrix":
Expand All @@ -76,7 +62,9 @@ def from_center(cls: any, lon: float, lat: float) -> "RefToLocalRotMatrix":
"""
ca, sa = math.cos(lon), math.sin(lon)
cd, sd = math.cos(lat), math.sin(lat)
return cls(ca * cd, sa * cd, sd, -sa, ca, 0.0, -ca * sd, -sa * sd, cd)
return cls(
np.array([[ca * cd, sa * cd, sd], [-sa, ca, 0.0], [-ca * sd, -sa * sd, cd]])
)

def to_global_xyz(self, x: float, y: float, z: float) -> tuple[float, float, float]:
"""Convert local cartesian coordinates to global cartesian coordinates.
Expand All @@ -96,11 +84,10 @@ def to_global_xyz(self, x: float, y: float, z: float) -> tuple[float, float, flo
The x, y, and z coordinates.
"""
return (
self.r11 * x + self.r21 * y + self.r31 * z,
self.r12 * x + self.r22 * y + self.r32 * z,
self.r13 * x + self.r23 * y + self.r33 * z,
rotated_matrix = np.sum(
np.multiply(self.rotation_matrix, np.array([[x], [y], [z]])), axis=0
)
return rotated_matrix[0], rotated_matrix[1], rotated_matrix[2]

def to_global_coo(self, x: float, y: float, z: float) -> tuple[float, float]:
"""Convert local cartesian coordinates to global spherical coordinates.
Expand Down

0 comments on commit b85d55a

Please sign in to comment.