Skip to content

Commit

Permalink
refactoring for ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuke-takase committed Nov 23, 2024
1 parent 1f06327 commit 7931a8b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
11 changes: 0 additions & 11 deletions litebird_sim/quaternions.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,17 +501,6 @@ def quat_rotation_brdcast(theta_rad, vec_matrix):
[vec_matrix * s, np.cos(theta_rad / 2) * np.ones((vec_matrix.shape[0], 1))]
)

def quat_rotation_brdcast_single_axis(theta_rad_array, vec):
"""This function rotates a quaternion by theta_rad about a specific axis.
Args:
theta_rad_array (numpy.array): The angles to rotate the quaternion by in radians.
vec (numpy.array[3]): The vector to rotate the quaternion about.
"""
s = np.sin(theta_rad_array / 2)
c = np.cos(theta_rad_array / 2)
return np.hstack(
[vec * s[:, np.newaxis], c[:, np.newaxis]]
)

def quat_rotation_x_brdcast(theta_rad_array):
"""Return a quaternion representing a rotation around the x axis
Expand Down
26 changes: 14 additions & 12 deletions litebird_sim/scanning.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,19 +483,19 @@ def __mul__(self, other: "RotQuaternion") -> "RotQuaternion":
assert (
self.quats.shape == other.quats.shape
), f"quaternions have different shapes: {self.quats.shape} vs {other.quats.shape}"
assert (
isinstance(self.start_time, type(other.start_time))
assert isinstance(
self.start_time, type(other.start_time)
), f"start_time must have the same type: {type(self.start_time)} vs {type(other.start_time)}"
if isinstance(self.start_time, float):
assert (
np.isclose(self.start_time, other.start_time)
assert np.isclose(
self.start_time, other.start_time
), f"start_time must be the same value: {self.start_time} vs {other.start_time}"
else:
assert (
self.start_time == other.start_time
), f"start_time must be the same value: {self.start_time} vs {other.start_time}"
assert (
np.isclose(self.sampling_rate_hz, other.sampling_rate_hz)
assert np.isclose(
self.sampling_rate_hz, other.sampling_rate_hz
), f"sampling_rate_hz must be the same value: {self.sampling_rate_hz} vs {other.sampling_rate_hz}"

result_start_time = self.start_time
Expand Down Expand Up @@ -540,12 +540,14 @@ def conj(self):
return RotQuaternion(
start_time=self.start_time,
sampling_rate_hz=self.sampling_rate_hz,
quats=np.array([
-self.quats[:,0],
-self.quats[:,1],
-self.quats[:,2],
self.quats[:,3]
]),
quats=np.array(
[
-self.quats[:, 0],
-self.quats[:, 1],
-self.quats[:, 2],
self.quats[:, 3],
]
),
)

def slerp(
Expand Down
12 changes: 6 additions & 6 deletions test/test_pointing_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import litebird_sim as lbs

make_reference_file = False # if True, generate reference file at `path_of_reference`.
make_reference_file = False # if True, generate reference file at `path_of_reference`.

telescopes = ["LFT", "MFT", "HFT"]
start_time = 0
Expand Down Expand Up @@ -271,7 +271,6 @@ def test_PointingSys_add_single_offset_to_spacecraft(
axis = "x"
pointing_sys.spacecraft.add_offset(single_offset, axis)


lbs.prepare_pointings(
sim.observations, sim.instrument, sim.spin2ecliptic_quats, hwp=sim.hwp
)
Expand Down Expand Up @@ -314,7 +313,6 @@ def test_PointingSys_add_common_disturb_to_spacecraft(
axis = "x"
pointing_sys.spacecraft.add_disturb(noise_rad_1d_array, axis)


lbs.prepare_pointings(
sim.observations, sim.instrument, sim.spin2ecliptic_quats, hwp=sim.hwp
)
Expand All @@ -339,6 +337,7 @@ def test_PointingSys_add_common_disturb_to_spacecraft(
atol=atol,
)


@pytest.mark.parametrize("telescope", telescopes)
def test_PointingSys_add_hwp_rot_disturb(
telescope, make_reference_file=make_reference_file
Expand All @@ -354,10 +353,11 @@ def test_PointingSys_add_hwp_rot_disturb(
wedge_angle_rad = np.deg2rad(1.0)
refractive_idx = 3.1
tilt_angle_rad = pointing_sys.hwp.get_wedgeHWP_pointing_shift_angle(
wedge_angle_rad,
refractive_idx
wedge_angle_rad, refractive_idx
)
pointing_sys.hwp.add_hwp_rot_disturb(
tilt_angle_rad, ang_speed_radpsec, tilt_phase_rad
)
pointing_sys.hwp.add_hwp_rot_disturb(tilt_angle_rad, ang_speed_radpsec, tilt_phase_rad)

lbs.prepare_pointings(
sim.observations, sim.instrument, sim.spin2ecliptic_quats, hwp=sim.hwp
Expand Down

0 comments on commit 7931a8b

Please sign in to comment.