ketch
11/10/2014 - 3:11 PM

A demo of how to plot AMRClaw output using yt (yt-project).

A demo of how to plot AMRClaw output using yt (yt-project).

import yt
from clawpack.pyclaw import Solution
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection


for frame in range(8):
    sol = Solution(frame,path='_hdf_output',file_format='hdf')

    grid_data = []

    for state in sorted(sol.states, key = lambda a: a.patch.level):
        patch = state.patch
        d = {
            'left_edge': patch.lower_global,
            'right_edge': patch.upper_global,
            'level': patch.level,
            'dimensions': patch.num_cells_global,
            'q': state.q[0,...],
            'number_of_particles': 0,
            }
        grid_data.append(d)

    ds = yt.load_amr_grids(grid_data, sol.patch.num_cells_global)

    slc = yt.SlicePlot(ds, 'x', "q")
    slc.set_log('q',False)
    slc.set_cmap('q', 'Reds')
    prj = yt.ProjectionPlot(ds,'x','q')
    prj.set_log('q',False)
    slc.save('slice_frame_'+str(frame).zfill(4)+'.png')
    prj.save('proj_frame_'+str(frame).zfill(4)+'.png')

    ad = ds.all_data()
    surface = ds.h.surface(ad,"q",0.2)
    p3dc = Poly3DCollection(surface.triangles, linewidth=0)#, linewidth=0.1,alpha=0.9)
    colors = yt.apply_colormap((surface["q"]), cmap_name="hot")
    p3dc.set_facecolors(colors[0,:,:]/255.)

    fig = plt.figure(figsize=(12,12))
    ax = fig.gca(projection='3d')
    ax.add_collection(p3dc)

    fig.savefig('iso_frame_'+str(frame).zfill(4)+'.png')