You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by jo...@apache.org on 2014/10/28 17:44:30 UTC
[1/4] git commit: CLIMATE-341: Port calcAnnualCycleMeans from
metrics_kyo to utils
Repository: climate
Updated Branches:
refs/heads/master 9183f5fea -> 6e4920c05
CLIMATE-341: Port calcAnnualCycleMeans from metrics_kyo to utils
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/d9b0e6b0
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/d9b0e6b0
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/d9b0e6b0
Branch: refs/heads/master
Commit: d9b0e6b0b1fe66040960a00e0cfb1a5db3d619f5
Parents: 9183f5f
Author: rlaidlaw <rl...@gmail.com>
Authored: Tue Oct 28 01:16:48 2014 -0700
Committer: rlaidlaw <rl...@gmail.com>
Committed: Tue Oct 28 01:16:48 2014 -0700
----------------------------------------------------------------------
ocw/tests/test_utils.py | 18 ++++++++++++++++++
ocw/utils.py | 20 ++++++++++++++++++++
2 files changed, 38 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/d9b0e6b0/ocw/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_utils.py b/ocw/tests/test_utils.py
index 48beb43..2c0981c 100644
--- a/ocw/tests/test_utils.py
+++ b/ocw/tests/test_utils.py
@@ -196,5 +196,23 @@ class TestCalcClimatologyYear(unittest.TestCase):
np.testing.assert_array_equal(
utils.calc_climatology_year(self.test_dataset)[1], total_mean)
+
+class TestCalcClimatologyMonthly(unittest.TestCase):
+ ''' Tests the 'calc_climatology_monthly' method from ocw.utils.py '''
+
+ def setUp(self):
+ self.lats = np.array([10, 20, 30, 40, 50])
+ self.lons = np.array([20, 30, 40, 50, 60])
+ self.times = np.array([datetime.datetime(2000, 1, 1) + relativedelta(months = x) for x in range(36)])
+ self.values = np.array([1]*300 + [2]*300 + [0]*300).reshape(36, 5, 5)
+ self.variable = 'testdata'
+ self.dataset = Dataset(self.lats, self.lons, self.times, self.values, self.variable)
+
+ def test_calc_climatology_monthly(self):
+ expected_result = np.ones(300).reshape(12, 5, 5)
+ actual_result = utils.calc_climatology_monthly(self.dataset)
+ np.testing.assert_array_equal(actual_result, expected_result)
+
+
if __name__ == '__main__':
unittest.main()
http://git-wip-us.apache.org/repos/asf/climate/blob/d9b0e6b0/ocw/utils.py
----------------------------------------------------------------------
diff --git a/ocw/utils.py b/ocw/utils.py
index 8c109b7..326cab9 100644
--- a/ocw/utils.py
+++ b/ocw/utils.py
@@ -311,3 +311,23 @@ def calc_climatology_season(month_start, month_end, dataset):
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: ocw.dataset.Dataset object
+
+ :returns: Mean values for each month of the year
+ :rtype: A 3D numpy array 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:
+ raise ValueError("The length of the time axis in the values array should be divisible by 12.")
+ else:
+ return reshape_monthly_to_annually(dataset).mean(axis=0)
+
[4/4] git commit: Resolve CLIMATE-341. Merge PR #120.
Posted by jo...@apache.org.
Resolve CLIMATE-341. Merge PR #120.
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/6e4920c0
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/6e4920c0
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/6e4920c0
Branch: refs/heads/master
Commit: 6e4920c050f14a75c19e7d5dbcd7c2b690d23921
Parents: 9183f5f b18d4d0
Author: Michael Joyce <jo...@apache.org>
Authored: Tue Oct 28 09:43:59 2014 -0700
Committer: Michael Joyce <jo...@apache.org>
Committed: Tue Oct 28 09:43:59 2014 -0700
----------------------------------------------------------------------
ocw/tests/test_utils.py | 21 +++++++++++++++++++++
ocw/utils.py | 24 ++++++++++++++++++++++++
2 files changed, 45 insertions(+)
----------------------------------------------------------------------
[2/4] git commit: CLIMATE-341: Minor correction to comments in
calc_climatology_monthly
Posted by jo...@apache.org.
CLIMATE-341: Minor correction to comments in calc_climatology_monthly
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/b9dcdcd3
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/b9dcdcd3
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/b9dcdcd3
Branch: refs/heads/master
Commit: b9dcdcd3033eaa9b645e947341da7ea323acac2c
Parents: d9b0e6b
Author: rlaidlaw <rl...@gmail.com>
Authored: Tue Oct 28 01:20:23 2014 -0700
Committer: rlaidlaw <rl...@gmail.com>
Committed: Tue Oct 28 01:20:23 2014 -0700
----------------------------------------------------------------------
ocw/utils.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/b9dcdcd3/ocw/utils.py
----------------------------------------------------------------------
diff --git a/ocw/utils.py b/ocw/utils.py
index 326cab9..0d8d8b5 100644
--- a/ocw/utils.py
+++ b/ocw/utils.py
@@ -316,14 +316,13 @@ def calc_climatology_season(month_start, month_end, dataset):
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.
+ :param dataset: Monthly binned Dataset object with the number of months divisible by 12
:type dataset: ocw.dataset.Dataset object
:returns: Mean values for each month of the year
:rtype: A 3D numpy array of shape (12, num_lats, num_lons)
- :raise ValueError: If the number of monthly bins is not divisible by 12.
+ :raise ValueError: If the number of monthly bins is not divisible by 12
'''
if dataset.values.shape[0] % 12:
[3/4] git commit: CLIMATE-341: Adjust formatting for pep8 compliance
Posted by jo...@apache.org.
CLIMATE-341: Adjust formatting for pep8 compliance
Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/b18d4d0d
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/b18d4d0d
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/b18d4d0d
Branch: refs/heads/master
Commit: b18d4d0d1515af825224f33f294ed062bea0bf53
Parents: b9dcdcd
Author: rlaidlaw <rl...@gmail.com>
Authored: Tue Oct 28 09:42:11 2014 -0700
Committer: rlaidlaw <rl...@gmail.com>
Committed: Tue Oct 28 09:42:11 2014 -0700
----------------------------------------------------------------------
ocw/tests/test_utils.py | 7 +++++--
ocw/utils.py | 9 +++++++--
2 files changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/climate/blob/b18d4d0d/ocw/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_utils.py b/ocw/tests/test_utils.py
index 2c0981c..da5ad42 100644
--- a/ocw/tests/test_utils.py
+++ b/ocw/tests/test_utils.py
@@ -203,10 +203,13 @@ class TestCalcClimatologyMonthly(unittest.TestCase):
def setUp(self):
self.lats = np.array([10, 20, 30, 40, 50])
self.lons = np.array([20, 30, 40, 50, 60])
- self.times = np.array([datetime.datetime(2000, 1, 1) + relativedelta(months = x) for x in range(36)])
+ start_date = datetime.datetime(2000, 1, 1)
+ self.times = np.array([start_date + relativedelta(months=x)
+ for x in range(36)])
self.values = np.array([1]*300 + [2]*300 + [0]*300).reshape(36, 5, 5)
self.variable = 'testdata'
- self.dataset = Dataset(self.lats, self.lons, self.times, self.values, self.variable)
+ self.dataset = Dataset(self.lats, self.lons, self.times,
+ self.values, self.variable)
def test_calc_climatology_monthly(self):
expected_result = np.ones(300).reshape(12, 5, 5)
http://git-wip-us.apache.org/repos/asf/climate/blob/b18d4d0d/ocw/utils.py
----------------------------------------------------------------------
diff --git a/ocw/utils.py b/ocw/utils.py
index 0d8d8b5..defe3d1 100644
--- a/ocw/utils.py
+++ b/ocw/utils.py
@@ -316,7 +316,8 @@ def calc_climatology_season(month_start, month_end, dataset):
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
+ :param dataset: Monthly binned Dataset object with the number of months
+ divisible by 12
:type dataset: ocw.dataset.Dataset object
:returns: Mean values for each month of the year
@@ -326,7 +327,11 @@ def calc_climatology_monthly(dataset):
'''
if dataset.values.shape[0] % 12:
- raise ValueError("The length of the time axis in the values array should be divisible by 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)