Repository: climate
Updated Branches:
  refs/heads/master 7461d1b7b -> bb415adee


CLIMATE-718 - Temporal slice of two-dimensional model output

- dataset_processor.temporal_slice 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/86cfed6f
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/86cfed6f
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/86cfed6f

Branch: refs/heads/master
Commit: 86cfed6f6e22c853f580211226ccf0940eaaa0d5
Parents: 7461d1b
Author: huikyole <[email protected]>
Authored: Fri Jan 15 15:29:33 2016 -0800
Committer: huikyole <[email protected]>
Committed: Fri Jan 15 15:29:33 2016 -0800

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


http://git-wip-us.apache.org/repos/asf/climate/blob/86cfed6f/ocw/dataset_processor.py
----------------------------------------------------------------------
diff --git a/ocw/dataset_processor.py b/ocw/dataset_processor.py
index effa64c..09edbaa 100755
--- a/ocw/dataset_processor.py
+++ b/ocw/dataset_processor.py
@@ -348,6 +348,31 @@ def subset(subregion, target_dataset, subregion_name=None):
         origin=target_dataset.origin
     )
 
+def temporal_slice(start_time_index, end_time_index, target_dataset):
+    '''Temporally slice given dataset(s) with subregion information. This does 
not
+    spatially subset the target_Dataset
+
+    :param start_time_index: time index of the start time
+    :type start_time_index: :class:'int'
+
+    :param end_time_index: time index of the end time
+    :type end_time_index: :class:'int'
+
+    :param target_dataset: The Dataset object to subset.
+    :type target_dataset: :class:`dataset.Dataset`
+
+    :returns: The subset-ed Dataset object
+    :rtype: :class:`dataset.Dataset`
+
+    :raises: ValueError
+    '''
+
+    timeStart = min(np.nonzero(target_dataset.times >= start_time_index)[0])
+    timeEnd = max(np.nonzero(target_dataset.times <= end_time_index)[0])
+    target_dataset.times = target_dataset.times[timeStart:timeEnd+1]
+    target_dataset.values = target_dataset.values[timeStart:timeEnd+1,:]
+
+    return target_dataset
 
 def safe_subset(subregion, target_dataset, subregion_name=None):
     '''Safely subset given dataset with subregion information

Reply via email to