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)
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() rh = f.sample('RH', lons, lats, times, Verbose=True) print "---> Interpolating RH with GFIO took ", now() - t_ t_ = now() ga('set z 1 72') rh_ = ga.sampleXYT('rh', lons, lats, tyme=times, Verbose=True) rh_ = rh_.T # transpose rh_ = rh_[-1::-1, :] # flip vertical print "---> Interpolating <RH> with PyGrADS took ", now() - t_
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() subplot(211) plot(lats, ts) title("Surface Temperature") xlabel('Latitude') subplot(212) plot(lons, ts) xlabel('Longitude') savefig('sampleXY1.png') figure()