build_gallery.py 3.34 KB
Newer Older
1 2 3 4
import os
import numpy as np
import matplotlib.pyplot as plt

5 6
from math import *

7 8 9
imgtypes = ['.pdf','.png']

def plot_sketch(fname):
10
    fname += '.oesk'
11 12 13 14 15 16 17 18 19 20
    print('Sketch: ' +fname)
    data = np.genfromtxt(fname, dtype=float, delimiter=',')
    plt.plot(data[:,0], data[:,1])
    plt.grid(True)
    plt.axes().set_aspect('equal','datalim')
    for ext in imgtypes:
        plt.savefig(fname+ext)
    plt.clf()

def plot_mesh(fname):
21
    fname += '.oeme'
22 23 24 25 26 27 28 29 30 31 32
    print('Mesh: '+fname)
    data = np.genfromtxt(fname, dtype=float, delimiter=',')
    x = data[:,[0,1,2,0]].transpose()
    y = data[:,[3,4,5,3]].transpose()
    plt.plot(x,y,'b')
    plt.grid(True)
    plt.axes().set_aspect('equal','datalim')
    for ext in imgtypes:
        plt.savefig(fname+ext)
    plt.clf()

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
def plot_scalar(fname):
    fname += '.oesc'
    print('Scalar: '+fname)
    
    tris = np.genfromtxt(fname, dtype=int, delimiter=',',skip_header=0,max_rows=1)
    tris = np.genfromtxt(fname, dtype=int, delimiter=',',skip_header=tris[0],max_rows=tris[1])

    nodes = np.genfromtxt(fname, dtype=int, delimiter=',',skip_header=1,max_rows=1)
    nodes = np.genfromtxt(fname, dtype=float, delimiter=',',skip_header=nodes[0],max_rows=nodes[1])

    vals = np.genfromtxt(fname, dtype=int, delimiter=',',skip_header=2,max_rows=1)
    vals = np.genfromtxt(fname, dtype=float, delimiter=',',skip_header=vals[0],max_rows=vals[1])

    plt.figure()
    plt.set_cmap('viridis')
    plt.gca().set_aspect('equal')
49
    plt.tripcolor(nodes[:,0],nodes[:,1],tris,vals,edgecolors='k',shading='gouraud')
50 51 52 53 54 55 56
    plt.colorbar()
    plt.grid(True)
    plt.axes().set_aspect('equal','datalim')
    for ext in imgtypes:
        plt.savefig(fname+ext)
    plt.clf()

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
def plot_vector(fname):
    fname += '.oeve'
    print('Vector: '+fname)
    
    tris = np.genfromtxt(fname, dtype=int, delimiter=',',skip_header=0,max_rows=1)
    tris = np.genfromtxt(fname, dtype=int, delimiter=',',skip_header=tris[0],max_rows=tris[1])

    nodes = np.genfromtxt(fname, dtype=int, delimiter=',',skip_header=1,max_rows=1)
    nodes = np.genfromtxt(fname, dtype=float, delimiter=',',skip_header=nodes[0],max_rows=nodes[1])

    vals = np.genfromtxt(fname, dtype=int, delimiter=',',skip_header=2,max_rows=1)
    vals = np.genfromtxt(fname, dtype=float, delimiter=',',skip_header=vals[0],max_rows=vals[1])

    mag = vals[:,0].copy()
    for i in range(0,len(vals)):
        mag[i] = hypot(vals[i,0], vals[i,1])
   
    xc = (nodes[tris[:,0],0]+nodes[tris[:,1],0]+nodes[tris[:,2],0])/3.0
    yc = (nodes[tris[:,0],1]+nodes[tris[:,1],1]+nodes[tris[:,2],1])/3.0

    plt.figure()
JasonPries's avatar
JasonPries committed
78
    plt.set_cmap('inferno')
79 80 81
    plt.gca().set_aspect('equal')
    plt.tripcolor(nodes[:,0],nodes[:,1],tris,facecolors = mag,edgecolors='k')
    plt.colorbar()
JasonPries's avatar
JasonPries committed
82
    #plt.quiver(xc,yc,vals[:,0],vals[:,1],mag,pivot='mid',edgecolors='k',linewidths=0.1)
83 84 85 86 87 88 89
    plt.grid(True)
    plt.axes().set_aspect('equal','datalim')
    for ext in imgtypes:
        plt.savefig(fname+ext)
    plt.clf()


90 91 92 93 94
root = os.getcwd()
root += '/build/test/output/'

for path, _, files in os.walk(root):
    for name in files:
95
        name, fext = os.path.splitext(name)
96
        fpath = os.path.join(path, name)
97
        if fext == '.oesk': 
98 99
            plot_sketch(fpath)
        elif fext == '.oeme':
100 101 102
            plot_mesh(fpath)
        elif fext == '.oesc':
            plot_scalar(fpath)
103 104
        elif fext == '.oeve':
	    plot_vector(fpath)