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 000CC18C7A for ; Fri, 31 Jul 2015 22:37:32 +0000 (UTC) Received: (qmail 77022 invoked by uid 500); 31 Jul 2015 22:37:32 -0000 Delivered-To: apmail-climate-commits-archive@climate.apache.org Received: (qmail 76942 invoked by uid 500); 31 Jul 2015 22:37:32 -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 76873 invoked by uid 99); 31 Jul 2015 22:37:32 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Jul 2015 22:37:32 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A026BE0523; Fri, 31 Jul 2015 22:37:32 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: huikyole@apache.org To: commits@climate.apache.org Date: Fri, 31 Jul 2015 22:37:33 -0000 Message-Id: <72a47815f70441e6913c060dc989d824@git.apache.org> In-Reply-To: <834b13160ea048b0a098933d68e6a546@git.apache.org> References: <834b13160ea048b0a098933d68e6a546@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/5] climate git commit: CLIMATE-647 Updated dataset_processor.temporal_subset CLIMATE-647 Updated dataset_processor.temporal_subset Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/d41cb795 Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/d41cb795 Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/d41cb795 Branch: refs/heads/master Commit: d41cb79589b22fc1b8f78d6238d40491dc716877 Parents: c032467 Author: huikyole Authored: Tue Jul 28 17:09:14 2015 -0700 Committer: huikyole Committed: Tue Jul 28 17:09:14 2015 -0700 ---------------------------------------------------------------------- ocw/dataset_processor.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/d41cb795/ocw/dataset_processor.py ---------------------------------------------------------------------- diff --git a/ocw/dataset_processor.py b/ocw/dataset_processor.py index 3e35003..a0169a7 100755 --- a/ocw/dataset_processor.py +++ b/ocw/dataset_processor.py @@ -29,7 +29,7 @@ import logging logger = logging.getLogger(__name__) -def temporal_subset(month_start, month_end, target_dataset): +def temporal_subset(month_start, month_end, target_dataset, average_each_year = False): """ Temporally subset data given month_index. :param month_start: An integer for beginning month (Jan=1) @@ -41,6 +41,9 @@ def temporal_subset(month_start, month_end, target_dataset): :param target_dataset: Dataset object that needs temporal subsetting :type target_dataset: Open Climate Workbench Dataset Object + :param average_each_year: If True, output dataset is averaged for each year + :type average_each_year: :class:'boolean' + :returns: A temporal subset OCW Dataset :rtype: Open Climate Workbench Dataset Object """ @@ -71,8 +74,32 @@ def temporal_subset(month_start, month_end, target_dataset): target_dataset.lons, target_dataset.times[time_index], target_dataset.values[time_index,:], - target_dataset.variable, - target_dataset.name) + variable=target_dataset.variable, + units=target_dataset.units, + name=target_dataset.name) + + if average_each_year: + nmonth = len(month_index) + ntime = new_dataset.times.size + nyear = ntime/nmonth + averaged_time = [] + ny, nx = target_dataset.values.shape[1:] + averaged_values =ma.zeros([nyear, ny, nx]) + for iyear in np.arange(nyear): + # centered time index of the season between month_start and month_end in each year + center_index = int(nmonth/2)+iyear*nmonth + if nmonth == 1: + center_index = iyear + averaged_time.append(new_dataset.times[center_index]) + averaged_values[iyear,:] = ma.average(new_dataset.values[nmonth*iyear:nmonth*iyear+nmonth,:], axis=0) + new_dataset = ds.Dataset(target_dataset.lats, + target_dataset.lons, + np.array(averaged_time), + averaged_values, + variable=target_dataset.variable, + units=target_dataset.units, + name=target_dataset.name) + return new_dataset def temporal_rebin(target_dataset, temporal_resolution):