You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by jo...@apache.org on 2014/11/06 21:51:10 UTC

[1/6] climate git commit: CLIMATE-542: Add TemporalCorrelation metric and unit tests

Repository: climate
Updated Branches:
  refs/heads/master 3e8d1bf0b -> cff5b5459


CLIMATE-542: Add TemporalCorrelation metric and unit tests


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/16578ed8
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/16578ed8
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/16578ed8

Branch: refs/heads/master
Commit: 16578ed8a42d6f5156c6803122c9434e9eb44632
Parents: 3e8d1bf
Author: rlaidlaw <rl...@gmail.com>
Authored: Wed Nov 5 17:16:40 2014 -0800
Committer: rlaidlaw <rl...@gmail.com>
Committed: Wed Nov 5 17:16:40 2014 -0800

----------------------------------------------------------------------
 ocw/metrics.py            | 35 +++++++++++++++++++++++++++++++
 ocw/tests/test_metrics.py | 47 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/16578ed8/ocw/metrics.py
----------------------------------------------------------------------
diff --git a/ocw/metrics.py b/ocw/metrics.py
index ee5c1f9..815380c 100644
--- a/ocw/metrics.py
+++ b/ocw/metrics.py
@@ -149,6 +149,41 @@ class PatternCorrelation(BinaryMetric):
         return stats.pearsonr(ref_dataset.values.flatten(), target_dataset.values.flatten())[0]
 
 
+class TemporalCorrelation(BinaryMetric):
+    '''Calculate the temporal correlation coefficients and associated
+       confidence levels between two datasets, using Pearson's correlation.'''
+
+    def run(self, reference_dataset, target_dataset):
+        '''Calculate the temporal correlation coefficients and associated
+           confidence levels between two datasets, using Pearson's correlation.
+
+        .. note::
+           Overrides BinaryMetric.run()
+
+        :param reference_dataset: The reference dataset to use in this metric
+            run
+        :type reference_dataset: ocw.dataset.Dataset object
+        :param target_dataset: The target dataset to evaluate against the
+            reference dataset in this metric run
+        :type target_dataset: ocw.dataset.Dataset object
+
+        :returns: A 2D array of temporal correlation coefficients and a 2D
+            array of confidence levels associated with the temporal correlation
+            coefficients
+        '''
+        nt, nx, ny = reference_dataset.values.shape
+        tc = numpy.zeros([nx, ny])
+        cl = numpy.zeros([nx, ny])
+        for ix in numpy.arange(nx):
+            for iy in numpy.arange(ny):
+                tc[ix, iy], cl[ix, iy] = stats.pearsonr(
+                                           reference_dataset.values[:, ix, iy],
+                                           target_dataset.values[:, ix, iy]
+                                         )
+                cl[ix, iy] = 1 - cl[ix, iy]
+        return tc, cl 
+
+
 class TemporalMeanBias(BinaryMetric):
     '''Calculate the bias averaged over time.'''
 

http://git-wip-us.apache.org/repos/asf/climate/blob/16578ed8/ocw/tests/test_metrics.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_metrics.py b/ocw/tests/test_metrics.py
index affb937..7f9bbae 100644
--- a/ocw/tests/test_metrics.py
+++ b/ocw/tests/test_metrics.py
@@ -132,6 +132,53 @@ class TestPatternCorrelation(unittest.TestCase):
         self.assertEqual(pattern, 1.0)
 
 
+class TestTemporalCorrelation(unittest.TestCase):
+    '''Test the metrics.TemporalCorrelation metric.'''
+    def setUp(self):
+        # Set metric.
+        self.metric = metrics.TemporalCorrelation()
+        # 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 datasets.
+        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_variable = "tgt"
+        self.tgt_values_inc = np.array(range(300, 600)).reshape(12, 5, 5)
+        self.tgt_values_dec = np.array(range(299, -1, -1)).reshape(12, 5, 5)
+        self.tgt_dataset_inc = Dataset(self.tgt_lats, self.tgt_lons,
+            self.tgt_times, self.tgt_values_inc, self.tgt_variable)
+        self.tgt_dataset_dec = Dataset(self.tgt_lats, self.tgt_lons,
+            self.tgt_times, self.tgt_values_dec, self.tgt_variable)
+
+    def test_temporal_correlation_identical_inputs(self):
+        expected = np.ones(25).reshape(5, 5)
+        tc, cl = self.metric.run(self.ref_dataset, self.ref_dataset)
+        np.testing.assert_array_equal(tc, expected)
+        np.testing.assert_array_equal(cl, expected)
+
+    def test_temporal_correlation_positive_correlation(self):
+        expected = np.ones(25).reshape(5, 5)
+        tc, cl = self.metric.run(self.ref_dataset, self.tgt_dataset_inc)
+        np.testing.assert_array_equal(tc, expected)
+        np.testing.assert_array_equal(cl, expected)
+
+    def test_temporal_correlation_negative_correlation(self):
+        expected_tc = np.array([-1] * 25).reshape(5, 5)
+        expected_cl = np.ones(25).reshape(5, 5)
+        tc, cl = self.metric.run(self.ref_dataset, self.tgt_dataset_dec)
+        np.testing.assert_array_equal(tc, expected_tc)
+        np.testing.assert_array_equal(cl, expected_cl)
+
+
 class TestTemporalMeanBias(unittest.TestCase):
     '''Test the metrics.TemporalMeanBias metric.'''
     def setUp(self):


[3/6] climate git commit: CLIMATE-542: Update names of test methods

Posted by jo...@apache.org.
CLIMATE-542: Update names of test methods


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/00bffd71
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/00bffd71
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/00bffd71

Branch: refs/heads/master
Commit: 00bffd71e42f57af5a163558674fccb4cc185773
Parents: e0393a1
Author: rlaidlaw <rl...@gmail.com>
Authored: Wed Nov 5 17:46:36 2014 -0800
Committer: rlaidlaw <rl...@gmail.com>
Committed: Wed Nov 5 17:46:36 2014 -0800

----------------------------------------------------------------------
 ocw/tests/test_metrics.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/00bffd71/ocw/tests/test_metrics.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_metrics.py b/ocw/tests/test_metrics.py
index 7f9bbae..571ad4d 100644
--- a/ocw/tests/test_metrics.py
+++ b/ocw/tests/test_metrics.py
@@ -159,19 +159,19 @@ class TestTemporalCorrelation(unittest.TestCase):
         self.tgt_dataset_dec = Dataset(self.tgt_lats, self.tgt_lons,
             self.tgt_times, self.tgt_values_dec, self.tgt_variable)
 
-    def test_temporal_correlation_identical_inputs(self):
+    def test_identical_inputs(self):
         expected = np.ones(25).reshape(5, 5)
         tc, cl = self.metric.run(self.ref_dataset, self.ref_dataset)
         np.testing.assert_array_equal(tc, expected)
         np.testing.assert_array_equal(cl, expected)
 
-    def test_temporal_correlation_positive_correlation(self):
+    def test_positive_correlation(self):
         expected = np.ones(25).reshape(5, 5)
         tc, cl = self.metric.run(self.ref_dataset, self.tgt_dataset_inc)
         np.testing.assert_array_equal(tc, expected)
         np.testing.assert_array_equal(cl, expected)
 
-    def test_temporal_correlation_negative_correlation(self):
+    def test_negative_correlation(self):
         expected_tc = np.array([-1] * 25).reshape(5, 5)
         expected_cl = np.ones(25).reshape(5, 5)
         tc, cl = self.metric.run(self.ref_dataset, self.tgt_dataset_dec)


[2/6] climate git commit: CLIMATE-542: Swap x and y names (lats = y axis, lons = x axis)

Posted by jo...@apache.org.
CLIMATE-542: Swap x and y names (lats = y axis, lons = x axis)


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/e0393a19
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/e0393a19
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/e0393a19

Branch: refs/heads/master
Commit: e0393a193f60bbbe1e718016a8a223ef5900eab4
Parents: 16578ed
Author: rlaidlaw <rl...@gmail.com>
Authored: Wed Nov 5 17:40:13 2014 -0800
Committer: rlaidlaw <rl...@gmail.com>
Committed: Wed Nov 5 17:40:13 2014 -0800

----------------------------------------------------------------------
 ocw/metrics.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/e0393a19/ocw/metrics.py
----------------------------------------------------------------------
diff --git a/ocw/metrics.py b/ocw/metrics.py
index 815380c..1504404 100644
--- a/ocw/metrics.py
+++ b/ocw/metrics.py
@@ -171,16 +171,16 @@ class TemporalCorrelation(BinaryMetric):
             array of confidence levels associated with the temporal correlation
             coefficients
         '''
-        nt, nx, ny = reference_dataset.values.shape
-        tc = numpy.zeros([nx, ny])
-        cl = numpy.zeros([nx, ny])
-        for ix in numpy.arange(nx):
-            for iy in numpy.arange(ny):
-                tc[ix, iy], cl[ix, iy] = stats.pearsonr(
-                                           reference_dataset.values[:, ix, iy],
-                                           target_dataset.values[:, ix, iy]
+        nt, ny, nx = reference_dataset.values.shape
+        tc = numpy.zeros([ny, nx])
+        cl = numpy.zeros([ny, nx])
+        for iy in numpy.arange(ny):
+            for ix in numpy.arange(nx):
+                tc[iy, ix], cl[iy, ix] = stats.pearsonr(
+                                           reference_dataset.values[:, iy, ix],
+                                           target_dataset.values[:, iy, ix]
                                          )
-                cl[ix, iy] = 1 - cl[ix, iy]
+                cl[iy, ix] = 1 - cl[iy, ix]
         return tc, cl 
 
 


[4/6] climate git commit: CLIMATE-542: Make variable names more meaningful

Posted by jo...@apache.org.
CLIMATE-542: Make variable names more meaningful


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/7363794b
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/7363794b
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/7363794b

Branch: refs/heads/master
Commit: 7363794bf0e3567a9e0627551e8885a00a85430a
Parents: 00bffd7
Author: rlaidlaw <rl...@gmail.com>
Authored: Thu Nov 6 12:04:37 2014 -0800
Committer: rlaidlaw <rl...@gmail.com>
Committed: Thu Nov 6 12:04:37 2014 -0800

----------------------------------------------------------------------
 ocw/metrics.py | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/7363794b/ocw/metrics.py
----------------------------------------------------------------------
diff --git a/ocw/metrics.py b/ocw/metrics.py
index 1504404..1ef5f87 100644
--- a/ocw/metrics.py
+++ b/ocw/metrics.py
@@ -171,17 +171,19 @@ class TemporalCorrelation(BinaryMetric):
             array of confidence levels associated with the temporal correlation
             coefficients
         '''
-        nt, ny, nx = reference_dataset.values.shape
-        tc = numpy.zeros([ny, nx])
-        cl = numpy.zeros([ny, nx])
-        for iy in numpy.arange(ny):
-            for ix in numpy.arange(nx):
-                tc[iy, ix], cl[iy, ix] = stats.pearsonr(
-                                           reference_dataset.values[:, iy, ix],
-                                           target_dataset.values[:, iy, ix]
-                                         )
-                cl[iy, ix] = 1 - cl[iy, ix]
-        return tc, cl 
+        nTimes, nLats, nLons = reference_dataset.values.shape
+        coefficients = numpy.zeros([nLats, nLons])
+        levels = numpy.zeros([nLats, nLons])
+        for iLats in numpy.arange(nLats):
+            for iLons in numpy.arange(nLons):
+                coefficients[iLats, iLons], levels[iLats, iLons] = (
+                    stats.pearsonr(
+                        reference_dataset.values[:, iLats, iLons],
+                        target_dataset.values[:, iLats, iLons]
+                    )
+                )
+                levels[iLats, iLons] = 1 - levels[iLats, iLons]
+        return coefficients, levels 
 
 
 class TemporalMeanBias(BinaryMetric):


[6/6] climate git commit: Resolve CLIMATE-542. Merge PR #127.

Posted by jo...@apache.org.
Resolve CLIMATE-542. Merge PR #127.


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/cff5b545
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/cff5b545
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/cff5b545

Branch: refs/heads/master
Commit: cff5b5459a400b8ba72791c3a847f153862fef75
Parents: 3e8d1bf 8859ab0
Author: Michael Joyce <jo...@apache.org>
Authored: Thu Nov 6 12:50:39 2014 -0800
Committer: Michael Joyce <jo...@apache.org>
Committed: Thu Nov 6 12:50:39 2014 -0800

----------------------------------------------------------------------
 ocw/metrics.py            | 37 +++++++++++++++++++++++++++++++++
 ocw/tests/test_metrics.py | 47 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)
----------------------------------------------------------------------



[5/6] climate git commit: CLIMATE-542: Change from camelcase to snakecase

Posted by jo...@apache.org.
CLIMATE-542: Change from camelcase to snakecase


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/8859ab0e
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/8859ab0e
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/8859ab0e

Branch: refs/heads/master
Commit: 8859ab0ebde89851fc498708609695a5e2c76d96
Parents: 7363794
Author: rlaidlaw <rl...@gmail.com>
Authored: Thu Nov 6 12:15:48 2014 -0800
Committer: rlaidlaw <rl...@gmail.com>
Committed: Thu Nov 6 12:15:48 2014 -0800

----------------------------------------------------------------------
 ocw/metrics.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/8859ab0e/ocw/metrics.py
----------------------------------------------------------------------
diff --git a/ocw/metrics.py b/ocw/metrics.py
index 1ef5f87..5c99e3e 100644
--- a/ocw/metrics.py
+++ b/ocw/metrics.py
@@ -171,18 +171,18 @@ class TemporalCorrelation(BinaryMetric):
             array of confidence levels associated with the temporal correlation
             coefficients
         '''
-        nTimes, nLats, nLons = reference_dataset.values.shape
-        coefficients = numpy.zeros([nLats, nLons])
-        levels = numpy.zeros([nLats, nLons])
-        for iLats in numpy.arange(nLats):
-            for iLons in numpy.arange(nLons):
-                coefficients[iLats, iLons], levels[iLats, iLons] = (
+        num_times, num_lats, num_lons = reference_dataset.values.shape
+        coefficients = numpy.zeros([num_lats, num_lons])
+        levels = numpy.zeros([num_lats, num_lons])
+        for i in numpy.arange(num_lats):
+            for j in numpy.arange(num_lons):
+                coefficients[i, j], levels[i, j] = (
                     stats.pearsonr(
-                        reference_dataset.values[:, iLats, iLons],
-                        target_dataset.values[:, iLats, iLons]
+                        reference_dataset.values[:, i, j],
+                        target_dataset.values[:, i, j]
                     )
                 )
-                levels[iLats, iLons] = 1 - levels[iLats, iLons]
+                levels[i, j] = 1 - levels[i, j]
         return coefficients, levels