Kernel: Python 3 (system-wide)
In [3]:
import os import numpy as np import matplotlib.pyplot as plt import matplotlib.transforms as mtransforms import scipy.integrate as integrate from scipy import signal from scipy.signal import find_peaks from matplotlib.lines import Line2D # have to do some memory management on cocalc servers from tempfile import mkdtemp import os.path as path plt.style.use('../jfm.mplstyle') rainbow = np.loadtxt("../rainbow.tsv") def array2cmpa(X): from matplotlib import colors # Assuming array is Nx3, where x3 gives RGB values # Append 1's for the alpha channel, to make X Nx4 X = np.c_[X,np.ones(len(X))] return colors.LinearSegmentedColormap.from_list('my_colormap', X) rainbow_map = array2cmpa(rainbow) colormap = rainbow_map #'coolwarm' #'plasma' #rainbow_map
In [4]:
!find ../Experimental_Dataset -type f -name "elevation.csv.gz" | xargs dirname | sort | grep "undular" | tee "data_directories.txt" > /dev/null
In [5]:
with open("data_directories.txt","r") as data_directories_file: data_directories = data_directories_file.read().splitlines() amp = 'a0.5cm' loc = 'y=+00.00cm' xlim = (-20,20) ylim = (50,130) dx,dt,h,g = 0.3,1/125,50,9810 t0 = np.sqrt(h/g) fig, axes = plt.subplots(ncols=2,nrows=1,figsize=(5.0,2.5),sharey='all',sharex='all',layout='constrained',dpi=300) kwargs = {'vmin':-0.03,'vmax':0.27,'cmap':colormap} vmin,vmax = kwargs['vmin'],kwargs['vmax'] levels = np.arange(vmin,vmax,0.018) data_dirs = [d for d in data_directories if loc in d and amp in d] # no-flow in the top row, with-flow in the bottom row for ax, data_dir in zip(axes.flat,data_dirs): time = np.loadtxt(f"{data_dir}/time.csv",delimiter=',',dtype=int) #t_off = np.loadtxt(f"{data_dir}/time_offset.csv") space = np.loadtxt(f"{data_dir}/space.csv",delimiter=',',dtype=int) # work with elev from disk instead of memory elev = np.memmap('elev.dat', dtype=float, mode='w+', shape=(time.size,space.size)) elev[:] = np.loadtxt(f"{data_dir}/elevation.csv",delimiter=',') space = space*dx/h time = (time*dt)/t0 elev /= h #print(np.amin(elev),np.amax(elev)) # work with X,T from disk instead of memory X = np.memmap('X.dat', dtype=float, mode='w+', shape=(time.size,space.size)) T = np.memmap('T.dat', dtype=float, mode='w+', shape=(time.size,space.size)) X[:],T[:] = np.meshgrid(space,time) cmp = ax.pcolormesh(X,T,elev,shading='nearest',**kwargs) ctl = ax.contour(X,T,elev,levels=levels,colors='k',linewidths=0.25) ax.set_xlim(*xlim) ax.set_ylim(*ylim) #title = 'with-flow' if 'with_flow' in data_dir else 'no-flow' #ax.set_title(title) # some more memory management for cocalc X,T,space,time,elev = None, None, None, None, None # some disk management os.remove('elev.dat') os.remove('X.dat') os.remove('T.dat') axes[0].set_ylabel(r'$t$') for ax in axes.flat: ax.set_xlabel(r'$x$') #axes[0].set_title(r'no-flow') #axes[1].set_title(r'with-flow') cbar = fig.colorbar(cmp, ax=axes.ravel().tolist(),location='right',shrink=0.90) cbar.ax.set_title(r'$\eta$') cbar.add_lines(ctl) #for label, ax in zip(['a)', 'b)'], axes): # ax.set_title(label,loc='left',fontfamily='Times New Roman',fontsize='9.0') # some more memory management cmp, ctl = None, None plt.savefig('Fig_21.jpg') plt.show()
Out[5]:
In [0]: