Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Add a unit test for Absolute Bias
  • Loading branch information
prateekiiest committed Jun 27, 2018
1 parent 8104a2b commit 0307574133ff50d8f7f019cf867aa8a2fa2c6bd1
Showing 1 changed file with 40 additions and 0 deletions.
@@ -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):

0 comments on commit 0307574

Please sign in to comment.