Repository: climate Updated Branches: refs/heads/master 2b71d0b9e -> f4d39668b
CLIMATE-483 - Add basic PatternCorrelation metric - Rename old PatternCorrelation metric to TemporalPatternCorrelation since it does an annual reshaping of the datasets before doing a comparison and that isn't adequately reflected in the metric's name. The new name also falls in line with the functionality of the TemporalStdDevRatio metric which also does such a rebin. - Add basic PatternCorrelation metric that uses scipy.stats.pearsonr to return the r_value for the reference and target datasets. Note, the metric no longer returns a tuple of values. It now only returns the r_value. This falls much more in line with the metrics name in my opinion. Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/4a5f3810 Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/4a5f3810 Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/4a5f3810 Branch: refs/heads/master Commit: 4a5f3810f1bbb937baad2c5f98a8d45976211792 Parents: 9b6d73d Author: Michael Joyce <[email protected]> Authored: Wed Jul 2 08:10:40 2014 -0700 Committer: Michael Joyce <[email protected]> Committed: Wed Jul 2 09:17:59 2014 -0700 ---------------------------------------------------------------------- ocw/metrics.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/4a5f3810/ocw/metrics.py ---------------------------------------------------------------------- diff --git a/ocw/metrics.py b/ocw/metrics.py index d040c11..3c400a7 100644 --- a/ocw/metrics.py +++ b/ocw/metrics.py @@ -141,6 +141,29 @@ class SpatialStdDevRatio(BinaryMetric): class PatternCorrelation(BinaryMetric): + '''Calculate the correlation coefficient between two datasets''' + + def run(self, ref_dataset, target_dataset): + '''Calculate the correlation coefficient between two dataset. + + .. note:: + Overrides BinaryMetric.run() + + :param ref_dataset: The reference dataset to use in this metric run. + :type ref_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: The correlation coefficient between a reference and target dataset. + ''' + # stats.pearsonr returns correlation_coefficient, 2-tailed p-value + # We only care about the correlation coefficient + # Docs at http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.pearsonr.html + return stats.pearsonr(ref_dataset.values.flatten(), target_dataset.values.flatten())[0] + + +class TemporalPatternCorrelation(BinaryMetric): '''Calculate the spatial correlation''' def run(self, ref_dataset, target_dataset):
