Ejemplo n.º 1
0
def buildT2():
  nyrs = 10
  lat = pyg.regularlat(31)
  lon = pyg.regularlon(60)
  time = pyg.ModelTime365(values=np.arange(nyrs*365), \
          units='days', startdate={'year':2011, 'month':1, 'day':1})
  pres = pyg.Pres(np.arange(1000, 0, -50.))
  z = 6.6 * pyg.log(1000./pres)

  ts1 = 2*pyg.sin(2*np.pi*time/365.) + 4*pyg.Var((time,), values=np.random.randn(nyrs*365))
  ts1 = ts1.smooth('time', 20)
  ts2 = -5 + 0.6*time/365. + 5*pyg.Var((time,), values=np.random.randn(nyrs*365))
  ts2 = ts2.smooth('time', 20)

  T_c = 260. + 40. * pyg.exp(-((lat - 10*np.sin(2*np.pi*time/365))/45.)**2)
  T_wave = 0.05 * lat * pyg.sind(6*lon - time)# * ts1
  T_lapse = -5*z

  Tf = (T_lapse + T_c + T_wave).transpose('time', 'pres', 'lat', 'lon')
  Tf.name = 'Temp'

  U_c = 40 * pyg.sind(2*lat)**2 * pyg.sin(2*np.pi * z / 12)**2
  U_wave = 0.08 * lat * pyg.sind(6*lon - time)
  U = (U_c + ts2*U_wave).transpose('time', 'pres', 'lat', 'lon')
  U.name = 'U'
  return pyg.Dataset([Tf, U], atts={'history':'Synthetic Temperature and Wind data generated by pygeode'})
Ejemplo n.º 2
0
def buildT2():
    nyrs = 10
    lat = pyg.regularlat(31)
    lon = pyg.regularlon(60)
    time = pyg.ModelTime365(values=np.arange(nyrs*365), \
            units='days', startdate={'year':2011, 'month':1, 'day':1})
    pres = pyg.Pres(np.arange(1000, 0, -50.))
    z = 6.6 * pyg.log(1000. / pres)

    ts1 = 2 * pyg.sin(2 * np.pi * time / 365.) + 4 * pyg.Var(
        (time, ), values=np.random.randn(nyrs * 365))
    ts1 = ts1.smooth('time', 20)
    ts2 = -5 + 0.6 * time / 365. + 5 * pyg.Var(
        (time, ), values=np.random.randn(nyrs * 365))
    ts2 = ts2.smooth('time', 20)

    T_c = 260. + 40. * pyg.exp(-(
        (lat - 10 * np.sin(2 * np.pi * time / 365)) / 45.)**2)
    T_wave = 0.05 * lat * pyg.sind(6 * lon - time)  # * ts1
    T_lapse = -5 * z

    Tf = (T_lapse + T_c + T_wave).transpose('time', 'pres', 'lat', 'lon')
    Tf.name = 'Temp'

    U_c = 40 * pyg.sind(2 * lat)**2 * pyg.sin(2 * np.pi * z / 12)**2
    U_wave = 0.08 * lat * pyg.sind(6 * lon - time)
    U = (U_c + ts2 * U_wave).transpose('time', 'pres', 'lat', 'lon')
    U.name = 'U'
    return pyg.Dataset(
        [Tf, U],
        atts={
            'history':
            'Synthetic Temperature and Wind data generated by pygeode'
        })
Ejemplo n.º 3
0
"""
Specify contour levels 
=======================
Use :func:`clfdict()` to create a set of contour levels and contour lines to plot. 

"""
import pygeode as pyg, numpy as np
import pylab as pyl
pyl.ioff()

lat = pyg.regularlat(60)
lon = pyg.regularlon(120)

z = pyg.sin(2 * np.pi * lat /
            180.)**10 + pyg.cos(10 +
                                (2 * np.pi / 180.)**2 * lat * lon) * pyg.cos(
                                    2 * np.pi * lat / 180.)

ax = pyg.plot.AxesWrapper()

contour_dict = pyg.clfdict(min=-1.2,
                           axes=ax,
                           cdelt=0.4,
                           ndiv=3,
                           nf=2,
                           nl=1,
                           extend='both',
                           cmap='RdGy')

pyg.vcontour(z, **contour_dict)
ax.setp(title='Using helper function to set up contour levels')
Ejemplo n.º 4
0
import pylab as pyl
import pygeode as pyg, numpy as np

lat = pyg.regularlat(60)
lon = pyg.regularlon(120)

x = pyg.sin(2 * np.pi * lon / 180.) * pyg.exp(-(lat - 30)**2 / (2 * 10**2))
y = pyg.sin(2 * np.pi * lon / 180.) * pyg.exp(-(lat + 40)**2 / (2 * 10**2))

pyl.ioff()
ax = pyg.plot.AxesWrapper()
pyg.vcontour(y,
             clevs=np.linspace(-1, 1, 21),
             clines=None,
             cmap=pyl.cm.PuBuGn,
             axes=ax)
pyg.vcontour(x,
             clevs=None,
             clines=np.linspace(-1, 1, 21),
             linewidths=1.,
             colors='k',
             axes=ax)

ax.setp(title='Filled contours and contour lines')

pyl.ion()
ax.render(1)
Ejemplo n.º 5
0
"""

import pylab as pyl
pyl.ioff()

import pygeode as pyg
import numpy as np
from pygeode.tutorial import t2

# Generate some data for a scatter plot
N = 50
x_values = np.linspace(-1, 1, N)
colors = np.random.rand(N)
area = 1000 * np.random.rand(N) * (1 - abs(x_values))

x = pyg.NamedAxis(values=x_values, name='x')
y = pyg.NamedAxis(values=x_values + np.random.rand(N), name='y')

ax_scatter = pyg.vscatter(x, y, c=colors, s=area, alpha=0.5)

# Make a vcontour
ax_vcontour = pyg.vcontour(t2.Temp(pres=500, time='10 May 2012') *
                           (pyg.cos(t2.lat)) * pyg.sin(t2.lon),
                           cmap='Oranges')

# Stitch the axes together side by side into a grid
ax_both = pyg.plot.grid([[ax_scatter, ax_vcontour]])

pyl.ion()
ax_both.render()
Ejemplo n.º 6
0
"""
import pygeode as pyg, numpy as np
import pylab as pyl

# Use longitudes as horizontal axis
x = pyg.regularlon(45)

lam = np.pi * x / 180.

pyl.ioff()

# Example 1: f = sin(x)
# F = int_0^x f dx' = 1 - cos(x)
# Different integration methods

f = pyg.sin(lam)

Fr = f.integrate('lon', dx = lam, type='rectr')
Fl = f.integrate('lon', dx = lam, type='rectl')
Ft = f.integrate('lon', dx = lam, type='trapz')

ax1 = pyg.showlines([1 - pyg.cosd(x), Fr, Fl, Ft], 
                   fmts = ['k+', '_', '_', 'x'], 
                   labels = [r'$1 - \cos x$', 'rectr', 'rectl', 'trapz'], fig=3)

# Set panel title and axes labels
ax1.setp(title = r"$\int_0^x \sin(x') dx'$", ylabel = '')
# Adjust size and axis padding
ax1.size = (4.1, 3)
ax1.pad = [0.5, 0.3, 0.1, 0.4]
Ejemplo n.º 7
0
import pylab as pyl 
import pygeode as pyg, numpy as np

t = pyg.ModelTime365(values = np.arange(100), units='days', startdate=dict(year=1, month=1))
y1 = pyg.exp(-t / 30.) * pyg.cos(2*np.pi * t / 20.)
y2 = pyg.exp(-t / 30.) * pyg.sin(2*np.pi * t / 20.)
y1 = y1.rename('y1')
y2 = y2.rename('y2')

pyl.ioff()
ax = pyg.plot.AxesWrapper()
pyg.vplot(y1, label='y1', c='r', lw=2, axes=ax)
pyg.vplot(y2, label='y2', c='b', lw=2, axes=ax)

ax.setp(title = 'Two lines', ylabel='')
ax.setp_xaxis(major_formatter=pyg.timeticker.TimeFormatter(t, '$b'))

ax.legend(loc='lower right', frameon=False)

pyl.ion()
ax.render(1)