Return-Path: X-Original-To: apmail-climate-commits-archive@minotaur.apache.org Delivered-To: apmail-climate-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 637B818EF5 for ; Wed, 19 Aug 2015 00:29:06 +0000 (UTC) Received: (qmail 65114 invoked by uid 500); 19 Aug 2015 00:29:06 -0000 Delivered-To: apmail-climate-commits-archive@climate.apache.org Received: (qmail 65076 invoked by uid 500); 19 Aug 2015 00:29:06 -0000 Mailing-List: contact commits-help@climate.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@climate.apache.org Delivered-To: mailing list commits@climate.apache.org Received: (qmail 65011 invoked by uid 99); 19 Aug 2015 00:29:06 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Aug 2015 00:29:06 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F2FE8E0974; Wed, 19 Aug 2015 00:29:05 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: huikyole@apache.org To: commits@climate.apache.org Date: Wed, 19 Aug 2015 00:29:08 -0000 Message-Id: <7ad50d83c4cd46afbc370c1dd271e0d6@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Fri Aug 14 10:12:22 2015 -0700 Committer: huikyole 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.'''