Exemplo n.º 1
0
 def testSanity(self):
     """cigaxg(cxgaig(n))==n for all n"""
     for name, proj, dims, xg, ig in self.knownValues:
         xgout = Fstdc.cigaxg(proj, ig[0], ig[1], ig[2], ig[3])
         igout = Fstdc.cxgaig(proj, xgout[0], xgout[1], xgout[2], xgout[3])
         self.assertEqual(igout, ig,
                          name + igout.__repr__() + xgout.__repr__())
Exemplo n.º 2
0
 def testCigaxgKnownValues(self):
     """Cigaxg should give known result with known input"""
     for name,proj,dims,xg,ig in self.knownValues:
         xgout = Fstdc.cigaxg(proj,ig[0],ig[1],ig[2],ig[3])
         self.assertAlmostEqual(xgout[0],xg[0],1,name+'[0]'+xgout.__repr__())
         self.assertAlmostEqual(xgout[1],xg[1],1,name+'[1]'+xgout.__repr__())
         self.assertAlmostEqual(xgout[2],xg[2],1,name+'[2]'+xgout.__repr__())
         self.assertAlmostEqual(xgout[3],xg[3],1,name+'[3]'+xgout.__repr__())
Exemplo n.º 3
0
 def testCigaxgKnownValues(self):
     """Cigaxg should give known result with known input"""
     for name,proj,dims,xg,ig in self.knownValues:
         xgout = Fstdc.cigaxg(proj,ig[0],ig[1],ig[2],ig[3])
         self.assertAlmostEqual(xgout[0],xg[0],1,name+'[0]'+xgout.__repr__())
         self.assertAlmostEqual(xgout[1],xg[1],1,name+'[1]'+xgout.__repr__())
         self.assertAlmostEqual(xgout[2],xg[2],1,name+'[2]'+xgout.__repr__())
         self.assertAlmostEqual(xgout[3],xg[3],1,name+'[3]'+xgout.__repr__())
Exemplo n.º 4
0
def cigaxg(grtyp, ig1, ig2=None, ig3=None, ig4=None):
    """Decode grid definition values into xg1-4 for the specified grid type

    (xg1, xg2, xg3, xg4) = cigaxg(grtyp, ig1, ig2, ig3, ig4):
    (xg1, xg2, xg3, xg4) = cigaxg(grtyp, (ig1, ig2, ig3, ig4)):

    @param grtyp
    @param ig1 ig1 value (int) or tuple of the form (ig1, ig2, ig3, ig4)
    @param ig2 ig2 value (int)
    @param ig3 ig3 value (int)
    @param ig4 ig4 value (int)
    @return Tuple of decoded grid desc values (xg1, xg2, xg3, xg4)
    @exception TypeError if args are of wrong type
    @exception ValueError if grtyp is not in ('A', 'B', 'E', 'G', 'L', 'N', 'S')

    Example of use (and doctest tests):

    >>> cigaxg('N', 2005,  2005,  2100,   400)
    (200.5, 200.5, 40000.0, 21.0)
    >>> cigaxg('N', 400,  1000, 29830, 57333)
    (200.5013427734375, 220.49639892578125, 40000.0, 260.0)
    >>> cigaxg('S', 2005,  2005,  2100,   400)
    (200.5, 200.5, 40000.0, 21.0)
    >>> cigaxg('L', 50,    50,    50, 18000)
    (-89.5, 180.0, 0.5, 0.5)
    >>> ig1234 = (50,    50,    50, 18000)
    >>> cigaxg('L', ig1234)
    (-89.5, 180.0, 0.5, 0.5)

    Example of bad use (and doctest tests):

    >>> cigaxg('L', 50,    50,    50, 18000.)
    Traceback (most recent call last):
    ...
    TypeError: cigaxg error: ig1, ig2, ig3, ig4 should be of type int:(50, 50, 50, 18000.0)
    >>> cigaxg('I', 50,    50,    50, 18000)
    Traceback (most recent call last):
    ...
    ValueError: cigaxg error: grtyp ['I'] must be one of ('A', 'B', 'E', 'G', 'L', 'N', 'S')
    """
    validgrtyp = ('A', 'B', 'E', 'G', 'L', 'N', 'S')  #I
    if ig2 == ig3 == ig4 == None and isinstance(
            ig1, (list, tuple)) and len(ig1) == 4:
        (ig1, ig2, ig3, ig4) = ig1
    if None in (grtyp, ig1, ig2, ig3, ig4):
        raise TypeError(
            'cigaxg error: missing argument, calling is cigaxg(grtyp, ig1, ig2, ig3, ig4)'
        )
    elif not grtyp in validgrtyp:
        raise ValueError('cigaxg error: grtyp [' + repr(grtyp) +
                         '] must be one of ' + repr(validgrtyp))
    elif not (type(ig1) == type(ig2) == type(ig3) == type(ig4) == type(0)):
        raise TypeError(
            'cigaxg error: ig1, ig2, ig3, ig4 should be of type int:' +
            repr((ig1, ig2, ig3, ig4)))
    else:
        return (Fstdc.cigaxg(grtyp, ig1, ig2, ig3, ig4))
Exemplo n.º 5
0
def cigaxg(grtyp, ig1, ig2=None, ig3=None, ig4=None):
    """Decode grid definition values into xg1-4 for the specified grid type

    (xg1, xg2, xg3, xg4) = cigaxg(grtyp, ig1, ig2, ig3, ig4):
    (xg1, xg2, xg3, xg4) = cigaxg(grtyp, (ig1, ig2, ig3, ig4)):

    @param grtyp
    @param ig1 ig1 value (int) or tuple of the form (ig1, ig2, ig3, ig4)
    @param ig2 ig2 value (int)
    @param ig3 ig3 value (int)
    @param ig4 ig4 value (int)
    @return Tuple of decoded grid desc values (xg1, xg2, xg3, xg4)
    @exception TypeError if args are of wrong type
    @exception ValueError if grtyp is not in ('A', 'B', 'E', 'G', 'L', 'N', 'S')

    Example of use (and doctest tests):

    >>> cigaxg('N', 2005,  2005,  2100,   400)
    (200.5, 200.5, 40000.0, 21.0)
    >>> cigaxg('N', 400,  1000, 29830, 57333)
    (200.5013427734375, 220.4964141845703, 40000.0, 260.0)
    >>> cigaxg('S', 2005,  2005,  2100,   400)
    (200.5, 200.5, 40000.0, 21.0)
    >>> cigaxg('L', 50,    50,    50, 18000)
    (-89.5, 180.0, 0.5, 0.5)
    >>> ig1234 = (50,    50,    50, 18000)
    >>> cigaxg('L', ig1234)
    (-89.5, 180.0, 0.5, 0.5)

    Example of bad use (and doctest tests):

    >>> cigaxg('L', 50,    50,    50, 18000.)
    Traceback (most recent call last):
    ...
    TypeError: cigaxg error: ig1, ig2, ig3, ig4 should be of type int:(50, 50, 50, 18000.0)
    >>> cigaxg('I', 50,    50,    50, 18000)
    Traceback (most recent call last):
    ...
    ValueError: cigaxg error: grtyp ['I'] must be one of ('A', 'B', 'E', 'G', 'L', 'N', 'S')
    """
    validgrtyp = ('A', 'B', 'E', 'G', 'L', 'N', 'S') #I
    if ig2 == ig3 == ig4 == None and type(ig1) in (type([]), type(())) and len(ig1) == 4:
        (ig1, ig2, ig3, ig4) = ig1
    if None in (grtyp, ig1, ig2, ig3, ig4):
        raise TypeError, 'cigaxg error: missing argument, calling is cigaxg(grtyp, ig1, ig2, ig3, ig4)'
    elif not grtyp in validgrtyp:
        raise ValueError, 'cigaxg error: grtyp ['+repr(grtyp)+'] must be one of '+repr(validgrtyp)
    elif not (type(ig1) == type(ig2) == type(ig3) == type(ig4) == type(0)):
        raise TypeError, 'cigaxg error: ig1, ig2, ig3, ig4 should be of type int:'+repr((ig1, ig2, ig3, ig4))
    else:
        return(Fstdc.cigaxg(grtyp, ig1, ig2, ig3, ig4))
Exemplo n.º 6
0
 def testSanity(self):
     """cigaxg(cxgaig(n))==n for all n"""
     for name,proj,dims,xg,ig in self.knownValues:
         xgout = Fstdc.cigaxg(proj,ig[0],ig[1],ig[2],ig[3])
         igout = Fstdc.cxgaig(proj,xgout[0],xgout[1],xgout[2],xgout[3])
         self.assertEqual(igout,ig,name+igout.__repr__()+xgout.__repr__())