Skip to content

Instantly share code, notes, and snippets.

@ketch
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ketch/30d8bdf41422dc20bb95 to your computer and use it in GitHub Desktop.
Save ketch/30d8bdf41422dc20bb95 to your computer and use it in GitHub Desktop.
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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment