Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Add a unit test for Absolute Bias
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekiiest authored Jun 27, 2018
1 parent 8104a2b commit 0307574
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions ocw/tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 0307574

Please sign in to comment.