示例#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
示例#2
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
示例#3
0
    def test_24(self):
        """
        Edit: New file from scratch

        This example shows how to
        * Create a record meta and data from scratch
        * Create grid descriptors for the data
        * Create vgrid descriptor for the data
        * write the recod data + meta
        * write the grid descriptors
        * write the vgrid descriptor

        See also:
        rpnpy.librmn.fstd98.fstopt
        rpnpy.librmn.fstd98.fstopenall
        rpnpy.librmn.fstd98.fstcloseall
        rpnpy.librmn.fstd98.fsrecr
        rpnpy.librmn.fstd98.dtype_fst2numpy
        rpnpy.librmn.grids.encodeGrid
        rpnpy.librmn.grids.defGrid_ZE
        rpnpy.librmn.grids.writeGrid
        rpnpy.librmn.base.newdate
        rpnpy.vgd.base.vgd_new
        rpnpy.vgd.base.vgd_new_pres
        rpnpy.vgd.base.vgd_new_get
        rpnpy.vgd.base.vgd_write
        rpnpy.librmn.const
        rpnpy.vgd.const
        """
        import os, sys
        import numpy as np
        import rpnpy.librmn.all as rmn
        import rpnpy.vgd.all as vgd

        # Restrict to the minimum the number of messages printed by librmn
        rmn.fstopt(rmn.FSTOP_MSGLVL, rmn.FSTOPI_MSG_CATAST)

        # Create Record grid
        gp = {
            'grtyp': 'Z',
            'grref': 'E',
            'ni': 90,
            'nj': 45,
            'lat0': 35.,
            'lon0': 250.,
            'dlat': 0.5,
            'dlon': 0.5,
            'xlat1': 0.,
            'xlon1': 180.,
            'xlat2': 1.,
            'xlon2': 270.
        }
        g = rmn.encodeGrid(gp)
        print("CB24: Defined a %s/%s grid of shape=%d, %d" %
              (gp['grtyp'], gp['grref'], gp['ni'], gp['nj']))

        # Create Record vgrid
        lvls = (500., 850., 1000.)
        v = vgd.vgd_new_pres(lvls)
        ip1list = vgd.vgd_get(v, 'VIPT')
        print("CB24: Defined a Pres vgrid with lvls=%s" % str(lvls))

        # Create Record data + meta
        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()  # Copy default record meta
        r.update(g)  # Update with grid info
        r.update({  # Update with specific meta and data array
            'nomvar':
            'MASK',
            'dateo':
            rmn.newdate(rmn.NEWDATE_PRINT2STAMP, 20160302, 1800000),
            'nk':
            len(ip1list),
            'ip1':
            0,  # level, will be set later, level by level
            'ip2':
            6,  # Forecast of 6h
            'deet':
            3600,  # Timestep in sec
            'npas':
            6,  # Step number
            'etiket':
            'my_etk',
            'nbits':
            32,  # Keep full 32 bits precision for that field
            'datyp':
            datyp,  # datyp (above) float_IEEE_compressed
            'd':
            np.empty(rshape, dtype=npdtype, order='FORTRAN')
        })
        print("CB24: Defined a new record of shape=%d, %d" %
              (r['ni'], r['nj']))

        # Compute record values
        r['d'][:, :, :] = 0.
        r['d'][10:-11, 5:-6, :] = 1.

        # Open Files
        fileNameOut = 'newfromscratch.fst'
        try:
            fileIdOut = rmn.fstopenall(fileNameOut, rmn.FST_RW)
        except:
            sys.stderr.write("Problem opening the file: %s, %s\n" %
                             fileNameOut)
            sys.exit(1)

        # Write record data + meta + grid + vgrid to file
        try:
            r2d = r.copy()
            r2d['nk'] = 1
            for k in range(len(ip1list)):
                r2d['ip1'] = ip1list[k]
                r2d['d'] = np.asfortranarray(r['d'][:, :, k])
                rmn.fstecr(fileIdOut, r2d['d'], r2d)
                print("CB24: wrote %s at ip1=%d" % (r2d['nomvar'], r2d['ip1']))
            rmn.writeGrid(fileIdOut, g)
            print("CB24: wrote the grid descriptors")
            vgd.vgd_write(v, fileIdOut)
            print("CB24: wrote the vgrid descriptor")
        except:
            raise
        finally:
            # Properly close files even if an error occured above
            # This is important when editing to avoid corrupted files
            rmn.fstcloseall(fileIdOut)
            os.unlink(fileNameOut)  # Remove test file
示例#4
0
    def test_24(self):
        """
        Edit: New file from scratch

        This example shows how to
        * Create a record meta and data from scratch
        * Create grid descriptors for the data
        * Create vgrid descriptor for the data
        * write the recod data + meta
        * write the grid descriptors
        * write the vgrid descriptor

        See also:
        rpnpy.librmn.fstd98.fstopt
        rpnpy.librmn.fstd98.fstopenall
        rpnpy.librmn.fstd98.fstcloseall
        rpnpy.librmn.fstd98.fsrecr
        rpnpy.librmn.fstd98.dtype_fst2numpy
        rpnpy.librmn.grids.encodeGrid
        rpnpy.librmn.grids.defGrid_ZE
        rpnpy.librmn.grids.writeGrid
        rpnpy.librmn.base.newdate
        rpnpy.vgd.base.vgd_new
        rpnpy.vgd.base.vgd_new_pres
        rpnpy.vgd.base.vgd_new_get
        rpnpy.vgd.base.vgd_write
        rpnpy.librmn.const
        rpnpy.vgd.const
        """
        import os, sys
        import numpy as np
        import rpnpy.librmn.all as rmn
        import rpnpy.vgd.all as vgd
        
        # Restrict to the minimum the number of messages printed by librmn
        rmn.fstopt(rmn.FSTOP_MSGLVL,rmn.FSTOPI_MSG_CATAST)

        # Create Record grid
        gp = {
            'grtyp' : 'Z',
            'grref' : 'E',
            'ni'    : 90,
            'nj'    : 45,
            'lat0'  : 35.,
            'lon0'  : 250.,
            'dlat'  : 0.5,
            'dlon'  : 0.5,
            'xlat1' : 0.,
            'xlon1' : 180.,
            'xlat2' : 1.,
            'xlon2' : 270.
        }
        g = rmn.encodeGrid(gp)
        print("CB24: Defined a %s/%s grid of shape=%d, %d" %
              (gp['grtyp'], gp['grref'], gp['ni'], gp['nj']))
            
        # Create Record vgrid
        lvls = (500.,850.,1000.)
        v = vgd.vgd_new_pres(lvls)
        ip1list = vgd.vgd_get(v, 'VIPT')
        print("CB24: Defined a Pres vgrid with lvls=%s" % str(lvls))
        
        # Create Record data + meta
        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() # Copy default record meta
        r.update(g)                         # Update with grid info
        r.update({                          # Update with specific meta and data array
            'nomvar': 'MASK',
            'dateo' : rmn.newdate(rmn.NEWDATE_PRINT2STAMP, 20160302, 1800000),
            'nk'    : len(ip1list),
            'ip1'   : 0,     # level, will be set later, level by level
            'ip2'   : 6,     # Forecast of 6h
            'deet'  : 3600,  # Timestep in sec
            'npas'  : 6,     # Step number
            'etiket': 'my_etk',
            'nbits' : 32,    # Keep full 32 bits precision for that field
            'datyp' : datyp, # datyp (above) float_IEEE_compressed
            'd'     : np.empty(rshape, dtype=npdtype, order='FORTRAN')
            })
        print("CB24: Defined a new record of shape=%d, %d" % (r['ni'], r['nj']))

        
        # Compute record values
        r['d'][:,:,:] = 0.
        r['d'][10:-11,5:-6,:] = 1.
        
        # Open Files
        fileNameOut = 'newfromscratch.fst'
        try:
            fileIdOut = rmn.fstopenall(fileNameOut, rmn.FST_RW)
        except:
            sys.stderr.write("Problem opening the file: %s, %s\n" % fileNameOut)
            sys.exit(1)

        # Write record data + meta + grid + vgrid to file
        try:
            r2d = r.copy()
            r2d['nk']  = 1
            for k in range(len(ip1list)):
                r2d['ip1'] = ip1list[k]
                r2d['d'] = np.asfortranarray(r['d'][:,:,k])
                rmn.fstecr(fileIdOut, r2d['d'], r2d)
                print("CB24: wrote %s at ip1=%d" % (r2d['nomvar'], r2d['ip1']))
            rmn.writeGrid(fileIdOut, g)
            print("CB24: wrote the grid descriptors")
            vgd.vgd_write(v, fileIdOut)
            print("CB24: wrote the vgrid descriptor")
        except:
            raise
        finally:
            # Properly close files even if an error occured above
            # This is important when editing to avoid corrupted files
            rmn.fstcloseall(fileIdOut)
            os.unlink(fileNameOut)  # Remove test file