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/16 14:45:58 UTC
svn commit: r1514685 - in /incubator/climate/branches/RefactorInput/ocw:
dataset_processor.py tests/test_dataset_processor.py
Author: joyce
Date: Fri Aug 16 12:45:58 2013
New Revision: 1514685
URL: http://svn.apache.org/r1514685
Log:
CLIMATE-237 - Fix casing of variables and cleanup.
Modified:
incubator/climate/branches/RefactorInput/ocw/dataset_processor.py
incubator/climate/branches/RefactorInput/ocw/tests/test_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=1514685&r1=1514684&r2=1514685&view=diff
==============================================================================
--- incubator/climate/branches/RefactorInput/ocw/dataset_processor.py (original)
+++ incubator/climate/branches/RefactorInput/ocw/dataset_processor.py Fri Aug 16 12:45:58 2013
@@ -139,7 +139,7 @@ def subset(subregion, target_dataset):
'''Subset given dataset(s) with subregion information
:param subregion: The bounds with which to subset the target dataset.
- The expected keys are `latMin, latMax, lonMin, lonMax, start, end`
+ The expected keys are `lat_min, lat_max, lon_min, lon_max, start, end`
:type subregion: Dictionary
:param target_dataset: The Dataset object to subset.
:type target_dataset: Dataset
@@ -157,19 +157,19 @@ def subset(subregion, target_dataset):
# Build new dataset with subset information
return ds.Dataset(
# Slice the lats array with our calculated slice indices
- target_dataset.lats[dataset_slices["latStart"]:
- dataset_slices["latEnd"] + 1],
+ target_dataset.lats[dataset_slices["lat_start"]:
+ dataset_slices["lat_end"] + 1],
# Slice the lons array with our calculated slice indices
- target_dataset.lons[dataset_slices["lonStart"]:
- dataset_slices["lonEnd"]+ 1],
+ target_dataset.lons[dataset_slices["lon_start"]:
+ dataset_slices["lon_end"] + 1],
# Slice the times array with our calculated slice indices
- target_dataset.times[dataset_slices["timeStart"]:
- dataset_slices["timeEnd"]+ 1],
+ target_dataset.times[dataset_slices["time_start"]:
+ dataset_slices["time_end"]+ 1],
# Slice the values array with our calculated slice indices
target_dataset.values[
- dataset_slices["timeStart"]:dataset_slices["timeEnd"] + 1,
- dataset_slices["latStart"]:dataset_slices["latEnd"] + 1,
- dataset_slices["lonStart"]:dataset_slices["lonEnd"] + 1],
+ dataset_slices["time_start"]:dataset_slices["time_end"] + 1,
+ dataset_slices["lat_start"]:dataset_slices["lat_end"] + 1,
+ dataset_slices["lon_start"]:dataset_slices["lon_end"] + 1],
target_dataset.variable,
target_dataset.name
)
@@ -587,7 +587,7 @@ def _check_validity_of_subregion(subregi
"dataset_processor.subset received invalid subregion. "
"Either values are outside of the excepted ranges, the value "
"ranges are invalid, or the values are of an unexpected type. "
- "-90 <= latMin < latMax <= 90 : -180 <= lonMin < lonMax <= 180 : "
+ "-90 <= lat_min < lat_max <= 90 : -180 <= lon_min < lon_max <= 180 : "
"start < end : type(start) == type(end) == datetime.datetime."
)
logging.error(error)
@@ -609,7 +609,7 @@ def _all_subregion_keys_exist(subregion)
:returns: True if well-formed, False otherwise
'''
- expected_keys = ['latMin', 'latMax', 'lonMin', 'lonMax', 'start', 'end']
+ expected_keys = ['lat_min', 'lat_max', 'lon_min', 'lon_max', 'start', 'end']
if not all(key in expected_keys for key in subregion.keys()):
return False
@@ -624,12 +624,12 @@ def _subregion_values_are_not_valid(subr
:returns: True if the values are invalid, False if the values are valid
'''
return (
- subregion["latMin"] < -90 or
- subregion["latMax"] > 90 or
- subregion["latMin"] >= subregion["latMax"] or
- subregion["lonMin"] < -180 or
- subregion["lonMax"] > 180 or
- subregion["lonMin"] >= subregion['lonMax'] or
+ subregion["lat_min"] < -90 or
+ subregion["lat_max"] > 90 or
+ subregion["lat_min"] >= subregion["lat_max"] or
+ subregion["lon_min"] < -180 or
+ subregion["lon_max"] > 180 or
+ subregion["lon_min"] >= subregion["lon_max"] or
type(subregion["start"]) is not datetime.datetime or
type(subregion["end"]) is not datetime.datetime or
subregion["start"] > subregion["end"]
@@ -647,13 +647,13 @@ def _is_subregion_contained_by_dataset(s
:returns: True if the subregion is contained by the Dataset, False
otherwise
'''
- latMin, latMax, lonMin, lonMax = target_dataset.spatial_boundaries()
+ lat_min, lat_max, lon_min, lon_max = target_dataset.spatial_boundaries()
start, end = target_dataset.time_range()
return (
- latMin <= subregion["latMin"] <= latMax and
- latMin <= subregion["latMax"] <= latMax and
- lonMin <= subregion["lonMin"] <= lonMax and
- lonMin <= subregion["lonMax"] <= lonMax and
+ lat_min <= subregion["lat_min"] <= lat_max and
+ lat_min <= subregion["lat_max"] <= lat_max and
+ lon_min <= subregion["lon_min"] <= lon_max and
+ lon_min <= subregion["lon_max"] <= lon_max and
start <= subregion["start"] <= end and
start <= subregion["end"] <= end
)
@@ -669,21 +669,21 @@ def _get_subregion_slice_indices(subregi
:returns: The indices to slice the Datasets arrays as a Dictionary.
'''
- latStart = np.nonzero(target_dataset.lats == subregion["latMin"])[0][0]
- latEnd = np.nonzero(target_dataset.lats == subregion["latMax"])[0][0]
+ latStart = np.nonzero(target_dataset.lats == subregion["lat_min"])[0][0]
+ latEnd = np.nonzero(target_dataset.lats == subregion["lat_max"])[0][0]
- lonStart = np.nonzero(target_dataset.lons == subregion["lonMin"])[0][0]
- lonEnd = np.nonzero(target_dataset.lons == subregion["lonMax"])[0][0]
+ lonStart = np.nonzero(target_dataset.lons == subregion["lon_min"])[0][0]
+ lonEnd = np.nonzero(target_dataset.lons == subregion["lon_max"])[0][0]
timeStart = np.nonzero(target_dataset.times == subregion["start"])[0][0]
timeEnd = np.nonzero(target_dataset.times == subregion["end"])[0][0]
return {
- "latStart" : latStart,
- "latEnd" : latEnd,
- "lonStart" : lonStart,
- "lonEnd" : lonEnd,
- "timeStart" : timeStart,
- "timeEnd" : timeEnd
+ "lat_start" : latStart,
+ "lat_end" : latEnd,
+ "lon_start" : lonStart,
+ "lon_end" : lonEnd,
+ "time_start" : timeStart,
+ "time_end" : timeEnd
}
Modified: incubator/climate/branches/RefactorInput/ocw/tests/test_dataset_processor.py
URL: http://svn.apache.org/viewvc/incubator/climate/branches/RefactorInput/ocw/tests/test_dataset_processor.py?rev=1514685&r1=1514684&r2=1514685&view=diff
==============================================================================
--- incubator/climate/branches/RefactorInput/ocw/tests/test_dataset_processor.py (original)
+++ incubator/climate/branches/RefactorInput/ocw/tests/test_dataset_processor.py Fri Aug 16 12:45:58 2013
@@ -150,10 +150,10 @@ class TestSubset(unittest.TestCase):
self.target_dataset = ten_year_monthly_dataset()
self.subregion = {
- 'latMin': -81,
- 'latMax': 81,
- 'lonMin': -161,
- 'lonMax': 161,
+ 'lat_min': -81,
+ 'lat_max': 81,
+ 'lon_min': -161,
+ 'lon_max': 161,
'start': datetime.datetime(2001, 1, 1),
'end': datetime.datetime(2004, 1, 1)
}
@@ -168,29 +168,29 @@ class TestSubset(unittest.TestCase):
self.assertEqual(subset.values.shape, (37, 82, 162))
def test_subset_with_out_of_range_subregion(self):
- # Out of range latMin test
- self.subregion['latMin'] = -91
+ # Out of range lat_min test
+ self.subregion['lat_min'] = -91
with self.assertRaises(ValueError):
dp.subset(self.subregion, self.target_dataset)
- self.subregion['latMin'] = -81
+ self.subregion['lat_min'] = -81
- # Out of range latMax test
- self.subregion['latMax'] = 91
+ # Out of range lat_max test
+ self.subregion['lat_max'] = 91
with self.assertRaises(ValueError):
dp.subset(self.subregion, self.target_dataset)
- self.subregion['latMax'] = 81
+ self.subregion['lat_max'] = 81
- # Out of range lonMin test
- self.subregion['lonMin'] = -191
+ # Out of range lon_min test
+ self.subregion['lon_min'] = -191
with self.assertRaises(ValueError):
dp.subset(self.subregion, self.target_dataset)
- self.subregion['lonMin'] = -161
+ self.subregion['lon_min'] = -161
- # Out of range lonMax test
- self.subregion['lonMax'] = 191
+ # Out of range lon_max test
+ self.subregion['lon_max'] = 191
with self.assertRaises(ValueError):
dp.subset(self.subregion, self.target_dataset)
- self.subregion['lonMax'] = 161
+ self.subregion['lon_max'] = 161
# Invalid start time
self.subregion['start'] = "This is not a datetime object!!"
@@ -208,29 +208,29 @@ class TestSubset(unittest.TestCase):
self.target_dataset.lats = np.array(range(-89, 88, 2))
self.target_dataset.lons = np.array(range(-179, 178, 2))
- # Out of dataset bounds latMin test
- self.subregion['latMin'] = -90
+ # Out of dataset bounds lat_min test
+ self.subregion['lat_min'] = -90
with self.assertRaises(ValueError):
dp.subset(self.subregion, self.target_dataset)
- self.subregion['latMin'] = -81
+ self.subregion['lat_min'] = -81
- # Out of dataset bounds latMax test
- self.subregion['latMax'] = 90
+ # Out of dataset bounds lat_max test
+ self.subregion['lat_max'] = 90
with self.assertRaises(ValueError):
dp.subset(self.subregion, self.target_dataset)
- self.subregion['latMax'] = 81
+ self.subregion['lat_max'] = 81
- # Out of dataset bounds lonMin test
- self.subregion['lonMin'] = -180
+ # Out of dataset bounds lon_min test
+ self.subregion['lon_min'] = -180
with self.assertRaises(ValueError):
dp.subset(self.subregion, self.target_dataset)
- self.subregion['lonMin'] = -161
+ self.subregion['lon_min'] = -161
- # Out of dataset bounds lonMax test
- self.subregion['lonMax'] = 180
+ # Out of dataset bounds lon_max test
+ self.subregion['lon_max'] = 180
with self.assertRaises(ValueError):
dp.subset(self.subregion, self.target_dataset)
- self.subregion['lonMax'] = 161
+ self.subregion['lon_max'] = 161
# Out of dataset bounds start time test
self.subregion['start'] = datetime.datetime(1999, 1, 1)
@@ -246,16 +246,16 @@ class TestSubset(unittest.TestCase):
def test_subset_with_mistmatched_bounds_subregion(self):
# lat min/max value mismatch
- self.subregion['latMin'] = 82
+ self.subregion['lat_min'] = 82
with self.assertRaises(ValueError):
dp.subset(self.subregion, self.target_dataset)
- self.subregion['latMin'] = -81
+ self.subregion['lat_min'] = -81
# lon min/max value mismatch
- self.subregion['lonMin'] = 162
+ self.subregion['lon_min'] = 162
with self.assertRaises(ValueError):
dp.subset(self.subregion, self.target_dataset)
- self.subregion['lonMin'] = -161
+ self.subregion['lon_min'] = -161
# start/end time range mismatch
self.subregion['start'] = datetime.datetime(2010, 2, 2)