Exemple #1
0
sigma_converter = sigma_class(copyaxes=True)
# - lecture de eta (sans sélection de domaine) et calcul des profondeurs
depths_in = sigma_converter().filled()
f.close()

# Creation de l'axe des profondeurs cibles
depth_out = create_depth(depths)

# Interpolation
xmap = (0, 2, 3) # la profondeur varie en T/Y/X
xmapper = np.rollaxis(depths_in, 1, 4) # profondeur = dernier axe
data_out = regrid1d(data_in, depth_out, axi=depths_in, axis=1, method='linear', extrap=1)

# Plot
kw = dict(show=False, vmin=10, vmax=14, xhide='auto', add_grid=True, ymax=0)
section2(data_in[0, :, 10], yaxis=depths_in[0, :, 10], subplot=211, title='Sigma', **kw)
s = section2(data_out[0, :, 10], subplot=212, title='Z', savefigs=__file__,
    close=True, **kw)

# Sauvegarde
outfile = __file__[:-2]+'nc'
if os.path.isfile(outfile):
  os.remove(outfile)
netcdf3()
f2 = cdms2.open(outfile,'w')
f2.write(data_out)
f2.close()
print 'Saved to', outfile

# Temps de calcul
print "Whole computation took %.2f s" % (time() - t0)
Exemple #2
0
sigma_converter = sigma_class(copyaxes=True)
# - lecture de eta (sans sélection de domaine) et calcul des profondeurs
depths_in = sigma_converter().filled()
f.close()

# Creation de l'axe des profondeurs cibles
depth_out = create_depth(depths)

# Interpolation
xmap = (0, 2, 3) # la profondeur varie en T/Y/X
xmapper = np.rollaxis(depths_in, 1, 4) # profondeur = dernier axe
data_out = regrid1d(data_in, depth_out, axi=depths_in, axis=1, method='linear', extrap=1)

# Plot
kw = dict(show=False, vmin=10, vmax=14, xhide='auto', add_grid=True, ymax=0)
section2(data_in[0, :, 10], yaxis=depths_in[0, :, 10], subplot=211, title='Sigma', **kw)
s = section2(data_out[0, :, 10], subplot=212, title='Z', savefigs=__file__, **kw)

# Sauvegarde
outfile = __file__[:-2]+'nc'
if os.path.isfile(outfile):
  os.remove(outfile)
netcdf3()
f2 = cdms2.open(outfile,'w')
f2.write(data_out)
f2.close()
print 'Saved to', outfile

# Temps de calcul
print "Whole computation took %.2f s" % (time() - t0)
print "End : " + strftime(print_time_format)
# ==> Practice: Create cdarr with depth/lat axes. - see doc Vacumm -
# # - depth
# ax1 = create_dep(N.linspace(-1000,0,10))
# # - latitude
# ax2 = create_lat(N.arange(15)*.5+44.)


# ==> Practice: Create cdarr with time/lat axes. - see doc Vacumm -
# # - time
# ax1 = create_time(N.arange(10.),
    # 'days since 2006-10-01',long_name='Mon axe de temps')
# # - latitude
# ax2 = create_lat(N.arange(15)*.5+44.)

# - cdms2 variable creation
cdarr = cdms2.createVariable(marr,axes=[ax1,ax2],id='test',attributes=dict(long_name='the main test',units='$m^3 s^{-1}$'))
print 'Array type - cdarr - :',type(cdarr)
print 'Variable :',cdarr.id
# print 'Longitude :',cdarr.getLongitude()
# print 'Latitude :',cdarr.getLatitude()
# print cdarr

# - Result snapshot
if islon(cdarr.getAxis(0)):
    map(cdarr, contour=False)
if isdep(cdarr.getAxis(0)):
    section2(cdarr, contour=False)
if istime(cdarr.getAxis(0)):
    hov2(cdarr, contour=False)
Exemple #4
0
# Creation d'un axe de profondeur
from vacumm.misc.axes import create_dep
ddep = 5.
dep = create_dep((-h0.max(), 0. + ddep, ddep))

# Creation de l'axe etendu (taille (ndep,nx))
depths = -N.outer(t.getAxis(0)[::-1], h0)
dep[-1] = depths[-1].max()

# Regrillage lineaire
from vacumm.misc.grid.regridding import regrid1d
tr = regrid1d(t, dep, 'linear', axi=depths, axis=0)
tr.long_name = 'Interpolated'
t.getAxis(0).designateLevel()

# Plot
from vacumm.misc.plot import savefigs, yscale, add_grid, section2
import pylab as P
P.figure(figsize=(5.5, 6))
kwplot = dict(show=False, bgcolor='.5', ylim=(-80, 0))
# - original
section2(t, yaxis=depths, subplot=211, hspace=.3, **kwplot)
add_grid((t.getLongitude(), depths[:]), linewidth=.3)

# - regridded
section2(tr, subplot=212, **kwplot)
add_grid((tr.getLongitude(), dep[:]), linewidth=.3)
savefigs(__file__)
P.close()
# Creation d'un axe de profondeur
from vacumm.misc.axes import create_dep
ddep = 5.
dep = create_dep((-h0.max(),0.+ddep , ddep))

# Creation de l'axe etendu (taille (ndep,nx))
depths = -N.outer(t.getAxis(0)[::-1], h0)
dep[-1] = depths[-1].max()

# Regrillage lineaire
from vacumm.misc.grid.regridding import regrid1d
tr = regrid1d(t, dep, 'linear', axi=depths, axis=0)
tr.long_name = 'Interpolated'
t.getAxis(0).designateLevel()

# Plot
from vacumm.misc.plot import savefigs,yscale, add_grid, section2
import pylab as P
P.figure(figsize=(5.5, 6))
kwplot = dict(show=False, bgcolor='.5', ylim=(-80, 0))
# - original
section2(t, yaxis=depths, subplot=211, hspace=.3, **kwplot)
add_grid((t.getLongitude(), depths[:]), linewidth=.3)

# - regridded
section2(tr, subplot=212, **kwplot)
add_grid((tr.getLongitude(), dep[:]), linewidth=.3)
savefigs(__file__)