Exemplo n.º 1
0
 def test_24qd(self):
     import os, sys
     import numpy as np
     import rpnpy.librmn.all as rmn
     import rpnpy.vgd.all as vgd
     g = rmn.defGrid_ZE(90, 45, 35., 250., 0.5, 0.5, 0., 180., 1., 270.)
     lvls = (500.,850.,1000.)
     v = vgd.vgd_new_pres(lvls)
     ip1list = vgd.vgd_get(v, 'VIPT')
     datyp   = rmn.FST_DATYP_LIST['float_IEEE_compressed']
     npdtype = rmn.dtype_fst2numpy(datyp)
     rshape  = (g['ni'], g['nj'], len(ip1list))
     r = rmn.FST_RDE_META_DEFAULT.copy()
     r.update(g)
     r.update({
         'nomvar': 'MASK',   'nk'    : len(ip1list),
         'dateo' : rmn.newdate(rmn.NEWDATE_PRINT2STAMP, 20160302, 1800000),
         'ip2'   : 6,        'deet'  : 3600, 'npas'  : 6,
         'etiket': 'my_etk', 'datyp' : datyp,
         'd'     : np.empty(rshape, dtype=npdtype, order='FORTRAN')
         })
     r['d'][:,:,:] = 0.
     r['d'][10:-11,5:-6,:] = 1.
     fileNameOut = 'newfromscratch.fst'
     fileIdOut = rmn.fstopenall(fileNameOut, rmn.FST_RW)
     r2d = r.copy()
     for k in range(len(ip1list)):
         r2d.update({'nk':1, 'ip1':ip1list[k], 'd':np.asfortranarray(r['d'][:,:,k])})
         rmn.fstecr(fileIdOut, r2d['d'], r2d)
     rmn.writeGrid(fileIdOut, g)
     vgd.vgd_write(v, fileIdOut)
     rmn.fstcloseall(fileIdOut)
     os.unlink(fileNameOut)  # Remove test file
Exemplo n.º 2
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])))
Exemplo n.º 3
0
 def test_24qd(self):
     import os, sys
     import numpy as np
     import rpnpy.librmn.all as rmn
     import rpnpy.vgd.all as vgd
     g = rmn.defGrid_ZE(90, 45, 35., 250., 0.5, 0.5, 0., 180., 1., 270.)
     lvls = (500., 850., 1000.)
     v = vgd.vgd_new_pres(lvls)
     ip1list = vgd.vgd_get(v, 'VIPT')
     datyp = rmn.FST_DATYP_LIST['float_IEEE_compressed']
     npdtype = rmn.dtype_fst2numpy(datyp)
     rshape = (g['ni'], g['nj'], len(ip1list))
     r = rmn.FST_RDE_META_DEFAULT.copy()
     r.update(g)
     r.update({
         'nomvar':
         'MASK',
         'nk':
         len(ip1list),
         'dateo':
         rmn.newdate(rmn.NEWDATE_PRINT2STAMP, 20160302, 1800000),
         'ip2':
         6,
         'deet':
         3600,
         'npas':
         6,
         'etiket':
         'my_etk',
         'datyp':
         datyp,
         'd':
         np.empty(rshape, dtype=npdtype, order='FORTRAN')
     })
     r['d'][:, :, :] = 0.
     r['d'][10:-11, 5:-6, :] = 1.
     fileNameOut = 'newfromscratch.fst'
     fileIdOut = rmn.fstopenall(fileNameOut, rmn.FST_RW)
     r2d = r.copy()
     for k in range(len(ip1list)):
         r2d.update({
             'nk': 1,
             'ip1': ip1list[k],
             'd': np.asfortranarray(r['d'][:, :, k])
         })
         rmn.fstecr(fileIdOut, r2d['d'], r2d)
     rmn.writeGrid(fileIdOut, g)
     vgd.vgd_write(v, fileIdOut)
     rmn.fstcloseall(fileIdOut)
     os.unlink(fileNameOut)  # Remove test file
Exemplo n.º 4
0
 def test_defGrid_ZE2(self):
     ## params = rmn.defGrid_ZE(90,45,10.,11.,1.,0.5,0.,180.,1.,270.)
     params = rmn.defGrid_ZE(90,45,10.,11.,1.,0.5,35.,230.,0.,320.)
     params2 = rmn.decodeGrid(params)
     for k in params.keys():
         if isinstance(params[k],np.ndarray):
             ok = np.any(np.abs(params[k]-params2[k]) > self.epsilon)
             #print k,not ok,np.max(np.abs(params[k]-params2[k])),np.min(params[k]),np.max(params[k])
             self.assertFalse(ok,(k,np.max(np.abs(params[k]-params2[k]))))
         elif isinstance(params[k],float):
             ok = abs(params[k]-params2[k]) > self.epsilon
             self.assertFalse(ok,(k,params[k]-params2[k]))
         else:
             #print k,params[k] == params2[k],params[k],params2[k]
             self.assertEqual(params[k],params2[k])
Exemplo n.º 5
0
 def test_defGrid_ZE2(self):
     ## params = rmn.defGrid_ZE(90,45,10.,11.,1.,0.5,0.,180.,1.,270.)
     params = rmn.defGrid_ZE(90, 45, 10., 11., 1., 0.5, 35., 230., 0., 320.)
     params2 = rmn.decodeGrid(params)
     for k in params.keys():
         if isinstance(params[k], np.ndarray):
             ok = np.any(np.abs(params[k] - params2[k]) > self.epsilon)
             #print k,not ok,np.max(np.abs(params[k]-params2[k])),np.min(params[k]),np.max(params[k])
             self.assertFalse(ok,
                              (k, np.max(np.abs(params[k] - params2[k]))))
         elif isinstance(params[k], float):
             ok = abs(params[k] - params2[k]) > self.epsilon
             self.assertFalse(ok, (k, params[k] - params2[k]))
         else:
             #print k,params[k] == params2[k],params[k],params2[k]
             self.assertEqual(params[k], params2[k])
Exemplo n.º 6
0
 def test_41qd(self):
     import os, sys, datetime
     import rpnpy.librmn.all as rmn
     fdate       = datetime.date.today().strftime('%Y%m%d') + '00_048'
     CMCGRIDF    = os.getenv('CMCGRIDF').strip()
     fileNameOut = 'p0fstfileqd.fst'
     fileIdIn    = rmn.fstopenall(os.getenv('CMCGRIDF')+'/prog/regeta/'+fdate)
     fileIdOut   = rmn.fstopenall(fileNameOut, rmn.FST_RW)
     gOut = rmn.defGrid_ZE(90, 45, 35., 250., 0.5, 0.5, 0., 180., 1., 270.)
     r    = rmn.fstlir(fileIdIn, nomvar='P0')
     gIn  = rmn.readGrid(fileIdIn, r)
     rmn.ezsetopt(rmn.EZ_OPT_INTERP_DEGREE, rmn.EZ_INTERP_LINEAR)
     d  = rmn.ezsint(gOut, gIn, r)
     r2 = r.copy()
     r2.update(gOut)
     r2.update({'etiket':'my_etk', 'd':d})
     rmn.fstecr(fileIdOut, r2)
     rmn.writeGrid(fileIdOut, gOut)
     rmn.fstcloseall(fileIdIn)
     rmn.fstcloseall(fileIdOut)
     os.unlink(fileNameOut)  # Remove test file
Exemplo n.º 7
0
 def test_41qd(self):
     import os, sys, datetime
     import rpnpy.librmn.all as rmn
     fdate = datetime.date.today().strftime('%Y%m%d') + '00_048'
     CMCGRIDF = os.getenv('CMCGRIDF').strip()
     fileNameOut = 'p0fstfileqd.fst'
     fileIdIn = rmn.fstopenall(
         os.getenv('CMCGRIDF') + '/prog/regeta/' + fdate)
     fileIdOut = rmn.fstopenall(fileNameOut, rmn.FST_RW)
     gOut = rmn.defGrid_ZE(90, 45, 35., 250., 0.5, 0.5, 0., 180., 1., 270.)
     r = rmn.fstlir(fileIdIn, nomvar='P0')
     gIn = rmn.readGrid(fileIdIn, r)
     rmn.ezsetopt(rmn.EZ_OPT_INTERP_DEGREE, rmn.EZ_INTERP_LINEAR)
     d = rmn.ezsint(gOut, gIn, r)
     r2 = r.copy()
     r2.update(gOut)
     r2.update({'etiket': 'my_etk', 'd': d})
     rmn.fstecr(fileIdOut, r2)
     rmn.writeGrid(fileIdOut, gOut)
     rmn.fstcloseall(fileIdIn)
     rmn.fstcloseall(fileIdOut)
     os.unlink(fileNameOut)  # Remove test file
Exemplo n.º 8
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])))