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 3940E11E5F for ; Wed, 11 Jun 2014 15:10:25 +0000 (UTC) Received: (qmail 43885 invoked by uid 500); 11 Jun 2014 15:10:25 -0000 Delivered-To: apmail-climate-commits-archive@climate.apache.org Received: (qmail 43850 invoked by uid 500); 11 Jun 2014 15:10:25 -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 43829 invoked by uid 99); 11 Jun 2014 15:10:25 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Jun 2014 15:10:25 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id CEF6492785A; Wed, 11 Jun 2014 15:10:24 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: joyce@apache.org To: commits@climate.apache.org Date: Wed, 11 Jun 2014 15:10:24 -0000 Message-Id: <3cdc13eb25ca484daee3fd023961dc81@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: CLIMATE-471 - Add seasonal std dev ratio and pattern corr metrics Repository: climate Updated Branches: refs/heads/master 41d4d0751 -> cbe10b793 CLIMATE-471 - Add seasonal std dev ratio and pattern corr metrics - Add seasonally averaged SpatialStdDevRatio and SeasonalPatternCorrelation metrics. - Note, these metrics need to have tests added for them. Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/18c941cd Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/18c941cd Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/18c941cd Branch: refs/heads/master Commit: 18c941cdde87b49bee124717a93a391db1c9076b Parents: 8b84418 Author: Michael Joyce Authored: Tue Jun 10 21:08:49 2014 -0700 Committer: Michael Joyce Committed: Tue Jun 10 21:08:49 2014 -0700 ---------------------------------------------------------------------- ocw/metrics.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/18c941cd/ocw/metrics.py ---------------------------------------------------------------------- diff --git a/ocw/metrics.py b/ocw/metrics.py index d85caec..b31cd66 100644 --- a/ocw/metrics.py +++ b/ocw/metrics.py @@ -194,3 +194,61 @@ class MeanBias(BinaryMetric): return mean_bias +class SeasonalSpatialStdDevRatio(BinaryMetric): + '''Calculate the ratio of spatial standard deviation (model standard + deviation)/(observed standard deviation)''' + + def __init__(self, month_start=1, month_end=12): + self.month_start = month_start + self.month_end = month_end + + def run(self, ref_dataset, target_dataset): + '''Calculate the ratio of spatial std. dev. between a reference and + target dataset. + + .. note:: + Overrides BinaryMetric.run() + + :param ref_dataset: The reference dataset to use in this metric run. + :type ref_dataset: Dataset. + :param target_dataset: The target dataset to evaluate against the + reference dataset in this metric run. + :type target_dataset: Dataset. + + :returns: The ratio of standard deviation of the reference and target + dataset. + ''' + + ref_t_series, ref_means = utils.calc_climatology_season(self.month_start, self.month_end, ref_dataset) + target_t_series, target_means = utils.calc_climatology_season(self.month_start, self.month_end, target_dataset) + + return numpy.std(ref_means) / numpy.std(target_means) + + +class SeasonalPatternCorrelation(BinaryMetric): + '''Calculate the spatial correlation''' + + def __init__(self, month_start=1, month_end=12): + self.month_start = month_start + self.month_end = month_end + + def run(self, ref_dataset, target_dataset): + '''Calculate the spatial correlation between a reference and target dataset. + Using: scipy.stats.pearsonr + + .. note:: + Overrides BinaryMetric.run() + + :param ref_dataset: The reference dataset to use in this metric run. + :type ref_dataset: Dataset. + :param target_dataset: The target dataset to evaluate against the + reference dataset in this metric run. + :type target_dataset: Dataset. + + :returns: The spatial correlation between a reference and target dataset. + ''' + ref_t_series, ref_means = utils.calc_climatology_season(self.month_start, self.month_end, ref_dataset) + target_t_series, target_means = utils.calc_climatology_season(self.month_start, self.month_end, target_dataset) + + pattern_correlation, p_value = stats.pearsonr(target_means.flatten(),ref_means.flatten()) + return pattern_correlation, p_value