|
| 1 | +import math |
1 | 2 | import unittest |
| 3 | +from datetime import datetime |
| 4 | +from unittest.mock import patch |
2 | 5 |
|
3 | 6 | import numpy as np |
4 | 7 |
|
5 | 8 | from imap_processing.swe.l3.science.moment_calculations import compute_maxwellian_weight_factors, \ |
6 | | - filter_and_flatten_regress_parameters, regress, calculate_fit_temperature_density_velocity |
| 9 | + filter_and_flatten_regress_parameters, regress, calculate_fit_temperature_density_velocity, rotate_temperature, \ |
| 10 | + rotate_dps_vector_to_rtn |
7 | 11 | from tests.test_helpers import get_test_data_path |
8 | 12 |
|
9 | 13 |
|
@@ -139,3 +143,44 @@ def test_filter_and_flatten_regress_parameters(self): |
139 | 143 | np.testing.assert_array_equal(vectors, [[3, 0, 0], [4, 0, 0], [10, 0, 0], [10, 0, 0], [0, 0, 0]]) |
140 | 144 | np.testing.assert_array_equal(actual_weights, [3, 1e-36, 10, 11, 12]) |
141 | 145 | np.testing.assert_array_equal(yreg, [np.log(3), -80.6, np.log(10), np.log(11), np.log(12)]) |
| 146 | + |
| 147 | + @patch('spiceypy.spiceypy.pxform') |
| 148 | + @patch('spiceypy.spiceypy.datetime2et') |
| 149 | + def test_rotate_dps_vector_to_rtn(self, mock_datetime2et, mock_pxform): |
| 150 | + epoch = datetime(year=2020, month=3, day=10) |
| 151 | + dsp_vector = np.array([0, 1, 0]) |
| 152 | + rotation_matrix = np.array([[0, 0, 1], [1, 0, 0], [0, 1, 0]]) |
| 153 | + mock_pxform.return_value = rotation_matrix |
| 154 | + |
| 155 | + rtn_vector = rotate_dps_vector_to_rtn(epoch, dsp_vector) |
| 156 | + mock_datetime2et.assert_called_once_with(epoch) |
| 157 | + |
| 158 | + mock_pxform.assert_called_once_with("IMAP_DPS", "IMAP_RTN", mock_datetime2et.return_value) |
| 159 | + |
| 160 | + np.testing.assert_array_equal(rtn_vector, rotation_matrix @ dsp_vector) |
| 161 | + |
| 162 | + @patch('spiceypy.spiceypy.pxform') |
| 163 | + @patch('spiceypy.spiceypy.datetime2et') |
| 164 | + def test_rotate_temperature(self, mock_datetime2et, mock_pxform): |
| 165 | + epoch = datetime(year=2020, month=3, day=11) |
| 166 | + temperature_alpha = math.pi / 4 |
| 167 | + temperature_beta = math.pi / 8 |
| 168 | + |
| 169 | + rotation_matrix = np.array([[0, 0, 1], [1, 0, 0], [0, 1, 0]]) |
| 170 | + mock_pxform.return_value = rotation_matrix |
| 171 | + |
| 172 | + theta, phi = rotate_temperature(epoch, temperature_alpha, temperature_beta) |
| 173 | + mock_datetime2et.assert_called_once_with(epoch) |
| 174 | + |
| 175 | + mock_pxform.assert_called_once_with("IMAP_DPS", "IMAP_RTN", mock_datetime2et.return_value) |
| 176 | + |
| 177 | + sin_dec = np.sin(temperature_beta) |
| 178 | + x = sin_dec * np.cos(temperature_alpha) |
| 179 | + y = sin_dec * np.sin(temperature_alpha) |
| 180 | + z = np.cos(temperature_beta) |
| 181 | + |
| 182 | + expected_rtn_temperature = rotation_matrix @ np.array([x, y, z]) |
| 183 | + expected_rtn_temperature /= np.linalg.norm(expected_rtn_temperature) |
| 184 | + |
| 185 | + self.assertEqual(np.asin(expected_rtn_temperature[2]), phi) |
| 186 | + self.assertEqual(np.atan2(expected_rtn_temperature[1], expected_rtn_temperature[0]), theta) |
0 commit comments