from trisurf.trisurf import Directory, Tape from trisurf import trisurf as ts #from hashlib import md5 import os import django import sys os.chdir('/home/samo/trisurf-server') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "web_trisurf.settings") django.setup() from database import models import numpy as np import ipyvolume as ipv import meshio import matplotlib.pyplot as plt import uuid def read_mesh(filename): tmpfilename='/tmp/{}.vtu'.format(str(uuid.uuid4())) with open (filename) as f: contents=f.read() valid_vtu=contents[0:contents.find("")]+contents[contents.find(""):] with open (tmpfilename, 'w') as f: f.write(valid_vtu) mesh=meshio.read(tmpfilename) os.unlink(tmpfilename) return mesh def display_vesicle(run, iteration=None, colormap='bwr', point_data='vertices_idx'): cmap=plt.get_cmap(colormap) if iteration is not None: filename=os.path.join(run.Dir.fullpath(),'timestep_{:06d}.vtu'.format(int(iteration))) else: filename=os.path.join(run.Dir.fullpath(),run.getLastVTU()) mesh=read_mesh(filename) fig=ipv.figure() color_data=mesh.point_data[point_data]/mesh.point_data[point_data].max() points=mesh.points.transpose() trimesh=ipv.plot_trisurf(*points, triangles=mesh.cells['triangle'], color=[c[0:3] for c in cmap(color_data)]) ipv.xlim(points[0,:].min(),points[0,:].max()) ipv.ylim(points[1,:].min(),points[1,:].max()) ipv.zlim(points[2,:].min(),points[2,:].max()) ipv.squarelim() #ipv.style.use('nobox') #ipv.pylab.style.use('nobox') return fig #ipv.show() def database2runs(objs): runs=[] for obj in objs: r=ts.Runner(tape='/home/samo/trisurf-tapes/{}/tape'.format(obj.id)) r.maindir=obj.simulation.directory r.subdir=obj.subdir runs.append(r) return runs