def load_data(): # Download and read the data from the Johns Hopkins University repo: # Credits and terms of use: https://github.com/CSSEGISandData/COVID-19 #0 1 2 3 4 5 6 #FIPS,Admin2,Province_State,Country_Region,Last_Update,Lat,Long_, #7 8 9 10 11 #Confirmed,Deaths,Recovered,Active,Combined_Key from vtkplotter import download url = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master' fpath = download(url + '/csse_covid_19_data/csse_covid_19_daily_reports/' + date + '.csv') with open(fpath, "r") as f: lines = f.readlines() data, allconf, allreco, alldeat, conf_us, reco_us, deat_us = [], 0, 0, 0, 0, 0, 0 for i, ln in enumerate(lines): if i < 1: continue ln = ln.replace("Korea,", "Korea").split(",") try: if not ln[5]: continue theta, phi = -float(ln[5]) / 57.3 + np.pi / 2, float( ln[6]) / 57.3 + np.pi confirmed, deaths, recos = int(ln[7]), int(ln[8]), int(ln[9]) Admin, Province, Country = ln[1:4] if Country == 'US': # group US data conf_us += confirmed deat_us += deaths reco_us += recos continue else: place = '' if Admin: place += Admin + '\n' if Province: place += Province + '\n' if Country: place += Country + '\n' allconf += confirmed alldeat += deaths allreco += recos if not confirmed: continue except: print('Line', i, ln[:4], "... skipped.") continue data.append([place, theta, phi, confirmed, deaths, recos]) data.append(['US\n', 0.9, 1.4, conf_us, deat_us, reco_us]) return data, allconf, alldeat, allreco
import trimesh import numpy as np from vtkplotter import show, Plane, printc, download # load the mesh from filename, file objects are also supported f = download( 'https://github.com/mikedh/trimesh/raw/master/models/featuretype.STL') mesh = trimesh.load_mesh(f) # get a single cross section of the mesh txt = 'cross section of the mesh' mslice = mesh.section(plane_origin=mesh.centroid, plane_normal=[0, 0, 1]) pl = Plane(mesh.centroid, normal=[0, 0, 1], sx=6, sy=4, alpha=0.3) slice_2D, to_3D = mslice.to_planar() # show objects on N=2 non-synced renderers: show([(mesh, pl), (slice_2D, txt)], N=2, sharecam=False, axes=True) # if we wanted to take a bunch of parallel slices, like for a 3D printer # we can do that easily with the section_multiplane method # we're going to slice the mesh into evenly spaced chunks along z # this takes the (2,3) bounding box and slices it into [minz, maxz] z_extents = mesh.bounds[:, 2] # slice every .125 model units (eg, inches) z_levels = np.arange(*z_extents, step=0.125) # find a bunch of parallel cross sections sections = mesh.section_multiplane(plane_origin=mesh.bounds[0], plane_normal=[0, 0, 1],
""" trimesh to vtkplotter interoperability """ # Install trimesh with: # sudo apt install python3-rtree # pip install rtree shapely # conda install trimesh import trimesh import vtkplotter from vtkplotter import trimesh2vtk, vtk2trimesh url = 'https://raw.githubusercontent.com/mikedh/trimesh/master/models/' filename = vtkplotter.download(url + 'machinist.XAML') mesh = trimesh.load(filename) vmesh = trimesh2vtk(mesh) # returns a Mesh(vtkActor) object from Trimesh vtkplotter.show(mesh) # vtkplotter visualizer (conversion is on the fly) trimsh_reconverted = vtk2trimesh(vmesh) trimsh_reconverted.show() # this is the trimesh built-in visualizer
""" trimesh to vtkplotter interoperability """ # Install trimesh with: # sudo apt install python3-rtree # pip install rtree shapely # conda install trimesh import trimesh from vtkplotter import download, trimesh2vtk, show url = 'https://raw.githubusercontent.com/mikedh/trimesh/master/models/' filename = download(url + 'machinist.XAML') mesh = trimesh.load(filename) actor = trimesh2vtk(mesh) # returns a Actor(vtkActor) object from Trimesh # Any of these will work: show(mesh) # conversion is on the fly (don't need 'actor') # or #actor.show() # or #show(actor) # or mesh.show() # this is the trimesh built-in visualizer
# Download a large file from a URL link and unzip it # from vtkplotter import download, gunzip, show fgz = download('https://vtkplotter.embl.es/examples/truck.vtk.gz') # 200MB filename = gunzip(fgz) print('gunzip-ped to temporary file:', filename) show(filename)
# ---------------------------------------------------------------------- # pick today date date = "04-18-2020" if len(sys.argv) > 1: date = sys.argv[1] else: import datetime from vtkplotter import download for i in range(3): try: yesterday = datetime.datetime.now() - datetime.timedelta(days=i) date = yesterday.strftime("%m-%d-%Y") url = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master' fpath = download( url + '/csse_covid_19_data/csse_covid_19_daily_reports/' + date + '.csv') break except: continue def load_data(): # Download and read the data from the Johns Hopkins University repo: # Credits and terms of use: https://github.com/CSSEGISandData/COVID-19 #0 1 2 3 4 5 6 #FIPS,Admin2,Province_State,Country_Region,Last_Update,Lat,Long_, #7 8 9 10 11 #Confirmed,Deaths,Recovered,Active,Combined_Key with open(fpath, "r") as f: lines = f.readlines()