Repository: climate Updated Branches: refs/heads/master 557a8b3a7 -> 2ccf7dd57
CLIMATE-489 - Add better subset error reporting - Bounds checking now builds a list of errors and reports all offending bounds values in a single ValueError. - Update subset docstring to reflect change in return value. Only True is returned when the subset is valid, otherwise a ValueError is raised. Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/11cd8ba2 Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/11cd8ba2 Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/11cd8ba2 Branch: refs/heads/master Commit: 11cd8ba286df8e4ce44fd59144e5ebc0a07b70d6 Parents: 557a8b3 Author: cgoodale <[email protected]> Authored: Tue Jul 8 07:39:45 2014 -0700 Committer: Michael Joyce <[email protected]> Committed: Mon Jul 14 07:55:46 2014 -0700 ---------------------------------------------------------------------- ocw/dataset_processor.py | 52 +++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/11cd8ba2/ocw/dataset_processor.py ---------------------------------------------------------------------- diff --git a/ocw/dataset_processor.py b/ocw/dataset_processor.py index 2f68c9e..c9f0196 100644 --- a/ocw/dataset_processor.py +++ b/ocw/dataset_processor.py @@ -156,13 +156,7 @@ def subset(subregion, target_dataset): ''' # Ensure that the subregion information is well formed - if not _are_bounds_contained_by_dataset(subregion, target_dataset): - error = ( - "dataset_processor.subset received a subregion that is not " - "completely within the bounds of the target dataset." - ) - logger.error(error) - raise ValueError(error) + _are_bounds_contained_by_dataset(subregion, target_dataset) # Get subregion indices into subregion data dataset_slices = _get_subregion_slice_indices(subregion, target_dataset) @@ -764,19 +758,43 @@ def _are_bounds_contained_by_dataset(bounds, dataset): Bounds :type dataset: Dataset - :returns: True if the Bounds are contained by the Dataset, False - otherwise + :returns: True if the Bounds are contained by the Dataset, Raises + a ValueError otherwise ''' lat_min, lat_max, lon_min, lon_max = dataset.spatial_boundaries() start, end = dataset.time_range() - return ( - lat_min <= bounds.lat_min <= lat_max and - lat_min <= bounds.lat_max <= lat_max and - lon_min <= bounds.lon_min <= lon_max and - lon_min <= bounds.lon_max <= lon_max and - start <= bounds.start <= end and - start <= bounds.end <= end - ) + errors = [] + + # TODO: THIS IS TERRIBLY inefficent and we need to use a geometry lib instead in the future + if not lat_min <= bounds.lat_min <= lat_max: + error = "bounds.lat_min: %s is not between lat_min: %s and lat_max: %s" % (bounds.lat_min, lat_min, lat_max) + errors.append(error) + + if not lat_min <= bounds.lat_max <= lat_max: + error = "bounds.lat_max: %s is not between lat_min: %s and lat_max: %s" % (bounds.lat_max, lat_min, lat_max) + errors.append(error) + + if not lon_min <= bounds.lon_min <= lon_max: + error = "bounds.lon_min: %s is not between lon_min: %s and lon_max: %s" % (bounds.lon_min, lon_min, lon_max) + errors.append(error) + + if not lon_min <= bounds.lon_max <= lon_max: + error = "bounds.lon_max: %s is not between lon_min: %s and lon_max: %s" % (bounds.lon_max, lon_min, lon_max) + errors.append(error) + + if not start <= bounds.start <= end: + error = "bounds.start: %s is not between start: %s and end: %s" % (bounds.start, start, end) + errors.append(error) + + if not start <= bounds.end <= end: + error = "bounds.end: %s is not between start: %s and end: %s" % (bounds.end, start, end) + errors.append(error) + + if len(errors) == 0: + return True + else: + error_message = '\n'.join(errors) + raise ValueError(error_message) def _get_subregion_slice_indices(subregion, target_dataset): '''Get the indices for slicing Dataset values to generate the subregion.
