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 2013/08/15 00:30:07 UTC
svn commit: r1514075 -
/incubator/climate/branches/RefactorInput/ocw/dataset_processor.py
Author: joyce
Date: Wed Aug 14 22:30:07 2013
New Revision: 1514075
URL: http://svn.apache.org/r1514075
Log:
CLIMATE-237 - Add helper to check for subregion containment by a Dataset
Modified:
incubator/climate/branches/RefactorInput/ocw/dataset_processor.py
Modified: incubator/climate/branches/RefactorInput/ocw/dataset_processor.py
URL: http://svn.apache.org/viewvc/incubator/climate/branches/RefactorInput/ocw/dataset_processor.py?rev=1514075&r1=1514074&r2=1514075&view=diff
==============================================================================
--- incubator/climate/branches/RefactorInput/ocw/dataset_processor.py (original)
+++ incubator/climate/branches/RefactorInput/ocw/dataset_processor.py Wed Aug 14 22:30:07 2013
@@ -572,7 +572,7 @@ def _check_validity_of_subregion(subregi
logging.error(error)
raise ValueError(error)
- if _subregion_is_not_contained_by_dataset(subregion, target_dataset):
+ if not _is_subregion_contained_by_dataset(subregion, target_dataset):
error = (
"dataset_processor.subset received a subregion that is not "
"completely within the bounds of the target dataset."
@@ -613,5 +613,22 @@ def _subregion_values_are_not_valid(subr
subregion.start > subregion.end
)
-def _subregion_is_not_contained_by_dataset(subregion, target_dataset):
- pass
+def _is_subregion_contained_by_dataset(subregion, target_dataset):
+ '''Check if a Dataset fully contains a subregion.
+
+ :param subregion: The subregion object to check.
+ :type subregion: Dictionary
+ :param target_dataset: The Dataset that should be fully contain the
+ subregion
+ :type target_dataset: Dataset
+
+ :returns: True if the subregion is contained by the Dataset, False
+ otherwise
+ '''
+ latMin, latMax, lonMin, lonMax = target_dataset.spatial_boundaries()
+ return (
+ latMin <= subregion.latMin <= latMax and
+ latMin <= subregion.latMax <= latMax and
+ lonMin <= subregion.lonMin <= lonMax and
+ lonMin <= subregion.lonMax <= lonMax
+ )