Example #1
0
    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)
Example #2
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()