Exemplo n.º 1
0
 def test_Fstdc_ezgetlalo_KnownValues2(self):
     """Fstdc_ezgetlalo corners should give known result with known input"""
     (ni,nj) = self.la.shape
     grtyp='L'
     grref='L'
     (ig1,ig2,ig3,ig4) =  Fstdc.cxgaig(grtyp,-69.5,180.0,0.5,0.5)
     hasAxes = 0
     doCorners = 1
     (i0,j0) = (0,0)
     (la2,lo2,cla2,clo2) = Fstdc.ezgetlalo((ni,nj),grtyp,(grref,ig1,ig2,ig3,ig4),(None,None),hasAxes,(i0,j0),doCorners)
     if numpy.any(self.la!=la2):
         print("\nLAT Expected:\n",self.la)
         print("LAT Got:\n",la2)
     if numpy.any(self.lo!=lo2):
         print("\nLON Expected:\n",self.lo)
         print("LON Got:\n",lo2)
     self.assertFalse(numpy.any(self.la!=la2))
     self.assertFalse(numpy.any(self.lo!=lo2))
     for ic in range(0,4):
         if numpy.any(self.cla[ic,...]!=cla2[ic,...]):
             print("\n",ic,'cla')
             print("LAT Expected:\n",self.cla[ic,...])
             print("LAT Got:\n",cla2[ic,...])
         self.assertFalse(numpy.any(self.cla[ic,...]!=cla2[ic,...]))
         if numpy.any(self.clo[ic,...]!=clo2[ic,...]):
             print("\n",ic,'clo')
             print("\nLON Expected:\n",self.clo[ic,...])
             print("LON Got:\n",clo2[ic,...])
         self.assertFalse(numpy.any(self.clo[ic,...]!=clo2[ic,...]))
Exemplo n.º 2
0
 def test_Fstdc_ezgetlalo_KnownValues2(self):
     """Fstdc_ezgetlalo corners should give known result with known input"""
     (ni,nj) = self.la.shape
     grtyp='L'
     grref='L'
     (ig1,ig2,ig3,ig4) =  Fstdc.cxgaig(grtyp,-69.5,180.0,0.5,0.5)
     hasAxes = 0
     doCorners = 1
     (i0,j0) = (0,0)
     (la2,lo2,cla2,clo2) = Fstdc.ezgetlalo((ni,nj),grtyp,(grref,ig1,ig2,ig3,ig4),(None,None),hasAxes,(i0,j0),doCorners)
     if numpy.any(self.la!=la2):
         print "\nLAT Expected:\n",self.la
         print "LAT Got:\n",la2
     if numpy.any(self.lo!=lo2):
         print "\nLON Expected:\n",self.lo
         print "LON Got:\n",lo2
     self.assertFalse(numpy.any(self.la!=la2))
     self.assertFalse(numpy.any(self.lo!=lo2))
     for ic in range(0,4):
         if numpy.any(self.cla[ic,...]!=cla2[ic,...]):
             print "\n",ic,'cla'
             print "LAT Expected:\n",self.cla[ic,...]
             print "LAT Got:\n",cla2[ic,...]
         self.assertFalse(numpy.any(self.cla[ic,...]!=cla2[ic,...]))
         if numpy.any(self.clo[ic,...]!=clo2[ic,...]):
             print "\n",ic,'clo'
             print "\nLON Expected:\n",self.clo[ic,...]
             print "LON Got:\n",clo2[ic,...]
         self.assertFalse(numpy.any(self.clo[ic,...]!=clo2[ic,...]))
Exemplo n.º 3
0
 def test_Fstdc_ezgetlalo_KnownValues2(self):
     """Fstdc_ezgetlalo corners should give known result with known input"""
     (ni, nj) = self.la.shape
     grtyp = "L"
     grref = "L"
     (ig1, ig2, ig3, ig4) = Fstdc.cxgaig(grtyp, -89.5, 180.0, 0.5, 0.5)
     hasAxes = 0
     doCorners = 1
     (i0, j0) = (0, 0)
     (la2, lo2, cla2, clo2) = Fstdc.ezgetlalo(
         (ni, nj), grtyp, (grref, ig1, ig2, ig3, ig4), (None, None), hasAxes, (i0, j0), doCorners
     )
     if numpy.any(self.la != la2):
         print self.la
         print la2
     if numpy.any(self.lo != lo2):
         print self.lo
         print lo2
     self.assertFalse(numpy.any(self.la != la2))
     self.assertFalse(numpy.any(self.lo != lo2))
     for ic in range(0, 4):
         if numpy.any(self.cla[ic, ...] != cla2[ic, ...]):
             print ic, "cla"
             print self.cla[ic, ...]
             print cla2[ic, ...]
         self.assertFalse(numpy.any(self.cla[ic, ...] != cla2[ic, ...]))
         if numpy.any(self.clo[ic, ...] != clo2[ic, ...]):
             print ic, "clo"
             print self.clo[ic, ...]
             print clo2[ic, ...]
         self.assertFalse(numpy.any(self.clo[ic, ...] != clo2[ic, ...]))
Exemplo n.º 4
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.º 5
0
def cxgaig(grtyp, xg1, xg2=None, xg3=None, xg4=None):
    """Encode grid definition values into ig1-4 for the specified grid type

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

    @param grtyp
    @param xg1 xg1 value (float) or tuple of the form (xg1, xg2, xg3, xg4)
    @param xg2 xg2 value (float)
    @param xg3 xg3 value (float)
    @param xg4 xg4 value (float)
    @return Tuple of encoded grid desc values (ig1, ig2, ig3, ig4)
    @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):

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

    Example of bad use (and doctest tests):

    >>> cxgaig('L', -89.5, 180  , 0.5, 0.5)
    Traceback (most recent call last):
    ...
    TypeError: cxgaig error: ig1, ig2, ig3, ig4 should be of type real:(-89.5, 180, 0.5, 0.5)
    >>> cxgaig('I', -89.5, 180.0, 0.5, 0.5)
    Traceback (most recent call last):
    ...
    ValueError: cxgaig error: grtyp ['I'] must be one of ('A', 'B', 'E', 'G', 'L', 'N', 'S')
    """
    validgrtyp = ('A', 'B', 'E', 'G', 'L', 'N', 'S')  #I
    if xg2 == xg3 == xg4 == None and isinstance(
            xg1, (list, tuple)) and len(xg1) == 4:
        (xg1, xg2, xg3, xg4) = xg1
    if None in (grtyp, xg1, xg2, xg3, xg4):
        raise TypeError(
            'cxgaig error: missing argument, calling is cxgaig(grtyp, xg1, xg2, xg3, xg4)'
        )
    elif not grtyp in validgrtyp:
        raise ValueError('cxgaig error: grtyp [' + repr(grtyp) +
                         '] must be one of ' + repr(validgrtyp))
    elif not (type(xg1) == type(xg2) == type(xg3) == type(xg4) == type(0.)):
        raise TypeError(
            'cxgaig error: ig1, ig2, ig3, ig4 should be of type real:' +
            repr((xg1, xg2, xg3, xg4)))
    else:
        return (Fstdc.cxgaig(grtyp, xg1, xg2, xg3, xg4))
Exemplo n.º 6
0
 def gridL(self,dlalo=0.5,nij=10):
     """provide grid and rec values for other tests"""
     grtyp='L'
     grref=grtyp
     la0 = 0.-dlalo*(nij/2.)
     lo0 = 180.-dlalo*(nij/2.)
     ig14 = (ig1,ig2,ig3,ig4) =  Fstdc.cxgaig(grtyp,la0,lo0,dlalo,dlalo)
     axes = (None,None)
     hasAxes = 0
     ij0 = (1,1)
     doCorners = 0
     (la,lo) = Fstdc.ezgetlalo((nij,nij),grtyp,(grref,ig1,ig2,ig3,ig4),axes,hasAxes,ij0,doCorners)
     return (grtyp,ig14,(nij,nij),la,lo)
Exemplo n.º 7
0
 def gridL(self,dlalo=0.5,nij=10):
     """provide grid and rec values for other tests"""
     grtyp='L'
     grref=grtyp
     la0 = 0.-dlalo*(nij/2.)
     lo0 = 180.-dlalo*(nij/2.)
     ig14 = (ig1,ig2,ig3,ig4) =  Fstdc.cxgaig(grtyp,la0,lo0,dlalo,dlalo)
     axes = (None,None)
     hasAxes = 0
     ij0 = (1,1)
     doCorners = 0
     (la,lo) = Fstdc.ezgetlalo((nij,nij),grtyp,(grref,ig1,ig2,ig3,ig4),axes,hasAxes,ij0,doCorners)
     return (grtyp,ig14,(nij,nij),la,lo)
Exemplo n.º 8
0
def cxgaig(grtyp, xg1, xg2=None, xg3=None, xg4=None):
    """Encode grid definition values into ig1-4 for the specified grid type

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

    @param grtyp
    @param xg1 xg1 value (float) or tuple of the form (xg1, xg2, xg3, xg4)
    @param xg2 xg2 value (float)
    @param xg3 xg3 value (float)
    @param xg4 xg4 value (float)
    @return Tuple of encoded grid desc values (ig1, ig2, ig3, ig4)
    @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):

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

    Example of bad use (and doctest tests):

    >>> cxgaig('L', -89.5, 180  , 0.5, 0.5)
    Traceback (most recent call last):
    ...
    TypeError: cxgaig error: ig1, ig2, ig3, ig4 should be of type real:(-89.5, 180, 0.5, 0.5)
    >>> cxgaig('I', -89.5, 180.0, 0.5, 0.5)
    Traceback (most recent call last):
    ...
    ValueError: cxgaig error: grtyp ['I'] must be one of ('A', 'B', 'E', 'G', 'L', 'N', 'S')
    """
    validgrtyp = ('A', 'B', 'E', 'G', 'L', 'N', 'S') #I
    if xg2 == xg3 == xg4 == None and type(xg1) in (type([]), type(())) and len(xg1) == 4:
        (xg1, xg2, xg3, xg4) = xg1
    if None in (grtyp, xg1, xg2, xg3, xg4):
        raise TypeError, 'cxgaig error: missing argument, calling is cxgaig(grtyp, xg1, xg2, xg3, xg4)'
    elif not grtyp in validgrtyp:
        raise ValueError, 'cxgaig error: grtyp ['+repr(grtyp)+'] must be one of '+repr(validgrtyp)
    elif not (type(xg1) == type(xg2) == type(xg3) == type(xg4) == type(0.)):
        raise TypeError, 'cxgaig error: ig1, ig2, ig3, ig4 should be of type real:'+repr((xg1, xg2, xg3, xg4))
    else:
       return(Fstdc.cxgaig(grtyp, xg1, xg2, xg3, xg4))
Exemplo n.º 9
0
 def test_Fstdc_ezgetlalo_KnownValues(self):
     """Fstdc_ezgetlalo should give known result with known input"""
     (ni,nj) = self.la.shape
     grtyp='L'
     grref='L'
     (ig1,ig2,ig3,ig4) =  Fstdc.cxgaig(grtyp,-69.5,180.0,0.5,0.5)
     hasAxes = 0
     doCorners = 0
     (i0,j0) = (0,0)
     (la2,lo2) = Fstdc.ezgetlalo((ni,nj),grtyp,(grref,ig1,ig2,ig3,ig4),(None,None),hasAxes,(i0,j0),doCorners)
     if numpy.any(self.la!=la2):
         print "\nLAT Expected:\n",self.la
         print "LAT Got:\n",la2
     if numpy.any(self.lo!=lo2):
         print "\nLON Expected:\n",self.lo
         print "LON Got:\n",lo2
     self.assertFalse(numpy.any(self.la!=la2))
     self.assertFalse(numpy.any(self.lo!=lo2))
Exemplo n.º 10
0
 def test_Fstdc_ezgetlalo_Dieze_KnownValues(self):
     """Fstdc_ezgetlalo with #-grid should give known result with known input"""
     (ni,nj) = self.la.shape
     grtyp='#'
     grref='L'
     (ig1,ig2,ig3,ig4) =  Fstdc.cxgaig(grref,0.,0.,1.,1.)
     xaxis = self.lo[:,0].reshape((self.lo.shape[0],1)).copy('FORTRAN')
     yaxis = self.la[0,:].reshape((1,self.la.shape[1])).copy('FORTRAN')
     hasAxes = 1
     doCorners = 0
     (i0,j0) = (2,2)
     (la2,lo2) = Fstdc.ezgetlalo((ni-1,nj-1),grtyp,(grref,ig1,ig2,ig3,ig4),(xaxis,yaxis),hasAxes,(i0,j0),doCorners)
     if numpy.any(self.la[1:,1:]!=la2):
         print "\nLAT Expected:\n",self.la[1:,1:]
         print "LAT Got:\n",la2
     if numpy.any(self.lo[1:,1:]!=lo2):
         print "\nLON Expected:\n",self.lo[1:,1:]
         print "LON Got:\n",lo2
     self.assertFalse(numpy.any(self.la[1:,1:]!=la2))
     self.assertFalse(numpy.any(self.lo[1:,1:]!=lo2))
Exemplo n.º 11
0
 def test_Fstdc_ezgetlalo_Dieze_KnownValues(self):
     """Fstdc_ezgetlalo with #-grid should give known result with known input"""
     (ni,nj) = self.la.shape
     grtyp='#'
     grref='L'
     (ig1,ig2,ig3,ig4) =  Fstdc.cxgaig(grref,0.,0.,1.,1.)
     xaxis = self.lo[:,0].reshape((self.lo.shape[0],1)).copy('FORTRAN')
     yaxis = self.la[0,:].reshape((1,self.la.shape[1])).copy('FORTRAN')
     hasAxes = 1
     doCorners = 0
     (i0,j0) = (2,2)
     (la2,lo2) = Fstdc.ezgetlalo((ni-1,nj-1),grtyp,(grref,ig1,ig2,ig3,ig4),(xaxis,yaxis),hasAxes,(i0,j0),doCorners)
     if numpy.any(self.la[1:,1:]!=la2):
         print("\nLAT Expected:\n",self.la[1:,1:])
         print("LAT Got:\n",la2)
     if numpy.any(self.lo[1:,1:]!=lo2):
         print("\nLON Expected:\n",self.lo[1:,1:])
         print("LON Got:\n",lo2)
     self.assertFalse(numpy.any(self.la[1:,1:]!=la2))
     self.assertFalse(numpy.any(self.lo[1:,1:]!=lo2))
Exemplo n.º 12
0
 def test_Fstdc_ezgetlalo_KnownValues(self):
     """Fstdc_ezgetlalo should give known result with known input"""
     (ni, nj) = self.la.shape
     grtyp = 'L'
     grref = 'L'
     (ig1, ig2, ig3, ig4) = Fstdc.cxgaig(grtyp, -89.5, 180.0, 0.5, 0.5)
     hasAxes = 0
     doCorners = 0
     (i0, j0) = (0, 0)
     (la2, lo2) = Fstdc.ezgetlalo((ni, nj), grtyp,
                                  (grref, ig1, ig2, ig3, ig4), (None, None),
                                  hasAxes, (i0, j0), doCorners)
     if numpy.any(self.la != la2):
         print self.la
         print la2
     if numpy.any(self.lo != lo2):
         print self.lo
         print lo2
     self.assertFalse(numpy.any(self.la != la2))
     self.assertFalse(numpy.any(self.lo != lo2))
Exemplo n.º 13
0
 def test_Fstdc_ezgetlalo_Z_KnownValues(self):
     """Fstdc_ezgetlalo with Z grid should give known result with known input"""
     (ni, nj) = self.la.shape
     grtyp = 'Z'
     grref = 'L'
     (ig1, ig2, ig3, ig4) = Fstdc.cxgaig(grref, 0., 0., 1., 1.)
     xaxis = self.lo[:, 0].reshape((self.lo.shape[0], 1)).copy('FORTRAN')
     yaxis = self.la[0, :].reshape((1, self.la.shape[1])).copy('FORTRAN')
     hasAxes = 1
     doCorners = 0
     (i0, j0) = (0, 0)
     (la2, lo2) = Fstdc.ezgetlalo(
         (ni, nj), grtyp, (grref, ig1, ig2, ig3, ig4), (xaxis, yaxis),
         hasAxes, (i0, j0), doCorners)
     if numpy.any(self.la != la2):
         print self.la
         print la2
     if numpy.any(self.lo != lo2):
         print self.lo
         print lo2
     self.assertFalse(numpy.any(self.la != la2))
     self.assertFalse(numpy.any(self.lo != lo2))
Exemplo n.º 14
0
 def test_Fstdc_ezgetlalo_Dieze_KnownValues(self):
     """Fstdc_ezgetlalo with #-grid should give known result with known input"""
     (ni, nj) = self.la.shape
     grtyp = "#"
     grref = "L"
     (ig1, ig2, ig3, ig4) = Fstdc.cxgaig(grref, 0.0, 0.0, 1.0, 1.0)
     xaxis = self.lo[:, 0].reshape((self.lo.shape[0], 1)).copy("FORTRAN")
     yaxis = self.la[0, :].reshape((1, self.la.shape[1])).copy("FORTRAN")
     hasAxes = 1
     doCorners = 0
     (i0, j0) = (2, 2)
     (la2, lo2) = Fstdc.ezgetlalo(
         (ni - 1, nj - 1), grtyp, (grref, ig1, ig2, ig3, ig4), (xaxis, yaxis), hasAxes, (i0, j0), doCorners
     )
     if numpy.any(self.la[1:, 1:] != la2):
         print self.la[1:, 1:]
         print la2
     if numpy.any(self.lo[1:, 1:] != lo2):
         print self.lo[1:, 1:]
         print lo2
     self.assertFalse(numpy.any(self.la[1:, 1:] != la2))
     self.assertFalse(numpy.any(self.lo[1:, 1:] != lo2))
Exemplo n.º 15
0
 def testCxgaigKnownValues(self):
     """Cxgaig should give known result with known input"""
     for name,proj,dims,xg,ig in self.knownValues:
         igout = Fstdc.cxgaig(proj,xg[0],xg[1],xg[2],xg[3])
         self.assertEqual(igout,ig,name+igout.__repr__())
Exemplo n.º 16
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.º 17
0
 def testCxgaigKnownValues(self):
     """Cxgaig should give known result with known input"""
     for name,proj,dims,xg,ig in self.knownValues:
         igout = Fstdc.cxgaig(proj,xg[0],xg[1],xg[2],xg[3])
         self.assertEqual(igout,ig,name+igout.__repr__())