You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by hu...@apache.org on 2015/08/19 02:29:08 UTC
[4/5] climate git commit: metrics.SpatialMeanOfTemporalMeanBias has
been restored with related test.
metrics.SpatialMeanOfTemporalMeanBias has been restored with related test.
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/b61b63e3
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/b61b63e3
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/b61b63e3
Branch: refs/heads/master
Commit: b61b63e372551e40113d1a825e94ec5c632d44a0
Parents: 055e28e
Author: huikyole <hu...@argo.jpl.nasa.gov>
Authored: Fri Aug 14 10:12:22 2015 -0700
Committer: huikyole <hu...@argo.jpl.nasa.gov>
Committed: Fri Aug 14 10:12:22 2015 -0700
----------------------------------------------------------------------
ocw/metrics.py | 18 ++++++++++++++++++
ocw/tests/test_metrics.py | 27 +++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/b61b63e3/ocw/metrics.py
----------------------------------------------------------------------
diff --git a/ocw/metrics.py b/ocw/metrics.py
index ae603c9..76fc78b 100644
--- a/ocw/metrics.py
+++ b/ocw/metrics.py
@@ -231,6 +231,24 @@ class TemporalMeanBias(BinaryMetric):
return calc_bias(target_dataset.values,ref_dataset.values, average_over_time=True)
+class SpatialMeanOfTemporalMeanBias(BinaryMetric):
+ '''Calculate the bias averaged over time and domain.'''
+
+ def run(self, reference_dataset, target_dataset):
+ '''Calculate the bias averaged over time and domain.
+ .. note::
+ Overrides BinaryMetric.run()
+ :param reference_dataset: The reference dataset to use in this metric
+ run
+ :type reference_dataset: :class:`dataset.Dataset`
+ :param target_dataset: The target dataset to evaluate against the
+ reference dataset in this metric run
+ :type target_dataset: :class:`dataset.Dataset`
+ :returns: The bias averaged over time and domain
+ '''
+
+ bias = target_dataset.values - reference_dataset.values
+ return ma.mean(bias)
class RMSError(BinaryMetric):
http://git-wip-us.apache.org/repos/asf/climate/blob/b61b63e3/ocw/tests/test_metrics.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_metrics.py b/ocw/tests/test_metrics.py
index 58cc76c..8d638be 100644
--- a/ocw/tests/test_metrics.py
+++ b/ocw/tests/test_metrics.py
@@ -229,6 +229,33 @@ class TestTemporalMeanBias(unittest.TestCase):
expected_result.fill(-300)
np.testing.assert_array_equal(self.mean_bias.run(self.target_dataset,self.reference_dataset), expected_result)
+class TestSpatialMeanOfTemporalMeanBias(unittest.TestCase):
+ '''Test the metrics.SpatialMeanOfTemporalMeanBias metric.'''
+ def setUp(self):
+ # Set metric.
+ self.metric = metrics.SpatialMeanOfTemporalMeanBias()
+ # Initialize reference dataset.
+ self.ref_lats = np.array([10, 20, 30, 40, 50])
+ self.ref_lons = np.array([5, 15, 25, 35, 45])
+ self.ref_times = np.array([dt.datetime(2000, x, 1)
+ for x in range(1, 13)])
+ self.ref_values = np.array(range(300)).reshape(12, 5, 5)
+ self.ref_variable = "ref"
+ self.ref_dataset = Dataset(self.ref_lats, self.ref_lons,
+ self.ref_times, self.ref_values, self.ref_variable)
+ # Initialize target dataset.
+ self.tgt_lats = np.array([10, 20, 30, 40, 50])
+ self.tgt_lons = np.array([5, 15, 25, 35, 45])
+ self.tgt_times = np.array([dt.datetime(2000, x, 1)
+ for x in range(1, 13)])
+ self.tgt_values = np.array(range(299, -1, -1)).reshape(12, 5, 5)
+ self.tgt_variable = "tgt"
+ self.tgt_dataset = Dataset(self.tgt_lats, self.tgt_lons,
+ self.tgt_times, self.tgt_values, self.tgt_variable)
+
+ def test_function_run(self):
+ result = self.metric.run(self.ref_dataset, self.tgt_dataset)
+ self.assertEqual(result, 0.0)
class TestRMSError(unittest.TestCase):
'''Test the metrics.RMSError metric.'''