def do_something(self): num, den = 0, 0 try: num / den except: self.exception('Division by 0 failed !\n%s', self.exception_trace()) self.info('The function emitting this message is: %s', self.func_name()) self.info('The stack trace of the function emitting this message is:\n%s', self.stack_trace()) t = create_time(['1900-01-01 00:00:00', '9999-12-31 23:59:59']) y = create_lat(range(-90, 90)) x = create_lon(range(-180, 180)) v = cdms2.createVariable(numpy.random.ranf((len(t), len(y), len(x))), axes=[t, y, x], id='data', long_name='random data') self.info('Time:\n%s', self.describe(t)) self.info('Latitude:\n%s', self.describe(y)) self.info('Longitude:\n%s', self.describe(x, stats=True)) self.info('Variable:\n%s', self.describe(v, stats=True))
yo = cdms2.createAxis(lai) LONGITUDE = create_lon(loi, id='longitude', attributes=dict( long_name='Longitude of each location', standard_name='longitude', units='degrees_east', valid_min='-180.', valid_max='180.', axis='X')) LATITUDE = create_lat(lai, id='latitude', attributes=dict( long_name='Latitude of each location', standard_name='latitude', units='degrees_north', valid_min='-90.', valid_max='90.', axis='Y')) z = U.getLevel() DEPTH = create_dep(z, attributes=dict(long_name='sea water depth', standard_name='depth', units='m', valid_min='0.', valid_max='12000.')) #axes = [TIME,DEPTH,LATITUDE,LONGITUDE] axes = [DEPTH, LATITUDE, LONGITUDE]
latname=options.latname, imargin=2, jmargin=2, maxvalue=None, reverse=options.reverse) # Interpolate on section bathy = b.bathy() lons, lats, xx, yy = transect_specs(bathy.getGrid(), options.x0, options.y0, options.x1, options.y1, getxy=True) tbathy = grid2xy(bathy, lons, lats) if not isinstance(options.along, basestring) or options.along not in ['lon', 'lat', 'm', 'km', 'dist', 'auto']: options.along = 'auto' if options.along=='auto': options.along = 'lon' if xx.max()-xx.min() > yy.max()-yy.min() else 'lat' if options.along=='lon': taxis = create_lon(lons) elif options.along=='lat': taxis = create_lat(lats) else: xy = N.sqrt((xx-xx[0])**2+(yy-yy[0])**2) if xy.max()-xy.min()>2500 or options.along=='km': units = 'km' xy *= 1e-3 else: units = 'm' taxis = cdms2.createAxis(xy) taxis.units = units taxis.long_name = 'Distance' tbathy.setAxis(0, taxis) # Plot c = curve2(tbathy, 'k', bgcolor=(.95, .95, 1), order='d-', show=False, yfmt='%gm', yunits=False, bottom=0.12, zorder=10,
# Grid (15x15) nx, ny = 15, 10 import numpy as N from vacumm.misc.axes import create_lon, create_lat lon = create_lon(N.linspace(-5.2, -4.4, nx)) lat = create_lat(N.linspace(48, 48.6, ny)) # Plot params import pylab as P import vacumm.misc.color as C P.figure(figsize=(6, 5)) P.subplots_adjust(top=.92, left=.03, bottom=.03, wspace=.05, hspace=.2) kwplot = dict(colorbar=False,cmap=C.cmap_linear([(.6, .8, 1), C.land]), \ contour=False,show=False,fillcontinents=False,fill='pcolor', drawmeridians=False, drawparallels=False, res='h', key=True, xymasked=False) # Mask using shoreline from vacumm.misc.grid.masking import polygon_mask from vacumm.misc.plot import map2 import MV2 as MV # - mask if central point sur terre (mode = 0 = 'inside') lon2, lat2 = N.meshgrid(lon, lat) mask0 = polygon_mask((lon2, lat2), 'h', mode=0, ocean=False) mask0 = MV.array(mask0, axes=[lat, lon]) mask0.long_name = "'inside'" map2(mask0, subplot=221, **kwplot) # - mask if cell more than 50% of land (mode = 1 = 'intersect') thresholds = .5 mask1 = polygon_mask((lon2, lat2), 'h', mode=1,
options.y0, options.x1, options.y1, getxy=True) tbathy = grid2xy(bathy, lons, lats) if not isinstance(options.along, basestring) or options.along not in [ 'lon', 'lat', 'm', 'km', 'dist', 'auto' ]: options.along = 'auto' if options.along == 'auto': options.along = 'lon' if xx.max() - xx.min() > yy.max() - yy.min( ) else 'lat' if options.along == 'lon': taxis = create_lon(lons) elif options.along == 'lat': taxis = create_lat(lats) else: xy = N.sqrt((xx - xx[0])**2 + (yy - yy[0])**2) if xy.max() - xy.min() > 2500 or options.along == 'km': units = 'km' xy *= 1e-3 else: units = 'm' taxis = cdms2.createAxis(xy) taxis.units = units taxis.long_name = 'Distance' tbathy.setAxis(0, taxis) # Plot c = curve2(tbathy, 'k',
print 'Array dimension :', marr.shape print 'Fill value: ',marr.fill_value # Back to numpy array ... nparr=marr.getValue() # print nparr # ---- A Cdms2 object = MV2 + Axes + Attributes ... print 10*'-'+' CDMS2 '+10*'-' # cdms2.createVariable() # Geographic axis creation # - longitude: changing 'lon' id to 'longitude' ax1 = create_lon(N.arange(10)-7.,id='longitude') # - latitude ax2 = create_lat(N.arange(15)*.5+44.) # ==> 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.)
lo = U.getLongitude() la = U.getLatitude() # Longitudes toute les 1 minute loi = np.arange(lo[0],lo[-1],1./60.) # Latitudes toute les 1 minute lai = np.arange(la[0],la[-1],1./60.) xo = cdms2.createAxis(loi) yo = cdms2.createAxis(lai) LONGITUDE = create_lon(loi, id='longitude', attributes=dict(long_name='Longitude of each location',standard_name='longitude',units='degrees_east',valid_min='-180.',valid_max='180.',axis='X')) LATITUDE = create_lat(lai, id='latitude', attributes=dict(long_name='Latitude of each location',standard_name='latitude',units='degrees_north',valid_min='-90.',valid_max='90.',axis='Y')) z = U.getLevel() DEPTH = create_dep(z,attributes=dict(long_name='sea water depth',standard_name='depth',units='m',valid_min='0.',valid_max='12000.')) #axes = [TIME,DEPTH,LATITUDE,LONGITUDE] axes = [DEPTH,LATITUDE,LONGITUDE] Uis=np.arange(U.getLevel().__len__()*yo.__len__()*xo.__len__()).reshape(U.getLevel().__len__(),yo.__len__(),xo.__len__()) Vis=np.arange(U.getLevel().__len__()*yo.__len__()*xo.__len__()).reshape(U.getLevel().__len__(),yo.__len__(),xo.__len__()) Uis = cdms2.createVariable(Uis, typecode='f',id='UZ', axes=axes, attributes=dict(long_name='3d zonal velocity',standard_name='eastward_sea_water_velocity',units='m.s-1',valid_min='-100.',valid_max='100.')) Vis = cdms2.createVariable(Vis, typecode='f',id='VZ', axes=axes, attributes=dict(long_name='3d meridional velocity',standard_name='northward_sea_water_velocity',units='m.s-1',valid_min='-100.',valid_max='100.'))
# Grid (15x15) nx, ny = 15, 10 import numpy as N from vacumm.misc.axes import create_lon, create_lat lon = create_lon(N.linspace(-5.2, -4.4, nx)) lat = create_lat(N.linspace(48, 48.6, ny)) # Plot params import pylab as P import vacumm.misc.color as C P.figure(figsize=(6, 5)) P.subplots_adjust(top=.92,left=.03,bottom=.03,wspace=.05,hspace=.2) kwplot = dict(colorbar=False,cmap=C.cmap_linear([(.6, .8, 1), C.land]), \ contour=False,show=False,fillcontinents=False,fill='pcolor', drawmeridians=False, drawparallels=False, res='h', key=True, xymasked=False) # Mask using shoreline from vacumm.misc.grid.masking import polygon_mask from vacumm.misc.plot import map2 import MV2 as MV # - mask if central point sur terre (mode = 0 = 'inside') lon2,lat2 = N.meshgrid(lon,lat) mask0 = polygon_mask((lon2, lat2), 'h', mode=0, ocean=False) mask0 = MV.array(mask0, axes=[lat, lon]) mask0.long_name = "'inside'" map2(mask0, subplot=221, **kwplot) # - mask if cell more than 50% of land (mode = 1 = 'intersect') thresholds = .5 mask1 = polygon_mask((lon2, lat2), 'h', mode=1, thresholds=thresholds, ocean=False) mask1 = MV.array(mask1, axes=[lat, lon]) mask1.long_name = "'intersect': threshold=%g" %thresholds