def testSanity(self): """levels_to_ip1(ip1_to_levels(n))==n for all n""" for lvlnew,lvlold,ipnew,ipold,kind in self.knownValues: (lvl2,kind2) = Fstdc.ip1_to_level([ipnew])[0] (ipnew2,ipold2) = Fstdc.level_to_ip1([lvl2],kind2)[0] self.assertEqual(ipnew2,ipnew) (lvl2,kind2) = Fstdc.ip1_to_level([ipold])[0] (ipnew2,ipold2) = Fstdc.level_to_ip1([lvl2],kind2)[0] self.assertEqual(ipold2,ipold)
def testip1_to_levelsKnownValues(self): """ip1_to_level should give known result with known input""" for lvlnew,lvlold,ipnew,ipold,kind in self.knownValues: (lvl2,kind2) = Fstdc.ip1_to_level([ipnew])[0] self.assertEqual(kind2,kind) self.assertAlmostEqual(lvlnew,lvl2,6) (lvl2,kind2) = Fstdc.ip1_to_level([ipold])[0] self.assertEqual(kind2,kind) self.assertAlmostEqual(lvlold,lvl2,6)
def ip1_to_levels(ip1list): """Decode ip1 value into (level, kind) levels_list = ip1_to_levels(ip1list) @param ip1list list of ip1 values to decode @return list of decoded level values-tuple ((level, kind), ...) kind = 0: levels are in height [m] (metres) with respect to sea level kind = 1: levels are in sigma [sg] (0.0 -> 1.0) kind = 2: levels are in pressure [mb] (millibars) kind = 3: levels are in arbitrary code kind = 4: levels are in height [M] (metres) with respect to ground level kind = 5: levels are in hybrid coordinates [hy] kind = 6: levels are in theta [th] @exception TypeError if ip1list is not a tuple or list Example of use (and doctest tests): >>> [(int(x*10.e6+0.5), y) for x, y in ip1_to_levels([0, 1, 1000, 1199, 1200, 1201, 9999, 12000, 12001, 12002, 13000])] [(0, 2), (10000000, 2), (10000000000, 2), (10000000, 3), (0, 3), (500, 2), (7999000, 1), (10000000, 1), (0, 0), (50000000, 0), (49950000000, 0)] >>> [(int(x*10.e6+0.5), y) for x, y in ip1_to_levels([15728640, 12001, 8523608, 12004, 6441456, 12301, 6843956, 13106, 5370380, 14551])] [(0, 0), (0, 0), (135000000, 0), (150000000, 0), (15000000000, 0), (15000000000, 0), (55250000000, 0), (55250000000, 0), (127500000000, 0), (127500000000, 0)] >>> [(int(x*10.e6+0.5), y) for x, y in ip1_to_levels([32505856, 2000, 27362976, 3000, 28511552, 2200, 30038128, 2068, 32805856, 2000])] [(0, 1), (0, 1), (1000000, 1), (1000000, 1), (200000, 1), (200000, 1), (67800, 1), (68000, 1), (30, 1), (0, 1)] >>> [(int(x*10.e6+0.5), y) for x, y in ip1_to_levels([39948288, 1024, 41744464, 850, 41544464, 650, 41394464, 500, 42043040, 10, 43191616, 1840, 44340192, 1660])] [(10240000000, 2), (10240000000, 2), (8500000000, 2), (8500000000, 2), (6500000000, 2), (6500000000, 2), (5000000000, 2), (5000000000, 2), (100000000, 2), (100000000, 2), (20000000, 2), (20000000, 2), (3000000, 2), (3000000, 2)] """ if not isinstance(ip1list, (list, tuple)): raise TypeError('ip1_to_levels: levels should be a list or a tuple') if isinstance(ip1list, tuple): levels = Fstdc.ip1_to_level(list(ip1list)) else: levels = Fstdc.ip1_to_level(ip1list) if not levels: raise TypeError( 'ip1_to_levels: wrong args type; ip1_to_levels(ip1list)') return (levels)
def ip1_to_levels(ip1list): """Decode ip1 value into (level, kind) levels_list = ip1_to_levels(ip1list) @param ip1list list of ip1 values to decode @return list of decoded level values-tuple ((level, kind), ...) kind = 0: levels are in height [m] (metres) with respect to sea level kind = 1: levels are in sigma [sg] (0.0 -> 1.0) kind = 2: levels are in pressure [mb] (millibars) kind = 3: levels are in arbitrary code kind = 4: levels are in height [M] (metres) with respect to ground level kind = 5: levels are in hybrid coordinates [hy] kind = 6: levels are in theta [th] @exception TypeError if ip1list is not a tuple or list Example of use (and doctest tests): >>> [(int(x*10.e6+0.5), y) for x, y in ip1_to_levels([0, 1, 1000, 1199, 1200, 1201, 9999, 12000, 12001, 12002, 13000])] [(0, 2), (10000000, 2), (10000000000, 2), (10000000, 3), (0, 3), (500, 2), (7999000, 1), (10000000, 1), (0, 0), (50000000, 0), (49950000000, 0)] >>> [(int(x*10.e6+0.5), y) for x, y in ip1_to_levels([15728640, 12001, 8523608, 12004, 6441456, 12301, 6843956, 13106, 5370380, 14551])] [(0, 0), (0, 0), (135000000, 0), (150000000, 0), (15000000000, 0), (15000000000, 0), (55250000000, 0), (55250000000, 0), (127500000000, 0), (127500000000, 0)] >>> [(int(x*10.e6+0.5), y) for x, y in ip1_to_levels([32505856, 2000, 27362976, 3000, 28511552, 2200, 30038128, 2068, 32805856, 2000])] [(0, 1), (0, 1), (1000000, 1), (1000000, 1), (200000, 1), (200000, 1), (67800, 1), (68000, 1), (30, 1), (0, 1)] >>> [(int(x*10.e6+0.5), y) for x, y in ip1_to_levels([39948288, 1024, 41744464, 850, 41544464, 650, 41394464, 500, 42043040, 10, 43191616, 1840, 44340192, 1660])] [(10240000000, 2), (10240000000, 2), (8500000000, 2), (8500000000, 2), (6500000000, 2), (6500000000, 2), (5000000000, 2), (5000000000, 2), (100000000, 2), (100000000, 2), (20000000, 2), (20000000, 2), (3000000, 2), (3000000, 2)] """ if not type(ip1list) in (type(()), type([])): raise TypeError, 'ip1_to_levels: levels should be a list or a tuple' if type(ip1list) == type(()): levels = Fstdc.ip1_to_level(list(ip1list)) else: levels = Fstdc.ip1_to_level(ip1list) if not levels: raise TypeError, 'ip1_to_levels: wrong args type; ip1_to_levels(ip1list)' return(levels)