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

[1/2] climate git commit: CLIMATE-694 - A new module to rebin a dataset using time index

Repository: climate
Updated Branches:
  refs/heads/master 799fde64b -> a38724e89


CLIMATE-694 - A new module to rebin a dataset using time index

- ocw.dataset_processor.temporal_rebin_with_time_index has been added


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

Branch: refs/heads/master
Commit: aa0317f940caec8623df057f02504e36d70b0b52
Parents: 799fde6
Author: huikyole <hu...@argo.jpl.nasa.gov>
Authored: Wed Oct 14 11:54:37 2015 -0700
Committer: huikyole <hu...@argo.jpl.nasa.gov>
Committed: Wed Oct 14 11:54:37 2015 -0700

----------------------------------------------------------------------
 ocw/dataset_processor.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/aa0317f9/ocw/dataset_processor.py
----------------------------------------------------------------------
diff --git a/ocw/dataset_processor.py b/ocw/dataset_processor.py
index e9e03db..8aebab5 100755
--- a/ocw/dataset_processor.py
+++ b/ocw/dataset_processor.py
@@ -141,6 +141,38 @@ def temporal_rebin(target_dataset, temporal_resolution):
     
     return new_dataset
 
+def temporal_rebin_with_time_index(target_dataset, nt_average):
+    """ Rebin a Dataset to a new temporal resolution
+
+    :param target_dataset: Dataset object that needs temporal rebinned
+    :type target_dataset: :class:`dataset.Dataset`
+
+    :param nt_average: Time resolution for the output datasets. 
+     It is the same as the number of time indicies to be averaged. (length of time dimension in the rebinned dataset) = (original time dimension length/nt_average)
+    :type temporal_resolution: integer
+
+    :returns: A new temporally rebinned Dataset
+    :rtype: :class:`dataset.Dataset`
+    """
+    nt = target_dataset.times.size
+    if nt % nt_average !=0:
+        print 'Warning: length of time dimension must be a multiple of nt_average'
+    # nt2 is the length of time dimension in the rebinned dataset
+    nt2 = nt/nt_average
+    binned_dates = target_dataset.times[np.arange(nt2)*nt_average]
+    binned_values = np.zeros(np.insert(target_dataset.values.shape[1:],0,nt2))
+    for it in np.arange(nt2):
+        binned_values[it,:] = ma.average(target_dataset.values[nt_average*it:nt_average*it+nt_average,:], axis=0)
+    new_dataset = ds.Dataset(target_dataset.lats,
+                             target_dataset.lons,
+                             binned_dates,
+                             binned_values,
+                             variable=target_dataset.variable,
+                             units=target_dataset.units,
+                             name=target_dataset.name,
+                             origin=target_dataset.origin)
+    return new_dataset
+
 def spatial_regrid(target_dataset, new_latitudes, new_longitudes):
     """ Regrid a Dataset using the new latitudes and longitudes
 


[2/2] climate git commit: CLIMATE-694 - A new module to rebin a dataset using time index

Posted by hu...@apache.org.
CLIMATE-694 - A new module to rebin a dataset using time index

- ocw.dataset_processor.temporal_rebin_with_time_index has been added


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

Branch: refs/heads/master
Commit: a38724e89a83896bc8bb8eeb6d49ca6d283486e6
Parents: 799fde6 aa0317f
Author: huikyole <hu...@argo.jpl.nasa.gov>
Authored: Wed Oct 14 12:11:10 2015 -0700
Committer: huikyole <hu...@argo.jpl.nasa.gov>
Committed: Wed Oct 14 12:11:10 2015 -0700

----------------------------------------------------------------------
 ocw/dataset_processor.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
----------------------------------------------------------------------