Example #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'
        })
Example #2
0
def buildT3():
    lon = pyg.regularlon(60)
    lat = pyg.gausslat(42)
    tm = pyg.modeltime365n('1 Jan 2000', 200)

    def eps_like(v):
        return pyg.Var(v.axes, values=np.random.randn(*v.shape))

    X1 = (5. * tm / 2000.) * pyg.cosd(lat)
    X2 = pyg.cosd(2 * np.pi * tm / 500.) * pyg.sind(0.5 * lon)
    X3 = pyg.sind(2 * np.pi * tm / 120.) * pyg.cosd(3 * lon)**2

    X1e = X1 + 0.1 * eps_like(X1)
    X2e = X2 + 0.2 * eps_like(X2)
    X3e = X3 + 0.2 * eps_like(X3)

    Y1 = -1. * pyg.sind(lon) * X1e + eps_like(X1).smooth('lat', 4)
    Y2 = -0.2 * X1e + 0.8 * X2e + -0.6 * X3e + 0.1 * eps_like(X1)

    X1 = X1.rename('X1')
    X2 = X2.rename('X2')
    X3 = X3.rename('X3')
    X1e = X1e.rename('X1e')
    X2e = X2e.rename('X2e')
    X3e = X3e.rename('X3e')
    Y1 = Y1.rename('Y1')
    Y2 = Y2.rename('Y2')
    Y3 = Y2.rename('Y3')

    return pyg.Dataset(
        [X1e, X2e, X3e, Y1, Y2],
        atts={'history': 'Synthetic dataset generated by pygeode'})
Example #3
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'})
Example #4
0
def buildT1():
  lat = pyg.regularlat(31)
  lon = pyg.regularlon(60)

  T_c = 260. + 40. * pyg.exp(-(lat/45.)**2)
  T_wave = 0.05 * lat * pyg.sind(6*lon)
  T = T_c + T_wave
  T.name = 'Temp'
  T.units = 'K'

  return pyg.Dataset([T], atts={'history':'Synthetic Temperature data generated by pygeode'})
Example #5
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')
Example #6
0
"""
Plot lines using showlines
==========================

Compute numerical integrals using :func:`Var.integrate` and use :func:`showlines` to make plot 
"""
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
Example #7
0
"""
Cartopy: Test regional projections
=============================================
"""
import pygeode as pyg, numpy as np, pylab as pyl
from cartopy import crs as ccrs
import cartopy

lat = pyg.gausslat(40)
lon = pyg.regularlon(80, origin=-180)

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()

prj_grid = ['PlateCarree', 'Mercator', 'Miller', 'TransverseMercator']
prj_reg  = ['AlbersEqualArea', 'EquidistantConic', 'LambertConformal', \
            'LambertCylindrical', 'RotatedPole']
prj_glob = ['AzimuthalEquidistant', 'Mollweide', 'Orthographic',  \
            'Stereographic', 'Robinson', 'Sinusoidal', \
            'Geostationary', 'LambertAzimuthalEqualArea', 'EckertIII']

prj = dict(central_longitude=60.)
gridlines = dict(draw_labels=False,
                 xlocs=range(0, 361, 30),
                 ylocs=range(-80, 81, 20)),
map = dict(gridline=gridlines)

i = 0
axr = []