def main(filename, start, count, output, write_start): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['ux','uz'] scale = 2.5 dpi = 300 title_func = lambda sim_time: r'$t = {:.3f}$'.format(sim_time) # savename_func = lambda write: 'yubo_{:06}.png'.format(write+write_start) def savename_func(write): # regex parse out filename number, 10 writes per file num_per_file = 10 write_num = (write - 1) % num_per_file filenum = int(re.match('.*s([\d]+)\.h5', filename)[1]) suffix_num = (filenum - 1) * num_per_file + write_num if suffix_num > 201: suffix_num -= 9 # hard coded, one of the restores is misnumbered print(suffix_num) return 'yubo_{:06}.png'.format(suffix_num) # Layout nrows, ncols = 1, 2 image = plot_tools.Box(1, 2) pad = plot_tools.Frame(0.2, 0.2, 0.1, 0.1) margin = plot_tools.Frame(0.3, 0.2, 0.1, 0.1) # Create multifigure mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale) fig = mfig.figure # Plot writes with h5py.File(filename, mode='r') as file: for index in range(start, start+count): for n, task in enumerate(tasks): # Build subfigure axes i, j = divmod(n, ncols) axes = mfig.add_axes(i, j, [0, 0, 1, 1]) # Call 3D plotting helper, slicing in time dset = file['tasks'][task] if n==0: #ux clim = [-0.25, 0.25] title = r'$u_x$' elif n==1: #uz clim = [-0.1, 0.1] title = r'$\Upsilon$' plot_tools.plot_bot_3d(dset, 0, index, axes=axes, title=title, even_scale=True,clim=clim) # Add time title title = title_func(file['scales/sim_time'][index]) title_height = 1 - 0.5 * mfig.margin.top / mfig.fig.y fig.suptitle(title, y=title_height) # Save figure savename = savename_func(file['scales/write_number'][index]) savepath = output.joinpath(savename) fig.savefig(str(savepath), dpi=dpi) fig.clear() plt.close(fig)
def midplane(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings #tasks = ['phi','w','n','phi2','w2','n2'] tasks = ['phi', 'w', 'n', 'phi ZF', 'w ZF', 'n ZF'] scale = 2.5 dpi = 100 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: 'mid_{:06}.png'.format(write) # Layout nrows, ncols = 2, 3 image = plot_tools.Box(1, 1) pad = plot_tools.Frame(0.2, 0.2, 0.1, 0.1) margin = plot_tools.Frame(0.3, 0.2, 0.1, 0.1) # Create multifigure mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale) fig = mfig.figure # Plot writes with h5py.File(filename, mode='r') as file: for index in range(start, start + count): for n, task in enumerate(tasks): # Build subfigure axes i, j = divmod(n, ncols) axes = mfig.add_axes(i, j, [0, 0, 1, 1]) # Call plotting helper (dset axes: [t, x, y, z]) dset = file['tasks'][task] logger.info('dset %s length %s' % (dset, len(dset.shape))) #if (n > 1): #dset = np.log10(np.absolute(dset)) #dset = file.create_dataset('log_%d' %n, data=dset) # image_axes = (2, 1) # data_slices = (index, slice(None), slice(None), 0) plot_tools.plot_bot_3d(dset, 0, index, axes=axes, title=task, even_scale=True) # Add time title title = title_func(file['scales/sim_time'][index]) title_height = 1 - 0.5 * mfig.margin.top / mfig.fig.y fig.suptitle(title, x=0.48, y=title_height, ha='left') # Save figure savename = savename_func(file['scales/write_number'][index]) savepath = output.joinpath(savename) fig.savefig(str(savepath), dpi=dpi) fig.clear() plt.close(fig)
def main(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['uphi', 'ur', 'vorticity', 'b'] scale = 2.5 dpi = 200 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: 'write_{:06}.png'.format(write) # Layout nrows, ncols = 2, 2 image = plot_tools.Box(1, 1) pad = plot_tools.Frame(0.2, 0.2, 0.1, 0.1) margin = plot_tools.Frame(0.3, 0.2, 0.1, 0.1) # Function def func(phimesh, rmesh, data): xmesh = rmesh * np.cos(phimesh) ymesh = rmesh * np.sin(phimesh) return xmesh, ymesh, data # Create multifigure mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale) fig = mfig.figure # Plot writes with h5py.File(filename, mode='r') as file: for index in range(start, start + count): for n, task in enumerate(tasks): # Build subfigure axes i, j = divmod(n, ncols) axes = mfig.add_axes(i, j, [0, 0, 1, 1]) # Call 3D plotting helper, slicing in time dset = file['tasks'][task] plot_tools.plot_bot_3d(dset, 0, index, axes=axes, title=task, even_scale=True, func=func) # Add time title title = title_func(file['scales/sim_time'][index]) title_height = 1 - 0.5 * mfig.margin.top / mfig.fig.y fig.suptitle(title, x=0.48, y=title_height, ha='left') # Save figure savename = savename_func(file['scales/write_number'][index]) savepath = output.joinpath(savename) fig.savefig(str(savepath), dpi=dpi) fig.clear() plt.close(fig)
def main(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['p', 'b', 'u', 'w'] scale = 2 dpi = 80 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: 'write_{:06}.png'.format(write) # Layout nrows, ncols = 1, 4 image = plot_tools.Box(1, 2) pad = plot_tools.Frame(0.2, 0.2, 0.1, 0.1) margin = plot_tools.Frame(0.3, 0.2, 0.1, 0.1) logmag = lambda xmesh, ymesh, data: (xmesh, ymesh, np.log10(np.abs(data))) clim = [-20, 0] # Create multifigure mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale) fig = mfig.figure # Plot writes with h5py.File(filename, mode='r') as file: for index in range(start, start + count): for n, task in enumerate(tasks): # Build subfigure axes i, j = divmod(n, ncols) axes = mfig.add_axes(i, j, [0, 0, 1, 1]) # Call 3D plotting helper, slicing in time dset = file['tasks'][task] plot_tools.plot_bot_3d(dset, 0, index, axes=axes, title=task, func=logmag, clim=clim) # Add time title title = title_func(file['scales/sim_time'][index]) title_height = 1 - 0.5 * mfig.margin.top / mfig.fig.y fig.suptitle(title, x=0.48, y=title_height, ha='left') # Save figure savename = savename_func(file['scales/write_number'][index]) savepath = output.joinpath(savename) fig.savefig(str(savepath), dpi=dpi) fig.clear() plt.close(fig)
def main(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['b', 'u', 'w'] scale = 2.5 dpi = 100 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: 'write_{:06}.png'.format(write) # Layout nrows, ncols = 3, 1 image = plot_tools.Box(4, 1) pad = plot_tools.Frame(0.2, 0.2, 0.1, 0.1) margin = plot_tools.Frame(0.3, 0.2, 0.1, 0.1) # Create multifigure mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale) fig = mfig.figure # Plot writes with h5py.File(filename, mode='r') as file: for index in range(start, start+count): for n, task in enumerate(tasks): # Build subfigure axes i, j = divmod(n, ncols) axes = mfig.add_axes(i, j, [0, 0, 1, 1]) # Call 3D plotting helper, slicing in time dset = file['tasks'][task] # if (task == 'b'): # print('task: ' + str(task)) # print(str(dset.shape)) # plt.plot(dset[0][0]) # plt.plot(dset[0][1]) # plt.plot(dset[0][2]) # plt.plot(dset[0][3]) # plt.show() plot_tools.plot_bot_3d(dset, 0, index, axes=axes, title=task, even_scale=True) # Add time title title = title_func(file['scales/sim_time'][index]) title_height = 1 - 0.5 * mfig.margin.top / mfig.fig.y fig.suptitle(title, x=0.48, y=title_height, ha='left') # Save figure savename = savename_func(file['scales/write_number'][index]) savepath = output.joinpath(savename) fig.savefig(str(savepath), dpi=dpi) fig.clear() plt.close(fig)
def midplane(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings #tasks = ['phi','w','n','phi2','w2','n2'] tasks = ['phi','w','n','phi ZF','w ZF','n ZF'] scale = 2.5 dpi = 100 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: 'mid_{:06}.png'.format(write) # Layout nrows, ncols = 2, 3 image = plot_tools.Box(1, 1) pad = plot_tools.Frame(0.2, 0.2, 0.1, 0.1) margin = plot_tools.Frame(0.3, 0.2, 0.1, 0.1) # Create multifigure mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale) fig = mfig.figure # Plot writes with h5py.File(filename, mode='r') as file: for index in range(start, start+count): for n, task in enumerate(tasks): # Build subfigure axes i, j = divmod(n, ncols) axes = mfig.add_axes(i, j, [0, 0, 1, 1]) # Call plotting helper (dset axes: [t, x, y, z]) dset = file['tasks'][task] logger.info('dset %s length %s' %(dset,len(dset.shape))) #if (n > 1): #dset = np.log10(np.absolute(dset)) #dset = file.create_dataset('log_%d' %n, data=dset) # image_axes = (2, 1) # data_slices = (index, slice(None), slice(None), 0) plot_tools.plot_bot_3d(dset,0, index, axes=axes, title=task, even_scale=True) # Add time title title = title_func(file['scales/sim_time'][index]) title_height = 1 - 0.5 * mfig.margin.top / mfig.fig.y fig.suptitle(title, x=0.48, y=title_height, ha='left') # Save figure savename = savename_func(file['scales/write_number'][index]) savepath = output.joinpath(savename) fig.savefig(str(savepath), dpi=dpi) fig.clear() plt.close(fig)
def main(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['vorticity'] cmap = plt.cm.RdBu_r savename_func = lambda write: 'write_{:06}.png'.format(write) title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) dpi = 200 func = lambda phi, r, data: (r * np.cos(phi), r * np.sin(phi), data) # Layout nrows, ncols = 1, 1 image = plot_tools.Box(1, 1) pad = plot_tools.Frame(0, 0, 0, 0) margin = plot_tools.Frame(0.1, 0.1, 0.1, 0.1) scale = 3 # Create figure mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale) fig = mfig.figure # Plotting loop with h5py.File(filename, mode='r') as file: for index in range(start, start + count): for n, task in enumerate(tasks): # Build subfigure axes i, j = divmod(n, ncols) axes = mfig.add_axes(i, j, [0, 0, 1, 1]) # Call 3D plotting helper, slicing in time dset = file['tasks'][task] paxes, caxes = plot_tools.plot_bot_3d(dset, 0, index, axes=axes, title=task, even_scale=True, visible_axes=False, func=func, cmap=cmap) paxes.axis('off') caxes.cla() caxes.axis('off') # Add time title title = title_func(file['scales/sim_time'][index]) title_height = 1 - 0.5 * mfig.margin.top / mfig.fig.y fig.suptitle(title, x=0.4, y=title_height, ha='left') # Save figure savename = savename_func(file['scales/write_number'][index]) savepath = output.joinpath(savename) fig.savefig(str(savepath), dpi=dpi) fig.clear() plt.close(fig)
def main(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings #tasks = ['invRi'] tasks = ['v'] scale = 2.5 dpi = 100 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: 'write_{:06}.png'.format(write) # Layout nrows, ncols = 1, 1 image = plot_tools.Box(2,1) pad = plot_tools.Frame(0.2, 0.2, 0.1, 0.1) margin = plot_tools.Frame(0.3, 0.2, 0.1, 0.1) # Create multifigure mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale) fig = mfig.figure # Plot writes with h5py.File(filename, mode='r') as file: for index in range(start, start+count): for n, task in enumerate(tasks): # Build subfigure axes i, j = divmod(n, ncols) axes = mfig.add_axes(i, j, [0, 0, 1, 1]) # Call 3D plotting helper, slicing in time dset = file['tasks'][task] # plot_tools.plot_bot_3d(dset, 0, index, axes=axes, clim=(0,0.01),title='Inverse Richardson', even_scale=True) plot_tools.plot_bot_3d(dset, 0, index, axes=axes, clim=(-0.2,0.2),title='Meridional Velocity (kmhr^(-1))', even_scale=True) # Add time title title = title_func(file['scales/sim_time'][index]) title_height = 1 - 0.5 * mfig.margin.top / mfig.fig.y fig.suptitle(title, x=0.48, y=title_height, ha='left') # Save figure savename = savename_func(file['scales/write_number'][index]) savepath = output.joinpath(savename) fig.savefig(str(savepath), dpi=dpi) fig.clear() plt.close(fig)
def main(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['b', 'p', 'u', 'w'] scale = 2.5 dpi = 100 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: 'write_{:06}.png'.format(write) # Layout nrows, ncols = 4, 1 image = plot_tools.Box(4, 1) pad = plot_tools.Frame(0.2, 0.2, 0.1, 0.1) margin = plot_tools.Frame(0.3, 0.2, 0.1, 0.1) # Create multifigure mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale) fig = mfig.figure # Plot writes with h5py.File(filename, mode='r') as file: for index in range(start, start+count): for n, task in enumerate(tasks): # Build subfigure axes i, j = divmod(n, ncols) axes = mfig.add_axes(i, j, [0, 0, 1, 1]) # Call 3D plotting helper, slicing in time dset = file['tasks'][task] plot_tools.plot_bot_3d(dset, 0, index, axes=axes, title=task, even_scale=True) # Add time title title = title_func(file['scales/sim_time'][index]) title_height = 1 - 0.5 * mfig.margin.top / mfig.fig.y fig.suptitle(title, x=0.48, y=title_height, ha='left') # Save figure savename = savename_func(file['scales/write_number'][index]) savepath = output.joinpath(savename) fig.savefig(str(savepath), dpi=dpi) fig.clear() plt.close(fig)
def make_plot(axs, solver, u_op, v_op, nz=16, nx=32, scale=4): # Plot solution ψ = solver.state['ψ'] ψ.require_grid_space() u = u_op.evaluate() u.set_scales(scale) u.require_grid_space() v = v_op.evaluate() v.set_scales(scale) v.require_grid_space() plt.sca(axs[0, 0]) plt.cla() plot_tools.plot_bot_3d(u, "z", scale * nz - 1, axes=axs[0, 0], even_scale=True) plt.sca(axs[0, 1]) plt.cla() plot_tools.plot_bot_3d(v, "z", scale * nz - 1, axes=axs[0, 1], even_scale=True) plt.sca(axs[1, 0]) plt.cla() plot_tools.plot_bot_3d(u, "y", int(scale * nx / 2), axes=axs[1, 0], even_scale=True) plt.sca(axs[1, 1]) plt.cla() plot_tools.plot_bot_3d(u, "x", int(scale * nx / 2), axes=axs[1, 1], even_scale=True) plt.pause(0.1)
def main(filename, start, count, output, write_start): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['ux', 'uz'] scale = 2.5 dpi = 300 # savename_func = lambda write: 'yubo_{:06}.png'.format(write+write_start) def savename_func(suffix_num): return 'yubo_{:06}'.format(suffix_num) # Layout nrows, ncols = 1, 2 image = plot_tools.Box(1, 2) pad = plot_tools.Frame(0.2, 0.2, 0.1, 0.1) margin = plot_tools.Frame(0.15, 0.15, 0.1, 0.1) # Create multifigure mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale) fig = mfig.figure # Plot writes with h5py.File(filename, mode='r') as f: for index in range(start, start + count): paxes0 = None # use this to overplot text for n, task in enumerate(tasks): # Build subfigure axes i, j = divmod(n, ncols) axes = mfig.add_axes(i, j, [0, 0, 1, 1]) # Call 3D plotting helper, slicing in time dset = f['tasks'][task] if n == 0: #ux clim = [-1.3, 1.3] title = r'$u_x / \overline{U}_c$' func = lambda xmesh, ymesh, data: (xmesh, ymesh, data / UX_C) elif n == 1: #U clim = [-0.1, 0.1] title = r'$\Upsilon \equiv \ln (\rho / \overline{\rho})$' func = None paxes, _ = plot_tools.plot_bot_3d(dset, 0, index, axes=axes, title=title, even_scale=True, clim=clim, func=func) if paxes0 is None: paxes0 = paxes # shade in forcing + damping zones x = paxes.get_xlim() plot_zbot, plot_ztop = paxes.get_ylim() paxes.fill_between(x, [plot_zbot, plot_zbot], [Z_BOT, Z_BOT], alpha=0.3, color='grey') paxes.fill_between(x, [Z_TOP, Z_TOP], [plot_ztop, plot_ztop], alpha=0.3, color='grey') paxes.fill_between(x, [Z0 + 3 * SIGMA, Z0 + 3 * SIGMA], [Z0 - 3 * SIGMA, Z0 - 3 * SIGMA], alpha=0.5, color='g') # Add time annotation sim_time = f['scales/sim_time'][index] time_str = '$t=%.1f/N$' % sim_time annotation = paxes0.text(0.1, 10.8, time_str, fontsize=14) # regex parse out filename number, 10 writes per f num_per_file = 10 write = f['scales/write_number'][index] write_num = (write - 1) % num_per_file filenum = int(re.match('.*s([\d]+)\.h5', filename)[1]) suffix_num = (filenum - 1) * num_per_file + write_num if suffix_num > 201: suffix_num -= 9 # hard coded, one of the restores is misnumbered print(suffix_num) # Save figure savename = savename_func(suffix_num) savepath = output.joinpath(savename) fig.savefig(str(savepath), dpi=dpi) # if in PLOT_IDXS, change overplotted text and plot separately try: fig_idx = PLOT_IDXS.index(suffix_num) annotation.remove() print('Adding extra annotation', suffix_num) overlay = '%s %s' % (PLOT_PREFIXES[fig_idx], time_str) paxes0.text(0.1, 10.8, overlay, fontsize=14) except ValueError: # suffix_num not in PLOT_IDXS, continue continue fig.savefig(str(savepath) + '_labeled', dpi=dpi) fig.clear() plt.close(fig)
import matplotlib as mpl mpl.use('Agg') import matplotlib.pyplot as plt import h5py import numpy as np plt.style.use('ggplot') mpl.rcParams['font.size'] = 18 import dedalus.extras.plot_tools as dpt from docopt import docopt # parse arguments args = docopt(__doc__) var = args['--var'] datadir = args['<datapath>'] integrals = h5py.File(datadir + "/integrals/integrals.h5", "r") fig = plt.figure(figsize=(14, 8)) st_ax = fig.add_axes([0.1, 0.1, 0.8, 0.8]) data = integrals['tasks/{}'.format(var)] dpt.plot_bot_3d(data, 2, 0, axes=st_ax) savefilename = datadir.rstrip('/') savefilename = savefilename.split('/')[1] fig.savefig('../figs/{}_var_{}_spacetime.png'.format(savefilename, var))
z = domain.grid(2, scales=scale) X, Y = np.meshgrid(x, y) u_surface_op = de.operators.interpolate(u, z=0) v_surface_op = de.operators.interpolate(v, z=0) u_surface = u_surface_op.evaluate() u_surface.set_scales(scale) plt.sca(axs[0, 0]) plt.pcolormesh(X, Y, u_surface['g'][:, :, -1]) #plot_tools.plot_bot_3d(u, "z", scale*nz-1, axes=axs[0, 0], even_scale=True) plt.sca(axs[0, 1]) plot_tools.plot_bot_3d(v, "z", scale * nz - 1, axes=axs[0, 1], even_scale=True) plt.sca(axs[1, 0]) plot_tools.plot_bot_3d(u, "y", int(scale * nx / 2), axes=axs[1, 0], even_scale=True) plt.sca(axs[1, 1]) plot_tools.plot_bot_3d(u, "x", int(scale * nx / 2), axes=axs[1, 1], even_scale=True)