Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tukiains committed Mar 28, 2024
1 parent 0a3d320 commit 54802cc
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions tests/test_get_ret_coeff_nc.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -117,13 +118,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":
Expand Down Expand Up @@ -176,13 +177,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":
Expand Down Expand Up @@ -237,7 +238,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":
Expand Down Expand Up @@ -308,13 +309,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":
Expand Down Expand Up @@ -360,7 +361,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)

Expand All @@ -377,11 +380,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])
Expand Down

0 comments on commit 54802cc

Please sign in to comment.