Exemplo n.º 1
0
 def testLevels_to_ip1KnownValues(self):
     """level_to_ip1 should give known result with known input"""
     for lvlnew,lvlold,ipnew,ipold,kind in self.knownValues:
         (ipnew2,ipold2) = Fstdc.level_to_ip1([lvlnew],kind)[0]
         self.assertEqual(ipnew2,ipnew)
         (ipnew2,ipold2) = Fstdc.level_to_ip1([lvlold],kind)[0]
         self.assertEqual(ipold2,ipold)
Exemplo n.º 2
0
 def testLevels_to_ip1KnownValues(self):
     """level_to_ip1 should give known result with known input"""
     for lvlnew,lvlold,ipnew,ipold,kind in self.knownValues:
         (ipnew2,ipold2) = Fstdc.level_to_ip1([lvlnew],kind)[0]
         self.assertEqual(ipnew2,ipnew)
         (ipnew2,ipold2) = Fstdc.level_to_ip1([lvlold],kind)[0]
         self.assertEqual(ipold2,ipold)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
def levels_to_ip1(levels, kind):
    """Encode level value into ip1 for the specified kind

    ip1_list = levels_to_ip1(level_list, kind)
    @param level_list list of level values [units depending on kind]
    @param kind   type of levels [units] to be encoded
        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
        Looks like the following are not suppored yet in the fortran func convip,
        because they depend upon the local topography
            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]
    @return list of encoded level values-tuple ((ip1new, ip1old), ...)
    @exception TypeError if level_list is not a tuple or list
    @exception ValueError if kind is not an int in range of allowed kind

    Example of use (and doctest tests):

    >>> levels_to_ip1([0., 13.5, 1500., 5525., 12750.], 0)
    [(15728640, 12001), (8523608, 12004), (6441456, 12301), (6843956, 13106), (5370380, 14551)]
    >>> levels_to_ip1([0., 0.1, .02, 0.00678, 0.000003], 1)
    [(32505856, 2000), (27362976, 3000), (28511552, 2200), (30038128, 2068), (32805856, 2000)]
    >>> levels_to_ip1([1024., 850., 650., 500., 10., 2., 0.3], 2)
    [(39948288, 1024), (41744464, 850), (41544464, 650), (41394464, 500), (42043040, 10), (43191616, 1840), (44340192, 1660)]
    """
    if not isinstance(levels, (list, tuple)):
        raise ValueError(
            'levels_to_ip1: levels should be a list or a tuple; ' +
            repr(levels))
    if not isinstance(kind, _integer_types):
        raise TypeError(
            'levels_to_ip1: kind should be an int in range [0, 3]; ' +
            repr(kind))
    elif not kind in (0, 1, 2, 3):  #(0, 1, 2, 3, 4, 5, 6):
        raise ValueError(
            'levels_to_ip1: kind should be an int in range [0, 3]; ' +
            repr(kind))
    if isinstance(levels, tuple):
        ip1_list = Fstdc.level_to_ip1(list(levels), kind)
    else:
        ip1_list = Fstdc.level_to_ip1(levels, kind)
    if not ip1_list:
        raise TypeError(
            'levels_to_ip1: wrong args type; levels_to_ip1(levels, kind)')
    return (ip1_list)
Exemplo n.º 6
0
def levels_to_ip1(levels, kind):
    """Encode level value into ip1 for the specified kind

    ip1_list = levels_to_ip1(level_list, kind)
    @param level_list list of level values [units depending on kind]
    @param kind   type of levels [units] to be encoded
        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
        Looks like the following are not suppored yet in the fortran func convip,
        because they depend upon the local topography
            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]
    @return list of encoded level values-tuple ((ip1new, ip1old), ...)
    @exception TypeError if level_list is not a tuple or list
    @exception ValueError if kind is not an int in range of allowed kind

    Example of use (and doctest tests):

    >>> levels_to_ip1([0., 13.5, 1500., 5525., 12750.], 0)
    [(15728640, 12001), (8523608, 12004), (6441456, 12301), (6843956, 13106), (5370380, 14551)]
    >>> levels_to_ip1([0., 0.1, .02, 0.00678, 0.000003], 1)
    [(32505856, 2000), (27362976, 3000), (28511552, 2200), (30038128, 2068), (32805856, 2000)]
    >>> levels_to_ip1([1024., 850., 650., 500., 10., 2., 0.3], 2)
    [(39948288, 1024), (41744464, 850), (41544464, 650), (41394464, 500), (42043040, 10), (43191616, 1840), (44340192, 1660)]
    """
    if not type(levels) in (type(()), type([])):
        raise ValueError, 'levels_to_ip1: levels should be a list or a tuple; '+repr(levels)
    if type(kind) <> type(0):
        raise TypeError, 'levels_to_ip1: kind should be an int in range [0, 3]; '+repr(kind)
    elif not kind in (0, 1, 2, 3): #(0, 1, 2, 3, 4, 5, 6): 
        raise ValueError, 'levels_to_ip1: kind should be an int in range [0, 3]; '+repr(kind)
    if type(levels) == type(()):
        ip1_list = Fstdc.level_to_ip1(list(levels), kind)
    else:
        ip1_list = Fstdc.level_to_ip1(levels, kind)
    if not ip1_list:
        raise TypeError, 'levels_to_ip1: wrong args type; levels_to_ip1(levels, kind)'
    return(ip1_list)