def test_bin_extentII(self): # This will describe an extent lat = [-25, -24] lon = [130, 131] bins = (1, 1) res = util.bin_extent(lat, lon, bins) expected_res = [[{'index': [0, 1], 'mid_lat_lon': (-24.5, 130.5)}]] for expected, actual in map(None, expected_res, res): for expected_dic, act_dic in map(None, expected, actual): self.failUnlessEqual(expected_dic['index'], act_dic['index']) self.failUnless(scipy.allclose( scipy.array(expected_dic['mid_lat_lon']), act_dic['mid_lat_lon']))
def test_bin_extentII(self): # This will describe an extent lat = [-25, -24] lon = [130, 131] bins = (1, 1) res = util.bin_extent(lat, lon, bins) expected_res = [[{'index': [0, 1], 'mid_lat_lon': (-24.5, 130.5)}]] for expected, actual in map(None, expected_res, res): for expected_dic, act_dic in map(None, expected, actual): self.failUnlessEqual(expected_dic['index'], act_dic['index']) self.failUnless( scipy.allclose(scipy.array(expected_dic['mid_lat_lon']), act_dic['mid_lat_lon']))
def test_bin_extent(self): ###### # Same data as first test, but calling bin_extent(), and bins=(3,2) ###### lon = [0.5, 1.3, 1.7, 2.3, 2.5, 2.7, 0.3, 0.7, 0.3, 0.7, 1.3] lat = [1.5, 1.7, 1.3, 1.3, 1.5, 1.7, 0.7, 0.7, 0.3, 0.3, 0.7] bins = (2, 3) # expected result for above data # Not checking the mid cell values, since I couldn't be bothered # calcing them... so this isn't that good a test. expected_res = [[{ 'index': [6, 7, 8, 9], 'mid_lat_lon': (0.5, 0.5) }, { 'index': [0], 'mid_lat_lon': (1.5, 0.5) }], [{ 'index': [10], 'mid_lat_lon': (0.5, 1.5) }, { 'index': [1, 2], 'mid_lat_lon': (1.5, 1.5) }], [{ 'index': [], 'mid_lat_lon': (0.5, 2.5) }, { 'index': [3, 4, 5], 'mid_lat_lon': (1.5, 2.5) }]] res = util.bin_extent(lat, lon, bins) for expected, actual in map(None, expected_res, res): for expected_dic, act_dic in map(None, expected, actual): self.failUnlessEqual(expected_dic['index'], act_dic['index'])
def test_bin_extent(self): ###### # Same data as first test, but calling bin_extent(), and bins=(3,2) ###### lon = [0.5, 1.3, 1.7, 2.3, 2.5, 2.7, 0.3, 0.7, 0.3, 0.7, 1.3] lat = [1.5, 1.7, 1.3, 1.3, 1.5, 1.7, 0.7, 0.7, 0.3, 0.3, 0.7] bins = (2, 3) # expected result for above data # Not checking the mid cell values, since I couldn't be bothered # calcing them... so this isn't that good a test. expected_res = [[{'index': [6, 7, 8, 9], 'mid_lat_lon': (0.5, 0.5)}, {'index': [0], 'mid_lat_lon': (1.5, 0.5)}], [{'index': [10], 'mid_lat_lon': (0.5, 1.5)}, {'index': [1, 2], 'mid_lat_lon': (1.5, 1.5)}], [{'index': [], 'mid_lat_lon': (0.5, 2.5)}, {'index': [3, 4, 5], 'mid_lat_lon': (1.5, 2.5)}]] res = util.bin_extent(lat, lon, bins) for expected, actual in map(None, expected_res, res): for expected_dic, act_dic in map(None, expected, actual): self.failUnlessEqual(expected_dic['index'], act_dic['index'])