# Changeset 6308

Ignore:
Timestamp:
15/01/10 08:44:39 (12 years ago)
Message:

Applied the fix to _mergeBounds so that it will cope with reversed bounds.

Location:
qesdi/geoplot/trunk/lib/geoplot
Files:
2 edited

Unmodified
Added
Removed
• ## qesdi/geoplot/trunk/lib/geoplot/grid_builder_base.py

 r6104 right-hand edge of grid box (x, y) is the same as the left-hand edge of grid box (x + 1, y) and similarly in y. There are 4 different types of bounds that might be received: 1. Descending with each bound low-to-high 2. Descending with each bound high-to-low 3. Ascending with each bound low-to-high 4. Ascending with each bound high-to-low In order to cater for these we just use all unique values in the bounds (which is fine given that we assume grid boxes are contiguous) and sort them. If bounds are in descending order then we reverse the 1D array so it is also descending. @param lonBounds: The longitude bounds array @param latBounds: the latitude bounds array """ # Get grid dimensions n = bounds.shape[0] # Take the lower bounds as the mesh point # except for the last index where the upper bounds is taken merged = N.resize(bounds[:, 0], (n + 1,)) merged[-1] = bounds[-1, 1] return merged # Set whether descending descending = False if bounds[0, 0] > bounds[-1, 0]: descending = True unique_bounds = N.unique(bounds) # Check length is correct if len(unique_bounds) != (bounds.shape[0] + 1): log.error("Length of merged bounds ('%s') does not equal length of bounds + 1 ('%s')." % (len(unique_bounds), bounds.shape[0])) # Sort it and then reverse it if descending unique_bounds.sort() if descending == True: merged = unique_bounds[::-1] else: merged = unique_bounds return merged
• ## qesdi/geoplot/trunk/lib/geoplot/tests/unit/test_grid_builder_base.py

 r5403 def test_011_mergeBounds(self): unmergedBounds = N.array([[0.75, 1.25], [1.25, 1.75], [1.75, 2.25], [2.25, 2.75]]) unmergedBounds = N.array([[0.75, 1.25], [1.25, 1.75], [1.75, 2.25], [2.25, 2.75]]) mergedBounds = GridBuilderBase._mergeBounds(unmergedBounds) nose.tools.assert_equal(mergedBounds.tolist(), [0.75, 1.25, 1.75, 2.25, 2.75]) # ascending, in order [low, high] unmergedBounds = N.array([[1.0, 2.0], [2.0, 3.0], [3.0, 4.0]]) mergedBounds = GridBuilderBase._mergeBounds(unmergedBounds) nose.tools.assert_equal(mergedBounds.tolist(), [1.0, 2.0, 3.0, 4.0]) # ascending in order [high, low] unmergedBounds = N.array([[2.0, 1.0], [3.0, 2.0], [4.0, 3.0]]) mergedBounds = GridBuilderBase._mergeBounds(unmergedBounds) nose.tools.assert_equal(mergedBounds.tolist(), [1.0, 2.0, 3.0, 4.0]) # decending in order [low, high] unmergedBounds = N.array([[3.0, 4.0], [2.0, 3.0], [1.0, 2.0]]) mergedBounds = GridBuilderBase._mergeBounds(unmergedBounds) nose.tools.assert_equal(mergedBounds.tolist(), [4.0, 3.0, 2.0, 1.0]) # decending in order [high, low] unmergedBounds = N.array([[4.0, 3.0], [3.0, 2.0], [2.0, 1.0]]) mergedBounds = GridBuilderBase._mergeBounds(unmergedBounds) nose.tools.assert_equal(mergedBounds.tolist(), [4.0, 3.0, 2.0, 1.0]) def test_012_getBoundsFromAxis(self): axis =  cdms.createAxis(N.array([10.0,20.0,30.0,40.0,50.0]))
Note: See TracChangeset for help on using the changeset viewer.