# Lecture de la température
f =cdms2.open(data_sample('mars3d.tsigyx.nc'))
data_in = f('TEMP', time=slice(0,2)) # T-YX (- = level)


# Détermination des profondeurs d'après les sigma
sigma_converter = NcSigma.factory(f)                # détection auto et initialisation du convertisseur
# -> VERIFIER QUE sigma_class EST BIEN SigmaGeneralized
depths_in = sigma_converter.sigma_to_depths(selector=dict(time=slice(0,2))).filled()          # lecture eta, etc + conversion
# (Equivalent à depths_in = sigma_converter(selector=dict(time=slice(0,2))).filled())
f.close()


# Creation de l'axe des profondeurs cibles
depths = N.array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
    22,24,26,28,30,32,34,36,38,40,45,50,55,60,65,70,75,80,85,90,95,100,120,140,160])
depths = -depths[::-1] # croissantes et négatives
depth_out = create_depth(depths)


# Interpolation
data_out = regrid1d(data_in, depth_out, axi=depths_in, axis=1, method='linear', extrap=1)


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


Beispiel #2
0
# Imports
from vcmq import N, MV2, cdms2, create_dep, rc, section2, code_file_name, os

# Init data with z 1D
nz = 8
nd = 10
var = N.dot(N.hanning(nz).reshape(nz, 1), N.hanning(nd).reshape(1, nd))
var = MV2.array(var)
d = cdms2.createAxis(N.arange(nd))
d.units = 'km'
d.long_name = 'Distance'
z1d = create_dep((-nz + 1, 1.))
var.setAxis(0, z1d)
var.setAxis(1, d)
z2d = N.resize(z1d[:].reshape(1, nz), (nd, nz)).T
z2d *= N.arange(1., nd + 1) / nd

# Plot with z 1D
rc('font', size=8)
kw = dict(show=False, bgcolor='0.5')
section2(var, subplot=211, **kw)

# Plot with z 2D
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
section2(var, yaxis=z2d, subplot=212, savefig=figfile, close=True, **kw)

# Result
result = dict(files=figfile)
# Imports
from vcmq import create_lon, N, MV2, create_dep, os, code_file_name, section2
from vacumm.misc.phys.units import deg2m

# Init data with z 1D
nz = 11
nx = 11
x = create_lon(N.arange(nx))
xm = deg2m(x[:],lat=45.) # meters
dx = xm[:].ptp()
z = create_dep((-nz+1, 1.), units='m', long_name='Depth')
dz = z[:].ptp()
scale = dz/dx
u = MV2.ones((nz,nx)) # 1 m/s
w = u*scale           # 1 m/s * scale
for var in u,w:
    var.setAxis(0, z)
    var.setAxis(1, x)
    var.units = 'm/s'

# Plot
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
s = section2((u,w), quiver_norm=1, fill=False, show=False,
    savefig=figfile, close=False, axes_aspect=1)

# Result
result = dict(files=figfile)


from vcmq import N, MV2, cdms2, create_dep, rc, section2, code_file_name, os

# Init data with z 1D
nz = 8
nd = 10
var = N.dot(N.hanning(nz).reshape(nz, 1), N.hanning(nd).reshape(1, nd))
var = MV2.array(var)
d = cdms2.createAxis(N.arange(nd))
d.units='km'
d.long_name='Distance'
z1d = create_dep((-nz+1, 1.))
var.setAxis(0, z1d)
var.setAxis(1, d)
z2d = N.resize(z1d[:].reshape(1, nz), (nd, nz)).T
z2d *= N.arange(1., nd+1)/nd

# Plot with z 1D
rc('font', size=8)
kw = dict(show=False, bgcolor='0.5')
section2(var, subplot=211, **kw)

# Plot with z 2D
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
section2(var, yaxis=z2d, subplot=212, savefig=figfile, close=True, **kw)

# Result
result = dict(files=figfile)


# Imports
from vcmq import create_lon, N, MV2, create_dep, os, code_file_name, section2
from vacumm.misc.phys.units import deg2m

# Init data with z 1D
nz = 11
nx = 11
x = create_lon(N.arange(nx))
xm = deg2m(x[:], lat=45.)  # meters
dx = xm[:].ptp()
z = create_dep((-nz + 1, 1.), units='m', long_name='Depth')
dz = z[:].ptp()
scale = dz / dx
u = MV2.ones((nz, nx))  # 1 m/s
w = u * scale  # 1 m/s * scale
for var in u, w:
    var.setAxis(0, z)
    var.setAxis(1, x)
    var.units = 'm/s'

# Plot
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
s = section2((u, w),
             quiver_norm=1,
             fill=False,
             show=False,
             savefig=figfile,
             close=True,
             axes_aspect=1)
                               tlons,
                               tlats,
                               getcoords=True,
                               outaxis='dist')
xdepth = transect(depth, tlons, tlats)
xmld = transect(mld, tlons, tlats)
xmld[:] *= -1

# Plot temperature
s = section2(
    xtemp,
    yaxis=xdepth,
    ymin=-800,
    fill='contourf',
    nmax=20,
    contour_linewidths=0.7,
    bgcolor='0.5',
    figsize=(7, 4),
    cmap='thermal',
    #    cmap='vacumm_rnb2_hymex',
    title='%(long_name)s (dens) along temp transect',
    show=False)

# Plot MLD
curve2(xmld, 'w-', linewidth=2, show=False)

# Add a small map to show the transect positions
add_map_lines(temp[-1],
              xlons,
              xlats,
              map_zoom=0.7,
Beispiel #7
0
depths = -depths[::-1]  # croissantes et négatives
depth_out = create_depth(depths)

# Interpolation
data_out = regrid1d(data_in,
                    depth_out,
                    axi=depths_in,
                    axis=1,
                    method='linear',
                    extrap=1)

# Plot
kw = dict(vmin=10,
          vmax=14,
          xhide='auto',
          add_grid=True,
          ymax=0,
          fill='contourf')  # FILL=PCOLOR ?
section2(data_in[0, :, 10],
         yaxis=depths_in[0, :, 10],
         subplot=211,
         title='Sigma',
         show=False,
         **kw)
s = section2(data_out[0, :, 10],
             subplot=212,
             title='Z',
             show=False,
             savefig=__file__,
             **kw)
mld = mixed_layer_depth(dens, depth=depth, mode='deltadens', format_axes=True)
del dens

# Compute transect
tlons = (lon0,lon1)
tlats = (lat0,lat1)
tlons = N.concatenate([N.linspace(lon0,lon1,100.),N.linspace(lon1,lon1,100.)])
tlats = N.concatenate([N.linspace(lat0,lat1,100.),N.linspace(lat1,lat0,100.)])
xtemp, xlons, xlats = transect(temp, tlons, tlats, getcoords=True, outaxis='dist')
xdepth = transect(depth, tlons, tlats)
xmld = transect(mld, tlons, tlats)
xmld[:]*=-1

# Plot temperature
s = section2(xtemp, yaxis=xdepth, ymin=-800, fill='contourf', nmax=20,
    contour_linewidths=0.7, bgcolor='0.5', figsize=(7,4),
    cmap='vacumm_rnb2_hymex',
    title='%(long_name)s (dens) along temp transect', show=False)

# Plot MLD
curve2(xmld, 'w-', linewidth=2, show=False)

# Add a small map to show the transect positions
add_map_lines(temp[-1], xlons, xlats, map_zoom=0.7, color='k')

# Save
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
s.savefig(figfile, pdf=True)