You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by wh...@apache.org on 2015/04/11 00:03:55 UTC

[1/2] climate git commit: Add unittest to test calc_time_series

Repository: climate
Updated Branches:
  refs/heads/master 5207ddaca -> 14e980fa6


Add unittest to test calc_time_series


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

Branch: refs/heads/master
Commit: 14e980fa63d809f02c39e8ab57fd3b943d1a5ca1
Parents: 6f49bd5
Author: Kim Whitehall <ki...@jpl.nasa.gov>
Authored: Mon Mar 23 10:15:40 2015 -0700
Committer: Kim Whitehall <ki...@jpl.nasa.gov>
Committed: Fri Apr 10 15:04:00 2015 -0700

----------------------------------------------------------------------
 ocw/tests/test_utils.py | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/14e980fa/ocw/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ocw/tests/test_utils.py b/ocw/tests/test_utils.py
index a5c8db6..36cf42f 100644
--- a/ocw/tests/test_utils.py
+++ b/ocw/tests/test_utils.py
@@ -213,11 +213,29 @@ class TestCalcClimatologyMonthly(unittest.TestCase):
 
     def test_calc_climatology_monthly(self):
         expected_result = np.ones(300).reshape(12, 5, 5)
-        expected_times = np.array([datetime.datetime(1, 1, 1) + relativedelta(months = x) for x in range(12)])
+        expected_times = np.array([datetime.datetime(1, 1, 1) + relativedelta(months = x) 
+                                   for x in range(12)])
         actual_result, actual_times = utils.calc_climatology_monthly(self.dataset)
         np.testing.assert_array_equal(actual_result, expected_result)
         np.testing.assert_array_equal(actual_times, expected_times)
 
+class TestCalcTimeSeries(unittest.TestCase):
+    ''' Tests the 'calc_time_series' 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])
+        start_date = datetime.datetime(2000, 1, 1)
+        self.times = np.array([start_date + relativedelta(months=x)
+                               for x in range(12)])
+        self.values = np.ones(300).reshape(12, 5, 5)
+        self.variable = 'testdata'
+        self.dataset = Dataset(self.lats, self.lons, self.times,
+                               self.values, self.variable)
+
+    def test_calc_time_series(self):
+        expected_result = np.ones(12)
+        np.testing.assert_array_equal(utils.calc_time_series(self.dataset), expected_result)
+        
 if __name__ == '__main__':
     unittest.main()


[2/2] climate git commit: Add a function to calculate time series

Posted by wh...@apache.org.
Add a function to calculate time series


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

Branch: refs/heads/master
Commit: 6f49bd5ebfa9a138148ed38a853add6dcc0e2bae
Parents: 5207dda
Author: Kim Whitehall <ki...@jpl.nasa.gov>
Authored: Sun Mar 22 10:23:20 2015 -0700
Committer: Kim Whitehall <ki...@jpl.nasa.gov>
Committed: Fri Apr 10 15:04:00 2015 -0700

----------------------------------------------------------------------
 ocw/utils.py | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/6f49bd5e/ocw/utils.py
----------------------------------------------------------------------
diff --git a/ocw/utils.py b/ocw/utils.py
index 00a6a01..f367dab 100644
--- a/ocw/utils.py
+++ b/ocw/utils.py
@@ -273,7 +273,7 @@ def calc_climatology_year(dataset):
     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)
+       # 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)
@@ -345,3 +345,17 @@ def calc_climatology_monthly(dataset):
                 for x in range(12)])
         return values, times
 
+def calc_time_series(dataset):
+    ''' Calculate time series mean values for a dataset
+
+    :param dataset: Dataset object 
+    :type dataset: :class:`dataset.Dataset`
+
+    :returns: time series for the dataset of shape (nT)
+    '''
+
+    t_series =[]
+    for t in xrange(dataset.values.shape[0]):
+        t_series.append(dataset.values[t,:,:].mean())
+    
+    return t_series