def lvrun(self, db=None, *args, **kwargs): if not db: db = self._db.path return lavavu.Viewer(cache=False, clearstep=True, database=db, timestep=self.step, *args, **kwargs)
def new_viewer(topo_file): import numpy as np import imageio, PIL.Image import stripy, lavavu print("Building spherical mesh ", flush=True) res_lon = 1800 res_lat = 900 mesh = stripy.hybrid_st_meshes.warped_xy_mesh_sphere(res_lon=res_lon, res_lat=res_lat) print("Reading topography data file ", flush=True) topography_data = np.array(imageio.imread(topo_file)) height = np.array( PIL.Image.fromarray(topography_data.view()).resize( (res_lon, res_lat))).astype(float) hrange = height.max() - height.min() height0 = (height - height.min()) / hrange XX = mesh.XX YY = mesh.YY ZZ = mesh.ZZ print("Building 3D viewer ") lv1 = lavavu.Viewer(border=False, resolution=[1066, 666], background="#FFFFFF") lv1["axis"] = False lv1['specular'] = 0.1 shrink_surface = 1.0 + 0.05 * height0.reshape(-1) tris1 = lv1.triangles("surfacemap", wireframe=False, colour="#000000:0.0") tris1.vertices( [XX * shrink_surface, YY * shrink_surface, ZZ * shrink_surface]) tris1.indices(mesh.simplices) tris1.texcoords([mesh.SS, mesh.TT]) from matplotlib import cm from matplotlib.colors import Normalize print("Laying down topography image") terrain_norm = Normalize(vmin=-5000.0, vmax=10000.0) texdata = cm.terrain(terrain_norm(topography_data)) tris1.texture(texdata, flip=False) print("Launching 3D viewer") lv1.window(menu=False) return lv1
def lvrun(self, db=None, *args, **kwargs): if not db: db = self._db.path if 'UW_VIS_PORT' in os.environ: kwargs['port'] = int(os.environ['UW_VIS_PORT']) return lavavu.Viewer(cache=False, clearstep=True, database=db, timestep=self.step, *args, **kwargs)
def second_viewer(): #return global debug lv2 = lavavu.Viewer(verbose=debug) lines2 = lv2.add("lines", colour="blue", link=True, geometry="lines") lines2.vertices([[1, -1, 1], [0, 0, 0], [1, -1, -1]]) lv2.test() lv2.init() lv2.image("lv2") #lv2.interactive() return lv2
def lvrun(self, db=None, *args, **kwargs): #Create and execute a new viewer with passed args if not db: db = self._db.path if 'UW_VIS_PORT' in os.environ: kwargs['port'] = int(os.environ['UW_VIS_PORT']) self.viewer = lavavu.Viewer(cache=False, clearstep=True, database=db, timestep=self.step, *args, **kwargs) return self.viewer
def __init__(self, model=None, bounding_box=None, nsteps=None, vertical_exaggeration=1., **kwargs): """ A wrapper to plot LoopStructural object with lavavu Parameters ---------- **kwargs : lavavu viewer kwargs objects : dictionary of objects that have been plotted """ # copied from pyvista if lavavu is None: logger.error("Lavavu isn't installed: pip install lavavu") return self._id_name = "{}-{}".format(str(hex(id(self))), len(_OPEN_VIEWERS)) _OPEN_VIEWERS[self._id_name] = self # self.lv = lavavu.Viewer(**kwargs) self.lv['orthographic'] = True self.lv.modelscale([1, 1, vertical_exaggeration]) self.objects = {} self.bounding_box = bounding_box self.nsteps = nsteps if model is not None: self.bounding_box = model.bounding_box self.nsteps = model.nsteps logger.debug("Using bounding box from model") if self.bounding_box is None or self.nsteps is None: logger.error("Plot area has not been defined.") self.bounding_box = np.array(self.bounding_box) self.nsteps = np.array(self.nsteps) self._model = model
def __init__(self, model=None, bounding_box=None, nsteps=None, **kwargs): if lavavu is None: logger.error( "Cannot use LavaVuModelViewer: Lavavu isn't installed \n pip install lavavu" ) return self._id_name = "{}-{}".format(str(hex(id(self))), len(_OPEN_VIEWERS)) _OPEN_VIEWERS[self._id_name] = self self.lv = lavavu.Viewer(**kwargs) self.lv["orthographic"] = True self.objects = {} super().__init__(model) self.bounding_box = bounding_box self.nsteps = nsteps if model is not None: self.bounding_box = model.bounding_box self.nsteps = model.nsteps logger.debug("Using bounding box from model") if self.bounding_box is None or self.nsteps is None: logger.warning( "Limited functionality for plot, bounding box is not defined.") self.bounding_box = np.array(self.bounding_box)
def view1Step(tin, flow, sea, scaleZ=40, maxZ=100, maxED=20,maxwED=5,flowlines=False): """Visualise a given time step of Badlands output. Parameters ---------- variable: tin TIN surface variable: flow Flow network variable: sea Sea level position variable: scaleZ Maximum vertical exageration variable: maxZ Maximum elevation (integer) variable: maxED Maximum erosion/deposition (integer) variable: maxwED Maximum wave erosion/deposition (integer) variable: flowlines Boolean to plot flow lines """ lv = lavavu.Viewer(border=False, axis=False, background="grey80") #Plot the triangles tris = lv.triangles("elevation") tris2 = lv.triangles("ero/dep") tris3 = lv.triangles("discharge") tris4 = lv.triangles("wave ero/dep") #Load the vertices verts = numpy.array(tin["coords"]) tris.vertices(verts) tris.indices(tin["cells"], offset=1) tris2.vertices(verts) tris2.indices(tin["cells"], offset=1) tris3.vertices(verts) tris3.indices(tin["cells"], offset=1) tris4.vertices(verts) tris4.indices(tin["cells"], offset=1) # Surface map tris.values(verts[:,2]-sea, 'height') cm = tris.colourmap("world", range=[-maxZ,maxZ]) cb = tris.colourbar() # Erosion depostion map tris2.values(tin['cumdiff'], 'erosion/deposition') cm2 = tris2.colourmap("polar", range=[-maxED,maxED]) cb2 = tris2.colourbar() # Wave erosion/deposition coefficient map tris4.values(tin['cumwave'], 'wave ero/dep') cm4 = tris4.colourmap("polar", range=[-maxwED,maxwED]) cb4 = tris4.colourbar() # Discharge map tris3.values(tin['discharge'], 'discharge') cm3 = tris3.colourmap("abyss", reverse=True, log=True) cb3 = tris3.colourbar() # Flow lines # if flowlines: # flines = lv.lines("flow") # flines.vertices(flow['coords']) # flines.indices(flow['connect'], offset=1) # #flines.values(flow['discharge'], 'discharge') # flines.values(flow['chi'], 'chi') # #flines.values(flow['sedload'], 'sedload') # flines.values(flow['basin'], 'basin') # flines.colourmap() # flines.colourbar() lv.translation(-851.394, 4214.401, -51083.648) lv.rotation(-54.936, -14.238, -2.516) lv.scale('z', 5) lv.control.Panel() lv.control.ObjectList() lv.control.Range(command='scale z', range=(1,scaleZ), step=1., value=2) lv.control.Range(command='background', range=(0,1), step=0.1, value=1) # if flowlines: # flines.control.List(options=['chi', 'basin'], property='colourby', label='Flow colour field') # flines.control.List(options=['spectral', 'cool', 'diverge', 'coolwarm'], property='colourmap', label='Flow colourmap', command="reload") # flines.control.Range('linewidth', range=(0.5,7.5)) lv.control.show() return
def viewTime(folder,steps=100,it=2,scaleZ=40, maxZ=100,maxED=20,maxwED=5,flowlines=False): """Visualise sequence of time steps of Badlands output. Parameters ---------- variable: folder Folder name of Badlands output variable: steps Time steps to load variable: it Output interval variable: scaleZ Maximum vertical exageration variable: maxZ Maximum elevation (integer) variable: maxED Maximum erosion/deposition (integer) variable: maxwED Maximum wave erosion/deposition (integer) variable: flowlines Boolean to plot flow lines """ lv = lavavu.Viewer(border=False, axis=False, background="grey80") for s in range(1,steps,it): values = [] tin,flow,sea = loadStep(folder, s, timev=False) #Add a new time step lv.addstep() #Plot the triangles if s == 1: tris = lv.triangles("elevation") tris2 = lv.triangles("ero/dep") tris3 = lv.triangles("discharge") tris4 = lv.triangles("wave ero/dep") # Load the vertices verts = numpy.array(tin["coords"]) tris.vertices(verts) tris.indices(tin["cells"], offset=1) tris2.vertices(verts) tris2.indices(tin["cells"], offset=1) tris3.vertices(verts) tris3.indices(tin["cells"], offset=1) tris4.vertices(verts) tris4.indices(tin["cells"], offset=1) # Surface map tris.values(verts[:,2]-sea, 'height') if s == 1: cm = tris.colourmap("world", range=[-maxZ,maxZ]) cb = tris.colourbar() # Erosion depostion map tris2.values(tin['cumdiff'], 'erosion/deposition') if s == 1: cm2 = tris2.colourmap("polar", range=[-maxED,maxED]) cb2 = tris2.colourbar() # Discharge map tris3.values(tin['discharge'], 'discharge') if s == 1: cm3 = tris3.colourmap("abyss", reverse=True, log=True) cb3 = tris3.colourbar() # Wave erosion/deposition coefficient map tris4.values(tin['cumwave'], 'wave ero/dep') if s == 1: cm4 = tris4.colourmap("polar", range=[-maxwED,maxwED]) cb4 = tris4.colourbar() # Flow lines # if flowlines: # if s == 1: # flines = lv.lines("flow") # # flines.vertices(flow['coords']) # flines.indices(flow['connect'], offset=1) # # #flines.values(flow['discharge'], 'discharge') # flines.values(flow['chi'], 'chi') # #flines.values(flow['sedload'], 'sedload') # flines.values(flow['basin'], 'basinID') # # if s == 1: # flines.colourmap() # flines.colourbar() lv.control.Panel() lv.control.TimeStepper() lv.control.Range(command='scale z', range=(1,scaleZ), step=1., value=2) lv.control.Range(command='background', range=(0,1), step=0.1, value=1) # if flowlines: # #flines.control.List(options=['discharge', 'chi', 'sedload', 'basin'], property='colourby', label='Flow colour field') # flines.control.List(options=['chi', 'basinID'], property='colourby', label='Flow colour field') # flines.control.List(options=['spectral', 'cool', 'diverge', 'coolwarm'], property='colourmap', label='Flow colourmap', command="reload") # flines.control.Range('linewidth', range=(0.5,7.5)) lv.control.ObjectList() lv.control.show() return
#!/usr/bin/env python import lavavu import numpy as np from itertools import islice import math import sys import os import re import random """ Create some points and save as a LAS file """ lv = lavavu.Viewer() sphere = lv.shapes(vertices=[0, 1.5, 0], colour="red", scaling=100) #A bit of hackyness to extract the sphere vertices lv.open() lv.select(1) lv.bake() d = sphere.data() spherev = d[0].get('vertices') spherev = spherev.reshape((-1, 3)) lv.clear() sphere = lv.points(vertices=spherev, colour="red", pointsize=5) groundv = lavavu.grid3d(corners=[[-10, 0, -10], [10, 0, -10], [10, 0, 10]], dims=(500, 500)) groundv = groundv.reshape((-1, 3))
def second_viewer(): #return global debug lv2 = lavavu.Viewer(verbose=debug) lines2 = lv2.add("lines", colour="blue", link=True, geometry="lines") lines2.vertices([[1, -1, 1], [0, 0, 0], [1, -1, -1]]) lv2.test() lv2.init() lv2.image("lv2") #lv2.interactive() return lv2 lv = lavavu.Viewer(verbose=debug) lv2 = second_viewer() print lv.image("initial") #Points points = lv.points(colour="red", pointsize=10, opacity=0.75, static=True, vertices=[[-1, -1, -1], [-1, 1, -1], [1, 1, -1], [1, -1, -1]]) points.vertices([[-1, -1, 1], [-1, 1, 1], [1, 1, 1], [1, -1, 1]]) points.values([1, 2, 3, 4, 5, 6, 7, 8])