Repository: climate Updated Branches: refs/heads/master db77e99ff -> dca99e085
add (optional) string subregion_name to subset parameter list update subset to use subregion_name in subsetted Datasets update safe_subset to the new capabilities in subset Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/e2718cb6 Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/e2718cb6 Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/e2718cb6 Branch: refs/heads/master Commit: e2718cb601305b5888f69efe9affee4f93b08f56 Parents: a0f0615 Author: Kim Whitehall <[email protected]> Authored: Thu Mar 12 12:21:02 2015 -0700 Committer: Kim Whitehall <[email protected]> Committed: Mon Mar 16 14:09:26 2015 -0700 ---------------------------------------------------------------------- ocw/dataset_processor.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/e2718cb6/ocw/dataset_processor.py ---------------------------------------------------------------------- diff --git a/ocw/dataset_processor.py b/ocw/dataset_processor.py index f00ab36..eb93104 100644 --- a/ocw/dataset_processor.py +++ b/ocw/dataset_processor.py @@ -152,7 +152,7 @@ def ensemble(datasets): return ensemble_dataset -def subset(subregion, target_dataset): +def subset(subregion, target_dataset, subregion_name=None): '''Subset given dataset(s) with subregion information :param subregion: The Bounds with which to subset the target Dataset. @@ -161,6 +161,9 @@ def subset(subregion, target_dataset): :param target_dataset: The Dataset object to subset. :type target_dataset: :class:`dataset.Dataset` + :param subregion_name: The subset-ed Dataset name + :type subregion_name: :mod:`string` + :returns: The subset-ed Dataset object :rtype: :class:`dataset.Dataset` @@ -173,6 +176,9 @@ def subset(subregion, target_dataset): # Get subregion indices into subregion data dataset_slices = _get_subregion_slice_indices(subregion, target_dataset) + if not subregion_name: + subregion_name = target_dataset.name + # Build new dataset with subset information return ds.Dataset( # Slice the lats array with our calculated slice indices @@ -191,11 +197,11 @@ def subset(subregion, target_dataset): dataset_slices["lon_start"]:dataset_slices["lon_end"] + 1], variable=target_dataset.variable, units=target_dataset.units, - name=target_dataset.name, + name=subregion_name, origin=target_dataset.origin ) -def safe_subset(subregion, target_dataset): +def safe_subset(subregion, target_dataset, subregion_name=None): '''Safely subset given dataset with subregion information A standard subset requires that the provided subregion be entirely contained @@ -208,6 +214,9 @@ def safe_subset(subregion, target_dataset): :param target_dataset: The Dataset object to subset. :type target_dataset: :class:`dataset.Dataset` + :param subregion_name: The subset-ed Dataset name + :type subregion_name: :mod:`string` + :returns: The subset-ed Dataset object :rtype: :class:`dataset.Dataset` ''' @@ -233,7 +242,7 @@ def safe_subset(subregion, target_dataset): if subregion.end > end: subregion.end = end - return subset(subregion, target_dataset) + return subset(subregion, target_dataset, subregion_name) def normalize_dataset_datetimes(dataset, timestep): ''' Normalize Dataset datetime values.
