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 main(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['b', 'p', 'u', 'w'] clims = [(-.5, .5), (-.15, .15), (-.5, .5), (-.5, .5)] 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) cmap = copy.copy(plt.cm.get_cmap("RdBu_r")) # Plot writes with h5py.File(filename, mode='r') as file: # Get the temperature data dset = file['tasks']['b'] for index in range(start, start + count): # Save figure savename = savename_func(file['scales/write_number'][index]) savepath = output.joinpath(savename) plt.imsave(str(savepath), np.flip(dset[index].T, axis=0), cmap=cmap, vmin=-0.5, vmax=0.5, dpi=dpi)
def main(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # To import the switchboard import sys switch_path = "../" + NAME sys.path.insert(0, switch_path) # Adds higher directory to python modules path import switchboard as sbp # Get relevant parameters from switchboard used in loop plot_all = sbp.plot_all_variables #bp_task_name = sbp.bp_task_name n_clrbar_ticks = sbp.n_clrbar_ticks #T = sbp.T # Display parameters x_f = sbp.x_0 + sbp.L_x_dis z_b = sbp.z_t - sbp.L_z_dis # Calculate aspect ratio AR = sbp.L_x_dis / sbp.L_z_dis # Set tuples for display boundaries x_lims = [sbp.x_0, x_f] y_lims = [z_b, sbp.z_t] # Change the size of the text overall font = {'size' : sbp.font_size} plt.rc('font', **font) # Set parameters based on switches tasks, nrows, ncols, title_str, time_factor = flip_the_switches(plot_all, sbp.plot_sponge, sbp.use_stop_sim_time, sbp.T) # Plot settings scale = sbp.scale dpi = sbp.dpi title_func = lambda sim_time: title_str.format(NAME, sim_time/time_factor) savename_func = lambda write: 'write_{:06}.png'.format(write) # Layout image = plot_tools.Box(AR, 1) pad = plot_tools.Frame(0.2, 0.2, 0.15, 0.15) 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): if (plot_all == False): # Plot stratification profile on the left ax0 = plot_bp_on_left(sbp.bp_task_name, sbp.snapshots_dir, sbp.bp_snap_dir, mfig, sbp.buffer, sbp.extra_buffer, sbp.vp_dis_ratio, y_lims) if sbp.plot_sponge: ax1 = add_sponge_profile(sbp.sl_task_name, sbp.snapshots_dir, sbp.sl_snap_dir, mfig, sbp.buffer, sbp.extra_buffer, sbp.vp_dis_ratio, y_lims) # shift n so that animation is on the right side n = 1 plot_one_task(n, ncols, mfig, file, task, index, x_lims, y_lims, n_clrbar_ticks) # Add title to frame add_frame_title(fig, file, index, title_func) # Save figure save_fig_as_frame(fig, file, index, savename_func, output, dpi) plt.close(fig)
def main(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings krel_list = [0.5, 1.0, 2.0, 3.0, 4.0, 5.0] 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 = 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) # Load projectors def get_evals_proj(krel): with np.load("data_modes_%s.npz" % krel, 'r') as file: evals = file['evals'] proj = file['proj'] return evals, proj evals_proj = {krel: get_evals_proj(krel) for krel in krel_list} # 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, krel in enumerate(krel_list): # Build subfigure axes i, j = divmod(n, ncols) ax = mfig.add_axes(i, j, [0, 0, 1, 1]) # Plot amplitudes data = build_state_vector(file, index, krel) evals, proj = evals_proj[krel] amps = proj @ data ax.loglog(evals.real, np.abs(amps), 'ob') ax.loglog(-evals.real, np.abs(amps), '.r') ax.set_title('krel = %s' % krel) ax.grid() ax.set_xlabel('ω') ax.set_ylabel('amp') ax.set_ylim(1e-26, 1e-2) # 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 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 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 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 = ['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 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 = ['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 main(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['phi', 'rho_g', 'w_g', 'w_m'] 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, 4 image = plot_tools.Box(1, 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) xlims = { 'phi': (0, 1), 'rho_g': (0, 0.1), 'w_g': (0, 4.0), 'w_m': (0, 4.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] z = file['scales/z/1.0'][:] axes.plot(dset[index], z, '.-') axes.set_title(task) axes.set_ylabel('z') axes.set_xlim(xlims[task]) # 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 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 #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 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 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)
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)
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)
ce2_bias_data = h5py.File(ce2_bias_file, 'r') ce2_image_axes = [0, 3] if xy: dns_image_axes = [0, 2] dns_data_slices = (slice(None), 0, slice(None)) else: dns_image_axes = [0, 1] dns_data_slices = (slice(None), slice(None), 0) ce2_data_slices = (slice(None), 0, 0, slice(None)) image_scales = ['sim_time', 0] nrows, ncols = 1, 3 image = plot_tools.Box(2, 1) pad = plot_tools.Frame(0.2, 0.1, 0.125, 0.125) margin = plot_tools.Frame(0.1, 0.12, 0.1, 0.05) 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,
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)
field = 'zeta' climits = (-1, 7) xlimits = (0, 63) ylimits = (1, 63) dns_tidx = -1 ce2_tidx = -1 label = None dns_filename = "../scratch/busse_annulus_ra4.00e+07_beta3.16e+05_C3.16e-01_Pr1.00e+00_filter5.00e-01_nx512_ny128_CFL/snapshots/snapshots_s2.h5" ce2_filename = "run_R_explicit_powerspec/data_snapshots/data_snapshots_s121.h5" ce2_b_filename = "run_S_explicit_no_mean_subtr/data_snapshots/data_snapshots_s68.h5" with h5py.File(dns_filename, 'r') as dns_data, h5py.File( ce2_filename, 'r') as ce2_data, h5py.File(ce2_b_filename, 'r') as ce2_b_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))
def main(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['btot', 'btot_stat'] #for bouyancy in non-hydrostat and hydrostat cases """much of these settings are probably not needed, but I didn't want to break the code by deleting them """ 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(len(tasks), 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: time = np.zeros(0) diff = np.zeros(0) for index in range(start, start + count): if index == 400: #for testing purposes break for n, task in enumerate(tasks): if n == 0: #zoomed bouyancy on top, would like to plot contours aswell # 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] ctour = plot_test.plot_bot_3d( dset, 0, index, k=1, axes=axes, title='b in Pycnocline (Non-Hydrostat)', even_scale=True, clim=(3, 5)) #get contours for Fourier transform # print(task) if index != 0: #bypass first snapshot, since 1st is 0 for all variables tour = ctour.collections[4].get_paths()[ 0] #gets 4th contour v = tour.vertices if index == 1: #only need to do this once Z = v[:, 1] #first set of z values in bouyancy x = v[:, 0] #gets x values which are constant if index > 1: z = v[:, 1] Z = np.vstack((Z, z)) #build array of z values if index % 5 == 0: #just to know where it is at print('n=', n, 'index=', index) #nth variable, ith timestep time = np.append(time, file['scales/sim_time'][index]) if len(time) >= 2: difference = time[index - 1] - time[ index - 2] #time series interval diff = np.append(diff, difference) #make an array if n == 1: #zoomed bouyancy on top, would like to plot contours aswell # 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] ctour = plot_test.plot_bot_3d( dset, 0, index, k=1, axes=axes, title='b in Pycnocline (Non-Hydrostat)', even_scale=True, clim=(3, 5)) #get contours for Fourier transform # print(task) if index != 0: #bypass first snapshot, since 1st is 0 for all variables tour = ctour.collections[4].get_paths()[ 0] #now we are on 2nd etc snapshots v = tour.vertices if index == 1: #only need to do this once Z_stat = v[:, 1] if index > 1: z_stat = v[:, 1] Z_stat = np.vstack( (Z_stat, z_stat)) #build array of z values if index % 1 == 0: #just to know where it is at print('n=', n, 'index=', index) # plt.plot(x,z) # plt.ylim(-0.15-1e-4, -0.15+1e-4) # elif n == 2: #zoomed bouyancy on top # # 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_test.plot_bot_3d(dset, 0, index, k=0, axes=axes, title='Change in b in Pycnocline ( Non-Hydrostat)', # even_scale=True, clim=(-5e-5,5e-5)) # elif n == 3: #zoomed bouyancy on top # # 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_test.plot_bot_3d(dset, 0, index, k=0, axes=axes, title='Change in b_stat in Pycnocline (Hydrostat)', # even_scale=True, clim=(-5e-5,5e-5)) # 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, fontsize='large')#, 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) ##colour plot for x,t,z where z is the dependant variable, just used for testing # X, T = np.meshgrid(x,time) #x,t mesh for z plot # fig, (ax0, ax1) = plt.subplots(ncols=2, sharex=True, sharey=True) #2 plots # im = ax0.pcolormesh(X, T, Z) # ax0.set_title('Nonhydrostatic') # ax0.set_ylabel('Time (s)') # # im = ax1.pcolormesh(X, T, Z_stat) # ax1.set_title('Hydrostatic') # ax0.set_xlabel('Horizontal Position (m)') # colorbar(im) #to fit in colorbar # plt.tight_layout(h_pad=1) # plt.savefig('Colorbar_graph2') # fig.clear() # exit() #Power Spectrum #nonhydrostatic Z = Z[30:, :] #delete first 30 rows, transients Z_c = np.fft.fft(Z, axis=0) #coeff matrix Z_p = np.abs(Z_c)**2 #power matrix #hydrostatic Z_stat = Z_stat[30:, :] #delete first n rows, transients Z_c_stat = np.fft.fft(Z, axis=0) #coeff matrix Z_p_stat = np.abs(Z_c)**2 #power matrix n = Z.shape[0] #length of time axis timestep = time[100] - time[99] #sampling interval, picked random interval freq = np.fft.fftfreq(n, d=timestep) #frequency axis X, w = np.meshgrid(x, freq) fig, (ax0, ax1) = plt.subplots(ncols=2, sharex=True, sharey=True) #2 plots im = ax0.pcolormesh(X, w, Z_p, vmin=1e-10, vmax=1e-8) ax0.set_title('Nonhydrostatic') ax0.set_ylabel('Freq (Hz)') im = ax1.pcolormesh(X, w, Z_p_stat, vmin=0, vmax=1e-8) ax1.set_title('Hydrostatic') ax0.set_xlabel('Horizontal Position (m)') colorbar(im) #to fit in colorbar plt.tight_layout(h_pad=1) plt.savefig('Powerspectrum_graph3') print(np.std(diff[10:, ]) * 100 / diff[100] ) #looking at std dev time intervals as fraction of a later interval print(len(time)) # look at number of time series fig.clear()
def main(filename, start, count, output): """Save plot of specified tasks for given range of analysis writes.""" # Plot settings tasks = ['u, 'v', 'b'] #for (change in) bouyancy in non-hydrostat and hydrostat cases 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 = 2, 1 #no. of columns and rows corresponding to desired variables image = plot_tools.Box(len(tasks), 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): if n ==0: #zoomed bouyancy on top, would like to plot contours aswell # 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_test.plot_bot_3d(dset, 0, index, k= 1, axes=axes, title='Horizontal Velocity u', even_scale=True, clim=(-5e-4,5e-4)) if n == 1: #zoomed bouyancy on top, would like to plot contours aswell # 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_test.plot_bot_3d(dset, 0, index, k=1, axes=axes, title='Vertical Velocity w', even_scale=True, clim=(-5e-5,5e-5)) if n == 2: #zoomed bouyancy on top # 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_test.plot_bot_3d(dset, 0, index, k=0, axes=axes, title='Change in Bouyancy b', even_scale=True, clim=(-5e-4,5e-4)) if n == 3: #not currently in use # 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_test.plot_bot_3d(dset, 0, index, k=0, axes=axes, title='Change in b_stat in Pycnocline (Hydrostat)', even_scale=True, clim=(-5e2,5e2)) # 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, fontsize='large')#, 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)