diff --git a/ocw/tests/test_metrics.py b/ocw/tests/test_metrics.py index ac786e54..2257112f 100644 --- a/ocw/tests/test_metrics.py +++ b/ocw/tests/test_metrics.py @@ -66,6 +66,46 @@ def test_function_run(self): expected_result.fill(-300) np.testing.assert_array_equal(self.bias.run( self.target_dataset, self.reference_dataset), expected_result) + + +class TestAbsoluteBias(unittest.TestCase): + '''Test the metrics.Bias metric.''' + + def setUp(self): + self.bias = metrics.AbsoluteBias() + # Initialize reference dataset + self.reference_lat = np.array([10, 12, 14, 16, 18]) + self.reference_lon = np.array([100, 102, 104, 106, 108]) + self.reference_time = np.array( + [dt.datetime(2000, x, 1) for x in range(1, 13)]) + flat_array = np.array(range(300)) + self.reference_value = flat_array.reshape(12, 5, 5) + self.reference_variable = 'prec' + self.reference_dataset = Dataset(self.reference_lat, + self.reference_lon, + self.reference_time, + self.reference_value, + self.reference_variable) + # Initialize target dataset + self.target_lat = np.array([1, 2, 4, 6, 8]) + self.target_lon = np.array([10, 12, 14, 16, 18]) + self.target_time = np.array( + [dt.datetime(2001, x, 1) for x in range(1, 13)]) + flat_array = np.array(range(300, 600)) + self.target_value = flat_array.reshape(12, 5, 5) + self.target_variable = 'tasmax' + self.target_dataset = Dataset(self.target_lat, + self.target_lon, + self.target_time, + self.target_value, + self.target_variable) + + def test_function_run(self): + '''Test bias function between reference dataset and target dataset.''' + expected_result = np.zeros((12, 5, 5), dtype=np.int) + expected_result.fill(300) + np.testing.assert_array_equal(self.bias.run( + self.target_dataset, self.reference_dataset), expected_result) class TestSpatialPatternTaylorDiagram(unittest.TestCase):