revisit CLIMATE-467, 3/20/2015
Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/a5d50bc4 Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/a5d50bc4 Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/a5d50bc4 Branch: refs/heads/master Commit: a5d50bc4a71daa5b6d539c9cc537bdeb778520a4 Parents: f79323b cfb120e Author: Huikyo Lee <[email protected]> Authored: Fri Mar 20 00:26:44 2015 -0700 Committer: Huikyo Lee <[email protected]> Committed: Fri Mar 20 00:26:44 2015 -0700 ---------------------------------------------------------------------- ocw/dataset_processor.py | 72 +++++++++++++++++++++++++++++++++++++++++++ ocw/utils.py | 17 ++++++++-- 2 files changed, 86 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/a5d50bc4/ocw/dataset_processor.py ---------------------------------------------------------------------- diff --cc ocw/dataset_processor.py index eb93104,e57263b..a03cac5 mode 100644,100755..100755 --- a/ocw/dataset_processor.py +++ b/ocw/dataset_processor.py http://git-wip-us.apache.org/repos/asf/climate/blob/a5d50bc4/ocw/utils.py ---------------------------------------------------------------------- diff --cc ocw/utils.py index c4b640f,cbdf85c..e3d3311 mode 100644,100755..100755 --- a/ocw/utils.py +++ b/ocw/utils.py @@@ -281,59 -289,3 +289,62 @@@ def calc_climatology_year(dataset) return annually_mean, total_mean ++<<<<<<< HEAD +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: :class:`int` + + :param month_end: An integer for ending month (Jan=1) + :type month_end: :class:`int` + + :param dataset: Dataset object with full-year format + :type dataset: :class:`dataset.Dataset` + + :returns: + t_series - monthly average over the given season + means - mean over the entire season + :rtype: A :func:`tuple` of two :class:`numpy.ndarray` + ''' + + 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 + + +def calc_climatology_monthly(dataset): + ''' Calculate monthly mean values for a dataset. + + :param dataset: Monthly binned Dataset object with the number of months + divisible by 12 + :type dataset: :class:`dataset.Dataset` + + :returns: Mean values for each month of the year + :rtype: A 3D :class:`numpy.ndarray` of shape (12, num_lats, num_lons) + + :raise ValueError: If the number of monthly bins is not divisible by 12 + ''' + + if dataset.values.shape[0] % 12: + error = ( + "The length of the time axis in the values array should be " + "divisible by 12." + ) + raise ValueError(error) + else: + return reshape_monthly_to_annually(dataset).mean(axis=0) + ++======= ++>>>>>>> cfb120e5eaea004e850b884e49d41f8a0c269b75
