Beispiel #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'
        })
Beispiel #2
0
def test_scalar_variable_read():
    import pygeode as pyg
    # Create a scalar variable and test reading from it
    v = pyg.Var((), name='scalar', values=10.)
    assert v[()] == 10.

    # Write to netcdf
    pyg.save('test_issue_108.nc', v)
Beispiel #3
0
def test_issue053():
    import pygeode as pyg
    import numpy as np
    l = pyg.regularlat(30)
    t = pyg.ModelTime365(values=np.arange(100),
                         units='days',
                         startdate=dict(year=1, month=1))
    v = pyg.Var((t, l), name='Test', values=np.ones((100, 30)))
    v.plotatts['scalefactor'] = 2.
    v.plotatts['plottitle'] = 'V'

    a = l * v
    b = t + v

    assert a.plotatts == v.plotatts
    assert b.plotatts == v.plotatts
Beispiel #4
0
 def eps_like(v):
     return pyg.Var(v.axes, values=np.random.randn(*v.shape))
Beispiel #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))[:]
Beispiel #6
0
               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', \
         values = data[:5, :5, :5])

sl2 = varTest('slice_stride', var(i_time=(1, -1, 4)), \
         values = data[1:-1:4, :, :])

sl3 = varTest('slice_negative_stride', var(i_time=(2, -5, -3)), \
Beispiel #7
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)