コード例 #1
0
ファイル: dial.py プロジェクト: sujayvkumar/GMAO_Shared
    def addVar(self, url, Vars=None, Verbose=True, Levels=None):
        """
        Sample variable along DIAL track.
        """
        from grads import GrADS
        ga = GrADS(Window=False, Echo=False)
        fh = ga.open(url)
        if Levels is not None:
            ga('set lev %s' % Levels)
        qh = ga.query('dims')

        if Vars is None:
            Vars = ga.query('file').vars
        elif type(Vars) is StringType:
            Vars = [
                Vars,
            ]
        for var in Vars:
            if Verbose:
                print ' Working on <%s>' % var
            if fh.Vars[var.lower()].levs == 0:
                ga('set lev 1')  # 2D variable
            else:
                ga.setdim(qh)
            q = ga.sampleXYT(var,
                             self.lon,
                             self.lat,
                             self.tyme,
                             Verbose=Verbose).data
            self.__dict__[var] = ma.MaskedArray(q, mask=q >= MAPL_UNDEF)
コード例 #2
0
def _estimate():

    from grads import GrADS
    
    man = MAN()
    
    ga = GrADS(Echo=0,Window=False)

#    fh = ga.open('nnr_001.modo.ddf')
#    man.addVar(ga,'nnr_001.modo.tau.npz',expr='tau')
#    man.addVar(ga,'nnr_001.modo.tau_.npz',expr='tau_')

    ga('reinit')
    fh = ga.open('nnr_001.mydo.ddf')
    man.addVar(ga,'nnr_001.mydo.tau.npz',expr='tau')
    man.addVar(ga,'nnr_001.mydo.tau_.npz',expr='tau_')
コード例 #3
0
class TestPdefFile(unittest.TestCase):
    def tearDown(self):
        del self.ga

    def test_01_Open(self):
        """
        Check whether file was opened correctly.
        """

        type = 'Gridded'
        vars = ['pslv']
        var_levs = [0]
        nx, ny, nz, nt = (333, 182, 20, 1)

        fh = self.fh
        self.assertEqual(type, fh.type)
        self.assertEqual(nx, fh.nx)
        self.assertEqual(ny, fh.ny)
        self.assertEqual(nz, fh.nz)
        self.assertEqual(nt, fh.nt)

        vars2 = fh.vars[:]
        var_levs2 = fh.var_levs[:]
        self.assertEqual(vars.sort(), vars2.sort())
        self.assertEqual(var_levs.sort(), var_levs2.sort())

    def test_03_Display(self):
        """
        Displays several variables and checks contour intervals
        """
        self._CheckCint('pslv', 1004, 1026, 2, z=1, t=1)

    def _CheckCint(self, name, cmin, cmax, cint, z=1, t=1):
        """
        Check contour intervals during display.
        """
        self.ga('clear')
        self.ga('display %s(z=%d,t=%d)' % (name, z, t))
        self.assertEqual(cmin, int(self.ga.rword(2, 2)))
        self.assertEqual(cmax, int(self.ga.rword(2, 4)))
        self.assertEqual(cint, int(self.ga.rword(2, 6)))

    def _GenericSetUp(self, bin):
        global GrADSTestFiles
        global GrADSBinaryFiles
        self.ga = GrADS(Bin=GrADSBinaryFiles[bin], Echo=False, Window=False)
        self.fh = self.ga.open(GrADSTestFiles['pdef'])
コード例 #4
0
ファイル: minx.py プロジェクト: sujayvkumar/GMAO_Shared
    def getMERRAero(self, npzFile=None, dir='/home/adasilva/iesa/MERRAero'):
        """
        Get Met fields from MERRA.
        """
        from grads import GrADS

        ga = GrADS(Window=False, Echo=False)

        ga.open(dir + '/geosgcm_surf.ddf')
        self.sampleFile(ga,
                        onlyVars=('ustar', 'bstar', 'pblh', 'shfx', 'lhfx',
                                  'rhos', 'ts'))
        ga('close 1')

        ga.open(dir + '/inst3d_prog_v.ddf')
        ga('set z 1 72')
        self.sampleFile(ga, onlyVars=('u', 'v', 't', 'qv'))
        ga('close 1')

        ga.open(dir + '/inst3d_aer_v.ddf')
        ga('set z 1 72')
        self.sampleFile(ga, onlyVars=('delp', ), npzFile=npzFile)
コード例 #5
0
ファイル: minx.py プロジェクト: sujayvkumar/GMAO_Shared
    def getMERRA(self, npzFile=None):
        """
        Get Met fields from MERRA.
        """
        from grads import GrADS

        ga = GrADS(Window=False, Echo=False)

        ga.open(
            'http://goldsmr2.sci.gsfc.nasa.gov:80/dods/MAT1NXFLX')  # 2D fluxes
        self.sampleFile(ga,
                        onlyVars=('ustar', 'bstar', 'pblh', 'hflux', 'eflux',
                                  'rhoa', 'tsh'))
        ga('close 1')

        ga.open(
            'http://goldsmr1.sci.gsfc.nasa.gov:80/dods/MAT3FVCHM')  # 3D fields
        ga('set z 1 72')
        self.sampleFile(ga,
                        onlyVars=('u', 'v', 't', 'qv', 'delp'),
                        npzFile=npzFile)
コード例 #6
0
ファイル: minx.py プロジェクト: sujayvkumar/GMAO_Shared
    def getFP(self,
              npzFile=None,
              dir='/home/adasilva/iesa/aerosol/experiments/seac4rs_01'):
        """
        Get Met fields from GEOS-5 Forward Processing.
        """
        from grads import GrADS

        ga = GrADS(Window=False, Echo=False)

        ga.open(dir + '/tavg1_2d_flx_Nx.ddf')
        self.sampleFile(ga,
                        onlyVars=('ustar', 'bstar', 'pblh', 'hflux', 'eflux',
                                  'rhoa', 'tsh'))
        ga('close 1')

        ga.open(dir + '/inst3_3d_asm_Nv.ddf')
        ga('set z 1 72')
        self.sampleFile(ga,
                        onlyVars=('u', 'v', 't', 'qv', 'o3', 'delp'),
                        npzFile=npzFile)
        ga('close 1')
コード例 #7
0
#!/usr/bin/env python
#Martin Iglesias Github SudestadaARG
import numpy as np
import os
import argparse
import gc
from datetime import datetime
from datetime import timedelta
from grads import GrADS

from mpl_toolkits.basemap import interp
from lectura_gefs_ctl import read_ctl
ga = GrADS(Bin='grads', Echo=False, Port=True, Window=False)

path_in = '/data/miglesias/GEFS_FCST12/GEFS_prono12h'
path_out = '/data/miglesias/verificacion_doc/variables_GEFS/'

# Defino argumentos para indicarle la fecha y el miembro por linea de comando:
parser = argparse.ArgumentParser(description='Year Month Day Hour Member FCST')
parser.add_argument('Year', type=int)
parser.add_argument('Month', type=int)
parser.add_argument('Day', type=int)
parser.add_argument('Hour', type=int)
parser.add_argument('Member', type=int)
parser.add_argument('FCST', type=str)
args = parser.parse_args()

Y = args.Year
M = args.Month
D = args.Day
H = args.Hour
コード例 #8
0
#!/usr/bin/env python
#
# Simple script testing the ext()/expr() methods
#

from pylab import *
from grads import GrADS

# Start GrADS and open the data file
# ----------------------------------
ga = GrADS(Bin='grads', Echo=False, Port=True, Window=False)
ga.open('../data/model.ctl')

# XY slices
# ---------
ts1 = ga.exp('ts')
ts2 = ga.expr('ts')
print "XY Skin temperature: "
print ts1.data - ts2.data

# XYT slices
# ----------
ga('set t 2 3')
ts1 = ga.exp('ts')
ts2 = ga.expr('ts')
print "XYT Skin temperature: "
print ts1.data - ts2.data

# XYZ slices
# ----------
ga('set t 3')
コード例 #9
0
class TestModelFile(unittest.TestCase):
    def tearDown(self):
        del self.ga
#        os.system("/bin/rm -rf output")

    def test_01_Open(self):
        """
        Check whether file was opened correctly.
        """
        type = 'Gridded'
        vars = ['ps', 'ts', 'pr', 'ua', 'va', 'zg', 'ta', 'hus']
        var_levs = [0, 0, 0, 7, 7, 7, 7, 7]
        nx, ny, nz, nt = (72, 46, 7, 5)

        fh = self.fh
        self.assertEqual(type, fh.type)
        self.assertEqual(nx, fh.nx)
        self.assertEqual(ny, fh.ny)
        self.assertEqual(nz, fh.nz)
        self.assertEqual(nt, fh.nt)

        vars2 = fh.vars[:]
        var_levs2 = fh.var_levs[:]
        self.assertEqual(vars.sort(), vars2.sort())
        self.assertEqual(var_levs.sort(), var_levs2.sort())

    def test_02_Execs(self):
        """
        Exercises the exec command using both Unix and DOS text files.
        """
        self.ga("exec Exec.ga")
        self.ga("exec Exec_dos.ga")

    def test_02_Prints(self):
        """
        Exercises print/print file.eps/printim but does verify results.
        This is not really a test as it does not check the outcome.
        """
        self.ga("display ps")
        #self.ga("print   output/ps.eps")
        #self.ga("enable print output/ps.gx")
        self.ga("gxprint   output/ps.eps")
        self.ga("gxprint   output/ps.pdf")
        self.ga("gxprint   output/ps.png")
        #self.ga("gxprint   output/ps.jpg")
        self.ga("gxprint   output/ps.svg")
        #self.ga("gxprint   output/ps.gif")
        #self.ga("disable print")

    def test_02_Printim(self):
        """
        Exercises printim - not really a test as it does not check outcome.
        """
        self.ga("q config")
        cf = self.ga.rline(1)
        if 'printim' in cf:
            self.ga("printim output/ps.png")

    def test_03_Display(self):
        """
        Displays several variables and checks contour intervals
        """
        self._CheckCint('ps', 500, 1000, 50, z=1, t=1)
        self._CheckCint('ts', 240, 310, 10, z=1, t=1)
        self._CheckCint('10000*pr', 0, 8, 1, z=1, t=1)

        self._CheckCint('ps', 500, 1000, 50, z=1, t=5)
        self._CheckCint('ts', 240, 310, 10, z=1, t=5)
        self._CheckCint('10000*pr', 0, 10, 1, z=1, t=5)

        self._CheckCint('ua', -12, 18, 3, z=1, t=1)
        self._CheckCint('va', -15, 15, 3, z=1, t=1)
        self._CheckCint('zg', -100, 300, 50, z=1, t=1)
        self._CheckCint('ta', 245, 300, 5, z=1, t=1)
        self._CheckCint('1000*hus', 2, 20, 2, z=1, t=5)

        self._CheckCint('ua', -15, 50, 5, z=7, t=5)
        self._CheckCint('va', -20, 20, 5, z=7, t=5)
        self._CheckCint('zg', 14800, 16400, 200, z=7, t=5)
        self._CheckCint('ta', 195, 225, 5, z=7, t=5)
        self._CheckCint('10000*hus', 1, 9, 1, z=5, t=5)

    def test_04_Write_generic(self):
        self.ga("set x 1 72")
        self.ga(
            "lats4d -o output/sequential -format sequential -vars ps ta -func sqrt(@) -time = = 2 "
        )

    def test_04_Write_stream(self):
        self.ga("set x 1 72")
        self.ga("lats4d -o output/stream -be -format stream")

    def test_05_Read_stream(self):
        fh = self.ga.open("stream.ctl")
        self._CompareFiles(self.fh, fh)
        self.ga('close %d' % fh.fid)

    def test_04_Write_sequential(self):
        self.ga("set x 1 72")
        self.ga("lats4d -o output/sequential -le -format sequential")

    def test_05_Read_sequential(self):
        fh = self.ga.open("sequential.ctl")
        self._CompareFiles(self.fh, fh)
        self.ga('close %d' % fh.fid)

    def test_04_stats(self):
        self.ga("set x 1 72")
        self.ga("lats4d -format stats")

    def test_04_Write_mean(self):
        self.ga("set x 1 72")
        self.ga("lats4d -o output/mean -format stream -mean")

    def xtest_06_regriding_linear(self):
        self._CheckCint2("re(ts,2,2,bl)", 240, 310, 10)
        self._CheckCint2("re(ts,2,1,bl)", 240, 310, 10)

    def xtest_06_regriding_bessel(self):
        self._CheckCint2("re(ts,2,2,bs)", 240, 310, 10)
        self._CheckCint2("re(ts,2,1,bs)", 240, 310, 10)

    def xtest_06_regriding_box_average(self):
        self._CheckCint2("re(ts,2,2,ba)", 240, 310, 10)
        self._CheckCint2("re(ts,2,1,ba)", 240, 310, 10)

    def xtest_06_regriding_box_voting(self):
        self._CheckCint2("1e4*re(pr,8,8,vt,0.6,0.2)", 0, 8, 1)

    def _CheckCint(self, name, cmin, cmax, cint, z=1, t=1):
        """
        Check contour intervals during display.
        """
        self.ga('clear')
        self.ga('display %s(z=%d,t=%d)' % (name, z, t))
        self.assertEqual(cmin, int(self.ga.rword(1, 2)))
        self.assertEqual(cmax, int(self.ga.rword(1, 4)))
        self.assertEqual(cint, int(self.ga.rword(1, 6)))

    def _CheckCint2(self, name, cmin, cmax, cint):
        """
        Check contour intervals during display.
        """
        self.ga.cmd('clear')
        self.ga.cmd('display %s' % name)
        self.assertEqual(cmin, int(self.ga.rword(1, 2)))
        self.assertEqual(cmax, int(self.ga.rword(1, 4)))
        self.assertEqual(cint, int(self.ga.rword(1, 6)))

    def _CompareFiles(self, fh1, fh2):
        vars1 = fh1.vars[:]
        vars2 = fh2.vars[:]
        self.assertEqual(vars1.sort(), vars2.sort())
        self.assertEqual(fh1.nt, fh2.nt)
        for i in range(len(fh1.vars)):
            var = fh1.vars[i]
            nz = fh1.var_levs[i]
            if nz == 0: nz = 1
            if var == 'hus': nz = 5
            nt = fh1.nt
            for t in range(1, nt + 1):
                for z in range(1, nz + 1):
                    self.ga('clear')
                    self.ga('display %s.%d(z=%d,t=%d) - %s.%d(z=%d,t=%d)'\
                                %(var,fh1.fid,z,t,var,fh2.fid,z,t))
                    #                    print ">>> t=%d, z=%d, %s --- %s "%(t,z,var,self.ga.rline(1))
                    self.assertEqual(self.ga.rline(1), \
                                     'Constant field.  Value = 0')

    def _GenericSetUp(self, bin, dat):
        global GrADSTestFiles
        global GrADSBinaryFiles
        self.ga = GrADS(Bin=GrADSBinaryFiles[bin], Echo=False, Window=False)
        self.fh = self.ga.open(GrADSTestFiles[dat])

    def notest_04_LATS_Coards_1(self):
        self.ga("set x 1 72")
        self.ga("lats4d -o output/model ")

    def notest_04_LATS_Coards_2(self):
        fh = self.ga.open("output/model.nc")
        self._CompareFiles(self.fh, fh)
        self.ga('close %d' % fh.fid)

    def notest_04_LATS_GaGrib_1(self):
        self.ga("set x 1 72")
        self.ga("lats4d -o output/model -format grads_grib")

    def notest_04_LATS_GaGrib_2(self):
        fh = self.ga.open("output/model.ctl")
        self._CompareFiles(self.fh, fh)
        self.ga('close %d' % fh.fid)

    def notest_04_LATS_grib(self):
        self.ga("set x 1 72")
        self.ga("lats4d -o output/model -format grib")
コード例 #10
0
#!/usr/bin/env python
#
# Simple script demonstrating the interp() method.
#

from pylab import *
from numpy import float32
from grads import GrADS, GaField

# Start GrADS and open the data file
# ----------------------------------
ga = GrADS(Bin='grads', Echo=False, Port=True, Window=False)
ga.open('../data/model.ctl')
ga('set t 1 5')
dh = ga.query('dims')
t1, t2 = dh.tyme
ga('set t 1')

# Create sample trajectory
# ------------------------
lats = array([-90, -60, -45, 0, 45, 60, 90])
lons = array([-180, -90, -45, 0, 45, 90, 180])
tyme = array([t1, t1, t1, t2, t2, t2, t2])

# Either do the plotting in Python ...
# ------------------------------------
ga('set t 1')
ts = ga.sampleXYT('ts', lons, lats, tyme)

clf()
コード例 #11
0
 def _GenericSetUp(self, bin):
     global GrADSTestFiles
     global GrADSBinaryFiles
     self.ga = GrADS(Bin=GrADSBinaryFiles[bin], Echo=False, Window=False)
     self.fh = self.ga.open(GrADSTestFiles['grb2'])
コード例 #12
0
class TestGrb2File(unittest.TestCase):
    def tearDown(self):
        del self.ga

    def _GenericSetUp(self, bin):
        global GrADSTestFiles
        global GrADSBinaryFiles
        self.ga = GrADS(Bin=GrADSBinaryFiles[bin], Echo=False, Window=False)
        self.fh = self.ga.open(GrADSTestFiles['grb2'])

    def test_01_Open(self):
        """
        Check whether file was opened correctly.
        """

        type = 'Gridded'
        vars = [
            'apcpsfc', 'hgtprs', 'prmslmsl', 'rhprs', 'tmpprs', 'ugrdprs',
            'vgrdprs'
        ]
        var_levs = [0, 3, 0, 3, 3, 3, 3]
        nx, ny, nz, nt = (144, 73, 3, 4)  # no E size yet

        fh = self.fh
        self.assertEqual(type, fh.type)
        self.assertEqual(nx, fh.nx)
        self.assertEqual(ny, fh.ny)
        self.assertEqual(nz, fh.nz)
        self.assertEqual(nt, fh.nt)

        vars2 = fh.vars[:]
        var_levs2 = fh.var_levs[:]
        self.assertEqual(vars.sort(), vars2.sort())
        self.assertEqual(var_levs.sort(), var_levs2.sort())

    def test_03_Display(self):
        """
        Displays several variables and checks contour intervals
        """
        self._CheckCint('apcpsfc', 0, 140, 10, z=1, t=2)
        self._CheckCint('0.01*prmslmsl', 950, 1050, 10, z=1, t=1)
        self._CheckCint('hgtprs', 900, 1600, 100, z=1, t=1)
        self._CheckCint('rhprs', 0, 100, 10, z=1, t=1)
        self._CheckCint('tmpprs', 235, 300, 5, z=1, t=1)
        self._CheckCint('ugrdprs', -30, 30, 10, z=1, t=1)
        self._CheckCint('vgrdprs', -25, 35, 5, z=1, t=1)

        self._CheckCint('apcpsfc', 0, 80, 10, z=1, t=4)
        self._CheckCint('0.01*prmslmsl', 950, 1040, 10, z=1, t=4)
        self._CheckCint('hgtprs', 900, 1600, 100, z=1, t=4)
        self._CheckCint('rhprs', 0, 100, 10, z=1, t=4)
        self._CheckCint('tmpprs', 240, 300, 5, z=1, t=4)
        self._CheckCint('ugrdprs', -25, 30, 5, z=1, t=4)
        self._CheckCint('vgrdprs', -25, 30, 5, z=1, t=4)

        self._CheckCint('hgtprs', 10800, 12400, 200, z=3, t=4)
        self._CheckCint('rhprs', 0, 100, 10, z=3, t=4)
        self._CheckCint('tmpprs', 200, 235, 5, z=3, t=4)
        self._CheckCint('ugrdprs', -40, 100, 10, z=3, t=4)
        self._CheckCint('vgrdprs', -50, 50, 10, z=3, t=4)

    def _CheckCint(self, name, cmin, cmax, cint, z=1, t=1):
        """
        Check contour intervals during display.
        """
        self.ga('clear')
        self.ga('display %s(z=%d,t=%d)' % (name, z, t))
        self.assertEqual(cmin, int(self.ga.rword(1, 2)))
        self.assertEqual(cmax, int(self.ga.rword(1, 4)))
        self.assertEqual(cint, int(self.ga.rword(1, 6)))

    def _GenericSetUp(self, bin):
        global GrADSTestFiles
        global GrADSBinaryFiles
        self.ga = GrADS(Bin=GrADSBinaryFiles[bin], Echo=False, Window=False)
        self.fh = self.ga.open(GrADSTestFiles['grb2'])
コード例 #13
0
 def _GenericSetUp(self, bin, url):
     self.ga = GrADS(Bin=GrADSBinaryFiles[bin], Echo=False, Window=False)
     self.fh = self.ga('open ' + url)
コード例 #14
0
class TestModelUrl(unittest.TestCase):
    def tearDown(self):
        del self.ga
#        os.system("/bin/rm -rf output")

    def test_01_Open(self):
        """
        Check whether file was opened correctly.
        """
        type = 'Gridded'
        vars = ['ps', 'ts', 'pr', 'ua', 'va', 'zg', 'ta', 'hus']
        var_levs = [0, 0, 0, 7, 7, 7, 7, 7]
        nx, ny, nz, nt = (72, 46, 7, 5)

        fh = self.fh
        self.assertEqual(type, fh.type)
        self.assertEqual(nx, fh.nx)
        self.assertEqual(ny, fh.ny)
        self.assertEqual(nz, fh.nz)
        self.assertEqual(nt, fh.nt)

        vars2 = fh.vars[:]
        var_levs2 = fh.var_levs[:]
        self.assertEqual(vars.sort(), vars2.sort())
        self.assertEqual(var_levs.sort(), var_levs2.sort())

    def test_03_Display(self):
        """
        Displays several variables and checks contour intervals
        """
        self._CheckCint('ps', 500, 1000, 50, z=1, t=1)
        self._CheckCint('ts', 240, 310, 10, z=1, t=1)
        self._CheckCint('10000*pr', 0, 8, 1, z=1, t=1)

        self._CheckCint('ps', 500, 1000, 50, z=1, t=5)
        self._CheckCint('ts', 240, 310, 10, z=1, t=5)
        self._CheckCint('10000*pr', 0, 10, 1, z=1, t=5)

        self._CheckCint('ua', -12, 18, 3, z=1, t=1)
        self._CheckCint('va', -15, 15, 3, z=1, t=1)
        self._CheckCint('zg', -100, 300, 50, z=1, t=1)
        self._CheckCint('ta', 245, 300, 5, z=1, t=1)
        self._CheckCint('1000*hus', 2, 20, 2, z=1, t=5)

        self._CheckCint('ua', -15, 50, 5, z=7, t=5)
        self._CheckCint('va', -20, 20, 5, z=7, t=5)
        self._CheckCint('zg', 14800, 16400, 200, z=7, t=5)
        self._CheckCint('ta', 195, 225, 5, z=7, t=5)
        self._CheckCint('10000*hus', 1, 9, 1, z=5, t=5)

    def _CheckCint(self, name, cmin, cmax, cint, z=1, t=1):
        """
        Check contour intervals during display.
        """
        sys.stdout.write(name + ' ... ')
        self.ga('clear')
        self.ga('display %s(z=%d,t=%d)' % (name, z, t))
        self.assertEqual(cmin, int(self.ga.rword(1, 2)))
        self.assertEqual(cmax, int(self.ga.rword(1, 4)))
        self.assertEqual(cint, int(self.ga.rword(1, 6)))

    def _GenericSetUp(self, bin, dat):
        global GrADSTestFiles
        global GrADSBinaryFiles
        self.ga = GrADS(Bin=GrADSBinaryFiles[bin], Echo=False, Window=False)
        self.fh = self.ga.open(GrADSTestFiles[dat])
コード例 #15
0
ファイル: gfio.py プロジェクト: sujayvkumar/GMAO_Shared
#...........................................................................

if __name__ == "__main__":

    from time import time as now
    from grads import GrADS

    f = GFIOctl('/nobackup/ARCTAS/opendap/arctas.ddf')

    lons = linspace(-45., -30., 100)
    lats = linspace(30., 50., 100)
    dt = f.dt / 10
    t0 = datetime(2008, 6, 29, 12)
    times = array([t0 + i * dt for i in range(100)])

    ga = GrADS(Window=False, Echo=0)
    fh = ga.open('/nobackup/ARCTAS/opendap/arctas.ddf')

    # Interpolating ps
    # ----------------
    t_ = now()
    ps = f.sample('ps', lons, lats, times, Verbose=True)
    print "---> Interpolating <ps> with GFIO took ", now() - t_
    t_ = now()
    ps_ = ga.sampleXYT('ps', lons, lats, tyme=times, Verbose=True)
    print "---> Interpolating <ps> with PyGrADS took ", now() - t_

    # Interpolating RH
    # ----------------
    print ""
    t_ = now()
コード例 #16
0
# para generar las matrices de GEFS de lat lon segui los siguientes pasos en ipython:
#Martin Iglesias Github SudestadaARG
import numpy as np
from grads import GrADS

ga = GrADS(Bin='grads', Echo=False, Port=True, Window=False)

CTL = ga.open('gens_20151201_0000_012_01.ctl')

ga('set lev 1000')
t = ga.exp('TMPPRS')

lats = t.grid.lat[:]  # (181,)
lons = t.grid.lon[:]  # (361,)

np.save('lon_gefs.npy', lons)
np.save('lat_gefs.npy', lats)

# Para generar las 2D con dimension (181,361):
lat2d = np.empty((181, 361))
for i in range(0, 361):
    lat2d[:, i] = lats

lon2d = np.empty((181, 361))
for i in range(0, 181):
    lon2d[i, :] = lons

np.save('lon2d_gefs.npy', lon2d)
np.save('lat2d_gefs.npy', lat2d)
コード例 #17
0
    def attach(self, filename, Vars=None, Cache=False):
        """
        Attach variables from gridded meteorological files, interpolating
        from the gridded values to the (lat,lon) of the fire. If the variables
        are 3D, the whole curtain is included. If *Vars* is not specified,
        all non-coordinate variables on file are included. 

        When *Cache* is true, the variables are saved locally to directory
        "__cache__". When the input file name is "__cache__", the variables are read
        from cache.

        """

        from grads import GrADS

        #       Expects GrADS v2
        #       ----------------
        ga = GrADS(Bin='grads', Window=False, Echo=False)

        #       Open the file
        #       -------------
        fh = ga.open(filename)
        ga('set lon -180 180')  # good for interpolation

        #       Either all varibles on file or user subset
        #       ------------------------------------------
        if Vars == None:
            vinfo = fh.var_info
        else:
            vinfo = []
            for v, k, l in fh.var_info:
                if v in Vars:
                    vinfo.append((v, k, l))
            if len(vinfo) == 0:
                print "IndexError: requested variables - ", Vars
                raise IndexError, "cannot find any matchig variable in file %f"\
                    %filename

#       For each observation, find the correspondng time on file
#       --------------------------------------------------------
        utimes = unique(self.tga)  # unique obs times in grads format
        self.tgaf = self.tga.copy()  # will hold times on file for each ob
        for tga in utimes:
            ga('set time %s' % tga, Quiet=True)
            qh = ga('query time', Quiet=True)
            self.tgaf[self.tga == tga] = ga.rword(1, 3)

#       Loop over each desired variable and interpolate it to
#        fire location
#       -----------------------------------------------------
        self.met = {}
        n = self.lon.size
        levs = 1000. * zeros(fh.nz)
        for v, nlevs, l in vinfo:
            if nlevs == 0:
                nlevs = 1
                y_f = zeros(n)
            else:
                y_f = zeros((n, nlevs))
            for tgaf in unique(self.tgaf):
                ga('set time %s' % tgaf, Quiet=True)
                ga('set z %d %d' % (1, nlevs), Quiet=True)
                m = (self.tgaf == tgaf)  # gather obs for this time
                lon_, lat_ = (self.lon[m], self.lat[m])
                print "- Interpolating %5d %s obs at %s" % (lon_.size, v, tgaf)
                y_f[m], levs = ga.interp(v, lon_, lat_)  # interp & scatter
            self.met[v] = y_f
        self.met['levs'] = levs  # record vertical levels
コード例 #18
0
ファイル: percentile.py プロジェクト: zhatin/pygrads2
#!/usr/bin/env python
#
# Simple script for computing percentiles for each horizontal
# gridpoint.
#

from pylab import *
from numpy import float32
from grads import GrADS, GaField

# Start GrADS and open the data file
# ----------------------------------
ga = GrADS(Bin='gradsnc',Echo=False,Port=True)
ga.open('../data/slp_djf.nc')

# Extract a timeseries
# --------------------
ga('set t 1 41')         
x = ga.exp('djfslp/100')
g = x.grid

# Transpose spatial/temporal dimensions
# -------------------------------------
(nt,ny,nx) = x.shape;
x = transpose(x.reshape((nt,nx*ny)))

# Compute percentiles using Matlab compatible prctile function
# ------------------------------------------------------------
p = ( 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 )
y = zeros((nx*ny,10),dtype=float32)
for i in range(nx*ny):