# -*- coding: utf8 -*- from vcmq import cdms2, curve2, map2, data_sample, N, P # Curve f = cdms2.open(data_sample('mars3d.t.nc')) sst = f('temp') f.close() c = curve2(sst, subplot=211, date_fmt='%b %d', date_locator='day', vmin=11.8, date_minor_locator='hour/6', show=False) # Add a letter for subfigures like "a)" c.add_key(1) # Add a simple text c.add_text(0.5, 0.5, 'Simple text', shadow=True) c.add_text('2008/01/08', 12.0, 'Simple text 2', size=15, weight='bold', glow=True, transform='data') c.add_text(0.1, 0.5, 'Simple text with box', rotation=90., va='center', bbox=dict(boxstyle='round4,pad=0.5', facecolor='r', alpha=0.5, linewidth=2)) # Add a label to the right/left/top/bottom c.add_right_label('Right label', pos=0.05, family='monospace') # Add lon/lat/time label c.add_lon_label(0.1, 0.9, -5.6, color='b') imin = N.argmin(sst) tmin = sst.getTime().asComponentTime()[imin] vmin = sst[imin] c.add_time_label(tmin, vmin, tmin, fmt='Min at%n%H:%M %d/%m/%Y', va='top', ha='center', color='g', transform='data')
sst2d = f('TEMP', time=slice(0, 1), level=slice(-1, None), squeeze=1) f.close() # 1D # - filtrages sst1d_gen13 = generic1d(sst1d, 13) sst1d_gen3 = generic1d(sst1d, [1., 1., 1.]) sst1d_sha = shapiro1d(sst1d) # -> SHAPIRO AVEC GENERIC1D sst1d_bar13 = bartlett1d(sst1d, 13) # -> TESTEZ GAUSSIEN SUR 13 HEURES # - plots curve2(sst1d, 'k', label='Original', show=False, figsize=(12, 5)) curve2(sst1d_gen13, 'r', label='Generic 13 pts', show=False) curve2(sst1d_gen3, 'g', label='Generic 3 pts', show=False) curve2(sst1d_sha, 'b', label='shapiro', show=False) curve2(sst1d_bar13, 'm', label='Bartlett', legend=True) # -> MASQUEZ UNE PARTIE DES DONNEES ET JOUEZ AVEC LE PARAMETRE MASK= # -> LISEZ UN BLOCK 3D ET FILTREZ LE SUIVANT LE TEMPS # 2D # - filtrage sst2d_gen13 = generic2d(sst2d, 13)
# - ouverture du fichier et infos temporelles f = cdms2.open(data_sample('mars3d.xt.xe.nc')) ctimes = f['xe'].getTime().asComponentTime() # - passage par un accumulateur de stats sa = StatAccum(tmean=True) # Boucle sur des intervals journaliers for itv in Intervals((ctimes[0], ctimes[-1], 'cc'), 'day'): # -> ESSAYER 2 JOURS # Lecture print itv tmp = f('xe', time=itv) # Accumulation sa += tmp del tmp # Finalisation # - restitution xem = sa.get_tmean() print N.ma.allclose(xem.asma(), f('xe').mean(axis=0)) curve2(xem) del sa # - fermeture f.close()
-8, va='center', ha='center', transform='data', fmt='%g') m.add_lat_label(-8, 47, 47, va='center', ha='center', transform='data') m.add_time_label(.1, .9, '2000') # Add place m.add_place(-2, 49, 'My place', text_family='monospace', text_size=15) # Add lines m.add_line([-8, 46, -1, 50], color='b') m.add_lines([-8, -1, -4, -8], [45, 45, 47, 45], color='r', linewidth=2, shadow=True) m.add_box([-8, 46, -1, 50], color='c') m.savefig(figfile % 0) m.close() # Test with dates var = MV2.array([3, 6]) time = create_time(['2000', '2005'], units='years since 2000') var.setAxis(0, time) c = curve2(var, show=False) c.add_point('2001', 4, marker='+', size=100, linewidth=2) c.savefig(figfile % 1) m.close()
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, show=False, key=2, savefigs=__file__, label="Interpolated", legend=True, tight_layout=True, legend_loc="lower right", )
ncfile = "swan.four.nc" lon0 = -5.1 lon1 = -4.9 lat0 = 48.35 lat1 = 48.55 # Imports from vcmq import cdms2, data_sample, N, transect, curve2, code_file_name, os, \ add_map_lines, P, add_shadow # Read data f = cdms2.open(data_sample(ncfile)) hs = f('HS', squeeze=1) f.close() # Compute transect hst, lons, lats = transect(hs, (lon0,lon1), (lat0,lat1), getcoords=True) # Plot along time s = curve2(hst, figsize=(8,3), title='Spatial transect on curved grid', show=False, top=0.85) # Add a small map to show the transect positions o = add_map_lines(hs, lons, lats, map_bgcolor='w', map_bbox= [.6, .2, .3, .5], map_anchor='W') # Save figfile = code_file_name(ext='png') if os.path.exists(figfile): os.remove(figfile) s.savefig(figfile, pdf=True)
# -*- coding: utf8 -*- # Read sea level at Brest from vcmq import cdms2, P, curve2, savefigs, data_sample f = cdms2.open(data_sample("tide.sealevel.BREST.mars.nc")) sea_level = f('sea_level') f.close() # Filtering from vacumm.tide.filters import demerliac cotes, tide = demerliac(sea_level, get_tide=True) # Plots kwplot = dict(date_fmt='%d/%m', show=False, date_rotation=0) # - tidal signal curve2(sea_level, 'k', subplot=211, label='Original', title='Sea level at Brest',**kwplot) curve2(tide, 'b', label='Tidal signal', **kwplot) P.legend().legendPatch.set_alpha(.7) # - surcotes/decotes curve2(cotes, 'r', subplot=212, hspace=.3, label='Demerliac', **kwplot) P.legend().legendPatch.set_alpha(.7) savefigs(__file__, savefigs_pdf=True)
"""Test :func:`~vacumm.misc.plot.curve2` with an arbitrary axis""" # Imports from vcmq import MV2, code_file_name, os, code_file_name, curve2 # Init var = MV2.arange(5.) var.units = '$Kg$' var.long_name = 'Flour' axis = var.getAxis(0) axis.units = 'm' axis.long_name = 'Distance' # Plot figfile = code_file_name(ext='png') if os.path.exists(figfile): os.remove(figfile) curve2(var, savefig=figfile, show=False, close=True)
# 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, color='k', map_cmap='thermal') # Save figfile = code_file_name(ext='png') if os.path.exists(figfile): os.remove(figfile) s.savefig(figfile, pdf=True)
"""Test :func:`~vacumm.misc.plot.curve2` with a latitude axis""" # Imports from vcmq import MV2, code_file_name, os, code_file_name, curve2, create_lat # Init var = MV2.arange(5.) var.units = 'mm' var.long_name = 'Precipitation' create_lat(var.getAxis(0)) # Plot figfile = code_file_name(ext='png') if os.path.exists(figfile): os.remove(figfile) curve2(var, savefig=figfile, show=False, close=True, latex_units=True)
# Imports from vcmq import cdms2, data_sample, N, transect, curve2, code_file_name, os, \ add_map_lines, P, add_shadow # Read data f = cdms2.open(data_sample(ncfile)) hs = f('HS', squeeze=1) f.close() # Compute transect hst, lons, lats = transect(hs, (lon0, lon1), (lat0, lat1), getcoords=True) # Plot along time s = curve2(hst, figsize=(8, 3), title='Spatial transect on curved grid', show=False, top=0.85) # Add a small map to show the transect positions o = add_map_lines(hs, lons, lats, map_bgcolor='w', map_bbox=[.6, .2, .3, .5], map_anchor='W') # Save figfile = code_file_name(ext='png') if os.path.exists(figfile): os.remove(figfile) s.savefig(figfile, pdf=True)
kwplot[att] = getattr(args, att) for att in ('color', 'linewidth'): val = getattr(args, att) if val is not None: kwplot[att] = val kwplot['quiver_norm'] = args.qnorm if len(vv)==2 and args.qonly: kwplot['contour'] = kwplot['fill'] = False if args.figsize: kwplot['figsize'] = tuple([float(v) for v in args.figsize.split(',')]) if args.res=='off': args.res = None kwplot['res'] = args.res #del kwplot['color'] #kwplot = {'color':None} # Adaptative plot if ndim==2: if order in ['yx', 'xy']: map2(vv, **kwplot) elif 't' in order: hov2(vv, **kwplot) else: plot2d(vv, **kwplot) else: if len(vv)>1: stick2(*vv, **kwplot) else: curve2(vv, **kwplot)
kwplot[att] = getattr(args, att) for att in ('color', 'linewidth'): val = getattr(args, att) if val is not None: kwplot[att] = val kwplot['quiver_norm'] = args.qnorm if len(vv) == 2 and args.qonly: kwplot['contour'] = kwplot['fill'] = False if args.figsize: kwplot['figsize'] = tuple([float(v) for v in args.figsize.split(',')]) if args.res == 'off': args.res = None kwplot['res'] = args.res #del kwplot['color'] #kwplot = {'color':None} # Adaptative plot if ndim == 2: if order in ['yx', 'xy']: map2(vv, **kwplot) elif 't' in order: hov2(vv, **kwplot) else: plot2d(vv, **kwplot) else: if len(vv) > 1: stick2(*vv, **kwplot) else: curve2(vv, **kwplot)
station = StationInfo('Brest') print station.attributes() print station.name, station.longitude print 'Niveau moyen a Brest:', station.nm # Read sea level at Brest f = cdms2.open(data_sample("tide.sealevel.BREST.mars.nc")) sea_level = f('sea_level') f.close() # Surcotes/decotes cotes, tide = demerliac(sea_level, get_tide=True) # -> ESSAYER GODIN kwp = dict(date_fmt='%b', date_locator='month') curve2(sea_level, 'b', show=False, figsize=(15, 4), **kwp) curve2(tide, 'r', **kwp) curve2(cotes, figsize=(15, 4), **kwp) # Extremas slzoom1 = sea_level(('2006-10-01', '2006-10-02'))[::4] # Toutes les heures bm, pm = extrema(slzoom1, spline=True, ref='mean') # -> SANS SPLINES zz = zeros(slzoom1, ref='mean') # -> AUTRES REFERENCE ? curve2(slzoom1, 'ko', markersize=3, figsize=(6, 4), show=False) curve2(zz, 'go', linewidth=0, show=False, xstrict=False) curve2(pm, 'ro', linewidth=0, show=False, xstrict=False) curve2(bm, 'bo', linewidth=0, xstrict=False, title="Niveau de la mer") # Outil marégraphique
# -*- coding: utf8 -*- from vcmq import cdms2, curve2, map2, data_sample, N, P # Curve f = cdms2.open(data_sample('mars3d.t.nc')) sst = f('temp') f.close() c = curve2(sst, subplot=211, date_fmt='%b %d', date_locator='day', vmin=11.8, date_minor_locator='hour/6', show=False) # Add a letter for subfigures like "a)" c.add_key(1) # Add a simple text c.add_text(0.5, 0.5, 'Simple text', shadow=True) c.add_text('2008/01/08', 12.0, 'Simple text 2', size=15, weight='bold', glow=True, transform='data') c.add_text(0.1, 0.5, 'Simple text with box', rotation=90.,
f.close() f = cdms2.open(data_sample('menor.nc')) sst2d = f('TEMP', time=slice(0, 1), level=slice(-1, None), squeeze=1) f.close() # 1D # - filtrages sst1d_gen13 = generic1d(sst1d, 13) sst1d_gen3 = generic1d(sst1d, [1., 1., 1.]) sst1d_sha = shapiro1d(sst1d) # -> SHAPIRO AVEC GENERIC1D sst1d_bar13 = bartlett1d(sst1d, 13) # -> TESTEZ GAUSSIEN SUR 13 HEURES # - plots curve2(sst1d, 'k', label='Original', show=False, figsize=(12, 5)) curve2(sst1d_gen13, 'r', label='Generic 13 pts', show=False) curve2(sst1d_gen3, 'g', label='Generic 3 pts', show=False) curve2(sst1d_sha, 'b', label='shapiro', show=False) curve2(sst1d_bar13, 'm', label='Bartlett', legend=True) # -> MASQUEZ UNE PARTIE DES DONNEES ET JOUEZ AVEC LE PARAMETRE MASK= # -> LISEZ UN BLOCK 3D ET FILTREZ LE SUIVANT LE TEMPS # 2D # - filtrage sst2d_gen13 = generic2d(sst2d, 13) sst2d_gau13 = gaussian2d(sst2d, 13)
# Interpolations for p in 'u', 'v', 'f', 'w': var[p] = ag.interp(var['t'], 't', p, mode='extrap') # Surface plots vmin, vmax = minmax(*[var[p][-1] for p in ['u', 'v', 'f']]) kw = dict(show=False, res=None, vmin=vmin, vmax=vmax, colorbar=False, grid=False, cmap='jet') m = map2(var['t'][-1], fill='pcolor', title='Interpolations on an Arakawa C grid: T->U/V/F', **kw) add_grid(var['t'], linestyle='-') kw.update(fill='scatter', contour=False, fill_s=60) markers = dict(u='>', v='^', f='D', t='o') for p in 't', 'u', 'v', 'f': m = map2(var[p][-1], fill_marker=markers[p], shadow=True, zorder=100, **kw) m.savefig(code_file_name(ext='_1.png')) m.close() # Vertical plot curve2(var['t'][:, 0, 0], 'o-b', ymax=0, show=False, title='Interpolations on an Arakawa C grid: T->W') curve2(var['w'][:, 0, 0], '^r', show=False, savefig=code_file_name(ext='_2.png')) result = [ ('assertEqual', [var['t'][0, 0, :2].mean(), var['u'][0, 0, 0]]), ('assertEqual', [var['t'][0, :2, 0].mean(), var['v'][0, 0, 0]]), ('assertEqual', [var['t'][0, :2, :2].mean(), var['f'][0, 0, 0]]), ('assertEqual', [var['t'][:2, 0, 0].mean(), var['w'][0, 0, 0]]), ]
# - ouverture du fichier et infos temporelles f = cdms2.open(data_sample("mars3d.xt.xe.nc")) ctimes = f["xe"].getTime().asComponentTime() # - passage par un accumulateur de stats sa = StatAccum(tmean=True) # Boucle sur des intervals journaliers for itv in Intervals((ctimes[0], ctimes[-1], "cc"), "day"): # -> ESSAYER 2 JOURS # Lecture print itv tmp = f("xe", time=itv) # Accumulation sa += tmp del tmp # Finalisation # - restitution xem = sa.get_tmean() print N.ma.allclose(xem.asma(), f("xe").mean(axis=0)) curve2(xem) del sa # - fermeture f.close()
# Add text m.add_text(0.1, 0.1, 'My text', color='r', shadow=True, weight='bold') m.add_text(-2, 50.5, 'My text with transform', transform='data', ha='center', bbox=dict(facecolor='y', alpha=.3)) m.add_lon_label(-8, 47.5, -8, va='center', ha='center', transform='data', fmt='%g') m.add_lat_label(-8, 47, 47, va='center', ha='center', transform='data') m.add_time_label(.1, .9, '2000') # Add place m.add_place(-2, 49, 'My place', text_family='monospace', text_size=15) # Add lines m.add_line([-8, 46, -1, 50], color='b') m.add_lines([-8, -1, -4, -8], [45, 45, 47, 45], color='r', linewidth=2, shadow=True) m.add_box([-8, 46, -1, 50], color='c') m.savefig(figfile%0) m.show() m.close() # Test with dates var = MV2.array([3, 6]) time = create_time(['2000', '2005'], units='years since 2000') var.setAxis(0, time) c = curve2(var, show=False) c.add_point('2001', 4, marker='+', size=100, linewidth=2) c.savefig(figfile%1) m.close()
"""Test :func:`~vacumm.misc.plot.curve2` with a time axis""" # Imports from vcmq import MV2, code_file_name, os, code_file_name, curve2 # Init var = MV2.arange(5.) var.units = 'W' var.long_name = 'Power' axis = var.getAxis(0) axis.units = 'months since 2013-01-01' axis.long_name = 'Time' axis.axis = 'T' # Plot figfile = code_file_name(ext='png') if os.path.exists(figfile): os.remove(figfile) curve2(var, savefig=figfile, show=True, close=True)
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., markersize=2, ymin=-.4, ymax=.1, show=False, subplot=212, label='Original') curve2(sph, '-r', err=speh.asma()/2., linewidth=1.5, show=False, key=2, savefigs=__file__, label='Interpolated', legend=True, tight_layout=True, legend_loc='lower right')
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, ymin=-.4, ymax=.1, show=False, subplot=212, label='Original') curve2(sph, '-r', err=speh.asma() / 2., linewidth=1.5, show=False, key=2, savefigs=__file__, label='Interpolated', legend=True, tight_layout=True, legend_loc='lower right',
"""Test :func:`~vacumm.misc.plot.curve2` with a call to :func:`~vacumm.misc.plot.hlitvs`""" # Imports from vcmq import MV2, code_file_name, os, code_file_name, curve2 # Init var = MV2.arange(5.0) var.units = "W" var.long_name = "Power" axis = var.getAxis(0) axis.units = "days since 2013-01-01" axis.long_name = "Time" axis.axis = "T" # Plot figfile = code_file_name(ext="png") if os.path.exists(figfile): os.remove(figfile) curve2(var, savefig=figfile, show=True, close=True, hlitvs=True)
# Stations station = StationInfo('Brest') print station.attributes() print station.name, station.longitude print 'Niveau moyen a Brest:', station.nm # Read sea level at Brest f = cdms2.open(data_sample("tide.sealevel.BREST.mars.nc")) sea_level = f('sea_level') f.close() # Surcotes/decotes cotes, tide = demerliac(sea_level, get_tide=True) # -> ESSAYER GODIN kwp = dict(date_fmt='%b', date_locator='month') curve2(sea_level, 'b', show=False, figsize=(15, 4), **kwp) curve2(tide, 'r', **kwp) curve2(cotes, figsize=(15, 4), **kwp) # Extremas slzoom1 = sea_level(('2006-10-01', '2006-10-02'))[::4] # Toutes les heures bm, pm = extrema(slzoom1, spline=True, ref='mean') # -> SANS SPLINES zz = zeros(slzoom1, ref='mean') # -> AUTRES REFERENCE ? curve2(slzoom1, 'ko', markersize=3, figsize=(6, 4), show=False) curve2(zz, 'go', linewidth=0, show=False, xstrict=False) curve2(pm, 'ro', linewidth=0, show=False, xstrict=False) curve2(bm, 'bo', linewidth=0, xstrict=False, title="Niveau de la mer") # Outil marégraphique slzoom2 = sea_level(('2006-10', '2006-11'))[::4] # Toutes les heures mg = Marigraph(slzoom2, verbose=True)
cmap='jet') m = map2(var['t'][-1], fill='pcolor', title='Interpolations on an Arakawa C grid: T->U/V/F', **kw) add_grid(var['t'], linestyle='-') kw.update(fill='scatter', contour=False, fill_s=60) markers = dict(u='>', v='^', f='D', t='o') for p in 't', 'u', 'v', 'f': m = map2(var[p][-1], fill_marker=markers[p], shadow=True, zorder=100, **kw) m.savefig(code_file_name(ext='_1.png')) m.close() # Vertical plot curve2(var['t'][:, 0, 0], 'o-b', ymax=0, show=False, title='Interpolations on an Arakawa C grid: T->W') curve2(var['w'][:, 0, 0], '^r', show=False, savefig=code_file_name(ext='_2.png')) result = [ ('assertEqual', [var['t'][0, 0, :2].mean(), var['u'][0, 0, 0]]), ('assertEqual', [var['t'][0, :2, 0].mean(), var['v'][0, 0, 0]]), ('assertEqual', [var['t'][0, :2, :2].mean(), var['f'][0, 0, 0]]), ('assertEqual', [var['t'][:2, 0, 0].mean(), var['w'][0, 0, 0]]), ]
# -*- coding: utf8 -*- # Read sea level at Brest from vcmq import cdms2, P, curve2, savefigs, data_sample f = cdms2.open(data_sample("tide.sealevel.BREST.mars.nc")) sea_level = f('sea_level') f.close() # Filtering from vacumm.tide.filters import demerliac cotes, tide = demerliac(sea_level, get_tide=True) # Plots kwplot = dict(date_fmt='%d/%m', show=False, date_rotation=0) # - tidal signal curve2(sea_level, 'k', subplot=211, label='Original', title='Sea level at Brest', **kwplot) curve2(tide, 'b', label='Tidal signal', **kwplot) P.legend().legendPatch.set_alpha(.7) # - surcotes/decotes curve2(cotes, 'r', subplot=212, hspace=.3, label='Demerliac', **kwplot) P.legend().legendPatch.set_alpha(.7) savefigs(__file__, savefigs_pdf=True) P.close()
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)