예제 #1
0
 def test_writeGrid(self):
     ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES')
     file0  = os.path.join(ATM_MODEL_DFILES.strip(),'bcmk/geophy.fst')
     funit  = rmn.fstopenall(file0)
     rec    = rmn.fstlir(funit, nomvar='ME')
     grid0  = rmn.readGrid(funit, rec)
     rmn.fstcloseall(funit)
     grid1  = rmn.defGrid_L(180,60,0.,180.,1.,0.5)
     grid2  = rmn.defGrid_ZE(90,45,10.,11.,1.,0.5,0.,180.,1.,270.)
     grid3  = rmn.defGrid_YY(31,5,0.,180.,1.,270.)
     
     self.erase_testfile()
     myfile = self.fname
     funit  = rmn.fstopenall(myfile, rmn.FST_RW)
     rmn.fstecr(funit,rec['d'],rec)
     rmn.writeGrid(funit, grid0)
     rmn.writeGrid(funit, grid1)
     rmn.writeGrid(funit, grid2)
     rmn.writeGrid(funit, grid3)
     rmn.fstcloseall(funit)
     
     funit  = rmn.fstopenall(myfile, rmn.FST_RO)
     rec    = rmn.fstlir(funit, nomvar='ME')
     grid0b = rmn.readGrid(funit, rec)
     rmn.fstcloseall(funit)
     self.erase_testfile()
     for k in grid0.keys():
         if isinstance(grid0[k],np.ndarray):
             ok = np.any(np.abs(grid0b[k]-grid0[k]) > self.epsilon)
             self.assertFalse(ok, 'For k=%s, grid0b - grid0 = %s' % (k,str(np.abs(grid0b[k]-grid0[k]))))
         else:
             self.assertEqual(grid0b[k],grid0[k], 'For k=%s, expected:%s, got:%s' % (k, str(grid0[k]), str(grid0b[k])))
예제 #2
0
 def test_defGrid_YY(self):
     params = rmn.defGrid_YY(31, 1.5)
     params2 = rmn.decodeGrid(params['id'])
     for k in params.keys():
         if k == 'subgrid':
             pass
         elif isinstance(params[k], np.ndarray):
             ok = np.any(np.abs(params[k] - params2[k]) > self.epsilon)
             self.assertFalse(ok)
         elif isinstance(params[k], float):
             self.assertTrue(abs(params[k] - params2[k]) < self.epsilon)
         else:
             self.assertEqual(
                 params[k], params2[k], 'For k=%s, expected:%s, got:%s' %
                 (k, str(params[k]), str(params2[k])))
     for i in (0, 1):
         p0 = params['subgrid'][i]
         p2 = params2['subgrid'][i]
         for k in p0.keys():
             if isinstance(p0[k], np.ndarray):
                 ok = np.any(np.abs(p0[k] - p2[k]) > self.epsilon)
                 self.assertFalse(ok)
             elif isinstance(p0[k], float):
                 self.assertTrue(abs(p0[k] - p2[k]) < self.epsilon)
             else:
                 self.assertEqual(
                     p0[k], p2[k],
                     'sugridid=%d, For k=%s, expected:%s, got:%s' %
                     (i, k, str(p0[k]), str(p2[k])))
예제 #3
0
 def test_defGrid_YY(self):
     params = rmn.defGrid_YY(31,1.5)
     params2 = rmn.decodeGrid(params['id'])
     for k in params.keys():
         if k == 'subgrid':
             pass
         elif isinstance(params[k],np.ndarray):
             ok = np.any(np.abs(params[k]-params2[k]) > self.epsilon)
             self.assertFalse(ok)
         elif isinstance(params[k],float):
             self.assertTrue(abs(params[k]-params2[k]) < self.epsilon)
         else:
             self.assertEqual(params[k],params2[k], 'For k=%s, expected:%s, got:%s' % (k, str(params[k]), str(params2[k])))
     for i in (0,1):
         p0 = params['subgrid'][i]
         p2 = params2['subgrid'][i]
         for k in p0.keys():
             if isinstance(p0[k],np.ndarray):
                 ok = np.any(np.abs(p0[k]-p2[k]) > self.epsilon)
                 self.assertFalse(ok)
             elif isinstance(p0[k],float):
                 self.assertTrue(abs(p0[k]-p2[k]) < self.epsilon)
             else:
                 self.assertEqual(p0[k],p2[k],'sugridid=%d, For k=%s, expected:%s, got:%s' % (i, k, str(p0[k]), str(p2[k])))
예제 #4
0
    def test_writeGrid(self):
        ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES')
        file0 = os.path.join(ATM_MODEL_DFILES.strip(), 'bcmk/geophy.fst')
        funit = rmn.fstopenall(file0)
        rec = rmn.fstlir(funit, nomvar='ME')
        grid0 = rmn.readGrid(funit, rec)
        rmn.fstcloseall(funit)
        grid1 = rmn.defGrid_L(180, 60, 0., 180., 1., 0.5)
        grid2 = rmn.defGrid_ZE(90, 45, 10., 11., 1., 0.5, 0., 180., 1., 270.)
        grid3 = rmn.defGrid_YY(31, 5, 0., 180., 1., 270.)

        self.erase_testfile()
        myfile = self.fname
        funit = rmn.fstopenall(myfile, rmn.FST_RW)
        rmn.fstecr(funit, rec['d'], rec)
        rmn.writeGrid(funit, grid0)
        rmn.writeGrid(funit, grid1)
        rmn.writeGrid(funit, grid2)
        rmn.writeGrid(funit, grid3)
        rmn.fstcloseall(funit)

        funit = rmn.fstopenall(myfile, rmn.FST_RO)
        rec = rmn.fstlir(funit, nomvar='ME')
        grid0b = rmn.readGrid(funit, rec)
        rmn.fstcloseall(funit)
        self.erase_testfile()
        for k in grid0.keys():
            if isinstance(grid0[k], np.ndarray):
                ok = np.any(np.abs(grid0b[k] - grid0[k]) > self.epsilon)
                self.assertFalse(
                    ok, 'For k=%s, grid0b - grid0 = %s' %
                    (k, str(np.abs(grid0b[k] - grid0[k]))))
            else:
                self.assertEqual(
                    grid0b[k], grid0[k], 'For k=%s, expected:%s, got:%s' %
                    (k, str(grid0[k]), str(grid0b[k])))