climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From huiky...@apache.org
Subject [3/5] climate git commit: Debugging: metrics.py
Date Wed, 19 Aug 2015 00:29:07 GMT
Debugging: metrics.py


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

Branch: refs/heads/master
Commit: 055e28e89f5caf9515844a8f70975692aa8de23f
Parents: 788e466
Author: huikyole <huikyole@argo.jpl.nasa.gov>
Authored: Wed Aug 12 00:40:30 2015 -0700
Committer: huikyole <huikyole@argo.jpl.nasa.gov>
Committed: Wed Aug 12 00:40:30 2015 -0700

----------------------------------------------------------------------
 ocw/metrics.py            | 15 ++++++---------
 ocw/tests/test_metrics.py |  5 +++--
 2 files changed, 9 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/055e28e8/ocw/metrics.py
----------------------------------------------------------------------
diff --git a/ocw/metrics.py b/ocw/metrics.py
index 3391ec1..ae603c9 100644
--- a/ocw/metrics.py
+++ b/ocw/metrics.py
@@ -108,10 +108,7 @@ class SpatialPatternTaylorDiagram(BinaryMetric):
         :returns: standard deviation ratio, pattern correlation coefficient
         :rtype: :float:'float','float' 
         '''
-        if ref_dataset.values.ndim >= 3 and target_dataset.values.ndim >= 3:
-            return calc_stddev_ratio(ref_dataset.values, target_dataset.values), calc_correlation(ref_dataset.values,
target_dataset.values)
-        else:
-            print 'Please check if both reference and target datasets have time dimensions'

+        return ma.array([calc_stddev_ratio(target_dataset.values, ref_dataset.values), calc_correlation(target_dataset.values,
ref_dataset.values)])
 
 
 class TemporalStdDev(UnaryMetric):
@@ -152,7 +149,7 @@ class StdDevRatio(BinaryMetric):
         :returns: The standard deviation ratio of the reference and target
         '''
        
-        return calc_stddev_ratio(ref_dataset.values, target_dataset.values)
+        return calc_stddev_ratio(target_dataset.values, ref_dataset.values)
 
 
 class PatternCorrelation(BinaryMetric):
@@ -177,7 +174,7 @@ class PatternCorrelation(BinaryMetric):
         # We only care about the correlation coefficient
         # Docs at http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.pearsonr.html
 
-        return calc_correlation(ref_dataset.values, target_dataset.values)
+        return calc_correlation(target_dataset.values, ref_dataset.values)
 
 
 class TemporalCorrelation(BinaryMetric):
@@ -208,8 +205,8 @@ class TemporalCorrelation(BinaryMetric):
         for i in numpy.arange(num_lats):
             for j in numpy.arange(num_lons):
                 coefficients[i, j] = calc_correlation(
-                        reference_dataset.values[:, i, j],
-                        target_dataset.values[:, i, j])
+                        target_dataset.values[:, i, j],
+                        reference_dataset.values[:, i, j])
         return coefficients 
 
 
@@ -314,7 +311,7 @@ def calc_stddev_ratio(target_array, reference_array):
     :type average_over_time: 'bool'
 
     :returns: (standard deviation of target_array)/(standard deviation of reference array)
-    :rtype: :class:'numpy.ma.core.MaskedArray'
+    :rtype: :class:'float'
     '''
 
     return calc_stddev(target_array)/calc_stddev(reference_array)

http://git-wip-us.apache.org/repos/asf/climate/blob/055e28e8/ocw/tests/test_metrics.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_metrics.py b/ocw/tests/test_metrics.py
index b61f9da..58cc76c 100644
--- a/ocw/tests/test_metrics.py
+++ b/ocw/tests/test_metrics.py
@@ -24,6 +24,7 @@ from ocw.dataset import Dataset
 import ocw.metrics as metrics
 
 import numpy as np
+import numpy.ma as ma
 import numpy.testing as npt
 
 class TestBias(unittest.TestCase):
@@ -79,7 +80,7 @@ class TestSpatialPatternTaylorDiagram(unittest.TestCase):
         )
 
     def test_function_run(self):
-        self.assertTrue(self.taylor_diagram.run(self.ref_dataset, self.tar_dataset), [2.5,1.0])
+        np.testing.assert_array_equal(self.taylor_diagram.run(self.ref_dataset, self.tar_dataset),
ma.array([0.4,1.0]))
 
 class TestTemporalStdDev(unittest.TestCase):
     '''Test the metrics.TemporalStdDev metric.'''
@@ -126,7 +127,7 @@ class TestStdDevRatio(unittest.TestCase):
         )
 
     def test_function_run(self):
-        self.assertTrue(self.std_dev_ratio.run(self.ref_dataset, self.tar_dataset), 2.5)
+        self.assertTrue(self.std_dev_ratio.run(self.ref_dataset, self.tar_dataset), 0.4)
 
 
 class TestPatternCorrelation(unittest.TestCase):


Mime
View raw message