|
| 1 | + |
| 2 | +import numpy as np |
| 3 | +import pandas as pd |
| 4 | +import matplotlib.pyplot as plt |
| 5 | +from scipy.interpolate import griddata |
| 6 | +import os |
| 7 | +import warnings |
| 8 | +# include FDS plot styles, etc. |
| 9 | +import fdsplotlib |
| 10 | + |
| 11 | +warnings.filterwarnings('ignore') |
| 12 | + |
| 13 | +# McGrattan |
| 14 | +# 9-27-2022 |
| 15 | +# FHWA_Tunnel.py |
| 16 | +# |
| 17 | +# This script creates several different kinds of contour and scatter plots for the FHWA Tunnel simulations. |
| 18 | + |
| 19 | +# clear all - not needed in Python |
| 20 | +# close all |
| 21 | +plt.close('all') |
| 22 | + |
| 23 | +outdir = '../../../out/FHWA_Tunnel/' |
| 24 | +expdir = '../../../exp/FHWA_Tunnel/' |
| 25 | +pltdir = '../../Manuals/FDS_Validation_Guide/SCRIPT_FIGURES/FHWA_Tunnel/' |
| 26 | + |
| 27 | +pos = [1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.5, 9.5, 10.5, 11.5] |
| 28 | +test = ['IFAB-07', 'IFAB-08', 'IFAB-09', 'IFAB-10', 'IFAB-11', 'IFAB-13', 'IFAB-14', 'IFAB-15', 'IFAB-19', 'IFAB-22', 'IFAB-24'] |
| 29 | +test2 = ['Test 7', 'Test 8', 'Test 9', 'Test 10', 'Test 11', 'Test 13', 'Test 14', 'Test 15', 'Test 19', 'Test 22', 'Test 24'] |
| 30 | +single_level = [50] |
| 31 | +setpoint = [10000, 400, 399, 338, 240, 322, 390, 420, 360, 10000, 10000] |
| 32 | + |
| 33 | +plot_style = fdsplotlib.get_plot_style("fds") |
| 34 | + |
| 35 | +def addverstr(ax, git_filename, style, x, y, fontname, interpreter, fontsize): |
| 36 | + """Add version string to plot - placeholder implementation""" |
| 37 | + # This function would read git information and add it to the plot |
| 38 | + # For now, we'll add a placeholder text |
| 39 | + if os.path.exists(git_filename): |
| 40 | + ax.text(x, y, 'Git Version Info', transform=ax.transAxes, |
| 41 | + fontname=fontname, fontsize=fontsize) |
| 42 | + |
| 43 | +for k in range(11): # Experiments (0-based indexing in Python) |
| 44 | + |
| 45 | + n_res = 1 |
| 46 | +# if k==7: # k==8 in MATLAB (1-based) corresponds to k==7 in Python (0-based) |
| 47 | +# n_res = 2 |
| 48 | + |
| 49 | + for jj in range(n_res): |
| 50 | + |
| 51 | + # clear M E - handled by reassignment |
| 52 | + |
| 53 | + if jj == 0: |
| 54 | + # M = importdata([outdir,test{k},'_cat_devc.csv'],',',2); |
| 55 | + M_data = pd.read_csv(outdir + test[k] + '_cat_devc.csv', skiprows=2) |
| 56 | + M = {'data': M_data.values} |
| 57 | + |
| 58 | + # E = importdata([expdir,test{k},'_avg.csv'],',',2); |
| 59 | + E_data = pd.read_csv(expdir + test[k] + '_avg.csv', skiprows=2) |
| 60 | + E = {'data': E_data.values} |
| 61 | + elif jj == 1: |
| 62 | + # M = importdata([outdir,test{k},'_fine_cat_devc.csv'],',',2); |
| 63 | + M_data = pd.read_csv(outdir + test[k] + '_fine_cat_devc.csv', skiprows=2) |
| 64 | + M = {'data': M_data.values} |
| 65 | + |
| 66 | + # E = importdata([expdir,test{k},'_avg.csv'],',',2); |
| 67 | + E_data = pd.read_csv(expdir + test[k] + '_avg.csv', skiprows=2) |
| 68 | + E = {'data': E_data.values} |
| 69 | + |
| 70 | + # For each experiment, make a contour plot of the extent of a single temperature contour at each time during the experiment |
| 71 | + |
| 72 | + # clear X_mod Y_mod Z_mod X_exp Y_exp Z_exp |
| 73 | + |
| 74 | + # [X_mod,Y_mod] = meshgrid(pos(1:16),M.data(:,1)/60); |
| 75 | + X_mod, Y_mod = np.meshgrid(pos[0:16], M['data'][:, 0]/60) |
| 76 | + |
| 77 | + # [X_exp,Y_exp] = meshgrid(pos(1:16),E.data(:,1)/60); |
| 78 | + X_exp, Y_exp = np.meshgrid(pos[0:16], E['data'][:, 0]/60) |
| 79 | + |
| 80 | + # Initialize Z_mod and Z_exp |
| 81 | + Z_mod = np.zeros((len(M['data'][:, 0]), 16)) |
| 82 | + Z_exp = np.zeros((len(E['data'][:, 0]), 16)) |
| 83 | + |
| 84 | + for kk in range(len(M['data'][:, 0])): |
| 85 | + for ii in range(16): |
| 86 | + Z_mod[kk, ii] = M['data'][kk, ii+1] |
| 87 | + |
| 88 | + for kk in range(len(E['data'][:, 0])): |
| 89 | + for ii in range(16): |
| 90 | + Z_exp[kk, ii] = E['data'][kk, ii+4] |
| 91 | + |
| 92 | + newpoints = 100 |
| 93 | + # [X_mod_interp,Y_mod_interp] = meshgrid(... |
| 94 | + # linspace(min(min(X_mod,[],2)),max(max(X_mod,[],2)),newpoints ),... |
| 95 | + # linspace(min(min(Y_mod,[],1)),max(max(Y_mod,[],1)),newpoints )... |
| 96 | + # ); |
| 97 | + X_mod_interp, Y_mod_interp = np.meshgrid( |
| 98 | + np.linspace(np.min(X_mod), np.max(X_mod), newpoints), |
| 99 | + np.linspace(np.min(Y_mod), np.max(Y_mod), newpoints) |
| 100 | + ) |
| 101 | + |
| 102 | + # Z_mod_interp = interp2(X_mod,Y_mod,Z_mod,X_mod_interp,Y_mod_interp,'makima'); |
| 103 | + # Flatten the arrays for griddata |
| 104 | + points_mod = np.column_stack((X_mod.ravel(), Y_mod.ravel())) |
| 105 | + values_mod = Z_mod.ravel() |
| 106 | + Z_mod_interp = griddata(points_mod, values_mod, |
| 107 | + (X_mod_interp, Y_mod_interp), method='cubic') |
| 108 | + |
| 109 | + # [X_exp_interp,Y_exp_interp] = meshgrid(... |
| 110 | + # linspace(min(min(X_exp,[],2)),max(max(X_exp,[],2)),newpoints ),... |
| 111 | + # linspace(min(min(Y_exp,[],1)),max(max(Y_exp,[],1)),newpoints )... |
| 112 | + # ); |
| 113 | + X_exp_interp, Y_exp_interp = np.meshgrid( |
| 114 | + np.linspace(np.min(X_exp), np.max(X_exp), newpoints), |
| 115 | + np.linspace(np.min(Y_exp), np.max(Y_exp), newpoints) |
| 116 | + ) |
| 117 | + |
| 118 | + # Z_exp_interp = interp2(X_exp,Y_exp,Z_exp,X_exp_interp,Y_exp_interp,'makima'); |
| 119 | + points_exp = np.column_stack((X_exp.ravel(), Y_exp.ravel())) |
| 120 | + values_exp = Z_exp.ravel() |
| 121 | + Z_exp_interp = griddata(points_exp, values_exp, |
| 122 | + (X_exp_interp, Y_exp_interp), method='cubic') |
| 123 | + |
| 124 | + if jj == 0: |
| 125 | + # reset(gca) |
| 126 | + # reset(gcf) |
| 127 | + plt.figure(figsize=(plot_style["Paper_Width"], plot_style["Paper_Height"])) |
| 128 | + mod_symbol = 'r-' |
| 129 | + else: |
| 130 | + mod_symbol = 'r--' |
| 131 | + |
| 132 | + # [C_mod,h_mod] = contour(X_mod_interp,Y_mod_interp,Z_mod_interp,single_level,mod_symbol) ; hold on |
| 133 | + CS_mod = plt.contour(X_mod_interp, Y_mod_interp, Z_mod_interp, single_level, colors='red', |
| 134 | + linestyles='-' if jj == 0 else '--') |
| 135 | + plt.clabel(CS_mod, fontsize=3, colors='red', inline_spacing=300) |
| 136 | + |
| 137 | + # [C_exp,h_exp] = contour(X_exp_interp,Y_exp_interp,Z_exp_interp,single_level,'k-') ; hold on |
| 138 | + CS_exp = plt.contour(X_exp_interp, Y_exp_interp, Z_exp_interp, single_level, colors='black', linestyles='-') |
| 139 | + plt.clabel(CS_exp, fontsize=3, colors='black', inline_spacing=300) |
| 140 | + |
| 141 | + # end grid resolution cases |
| 142 | + |
| 143 | + # plot([5.5 5.5],[0 15],'k--') |
| 144 | + plt.plot([5.5, 5.5], [0, 15], 'k--') |
| 145 | + |
| 146 | + # plot([0.0 15.],[setpoint(k)/60 setpoint(k)/60],'k:') |
| 147 | + plt.plot([0.0, 15.0], [setpoint[k]/60, setpoint[k]/60], 'k:') |
| 148 | + |
| 149 | + # xticks(pos) |
| 150 | + # xticklabels({'1.0','1.5','2.0','2.5','3.0','3.5','4.0','4.5','5.0','5.5','6.0','6.5','7.5','9.5','10.5','11.5'}) |
| 151 | + # ax = gca; |
| 152 | + ax = plt.gca() |
| 153 | + |
| 154 | + # ax.XAxis.FontSize = 16; |
| 155 | + # ax.YAxis.FontSize = 16; |
| 156 | + ax.tick_params(axis='both', which='major', labelsize=16) |
| 157 | + |
| 158 | + # xlabel('Position (m)','FontSize',16,'Interpreter',Font_Interpreter) |
| 159 | + plt.xlabel('Position (m)', fontsize=16) |
| 160 | + |
| 161 | + # ylabel('Time (min)','FontSize',16,'Interpreter',Font_Interpreter) |
| 162 | + plt.ylabel('Time (min)', fontsize=16) |
| 163 | + |
| 164 | + plt.subplots_adjust(left=plot_style["Plot_X"]/plot_style["Paper_Width"], bottom=plot_style["Plot_Y"]/plot_style["Paper_Height"], |
| 165 | + right=(plot_style["Plot_X"]+plot_style["Plot_Width"])/plot_style["Paper_Width"], |
| 166 | + top=(plot_style["Plot_Y"]+plot_style["Plot_Height"])/plot_style["Paper_Height"]) |
| 167 | + |
| 168 | + plt.rcParams['font.family'] = plot_style["Font_Name"] |
| 169 | + |
| 170 | + plt.axis([0, 15, 0, 15]) |
| 171 | + |
| 172 | + plt.text(0.5, 4, test2[k], fontname=plot_style["Font_Name"], fontsize=10) |
| 173 | + plt.text(0.5, 3, 'FDS red; Exp black', fontname=plot_style["Font_Name"], fontsize=10) |
| 174 | + |
| 175 | + # Git_Filename = [outdir,test{k},'_cat_git.txt']; |
| 176 | + Git_Filename = outdir + test[k] + '_cat_git.txt' |
| 177 | + |
| 178 | + # addverstr(gca,Git_Filename,'linear',0.6,1.05,'Times','TeX',10) |
| 179 | + addverstr(ax, Git_Filename, 'linear', 0.6, 1.05, 'Times', 'TeX', 10) |
| 180 | + |
| 181 | + # set(gcf,'Units',Paper_Units); |
| 182 | + # set(gcf,'PaperUnits',Paper_Units); |
| 183 | + # set(gcf,'PaperSize',[Paper_Width Paper_Height]); |
| 184 | + # set(gcf,'Position',[0 0 Paper_Width Paper_Height]); |
| 185 | + fig = plt.gcf() |
| 186 | + fig.set_size_inches(plot_style["Paper_Width"], plot_style["Paper_Height"]) |
| 187 | + |
| 188 | + # print(gcf,'-dpdf',[pltdir,test{k},'_tvT']) |
| 189 | + plt.savefig(pltdir + test[k] + '_tvT.pdf', format='pdf', bbox_inches='tight') |
| 190 | + |
| 191 | + # hold off |
| 192 | + plt.clf() # Clear the figure for next iteration |
| 193 | + |
| 194 | +# end Experiment loop |
| 195 | + |
| 196 | +print('FHWA_Tunnel completed successfully') |
| 197 | + |
| 198 | + |
0 commit comments