Exemple #1
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'})
Exemple #2
0
def test_issue046():
    import pygeode as pyg
    import numpy as np
    V = pyg.Var((pyg.Lat(32), ), name='Test', values=np.zeros(32) * np.nan)
    V.interpolate('lat', pyg.gausslat(32))[:]
Exemple #3
0
         def test_serialize(self):
            for k, f in formats.items():
               fname = '%s.%s' % (testname, k)

               f.save(fname, [self.var])    
               d = f.open(fname)         
               assertSameVar(d.vardict[self.name], self.var)
               
               os.remove(fname)              
            

   tc.__name__ = testname
   return tc

ax1 = pyg.StandardTime(values=np.arange(365.), units='days', startdate={'year':2001})
ax2 = pyg.gausslat(32)
ax3 = pyg.Pres(np.arange(0, 100, 10.))

shape = (365, 32, 10)
data = np.random.randn(*shape)
ltwts = ax2.auxarrays['weights']
var = pyg.Var((ax1, ax2, ax3), values=data, name='var')

tv = varTest('1_Simple', var, \
         name = 'var', axes = (ax1, ax2, ax3), \
         values = data, serialize=True)
         
sl1 = varTest('slice_simple', var(i_time=(0, 5), i_lat=(0, 5), i_pres=(0, 5)), \
         shape = (5, 5, 5), \
         axes = (ax1(i_time=(0, 5)), ax2(i_lat=(0, 5)), ax3(i_pres=(0, 5))), \
         name = 'var', \
Exemple #4
0
import pygeode as pyg
import numpy as np
import pylab as pyl
from pygeode.formats import netcdf as nc

lat = pyg.gausslat(32)
lon = pyg.Lon(np.arange(0, 360, 360 / 64.))

ln_grid, lt_grid = np.meshgrid(lon.values, lat.values)
T_values = 260. + 40 * np.exp(-(lt_grid / 45.)**2) + 0.05 * lt_grid * np.sin(
    3 * ln_grid * np.pi / 180.)
T_c = 260. + 40 * np.exp(-(lt_grid / 45.)**2)
T_wave = 0.05 * lt_grid * np.sin(3 * ln_grid * np.pi / 180.)

T = pyg.Var((lat, lon), name='Temp', values=T_c + T_wave, atts={'units': 'K'})
d = pyg.Dataset(
    [T], atts={'history': 'Synthetic Temperature data generated by pygeode'})
nc.save('t_sample.nc', d)
Exemple #5
0
def test_issue046():
  import pygeode as pyg
  import numpy as np
  V = pyg.Var((pyg.Lat(32),), name='Test', values=np.zeros(32) * np.nan)
  V.interpolate('lat', pyg.gausslat(32))[:]
"""
Cartopy: Use Cartopy Features
=============================
"""
import pygeode as pyg, numpy as np, pylab as pyl
from cartopy import crs as ccrs
import cartopy
from cartopy.feature.nightshade import Nightshade
from datetime import datetime as dt

lat = pyg.gausslat(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()
prj = dict(central_longitude = 60)
#ax = pyg.plot.CartopyAxes(projection = 'NearsidePerspective', prj_args = prj)

map = dict(projection = 'NearsidePerspective', prj_args = prj)
#map = dict(projection = 'LambertConformal', prj_args = prj)

cl = pyg.cldict(0.1, nozero=True)
ax = pyg.vcontour(x, map = map, **cl)
ax.add_feature(cartopy.feature.OCEAN)
ax.add_feature(Nightshade(dt.utcnow()))
ax.setp(title = '')

pyl.ion()
ax.render(2)
Exemple #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 = []