Repository: climate
Updated Branches:
  refs/heads/master 278b35fef -> f38d82ddc


CLIMATE-439 Added calc_climatology_year function


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/8a7f1d45
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/8a7f1d45
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/8a7f1d45

Branch: refs/heads/master
Commit: 8a7f1d450a582b6297496b45f9b3392c30557e14
Parents: 14d7f6e
Author: Maziyar Boustani <[email protected]>
Authored: Thu May 22 15:31:00 2014 -0700
Committer: Maziyar Boustani <[email protected]>
Committed: Thu May 22 15:31:00 2014 -0700

----------------------------------------------------------------------
 ocw/utils.py | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/8a7f1d45/ocw/utils.py
----------------------------------------------------------------------
diff --git a/ocw/utils.py b/ocw/utils.py
index 38e4cfd..ec4a021 100644
--- a/ocw/utils.py
+++ b/ocw/utils.py
@@ -245,3 +245,30 @@ def reshape_monthly_to_annually(dataset):
     values.shape = new_shape
 
     return values
+
+def calc_climatology_year(dataset):
+    ''' Calculate climatology of dataset's values for each year
+
+    :param dataset: Dataset object with full-year format
+    :type dataset: Open Climate Workbench Dataset Object
+
+    :returns: Mean values for each year (annually_mean)
+            and mean values for all years (total_mean)
+    :rtype: A tuple of two numpy arrays
+
+    :raise ValueError: If the time shape of values in not divisble by 12 (not 
full-year)
+    '''
+
+    values_shape = dataset.values.shape
+    time_shape = values_shape[0]
+    if time_shape % 12:
+        raise ValueError('The dataset should be in full-time format.')
+    else:
+        # Get values reshaped to (num_year, 12, num_lats, num_lons)
+        values = reshape_monthly_to_annually(dataset)
+        # Calculate mean values over year (num_year, num_lats, num_lons)
+        annually_mean = values.mean(axis=1)
+        # Calculate mean values over all years (num_lats, num_lons)
+        total_mean = annually_mean.mean(axis=0)
+
+    return annually_mean, total_mean

Reply via email to