Kernel: Python 3 (system-wide)
In [3]:
import os import cv2 as cv import numpy as np import matplotlib.pyplot as plt import matplotlib.transforms as mtransforms from matplotlib.lines import Line2D plt.style.use('../jfm.mplstyle')
In [4]:
!find ../Experimental_Dataset -type f -name "elevation.csv.gz" | xargs dirname | sort | grep "undular" | tee "data_directories.txt" > /dev/null
In [5]:
def find_idx_nearest(x,v): return np.argmin(np.abs(x-v)) with open("data_directories.txt","r") as data_directories_file: data_directories = data_directories_file.read().splitlines() data_directories = sorted([data_dir for data_dir in data_directories if 'y=+00.00cm' in data_dir]) h0, a0, g = 50, 5, 9810 c0 = np.sqrt(g*h0) t0 = h0/c0 c_t_kwargs = {'delimiter':',','dtype':int,'usecols':(0,)} c_v_kwargs = {'delimiter':',','dtype':float,'usecols':(1,)} linestyles = ['-','--','-.',':'] colorstyles = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'] labels = ['1st','2nd','4th','5th'] fig, axes = plt.subplots(nrows=2,ncols=2,figsize=(5.0,2.7),sharex='all',layout='constrained') # choose the first axis for no-flow case ax = axes[0,0] data_dir = data_directories[0] # load and plot data space = np.loadtxt(f"{data_dir}/space.csv",delimiter=',',dtype=int) x = space*0.3/h0 filenames = sorted([ f"{data_dir}/{name}" for name in os.listdir(data_dir) if "crests" in name ]) for name,linestyle,label,color in zip(filenames,linestyles,labels,colorstyles): c_t = (np.loadtxt(name,**c_t_kwargs)/125)/t0 c_v = np.loadtxt(name,**c_v_kwargs)/h0 crest_limit = 62 - x if not '1st' in name else 120 mask = np.logical_or(c_t < crest_limit, x>0) c_v[~mask] = np.nan ax.plot(x,c_v,color=color,label=label) # choose the second axis for with-flow case ax = axes[0,1] data_dir = data_directories[1] # load and plot data space = np.loadtxt(f"{data_dir}/space.csv",delimiter=',',dtype=int) x = space*0.3/h0 filenames = sorted([ f"{data_dir}/{name}" for name in os.listdir(data_dir) if "crests" in name ]) for name,linestyle,label,color in zip(filenames,linestyles,labels,colorstyles): c_t = (np.loadtxt(name,**c_t_kwargs)/125)/t0 c_v = np.loadtxt(name,**c_v_kwargs)/h0 crest_limit = 67 - x if not '1st' in name else 120 mask = np.logical_or(c_t < crest_limit, x>0) c_v[~mask] = np.nan ax.plot(x,c_v,color=color,label=label) # choose the first axis for no-flow case ax = axes[1,0] data_dir = data_directories[0] # load and plot data space = np.loadtxt(f"{data_dir}/space.csv",delimiter=',',dtype=int) x = space*0.3/h0 filenames = sorted([ f"{data_dir}/{name}" for name in os.listdir(data_dir) if "crests" in name ]) for name,linestyle,label,color in zip(filenames,linestyles,labels,colorstyles): c_t = (np.loadtxt(name,**c_t_kwargs)/125)/t0 c_v = np.loadtxt(name,**c_v_kwargs)/h0 crest_limit = 62 - x if not '1st' in name else 120 mask = np.logical_or(c_t < crest_limit, x>0) c_v[~mask] = np.nan xoff_idx = find_idx_nearest(x,-20) aoff = c_v[xoff_idx] c = c_v/aoff #- 1 ax.axhline(1,color='k',linewidth=0.5) ax.plot(x,c,color=color,label=label) # choose the second axis for with-flow case ax = axes[1,1] data_dir = data_directories[1] # load and plot data space = np.loadtxt(f"{data_dir}/space.csv",delimiter=',',dtype=int) x = space*0.3/h0 filenames = sorted([ f"{data_dir}/{name}" for name in os.listdir(data_dir) if "crests" in name ]) for name,linestyle,label,color in zip(filenames,linestyles,labels,colorstyles): c_t = (np.loadtxt(name,**c_t_kwargs)/125)/t0 c_v = np.loadtxt(name,**c_v_kwargs)/h0 crest_limit = 67 - x if not '1st' in name else 120 mask = np.logical_or(c_t < crest_limit, x>0) c_v[~mask] = np.nan xoff_idx = find_idx_nearest(x,-20) aoff = c_v[xoff_idx] c = c_v/aoff #- 1 ax.axhline(1,color='k',linewidth=0.5) ax.plot(x,c,color=color,label=label) xlim = (-20,20) ylim = (0 ,0.26) for ax, title in zip(axes[0,:],['no-flow','with-flow']): ax.set_xlim(*xlim) ax.set_ylim(*ylim) ax.set_ylabel(fr"$a$") ax.set_title(title) xlim = (-20,20) ylim = (0.95,1.65) for ax in axes[1,:]: ax.set_xlim(*xlim) ax.set_ylim(*ylim) ax.set_xlabel(r'$x$') ax.set_ylabel(fr"$a/a_i$") lines = [ Line2D([0],[0],color=color,linestyle='-') for color in colorstyles ] labels = [ '1st', '2nd', '4th', '5th' ] axes[0,1].legend(lines,labels,title='crest',bbox_to_anchor=(1, 0.5),loc='center left') #for label, ax in zip(['a)', 'b)', 'c)', 'd)'], axes[:,0]): # trans = mtransforms.ScaledTranslation(-29/72, 7/72, fig.dpi_scale_trans) # ax.text(0.0, 1.0, label, transform=ax.transAxes + trans, # fontsize='9.0', verticalalignment='top', fontfamily='Times New Roman', # bbox=dict(facecolor='1.0', edgecolor='none', pad=2.0)) plt.savefig('Fig_24.pdf') plt.show()
Out[5]: