diff --git a/tests/test_get_ret_coeff.py b/tests/test_get_ret_coeff.py index 2dc5cab..07735bc 100644 --- a/tests/test_get_ret_coeff.py +++ b/tests/test_get_ret_coeff.py @@ -44,6 +44,8 @@ def test_coefficients(): "W2": ((-10.072118, -9.450926, -2.7468667), (19, 10)), "RM": ((0.00434408, 0.19351903, 0.041093733), (19, 1)), "FR_BL": ((23.04, 58.0, 41.699997), (13,)), + "retrieval_elevation_angles": ((90.0, 4.199999, 27.473684), (19,)), + "retrieval_frequencies": ((23.04, 58.0, 41.69999), (13,)), }, "iwv": { "DY": ((1, 1, 1), (1,)), @@ -64,6 +66,8 @@ def test_coefficients(): "W2": ((-8.668256, 10.204778, -3.7813265), (19, 10)), "RM": ((0.088511630, 3.4751670360, 0.7352865), (19, 1)), "FR_BL": ((23.04, 58.0, 41.699997), (13,)), + "retrieval_elevation_angles": ((90.0, 4.199999, 27.473684), (19,)), + "retrieval_frequencies": ((23.04, 58.0, 41.69999), (13,)), }, "tpt": { "DY": ((1, 1, 1), (1,)), @@ -85,6 +89,8 @@ def test_coefficients(): "W2": ((6.22275257, 1.43107211, -1.814291954), (93, 13, 1)), "RM": ((2.035391330, 3.3711481, 1.282065437), (93, 1)), "FR_BL": ((23.04, 58.0, 41.699997), (13,)), + "retrieval_elevation_angles": ((90.0, 90, 90), (1,)), + "retrieval_frequencies": ((23.04, 58.0, 41.69999), (13,)), }, "tpb": { "DY": ((1, 1, 1), (1,)), @@ -106,6 +112,8 @@ def test_coefficients(): "W2": ((4.33258, -0.72129, -1.55458), (93, 16)), "RM": ((0.8922356963, 3.0863358, 1.051631445), (93, 1)), "FR_BL": ((23.04, 58.0, 41.699997), (13,)), + "retrieval_elevation_angles": ((90.0, 4.199999, 19.44), (10,)), + "retrieval_frequencies": ((23.04, 58.0, 41.699997), (13,)), }, "hpt": { "DY": ((1, 1, 1), (1,)), @@ -127,6 +135,8 @@ def test_coefficients(): "W2": ((-6.617764472961, -5.96833944320, -4.42309951782), (93, 10, 1)), "RM": ((0.783515751, 0.00679313, 0.440780830021), (93, 1)), "FR_BL": ((23.04, 58.0, 41.699997), (13,)), + "retrieval_elevation_angles": ((90.0, 90, 90), (1,)), + "retrieval_frequencies": ((23.04, 58.0, 41.69999), (13,)), }, } @@ -150,11 +160,16 @@ def test_coefficients(): first, last, mean = item[name][0] shape = item[name][1] # print(key, name, first, last, mean, shape) - _check(value, float(first), float(last), float(mean), shape=shape) + _check(name, value, float(first), float(last), float(mean), shape=shape) def _check( - data: np.ndarray, first: float, last: float, mean_value: float, shape: tuple + key: str, + data: np.ndarray, + first: float, + last: float, + mean_value: float, + shape: tuple, ): assert data.ndim in (1, 2, 3) if data.ndim == 1: @@ -169,6 +184,9 @@ def _check( if isinstance(first_value, str): return + + # print(key, f"{first_value}, {last_value}, {np.mean(data)}, {first}, {last}, {mean_value}, {shape}, {data.shape}") + assert_array_almost_equal(first_value, first, decimal=4) assert_array_almost_equal(last_value, last, decimal=4) assert_array_almost_equal(np.mean(data), mean_value, decimal=4) diff --git a/tests/test_get_ret_coeff_nc.py b/tests/test_get_ret_coeff_nc.py index f2ab8a5..8026727 100644 --- a/tests/test_get_ret_coeff_nc.py +++ b/tests/test_get_ret_coeff_nc.py @@ -1,4 +1,5 @@ import numpy as np +from numpy import ma from numpy.testing import assert_array_almost_equal from mwrpy.level2.get_ret_coeff import get_mvr_coeff @@ -51,13 +52,13 @@ def test_lwp_coefficients(self): case "DY" | "PS" | "DB" | "RB": data = (1, 1, 1) case "RT": - data = (-99, -99, -99) + data = (-1, -1, -1) case "VN": data = (110, 110, 110) case "ND": data = (9, 4, 6.5) case "FR": - data = (22.239999771118164, -999.0, -486.6399999346052) + data = (22.239999771118164, ma.masked, 25.72000013) case "AG": data = (90, 90, 90) case "NP": @@ -88,6 +89,10 @@ def test_lwp_coefficients(self): -0.15209339559078217, -0.15209339559078217, ) + case "retrieval_elevation_angles": + data = (90, 90, 90) + case "retrieval_frequencies": + data = (22.23999, 31.39999, 25.719999) case _: self._print_test_data(key) raise ValueError(f"Unknown key: {key}") @@ -117,13 +122,13 @@ def test_iwv_coeffecients(self): case "RP" | "DB" | "PS" | "DY": data = (1, 1, 1) case "RT": - data = (-99, -99, -99) + data = (-1, -1, -1) case "VN": data = (110, 110, 110) case "ND": data = (9, 4, 6.5) case "FR": - data = (22.239999771118164, -999.0, -486.6399999346052) + data = (22.239999771118164, ma.masked, 25.720000) case "AG": data = (90, 90, 90) case "NP": @@ -154,6 +159,10 @@ def test_iwv_coeffecients(self): -0.5454273819923401, -0.5454273819923401, ) + case "retrieval_elevation_angles": + data = (90, 90, 90) + case "retrieval_frequencies": + data = (22.23999, 31.39999, 25.719999) case _: self._print_test_data(key) raise ValueError(f"Unknown key: {key}") @@ -176,13 +185,13 @@ def test_tpt_coefficients(self): case "RP": data = (4, 4, 4) case "RT": - data = (-99, -99, -99) + data = (-1, -1, -1) case "VN": data = (110, 110, 110) case "ND": data = (12, 4, 8) case "FR": - data = (-999.0, 58.0, -472.05000032697404) + data = (ma.masked, 58.0, 54.89999) case "AG": data = (90, 90, 90) case "NP": @@ -215,6 +224,10 @@ def test_tpt_coefficients(self): data = (-119.42852020263672, 1605.0447998046875, -8.820448498393214) case "n_height_grid": data = (43, 43, 43) + case "retrieval_elevation_angles": + data = (90, 90, 90) + case "retrieval_frequencies": + data = (51.2599, 58.0, 54.89999) case _: self._print_test_data(key) raise ValueError(f"Unknown key: {key}") @@ -237,7 +250,7 @@ def test_tpb_coefficients(self): case "RP": data = (5, 5, 5) case "RT": - data = (-99, -99, -99) + data = (-1, -1, -1) case "VN": data = (110, 110, 110) case "ND": @@ -286,6 +299,10 @@ def test_tpb_coefficients(self): -0.13281039893627167, 0.03465010225772858, ) + case "retrieval_elevation_angles": + data = (5.4, 90, 32.8) + case "retrieval_frequencies": + data = (51.25999, 58.0, 54.89999) case _: self._print_test_data(key) raise ValueError(f"Unknown key: {key}") @@ -308,13 +325,13 @@ def test_hpt_coefficients(self): case "RP": data = (3, 3, 3) case "RT": - data = (-99, -99, -99) + data = (-1, -1, -1) case "VN": data = (110, 110, 110) case "ND": data = (9, 4, 6.5) case "FR": - data = (22.239999771118164, -999.0, -486.6399999346052) + data = (22.239999771118164, ma.masked, 25.720000) case "AG": data = (90.0, 90, 90) case "NP": @@ -351,6 +368,10 @@ def test_hpt_coefficients(self): ) case "n_height_grid": data = (43, 43, 43) + case "retrieval_elevation_angles": + data = (90, 90, 90) + case "retrieval_frequencies": + data = (22.23999, 31.39999, 25.719999) case _: self._print_test_data(key) raise ValueError(f"Unknown key: {key}") @@ -360,7 +381,9 @@ def test_hpt_coefficients(self): def _check( self, key: str, first: float = 0, last: float = 0, mean_value: float = 0 ): - item = np.array(self.coeff[key]) + item = self.coeff[key] + if not isinstance(item, np.ndarray): + item = np.array(item) assert item.ndim in (0, 1, 2, 3) @@ -377,11 +400,18 @@ def _check( first_value = item[0, 0, 0] last_value = item[-1, -1, -1] - # print(key, f"{first_value}, {last_value}, {np.mean(item)}") + print(key, f"{first_value}, {last_value}, {ma.mean(item)}") + + if not ma.is_masked(first): + assert_array_almost_equal(first_value, first, decimal=4) + else: + assert ma.is_masked(first_value) + if not ma.is_masked(last): + assert_array_almost_equal(last_value, last, decimal=4) + else: + assert ma.is_masked(last_value) - assert_array_almost_equal(first_value, first, decimal=4) - assert_array_almost_equal(last_value, last, decimal=4) - assert_array_almost_equal(np.mean(item), mean_value, decimal=4) + assert_array_almost_equal(ma.mean(item), mean_value, decimal=4) def _print_test_data(self, key: str): item = np.array(self.coeff[key])