def build(self): print "Processing vars %s from file %s" % (str( self.varnames), self.file_path) plot_args = [] for varname in self.varnames: var = self.file[varname] var = var( lon=(self.roi[0], self.roi[1]), lat=(self.roi[2], self.roi[3]), squeeze=1, ) if self.roi else var(squeeze=1, ) plot_args.append(var) self.canvas = vcs.init() self.canvas.drawlogooff() self.gm = vcs.get3d_scalar(self.template) if ( self.ptype == '3d_scalar') else vcs.get3d_vector(self.template) for pitem in self.parameters.items(): self.gm.setParameter(pitem[0], pitem[1]) plot_args.append(self.gm) plot_kwargs = {'cdmsfile': self.file.id, 'window_size': (900, 600)} self.canvas.setantialiasing(False) self.canvas.plot(*plot_args, **plot_kwargs) self.plot = self.canvas.backend.plotApps[self.gm]
def initialize(self): print "initialize" global renderer, renderWindow, renderWindowInteractor, cone, mapper, actor # Bring used components self.registerVtkWebProtocol(protocols.vtkWebMouseHandler()) self.registerVtkWebProtocol(protocols.vtkWebViewPort()) self.registerVtkWebProtocol(protocols.vtkWebViewPortImageDelivery()) self.registerVtkWebProtocol(protocols.vtkWebViewPortGeometryDelivery()) self.registerVtkWebProtocol(protocols.vtkWebFileBrowser('.', '.')) # Create default pipeline (Only once for all the session) # Update authentication key to use self.updateSecret(_WebCone.authKey) if not _WebCone.view: # # VTK specific code # renderer = vtk.vtkRenderer() # renderWindow = vtk.vtkRenderWindow() # renderWindow.AddRenderer(renderer) # renderWindowInteractor = vtk.vtkRenderWindowInteractor() # renderWindowInteractor.SetRenderWindow(renderWindow) # renderWindowInteractor.GetInteractorStyle().SetCurrentStyleToTrackballCamera() # cone = vtk.vtkConeSource() # mapper = vtk.vtkPolyDataMapper() # actor = vtk.vtkActor() # mapper.SetInputConnection(cone.GetOutputPort()) # actor.SetMapper(mapper) # renderer.AddActor(actor) # renderer.ResetCamera() # renderWindow.Render() # VCS specific code import vcs, cdms2, sys x = vcs.init(bg=1) f = cdms2.open(vcs.sample_data + "/geos5-sample.nc") v = f["uwnd"] dv3d = vcs.get3d_scalar() dv3d.ToggleClipping = (40, 360, -28, 90) dv3d.YSlider = (0.0, vcs.off) dv3d.XSlider = (180.0, vcs.on) dv3d.ZSlider = (0.0, vcs.on) dv3d.ToggleVolumePlot = vcs.on dv3d.ToggleSurfacePlot = vcs.on dv3d.IsosurfaceValue = 31.0 dv3d.ScaleOpacity = [0.0, 1.0] dv3d.BasemapOpacity = 0.5 dv3d.Camera = { 'Position': (-161, -171, 279), 'ViewUp': (.29, 0.67, 0.68), 'FocalPoint': (146.7, 8.5, -28.6) } dv3d.VerticalScaling = 5.0 dv3d.ScaleColormap = [-46.0, 48.0] dv3d.ScaleTransferFunction = [12.0, 77.0] x.plot(v, dv3d) renderWindow = x.backend.renWin # VTK Web application specific _WebCone.view = renderWindow self.getApplication().GetObjectIdMap().SetActiveObject( "VIEW", renderWindow)
def simpleanimation(): import vcs, cdms2, sys x = vcs.init() f = cdms2.open(vcs.sample_data + "/clt.nc") v = f["clt"] dv3d = vcs.get3d_scalar() x.plot(v, dv3d) x.interact()
def simpleanimation(): import vcs, cdms2, sys x = vcs.init() f = cdms2.open(vcs.prefix+"/sample_data/clt.nc") v = f["clt"] dv3d = vcs.get3d_scalar() x.plot( v, dv3d ) x.interact()
def initialize(self): print "initialize" global renderer, renderWindow, renderWindowInteractor, cone, mapper, actor # Bring used components self.registerVtkWebProtocol(protocols.vtkWebMouseHandler()) self.registerVtkWebProtocol(protocols.vtkWebViewPort()) self.registerVtkWebProtocol(protocols.vtkWebViewPortImageDelivery()) self.registerVtkWebProtocol(protocols.vtkWebViewPortGeometryDelivery()) self.registerVtkWebProtocol(protocols.vtkWebFileBrowser('.', '.')) # Create default pipeline (Only once for all the session) # Update authentication key to use self.updateSecret(_WebCone.authKey) if not _WebCone.view: # # VTK specific code # renderer = vtk.vtkRenderer() # renderWindow = vtk.vtkRenderWindow() # renderWindow.AddRenderer(renderer) # renderWindowInteractor = vtk.vtkRenderWindowInteractor() # renderWindowInteractor.SetRenderWindow(renderWindow) # renderWindowInteractor.GetInteractorStyle().SetCurrentStyleToTrackballCamera() # cone = vtk.vtkConeSource() # mapper = vtk.vtkPolyDataMapper() # actor = vtk.vtkActor() # mapper.SetInputConnection(cone.GetOutputPort()) # actor.SetMapper(mapper) # renderer.AddActor(actor) # renderer.ResetCamera() # renderWindow.Render() # VCS specific code import vcs, cdms2, sys x = vcs.init(bg=1) f = cdms2.open( vcs.sample_data+"/geos5-sample.nc" ) v = f["uwnd"] dv3d = vcs.get3d_scalar() dv3d.ToggleClipping = ( 40, 360, -28, 90 ) dv3d.YSlider = ( 0.0, vcs.off) dv3d.XSlider = ( 180.0, vcs.on ) dv3d.ZSlider = ( 0.0, vcs.on ) dv3d.ToggleVolumePlot = vcs.on dv3d.ToggleSurfacePlot = vcs.on dv3d.IsosurfaceValue = 31.0 dv3d.ScaleOpacity = [0.0, 1.0] dv3d.BasemapOpacity = 0.5 dv3d.Camera={ 'Position': (-161, -171, 279), 'ViewUp': (.29, 0.67, 0.68), 'FocalPoint': (146.7, 8.5, -28.6) } dv3d.VerticalScaling = 5.0 dv3d.ScaleColormap = [ -46.0, 48.0 ] dv3d.ScaleTransferFunction = [ 12.0, 77.0 ] x.plot( v, dv3d ) renderWindow = x.backend.renWin # VTK Web application specific _WebCone.view = renderWindow self.getApplication().GetObjectIdMap().SetActiveObject("VIEW", renderWindow)
def run_scalar_ctest( filename, varname, parms, template = "default" ): import vcs, cdms2 x = vcs.init() f = cdms2.open(vcs.sample_data+"/"+filename ) v = f[varname] dv3d = vcs.get3d_scalar( template ) for item in parms.items(): dv3d.setParameter( item[0], item[1] ) x.plot( v, dv3d ) x.interact()
def run_scalar_ctest(filename, varname, parms, template="default"): import vcs, cdms2 x = vcs.init() f = cdms2.open(vcs.sample_data + "/" + filename) v = f[varname] dv3d = vcs.get3d_scalar(template) for item in parms.items(): dv3d.setParameter(item[0], item[1]) x.plot(v, dv3d) x.interact()
def build(self): print "Processing vars %s from file %s" % ( str(self.varnames), self.file_path ) plot_args = [] for varname in self.varnames: var = self.file[varname] var = var( lon=( self.roi[0], self.roi[1] ), lat=( self.roi[2], self.roi[3] ), squeeze=1, ) if self.roi else var( squeeze=1, ) plot_args.append( var ) self.canvas = vcs.init() self.gm = vcs.get3d_scalar( self.template ) if ( self.ptype == 'scalar' ) else vcs.get3d_vector( self.template ) for pitem in self.parameters.items(): self.gm.setParameter( pitem[0], pitem[1] ) plot_args.append( self.gm ) plot_kwargs = { 'cdmsfile': self.file.id, 'window_size': (900,600) } self.canvas.plot( *plot_args, **plot_kwargs ) self.plot = self.canvas.backend.plotApps[ self.gm ]
def simplevolume(): import vcs, cdms2, sys x = vcs.init() f = cdms2.open(vcs.prefix+"/sample_data/geos5-sample.nc") u = f["uwnd"] dv3d = vcs.get3d_scalar() dv3d.VerticalScaling = 3.0 dv3d.ScaleOpacity = [0.0, 0.8] dv3d.ScaleColormap = [-46.0, 45, 1] dv3d.ScaleTransferFunction = [8.6, 76.7, 1] dv3d.BasemapOpacity = [0.5] dv3d.XSlider = vcs.off dv3d.ZSlider = vcs.off dv3d.YSlider = vcs.off dv3d.ToggleVolumePlot = vcs.on dv3d.ToggleSurfacePlot = vcs.off dv3d.Camera={'Position': (-161, -171, 279), 'ViewUp': (.29, 0.67, 0.68), 'FocalPoint': (146.7, 8.5, -28.6)} x.plot( u, dv3d ) x.interact()
def simplevolume(): import vcs, cdms2, sys x = vcs.init() f = cdms2.open(vcs.sample_data + "/geos5-sample.nc") u = f["uwnd"] dv3d = vcs.get3d_scalar() dv3d.VerticalScaling = 3.0 dv3d.ScaleOpacity = [0.0, 0.8] dv3d.ScaleColormap = [-46.0, 45, 1] dv3d.ScaleTransferFunction = [8.6, 76.7, 1] dv3d.BasemapOpacity = [0.5] dv3d.XSlider = vcs.off dv3d.ZSlider = vcs.off dv3d.YSlider = vcs.off dv3d.ToggleVolumePlot = vcs.on dv3d.ToggleSurfacePlot = vcs.off dv3d.Camera = { 'Position': (-161, -171, 279), 'ViewUp': (.29, 0.67, 0.68), 'FocalPoint': (146.7, 8.5, -28.6) } x.plot(u, dv3d) x.interact()
import vcs, cdms2, sys x = vcs.init() f = cdms2.open(sys.prefix+"/sample_data/clt.nc") v = f["clt"] dv3d = vcs.get3d_scalar('xyt') x.plot( v, dv3d ) x.interact()
import vcs, cdms2, sys x = vcs.init() f = cdms2.open(vcs.prefix + "/sample_data/clt.nc") v = f["clt"] dv3d = vcs.get3d_scalar('Hovmoller3D') dv3d.ToggleSurfacePlot = vcs.on dv3d.ToggleVolumePlot = vcs.on dv3d.IsosurfaceValue = [10.0] dv3d.ToggleClipping = [-180.0, 175.0, -22.0, 90.0, 0.0, 119.0] dv3d.ScaleTransferFunction = [80, 100, 1] dv3d.ScaleOpacity = {'Volume': [0.0, 0.2]} dv3d.ZSlider = (0.0, vcs.on) dv3d.YSlider = (20.0, vcs.on) dv3d.Camera = { 'Position': (436.8, -126.3, 285.2), 'ViewUp': (-0.5, 0.25, 0.83), 'FocalPoint': (9.6, 19.9, -3.2) } x.plot(v, dv3d) x.interact()
print ' ---------- DV3D (Gfdv3d) member (attribute) listings ---------' print 'name =', self.name print 'axes =', self.axes for pname in self.parameter_names: pval = self.getParameter(pname) print pname, '=', repr(pval) class Gf3Dvector(Gfdv3d): def __init__(self, Gfdv3d_name, Gfdv3d_name_src='default'): self.g_name = '3d_vector' Gfdv3d.__init__(self, Gfdv3d_name, Gfdv3d_name_src='default') class Gf3Dscalar(Gfdv3d): def __init__(self, Gfdv3d_name, Gfdv3d_name_src='default'): self.g_name = '3d_scalar' Gfdv3d.__init__(self, Gfdv3d_name, Gfdv3d_name_src='default') self.VectorDisplay = Gfdv3d_name class Gf3DDualScalar(Gfdv3d): def __init__(self, Gfdv3d_name, Gfdv3d_name_src='default'): self.g_name = '3d_dual_scalar' Gfdv3d.__init__(self, Gfdv3d_name, Gfdv3d_name_src='default') if __name__ == '__main__': dv3d = vcs.get3d_scalar() dv3d.script('/tmp/test.json')
f = cdms2.open( datasetPath ) varname = "U" else: dataDir1 = "/Users/tpmaxwell/data/AConaty/comp-ECMWF" datasetPath = os.path.join( dataDir1, "geos5.xml") f = cdms2.open( datasetPath ) varname = "uwnd" # print "Reading variable %s in dataset %s " % ( varname, datasetPath ) # f = cdms2.open( os.path.join( sys.prefix, "sample_data", "geos5-sample.nc") ) # u = f["uwnd"] # dv3d = vcs.create3d_scalar('hoffmuller','xyt') u = f[varname] if not u is None: # dv3d = vcs.get3d_scalar('xyt') dv3d = vcs.get3d_scalar() x = vcs.init() x.plot( u, dv3d, blocking=True ) x.interact() else: print>>sys.stderr, "\n\n Can't find variable %s in dataset %s" % ( varname, datasetPath )
@author: tpmaxwel ''' import cdms2, cdutil, genutil import vcs, os image_check = False if __name__ == '__main__': import sys f = cdms2.open( os.path.join( sys.prefix, "sample_data", "geos5-sample.nc") ) U = f["uwnd"] U = U(lon=(-105.0, -15.0),lev=(1000.0, 0.10000000100000001),lat=(7.0, 50.0),squeeze=1,) canvas = vcs.init() gm3D_Scalar = vcs.get3d_scalar('default') args = [] args.append(U) gm3D_Scalar.VerticalScaling = 1.0 gm3D_Scalar.IsosurfaceValue = 24.463887522462002 gm3D_Scalar.ToggleVolumePlot = vcs.on gm3D_Scalar.ScaleColormap = [-15.383988656109274, 10.447561660497996, 1] gm3D_Scalar.ScaleTransferFunction = [6.016036405845739, 12.382244144298838, 1] gm3D_Scalar.XSlider = -105.0 gm3D_Scalar.ScaleOpacity = [0.0, 0.42135967065922453] gm3D_Scalar.Animation = 0.0 gm3D_Scalar.ZSlider = 0.0, vcs.on gm3D_Scalar.YSlider = 7.0, vcs.on kwargs = { 'cdmsfile': f.id } args.append( gm3D_Scalar ) canvas.plot( *args, **kwargs )
def scalar_3d(name): try: obj = vcs.get3d_scalar(str(name)) except: abort(404) return jsonify(vcs.utils.dumpToDict(obj)[0])
import vcs, cdms2, sys x = vcs.init() f = cdms2.open(vcs.prefix+"/sample_data/clt.nc") v = f["clt"] dv3d = vcs.get3d_scalar('Hovmoller3D') dv3d.ToggleSurfacePlot = vcs.on dv3d.ToggleVolumePlot = vcs.on dv3d.IsosurfaceValue = [ 10.0 ] dv3d.ToggleClipping = [-180.0, 175.0, -22.0, 90.0, 0.0, 119.0 ] dv3d.ScaleTransferFunction = [80, 100, 1] dv3d.ScaleOpacity={ 'Volume': [0.0, 0.2] } dv3d.ZSlider = ( 0.0, vcs.on ) dv3d.YSlider = ( 20.0, vcs.on ) dv3d.Camera={'Position': (436.8, -126.3, 285.2), 'ViewUp': (-0.5, 0.25, 0.83), 'FocalPoint': (9.6, 19.9, -3.2)} x.plot( v, dv3d ) x.interact()
U_velocity = cdmsfile('U_velocity') U_velocity = U_velocity(isobaric=(1000.0, 10.0),lon=(0.0, 359.0),time=('2011-5-20 0:0:0.0', '2011-5-20 0:0:0.0'),lat=(90.0, -90.0),squeeze=1,) axesOperations = eval("{'lat': 'def', 'isobaric': 'def', 'lon': 'def', 'time': 'def'}") for axis in list(axesOperations): if axesOperations[axis] == 'sum': U_velocity = cdutil.averager(U_velocity, axis='(%s)'%axis, weight='equal', action='sum') elif axesOperations[axis] == 'avg': U_velocity = cdutil.averager(U_velocity, axis='(%s)'%axis, weight='equal') elif axesOperations[axis] == 'wgt': U_velocity = cdutil.averager(U_velocity, axis='(%s)'%axis) elif axesOperations[axis] == 'gtm': U_velocity = genutil.statistics.geometricmean(U_velocity, axis='(%s)'%axis) elif axesOperations[axis] == 'std': U_velocity = genutil.statistics.std(U_velocity, axis='(%s)'%axis) canvas = vcs.init() gm3D_Scalar = vcs.get3d_scalar('default') args = [] args.append(U_velocity) gm3D_Scalar.axes = [['xyz']] gm3D_Scalar.Colorbar = [[1]] gm3D_Scalar.VerticalScaling = [5.0686491905313265] gm3D_Scalar.IsosurfaceValue = [16.432937622070312] gm3D_Scalar.ToggleVolumePlot = [[1]], vcs.on gm3D_Scalar.ScaleColormap = [-14.551153825899483, 17.267348412394284, 1] gm3D_Scalar.ScaleTransferFunction = [20.770853227597186, 81.085205, 1], vcs.on gm3D_Scalar.XSlider = [119.87534943731247], vcs.on gm3D_Scalar.ScaleOpacity = [1.0, 1.0] gm3D_Scalar.Animation = [0.0] gm3D_Scalar.ZSlider = [0.6777807722949307], vcs.on gm3D_Scalar.YSlider = [21.796957974561707], vcs.on gm3D_Scalar.BasemapOpacity = [0.5]
import vcs import numpy import cdms2 import MV2 # prepare some data f = cdms2.open(vcs.sample_data + "/geos5-sample.nc") clt = f("tmpu") f = cdms2.open(vcs.sample_data + "/clt.nc") clt = f("clt") canvas = vcs.init() dv3d = vcs.get3d_scalar("Hovmoller3D") #dv3d.ToggleClipping = ( 40, 360, -28, 90 ) dv3d.ToggleVolumePlot = vcs.on dv3d.VerticalScaling = 3.0 #dv3d.ToggleSurfacePlot = vcs.on #dv3d.IsosurfaceValue = 31.0 #dv3d.ScaleOpacity = [0.0, 1.0] #dv3d.BasemapOpacity = 0.5 dv3d.Camera = { 'Position': (-421, -991, 879), 'ViewUp': (.29, 0.77, 0.68), 'FocalPoint': (146.7, 8.5, -18.6) } #dv3d.ScaleColormap = [ -46.0, 48.0 ] #dv3d.ScaleTransferFunction = [ 12.0, 77.0 ] canvas.plot(clt, dv3d)