Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for JFM-2024-1227.
Download
3482 views
unlisted
ubuntu2204
Kernel: Python 3 (system-wide)

import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.transforms as mtransforms from matplotlib.colors import LinearSegmentedColormap from scipy import signal from scipy.signal import convolve2d from scipy.stats import linregress from scipy.special import erf from itertools import cycle plt.style.use('../jfm.mplstyle') rainbow = np.loadtxt('../rainbow.tsv') mymap = LinearSegmentedColormap.from_list('rainbow', rainbow) data_dir = '../Experimental_Dataset/with_flow/5cm_water_depth/particle_image_velocimitry'
x_int = np.loadtxt(f'{data_dir}/velocity_x_interp.txt',dtype=int) y_int = np.loadtxt(f'{data_dir}/velocity_y_interp.txt',dtype=int) u = np.loadtxt(f'{data_dir}/velocity_u_interp.txt',dtype="float32") v = np.loadtxt(f'{data_dir}/velocity_v_interp.txt',dtype="float32") m = np.loadtxt(f'{data_dir}/velocity_m_interp.txt',dtype="float32") u_std = np.loadtxt(f'{data_dir}/velocity_u_std_interp.txt',dtype="float32") v_std = np.loadtxt(f'{data_dir}/velocity_v_std_interp.txt',dtype="float32") m_std = np.loadtxt(f'{data_dir}/velocity_m_std_interp.txt',dtype="float32") h, g, b0 = 50, 9810, 229 c = np.sqrt(g*h) x = (x_int/h) y = (y_int/h) u /= c v /= c m /= c u_std /=c v_std /= c m_std /= c
N = 5 k = np.ones((N,N))/(N**2) kwargs = {'mode':'same','boundary':'fill','fillvalue':np.nan} u_smooth = convolve2d(u,k,**kwargs) v_smooth = convolve2d(v,k,**kwargs) m_smooth = convolve2d(m,k,**kwargs) u_std_smooth = convolve2d(u_std,k,**kwargs) v_std_smooth = convolve2d(v_std,k,**kwargs) m_std_smooth = convolve2d(m_std,k,**kwargs)
fig, ax = plt.subplots(figsize=(5.0,2.0)) xlim = (-45,10) ylim = (-10,10) line_kwargs = {'color':'k','linewidth':2} step_x = 125 step_y = 40 mask = np.logical_and(x_int%step_x==0,y_int%step_y==0) cmap = ax.pcolormesh(x,y,m_std_smooth,cmap=mymap,vmin=0,shading='gouraud') quiver = ax.quiver(x[mask],y[mask],u_smooth[mask]*c/h,v_smooth[mask]*c/h, units='xy',angles='xy',scale_units='xy',scale=0.6,pivot='tail',color='k', width=0.15) ax.quiver([5],[5],[-0.1*c/h],[0], units='xy',angles='xy',scale_units='xy',scale=0.6,pivot='mid',color='k', width=0.15) ax.hlines( 115/h,xmin=600/h,xmax=0 ,**line_kwargs) ax.hlines( -115/h,xmin=600/h,xmax=0 ,**line_kwargs) ax.hlines( 1360/h,xmin=0 ,xmax=-2250/h,**line_kwargs) ax.vlines( 0,ymin= 115/h,ymax= 1360/h,**line_kwargs) ax.vlines( 0,ymin=-115/h,ymax=-500/h,**line_kwargs) ax.axis('scaled') ax.set_xlim(*xlim) ax.set_ylim(*ylim) #for ax, label in zip(axes,['(a)','(b)']): # ax.text(-0.16, 1.1, label, transform=ax.transAxes, size=7) #plt.tight_layout() clb = plt.colorbar(cmap,ax=ax, location='right',orientation='vertical',shrink=0.7) clb.set_ticks([0,0.007,0.014]) #clb.ax.set_title(r'$\sigma(|\vec{u}|)$') clb.set_label(r'$\sigma(|\vec{u}|)$', labelpad=-30, y=1.2, rotation=0) ax.set_xlabel(r'$x$') ax.set_ylabel(r'$y$') plt.tight_layout() #plt.savefig('Fig_03.pdf') plt.savefig('Fig_03.jpg') plt.show()
Image in a Jupyter notebook