From 7f64589f9f172b7965a086bcceed8c47a51daca7 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Mon, 15 Jul 2019 09:14:08 +0000
Subject: [PATCH] Add missing file

---
 trisurf/notebook.py |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/trisurf/notebook.py b/trisurf/notebook.py
new file mode 100644
index 0000000..e5f070e
--- /dev/null
+++ b/trisurf/notebook.py
@@ -0,0 +1,56 @@
+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("<trisurfversion>")]+contents[contents.find("<UnstructuredGrid>"):]
+    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

--
Gitblit v1.9.3