def plot_slice(filename, start, count, output, loc, name): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings fields = ['b', 'u', 'v', 'w', 'ωz'] scale = 2.5 dpi = 100 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: '{}_{:06}.png'.format(name, write) # Layout if loc[0] == 'x': nrows, ncols = 5, 1 image = plot_tools.Box(6, 1) image_axes = (2, 3) data_slices = (0, slice(None), slice(None)) elif loc[0] == 'y': nrows, ncols = 5, 1 image = plot_tools.Box(6, 1) image_axes = (1, 3) data_slices = (slice(None), 0, slice(None)) elif loc[0] == 'z': nrows, ncols = 2, 3 image = plot_tools.Box(2, 2) image_axes = (1, 2) data_slices = (slice(None), slice(None), 0) 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, field in enumerate(fields): # 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]) task = f"interp({field}, {loc})" dset = file['tasks'][task] plot_tools.plot_bot(dset, image_axes, (index, ) + data_slices, 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 integral(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['ZF'] scale = 2.5 dpi = 100 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: 'ZF_{:06}.png'.format(write) # Layout nrows, ncols = 1, 1 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) with h5py.File(filename, mode='r') as file: time = file['scales']['sim_time'] xaxis = file['scales']['x']['1.0'] dset = file['tasks']['ZF'] f = open('zf_set', 'w') for j in range(0, len(time)): for k in range(0, len(xaxis)): f.write('%f %f %f\n' % (time[j], xaxis[k], dset[j][k][0])) f.write('\n') f.close() return # 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))) image_axes = (1, 1) data_slices = (index, slice(None), slice(None), 0) plot_tools.plot_bot(dset, (1, 2), (slice(None), slice(None))) # 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 integral(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['ZF'] scale = 2.5 dpi = 100 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: 'ZF_{:06}.png'.format(write) # Layout nrows, ncols = 1, 1 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) with h5py.File(filename, mode='r') as file: time = file['scales']['sim_time'] xaxis = file['scales']['x']['1.0'] dset = file['tasks']['ZF'] f = open('zf_set','w') for j in range(0,len(time)): for k in range(0,len(xaxis)): f.write('%f %f %f\n' %( time[j], xaxis[k] ,dset[j][k][0] )) f.write('\n') f.close() return # 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))) image_axes = (1, 1) data_slices = (index, slice(None), slice(None), 0) plot_tools.plot_bot(dset,(1,2),(slice(None),slice(None))) # 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 vertical(filename, start, count, output): """Slices in y-z at edge (x=0).""" # Plot settings tasks = [ 'b vertical', 'q vertical', 'temp vertical', 'u vertical', 'v vertical', 'w vertical' ] even_scale = [False, False, False, True, True, True] scale = 2.5 dpi = 100 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: 'vert_{:06}.png'.format(write) # Layout nrows, ncols = 2, 3 image = plot_tools.Box(2, 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 plotting helper (dset axes: [t, x, y, z]) dset = file['tasks'][task] image_axes = (2, 3) data_slices = (index, 0, slice(None), slice(None)) plot_tools.plot_bot(dset, image_axes, data_slices, axes=axes, title=task, even_scale=even_scale[n]) # 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 = ['u', 'v', 'vorticity'] scale = 2.5 dpi = 400 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: 'ucvc_{:06}.png'.format(write) # Layout nrows, ncols = 1, 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 current_cmap = matplotlib.cm.viridis current_cmap.set_bad(color='white') # 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] image_axes = (1, 2) data_slices = [index, slice(None), slice(None)] plot_tools.plot_bot(dset, image_axes, data_slices, axes=axes, title=task, cmap=current_cmap) #, clim=[-1,1]) # 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 plot_spectra(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['b', 'u', 'v', 'w'] title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: 'spec_{:06}.png'.format(write) # Layout nrows = 3 ncols = len(tasks) image = plot_tools.Box(4, 4) pad = plot_tools.Frame(0.2, 0.2, 0.1, 0.1) margin = plot_tools.Frame(0.3, 0.2, 0.1, 0.1) scale = 2 dpi = 100 # 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 j, task in enumerate(tasks): dset = file['tasks'][task] # Load field in grid layout field.set_scales(1) field['g'] = dset[index] for i in range(3): data = np.log10(integrated_spectra(field, axis=i).T) image_axes = [0, 1, 2] image_axes.pop(i) # Build subfigure axes axes = mfig.add_axes(i, j, [0, 0, 1, 1]) plot_tools.plot_bot(field, image_axes, data=data, axes=axes, title=task, even_scale=False, cmap='viridis') # 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 #with h5py.File(filename, mode='r') as file: # tasks = sorted(file['tasks'].keys()) tasks = ['u', 'v', 'w'] scale = 4 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, 3 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) plt.style.use('prl') # 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_axes = [3,1] new_slices = [index] + run_slices plot_tools.plot_bot(dset, plot_axes, new_slices, 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(prefix, start, count, output, task): """Save plot of specified task at given time for six (6) runs.""" task = str(task) scale = 4 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, 2 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) plt.style.use('prl') # Create multifigure mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale) fig = mfig.figure for folder in glob.glob(prefix): filename = folder + "snapshots/snapshots_s1.h5" with h5py.File(filename, mode='r') as file: # 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_title = 'tasks/' + task dset = file[dset_title][10, ] new_slices = [index] + run_slices plot_tools.plot_bot(dset, plot_axes, new_slices, 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 integral(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['b integral x4'] scale = 2.5 dpi = 100 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: 'int_{:06}.png'.format(write) # Layout nrows, ncols = 1, 1 image = plot_tools.Box(2, 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 plotting helper (dset axes: [t, x, y, z]) dset = file['tasks'][task] image_axes = (2, 1) data_slices = (index, slice(None), slice(None), 0) plot_tools.plot_bot(dset, image_axes, data_slices, axes=axes, title=task, even_scale=True, cmap='Greys') # 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 planes(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['ze bot','tf bot', 'ze mid', 'tf mid', 'ze top', 'tf top'] scale = 2.0 dpi = 200 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: 'mid_{:06}.png'.format(write) # Layout nrows, ncols = 3, 2 image = plot_tools.Box(2, 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 plotting helper (dset axes: [t, x, y, z]) dset = file['tasks'][task] image_axes = (2, 1) data_slices = (index, slice(None), slice(None), 0) plot_tools.plot_bot(dset, image_axes, data_slices, 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)
image = plot_tools.Box(2, 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 tasks = ['b', 'q', 'temp', 'u', 'v', 'w'] even_scale = [False, False, False, True, True, True] with h5py.File(filename, 'r') as df: for n, task in enumerate(tasks): i, j = divmod(n, ncols) axes = mfig.add_axes(i, j, [0, 0, 1, 1]) dset = df['tasks'][task] image_axes = (0, 3) data_slices = (slice(None), 0, 0, slice(None)) plot_tools.plot_bot(dset, image_axes, data_slices, axes=axes, title=task, even_scale=even_scale[n]) for f in filename.parts: if f.startswith('rainy_benard'): plot_base = f plot_file_name = Path(plot_base + '_profiles.png') plt.savefig(outbase / plot_file_name, dpi=300)
def main(file_path, output_path): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings # with h5py.File(file_path, mode='r') as file: # tasks = sorted(file['tasks'].keys()) # tasks = tasks[MPI.COMM_WORLD.rank::MPI.COMM_WORLD.size] #tasks = ["P1(cz)"] dpi = 128 savename = lambda task: str(output_path.joinpath('hov_{:}.png'.format(task))) # Selection settings keep_axis = A = 3 index = 0 # Plot Hovmoller image_axes = [0, A] image_scales = ['sim_time', 0] data_slices = (slice(None), 0, 0, slice(None)) with h5py.File(file_path, 'r') as file: sim_time = file['scales']['sim_time'][:] fig = plt.figure(figsize=(16,8)) data_slices = (slice(None), 0, 0, slice(None)) for task_name in file['tasks']: dset = file['tasks'][task_name] # Plot Hovmoller axes = fig.add_axes([0.05, 0.4, 0.75, 0.45]) plot_tools.plot_bot(dset, image_axes, data_slices, image_scales, even_scale=True, axes=axes, title=task_name) # Plot average vs time axes = fig.add_axes([0.05+0.03*0.75, 0.1, 0.75*0.94, 0.2]) x = sim_time[data_slices[0]] y = np.mean(dset[data_slices], axis=1) plt.plot(x, y, '-k') plt.xlabel(image_scales[0]) plt.title('<'+task_name+'>') plt.xlim(min(x), max(x)) # Plot average vs height y = file['scales']['y1']['1.0'] #t1 = np.max(sim_time) * 0.25 #x1 = np.mean(dset[data_slices][sim_time < t1], axis=0) t1 = sim_time[data_slices[0]][0] x1 = dset[data_slices][0] #t2 = np.max(sim_time) * 0.75 #x2 = np.mean(dset[data_slices][sim_time > t2], axis=0) t2 = sim_time[data_slices[0]][-1] x2 = dset[data_slices][-1] axes = fig.add_axes([0.85, 0.4, 0.1, 0.45*0.94]) plt.plot(x1, y, '-k') plt.plot(x2, y, '--k') #plt.title(' t < %.1f (solid) \n t > %.1f (dashed)' %(t1, t2)) plt.title('t = %.1f (solid) \n t = %.1f (dashed)' %(t1, t2)) plt.ylabel('y') plt.ylim(min(y), max(y)) plt.setp(plt.gca().get_xticklabels(), rotation=90) # Print double average fig.text(0.8, 0.2, ' <%s> \n t < %.1f = %.3e +- %.3e \n t > %.1f = %.3e +- %.3e ' %(task_name, t1, np.mean(x1), np.std(x1), t2, np.mean(x2), np.std(x2))) # Save figure #fig.suptitle('Reynolds = %.2e, Prandtl = %.2e, Schmidt = %.2e' %(param.Reynolds, param.Prandtl, param.Schmidt)) fig.savefig(savename(task_name), dpi=dpi) fig.clear() plt.close(fig)
nrows, ncols = 2, 1 image = plot_tools.Box(2, 1) pad = plot_tools.Frame(0.2, 0.1, 0.1, 0.1) margin = plot_tools.Frame(0.1, 0.1, 0.1, 0.1) scale = 4 mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale) fig = mfig.figure axes = mfig.add_axes(0, 0, [0, 0, 1, 1]) # DNS print("dns_data shape", dns_data['tasks/<u>_x'].shape) print('ce2 data shape', ce2_data['tasks/cu'].shape) pax, cax = plot_tools.plot_bot(dns_data['tasks/<u>_x'], dns_image_axes, dns_data_slices, image_scales, axes=axes, title=r'$\left<u\right>$ DNS', even_scale=True, clim=limits) #pax.set_xlim(0,0.125) pax.xaxis.set_label_text("time") pax.yaxis.set_label_text("$y$") pax.yaxis.label.set_rotation('horizontal') pax.text(0.95,0.85, 'a', bbox={'facecolor': 'grey', 'alpha': 0.5, 'boxstyle':'round'},transform=pax.transAxes, fontsize=18) pax.set_rasterized(True) axes = mfig.add_axes(1, 0, [0, 0, 1, 1]) # CE2 pax, cax = plot_tools.plot_bot(ce2_data['tasks/cu'], ce2_image_axes, ce2_data_slices, image_scales, axes=axes, title=r'$\left<u\right>$ CE2', even_scale=True, clim=limits) pax.xaxis.set_label_text("time") pax.yaxis.set_label_text("$y_1$") pax.yaxis.label.set_rotation('horizontal')
datadir.joinpath(x) for x in ['data_snapshots_s1.h5', 'data_snapshots_s3.h5', 'data_snapshots_s101.h5'] ] title = r'$c_{\theta\theta}$' #(\xi, y_1, y_2=0.5)$' for n, fn in enumerate(filenames): i, j = divmod(n, ncols) axes = mfig.add_axes(i, j, [0, 0, 1, 1]) with h5py.File(fn, 'r') as df: dset = df['tasks/interp(ctt, y1=0.500)'] image_axes = [1, 2] data_slices = [0, slice(None), slice(None), 0] pax, cax = plot_tools.plot_bot(dset, image_axes, data_slices, axes=axes, title=title, even_scale=True, clim=limits) pax.set_rasterized(True) time = df['scales/sim_time'][0] pax.text(0.1, 0.8, 't = {:3.2f}'.format(time), bbox={ 'facecolor': 'grey', 'alpha': 0.5, 'boxstyle': 'round' }, transform=axes.transAxes, fontsize=18)
y_ticks = (0.2, 0.4, 0.6, 0.8, 1.0) scale = 2 mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale) fig = mfig.figure axes = mfig.add_axes(0, 0, [0, 0, 1, 1]) # DNS print("dns_data shape", dns_data['tasks/<u>_x'].shape) print('ce2 data shape', ce2_data['tasks/cu'].shape) pax, cax = plot_tools.plot_bot(dns_data['tasks/<u>_x'], dns_image_axes, dns_data_slices, image_scales, axes=axes, title=r'$c_u$', even_scale=True, clim=limits, cmap=cc.cm['bwy']) #pax.set_xlim(0,0.125) pax.xaxis.set_label_text(r"$t$") pax.yaxis.set_label_text("$y$") pax.set_yticks(y_ticks) pax.yaxis.label.set_rotation('horizontal') pax.text(0.95, 0.85, 'a', bbox={ 'facecolor': 'grey', 'alpha': 0.5,
power_axis_label = r"$\log_{10} |\hat{\zeta}|^2$" elif field == 'theta': power_axis_label = r"$\log_{10} |\hat{\theta}|^2$" else: raise NotImplementedError( "Field can only be theta or zeta, not {}".format(field)) # DNS dns_image_axes = (2, 1) dns_image_slices = (dns_tidx, slice(None), slice(None)) dns_kspace_data = dns_data['tasks/{}_kspace'.format(field)] dns_time = dns_data['scales/sim_time'][dns_tidx] pax, cax = plot_tools.plot_bot(dns_kspace_data, dns_image_axes, dns_image_slices, func=calc_dns_power, clim=climits, cmap='viridis', axes=dns_axes) pax.xaxis.set_major_locator(MaxNLocator(integer=True)) #pax.yaxis.set_major_locator(MaxNLocator(integer=True)) pax.set_xlim(xlimits) pax.set_ylim(ylimits) cax.set_xlabel(power_axis_label) pax.set_xlabel(r"$k_x$") pax.set_ylabel(r"$k_{y}$") pax.text(0.9, 0.85, 'a', bbox={ 'facecolor': 'grey',
def abs_sqr(xmesh, ymesh, data): newdata = np.abs(data)**2 return xmesh, ymesh, newdata folders = sorted(glob.glob(prefix), key=lambda folder: int(folder.split("_")[-1])) for folder in folders: filename = folder + "/spectra/spectra_s1.h5" datafile = h5py.File(filename, 'r') coeff = datafile['tasks/vc'] print(coeff.shape) plot_axes = [1, 2] slices = [-1, slice(None), slice(None), 0] plot_tools.plot_bot(coeff, plot_axes, slices, func=abs_sqr) plt.tight_layout() plt.savefig("spectral_plot_" + str(folder.split("_")[-1]) + ".png", dpi=300) """ # Create plot plt.imshow(v_tot) plt.gca().invert_yaxis() plt.legend() plt.tight_layout() plot_file_name = 'v_tot_timeseries.png' plt.savefig(plot_file_name, dpi=300) """
def main(filename, start, count, output="./img_snapshots", slice_type="side"): """Save plot of specified tasks for given range of analysis writes.""" filename = pathlib.Path(filename) stem = filename.stem.split("_")[0] if (slice_type == "top"): nrows, ncols = 2,2 image_axes = [2, 3] data_slices = [0, 0,slice(None), slice(None)] tasks = ['Pressure(z=+1)', 'Ux(z=+1)', 'Uy(z=+1)'] elif (slice_type == "mid"): nrows, ncols = 2,2 image_axes = [2, 3] data_slices = [0, 0,slice(None), slice(None)] tasks = ['W(z=+0.5)', 'T(z=+0.5)'] elif (slice_type == "side"): nrows, ncols = 2,2 image_axes = [2, 1] data_slices = [0, slice(None), slice(None),0] tasks = ['Temperature(y=+1)', 'Pressure(y=+1)', 'Ox(y=+1)', 'Oz(y=+1)'] elif (slice_type == 'small'): nrows, ncols = 2,2 image_axes = [2, 1] data_slices = [0, slice(None), slice(None),0] tasks = ['Temperature(y=+1)', 'Pressure(y=+1)', 'Oz(y=+1)'] else: raise ValueError("must be side, mid or top slice. got {}".format(str(filename))) # Plot settings scale = 4 dpi = 100 title_func = lambda sim_time: 't = {:.3f}'.format(sim_time) savename_func = lambda write: '{}_{:06}.png'.format(stem, write) # Layout image = plot_tools.Box(3, 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] data_slices[0] = index plot_tools.plot_bot(dset, image_axes, data_slices, 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 plot_power_spectra(ce2_filename, start, count, output='write_', field='zeta', climits=None, xlimits=None, ylimits=None, dns_tidx=-1, ce2_tidx=-1, label=None, dns_filename=None): with h5py.File(dns_filename, 'r') as dns_data, h5py.File(ce2_filename, 'r') as ce2_data: nrows, ncols = 1, 3 image = plot_tools.Box(1, 1) pad = plot_tools.Frame(0.2, 0.1, 0.1, 0.1) margin = plot_tools.Frame(0.1, 0.1, 0.1, 0.1) scale = 4 mfig = plot_tools.MultiFigure(nrows, ncols, image, pad, margin, scale) fig = mfig.figure dns_axes = mfig.add_axes(0, 0, [0, 0, 1, 1]) if field == 'zeta': power_axis_label = r"$\log_{10} |\hat{\zeta}|^2$" elif field == 'theta': power_axis_label = r"$\log_{10} |\hat{\theta}|^2$" else: raise NotImplementedError( "Field can only be theta or zeta, not {}".format(field)) # DNS dns_image_axes = (2, 1) dns_image_slices = (dns_tidx, slice(None), slice(None)) dns_kspace_data = dns_data['tasks/{}_kspace'.format(field)] dns_time = dns_data['scales/sim_time'][dns_tidx] pax, cax = plot_tools.plot_bot(dns_kspace_data, dns_image_axes, dns_image_slices, func=calc_dns_power, clim=climits, cmap='viridis', axes=dns_axes) pax.xaxis.set_major_locator(MaxNLocator(integer=True)) #pax.yaxis.set_major_locator(MaxNLocator(integer=True)) pax.set_xlim(xlimits) pax.set_ylim(ylimits) cax.set_xlabel(power_axis_label) pax.set_xlabel(r"$k_x$") pax.set_ylabel(r"$k_{y}$") pax.text(0.9, 0.85, 'a', bbox={ 'facecolor': 'grey', 'alpha': 0.5, 'boxstyle': 'round' }, transform=pax.transAxes, fontsize=18, color='white') pax.set_rasterized(True) # CE2 ce2_axes = mfig.add_axes(0, 1, [0, 0, 1, 1]) ce2_image_axes = (1, 3) ce2_image_slices = (ce2_tidx, slice(None), 0, slice(None)) ce2_kspace_data = ce2_data['tasks/{}_power'.format(field)] ce2_time = ce2_data['scales/sim_time'][ce2_tidx] ce2_write = ce2_data['scales/write_number'][ce2_tidx] pax, cax = plot_tools.plot_bot(ce2_kspace_data, ce2_image_axes, ce2_image_slices, func=calc_ce2_power, clim=climits, cmap='viridis', axes=ce2_axes) cax.set_xlabel(power_axis_label) pax.xaxis.set_major_locator(MaxNLocator(integer=True)) pax.set_xlim(xlimits) pax.set_ylim(ylimits) pax.set_xlabel(r"$k_x$") pax.set_ylabel(r"$k_{y}$") pax.text(0.9, 0.85, 'b', bbox={ 'facecolor': 'grey', 'alpha': 0.5, 'boxstyle': 'round' }, transform=pax.transAxes, fontsize=18, color='white') pax.set_rasterized(True) # plot only kx = 0 mode kx0_axes = mfig.add_axes(0, 2, [0.03, 0, 0.94, 0.94]) kx, ky, data = plot_tools.get_plane(ce2_kspace_data, ce2_image_axes[0], ce2_image_axes[1], ce2_image_slices) ce2_kx, ce2_ky, ce2_power = calc_ce2_power(kx, ky, data) kx, ky, data = plot_tools.get_plane(dns_kspace_data, dns_image_axes[0], dns_image_axes[1], dns_image_slices) dns_kx, dns_ky, dns_power = calc_dns_power(kx, ky, data) kx0_axes.plot(dns_power[:, 0], label='DNS t = {:5.2e}'.format(dns_time)) kx0_axes.plot(ce2_power[:, 0], label='CE2 t = {:5.2e}'.format(ce2_time)) kx0_axes.set_xlabel(r"$k_{y}$") kx0_axes.set_ylabel(power_axis_label) #kx0_axes.set_xlim(1,15) kx0_axes.text(0.9, 0.85, 'c', bbox={ 'facecolor': 'grey', 'alpha': 0.5, 'boxstyle': 'round' }, transform=kx0_axes.transAxes, fontsize=18, color='black') kx0_axes.xaxis.set_major_locator(MaxNLocator(integer=True)) kx0_axes.legend(loc='lower right') outputdir = pathlib.Path(output) for ext in ['png']: #,'pdf']: outfilen = "power_spectra_dns_ce2_{}_field_{}_write_{:05d}.{}".format( label, field, ce2_write, ext) fig.savefig(str(outputdir / outfilen), dpi=400)