# 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)
# - plot P.figure(figsize=(6, 6)) P.subplot(211) P.plot(lags, els, 'o') P.plot([0, lags[-1]], [b, a * lags[-1] + b], 'g') P.axhline(b, color='0.8', ls='--') P.ylim(ymin=0) P.xlabel('Lag [hour]') P.ylabel('Error [m s-1]') add_key(1) P.title('Linear lag error model') # Interpolation sph, speh = regrid1d(sp, taxo, method='cellerr', erri=spe, errl=-a, geterr=True) # Time zoom for plot clarity tzoom = (ct1.sub(7, cdtime.Hour), ctimesi[-1]) sp = sp(tzoom) spe = spe(tzoom) sph = sph(tzoom) speh = speh(tzoom) # Main plot curve2(sp, 'o', err=spe.asma() / 2., markersize=2,
def slice_gridded_var(var, member=None, time=None, depth=None, lat=None, lon=None): """Make slices of a variable and squeeze out singletons to reduce it The "member" axis is considered here as a generic name for the first axis of unkown type. .. warning:: All axes must be 1D """ # Check order var = var(squeeze=1) order = var.getOrder() # Unkown axis if '-' in order and member is not None: i = order.find('-') id = var.getAxisIds()[i] if isinstance(member, slice): kw = {id:member} var = var(**kw) else: axo = create_axis(member) cp_atts(var.getAxis(i), axo) var = regrid1d(var, axo, iaxi=i)(squeeze=N.isscalar(member)) # Time interpolation if 't' in order and time is not None: axi = var.getTime() if isinstance(time, slice): var = var(time=time) else: axo = create_time(time, axi.units) var = regrid1d(var, axo)(squeeze=N.isscalar(time)) # Depth interpolation if 'z' in order and depth is not None: if depth=='bottom': var = slice_bottom(var) else: if depth=='surf': depth = slice(-1, None) if isinstance(depth, slice): var = var(level=depth, squeeze=1) # z squeeze only? elif (N.isscalar(depth) and var.getLevel()[:].ndim==1 and depth in var.getLevel()): var = var(level=depth) else: axo = create_dep(depth) if axo[:].max()>10: sonat_warn('Interpolation depth is positive. Taking this opposite') axo[:] *=-1 var = regrid1d(var, axo)(squeeze=N.isscalar(depth)) # Point if (order.endswith('yx') and lon is not None and lat is not None and not isinstance(lat, slice) and not isinstance(lon, slice)): var = grid2xy(var, lon, lat)(squeeze=N.isscalar(lon)) else: # Latitude interpolation if 'y' in order and lat: if isinstance(lat, slice): var = var(lat=lat) else: axo = create_lat(lat) var = regrid1d(var, axo)(squeeze=N.isscalar(lat)) # Longitude interpolation if 'x' in order and lon: if isinstance(lon, slice): var = var(lon=lon) else: axo = create_lon(lon) var = regrid1d(var, axo)(squeeze=N.isscalar(lon)) return var
els = N.array(els) a, b, _, _, _ = linregress(lags, els) # - plot P.figure(figsize=(6, 6)) P.subplot(211) P.plot(lags, els, "o") P.plot([0, lags[-1]], [b, a * lags[-1] + b], "g") P.axhline(b, color="0.8", ls="--") P.ylim(ymin=0) P.xlabel("Lag [hour]") P.ylabel("Error [m s-1]") add_key(1) P.title("Linear lag error model") # Interpolation sph, speh = regrid1d(sp, taxo, method="cellerr", erri=spe, errl=-a, geterr=True) # Time zoom for plot clarity tzoom = (ct1.sub(7, cdtime.Hour), ctimesi[-1]) sp = sp(tzoom) spe = spe(tzoom) sph = sph(tzoom) speh = speh(tzoom) # Main plot curve2(sp, "o", err=spe.asma() / 2.0, markersize=2, ymin=-0.4, ymax=0.1, show=False, subplot=212, label="Original") curve2( sph, "-r", err=speh.asma() / 2.0, linewidth=1.5,
# (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,