Repository: climate Updated Branches: refs/heads/master 2a0a56951 -> b8c3503c7
CLIMATE-464 - move clacClimSeason to utils Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/3e163f3e Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/3e163f3e Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/3e163f3e Branch: refs/heads/master Commit: 3e163f3e2434b7d8d8be772c1ab5bf025a453d81 Parents: 8b84418 Author: Shakeh <[email protected]> Authored: Thu Jun 5 14:33:16 2014 -0700 Committer: Shakeh <[email protected]> Committed: Wed Jun 11 09:34:19 2014 -0400 ---------------------------------------------------------------------- ocw/utils.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/3e163f3e/ocw/utils.py ---------------------------------------------------------------------- diff --git a/ocw/utils.py b/ocw/utils.py index 38a399f..a1edeac 100644 --- a/ocw/utils.py +++ b/ocw/utils.py @@ -271,3 +271,34 @@ def calc_climatology_year(dataset): total_mean = annually_mean.mean(axis=0) return annually_mean, total_mean + +def calc_climatology_season(month_start, month_end, dataset): + ''' Calculate seasonal mean and time series for given months. + + :param month_start: An integer for beginning month (Jan=1) + :type month_start: Integer + :param month_end: An integer for ending month (Jan=1) + :type month_end: Integer + :param dataset: Dataset object with full-year format + :type dataset: Open Climate Workbench Dataset Object + + :returns: + t_series - monthly average over the given season + means - mean over the entire season + :rtype: A tuple of two numpy arrays + ''' + + if month_start > month_end: + # Offset the original array so that the the first month + # becomes month_start, note that this cuts off the first year of data + offset = slice(month_start - 1, month_start - 13) + reshape_data = reshape_monthly_to_annually(dataset[offset]) + month_index = slice(0, 13 - month_start + month_end) + else: + # Since month_start <= month_end, just take a slice containing those months + reshape_data = reshape_monthly_to_annually(dataset) + month_index = slice(month_start - 1, month_end) + + t_series = reshape_data[:, month_index].mean(axis=1) + means = t_series.mean(axis=0) + return t_series, means
