|
1 | 1 | import numpy as np |
2 | 2 | import matplotlib.pyplot as plt |
3 | | -import os |
| 3 | +import os, sys |
4 | 4 | import pandas as pd |
| 5 | +from matplotlib.ticker import ScalarFormatter |
5 | 6 |
|
6 | 7 | # include FDS plot styles, etc. |
| 8 | +filedir = os.path.dirname(__file__) |
| 9 | +firemodels = os.path.join(filedir,'..','..','..','..') |
| 10 | +sys.path.append(filedir+os.sep+'..'+os.sep) |
7 | 11 | import fdsplotlib |
8 | 12 |
|
| 13 | + |
9 | 14 | # Get plot style parameters |
| 15 | +plt.rcParams["pdf.use14corefonts"] = True # forces matplotlib to write native pdf fonts rather then embed |
10 | 16 | plot_style = fdsplotlib.get_plot_style("fds") |
11 | | -plt.rcParams['text.usetex'] = True # supports latex math (set per plot below) |
12 | | -plt.rcParams["pdf.use14corefonts"] = True # forces matplotlib to write native pdf fonts rather than embed |
13 | | -plt.rcParams["font.family"] = plot_style["Font_Name"] |
14 | | -plt.rcParams["font.size"] = plot_style["Label_Font_Size"] |
15 | 17 |
|
16 | 18 | # Define paths |
17 | | -base_path = "../../../out/USFS_Catchpole/" |
18 | | -fig_path = "../../Manuals/FDS_Validation_Guide/SCRIPT_FIGURES/USFS_Catchpole/" |
| 19 | +base_path = os.path.join(firemodels,'out','USFS_Catchpole') |
| 20 | +fig_path = os.path.join(firemodels,'fds','Manuals','FDS_Validation_Guide','SCRIPT_FIGURES','USFS_Catchpole') |
| 21 | +validation_path = os.path.join(firemodels,'fds','Validation','USFS_Catchpole','FDS_Input_Files') |
19 | 22 |
|
20 | 23 | # Experiment parameters |
21 | | -tests = pd.read_csv("../../Validation/USFS_Catchpole/FDS_Input_Files/Test_Matrix.csv") |
| 24 | +tests = pd.read_csv(os.path.join(validation_path,"Test_Matrix.csv")) |
22 | 25 |
|
23 | 26 | for ti,test in tests.iterrows(): |
24 | | - chid = test['Test'] |
| 27 | + R = tests['R'].iloc[ti] |
| 28 | + chid = tests['Test'].iloc[ti] |
25 | 29 | fds_file = os.path.join(base_path, f"{chid}_devc.csv") |
26 | 30 | git_file = os.path.join(base_path, f"{chid}_git.txt") |
27 | 31 | fig_file = os.path.join(fig_path, f"{chid}.pdf") |
|
44 | 48 | if R_FDS<0: |
45 | 49 | R_FDS=0 |
46 | 50 |
|
47 | | - fig, ax = plt.subplots(figsize=(plot_style["Paper_Width"], plot_style["Paper_Height"])) |
48 | | - |
49 | 51 | # Exp results |
50 | 52 | x_exp = np.array([0., 8.]) |
51 | | - t_exp = np.array([0., 8./test['R']]) |
52 | | - ax.plot(t_exp,x_exp,'k-',label='Exp') |
53 | | - |
54 | | - # FDS results |
55 | | - ax.plot(fds_data['Time'],fds_data['x'],'k--',label='FDS') |
56 | | - |
57 | | - # plot attributes |
58 | | - ax.set_xlabel("Time (s)", |
59 | | - fontdict={"fontname": plot_style["Font_Name"], |
60 | | - "fontsize": plot_style["Label_Font_Size"]}) |
61 | | - ax.set_ylabel("Distance (m)", |
62 | | - fontdict={"fontname": plot_style["Font_Name"], |
63 | | - "fontsize": plot_style["Label_Font_Size"]}) |
64 | | - t_end = max(fds_data['Time'].max(),8./test['R']) |
65 | | - ax.set_xlim([0, t_end]) |
66 | | - ax.set_ylim([0, 8.]) |
67 | | - plt.legend(loc="lower right", fontsize=plot_style["Key_Font_Size"], |
68 | | - framealpha=1,frameon=True) |
69 | | - ax.set_title(chid,fontsize=plot_style["Title_Font_Size"], |
70 | | - loc="left",x=0.05,y=0.9) |
71 | | - |
72 | | - # add version sting |
73 | | - version_str = fdsplotlib.get_version_string(git_file) |
74 | | - fdsplotlib.add_version_string(ax, version_str, plot_type='linear') |
75 | | - |
76 | | - fig.tight_layout() |
77 | | - plt.savefig(fig_file) |
| 53 | + t_exp = np.array([0., 8./R]) |
| 54 | + version_string = fdsplotlib.get_version_string(git_file) |
| 55 | + fig = fdsplotlib.plot_to_fig(x_data=t_exp, y_data=x_exp, |
| 56 | + data_label='EXP', |
| 57 | + marker_style='k-') |
| 58 | + |
| 59 | + fig = fdsplotlib.plot_to_fig(x_data=fds_data['Time'].values, y_data=fds_data['x'].values, |
| 60 | + revision_label=version_string, |
| 61 | + figure_handle=fig, |
| 62 | + data_label='FDS', |
| 63 | + x_label='Time (s)', |
| 64 | + y_label='Distance (m)', |
| 65 | + marker_style='k--', |
| 66 | + y_min=0.,y_max=8., |
| 67 | + x_min=0.,x_max=8./R, |
| 68 | + legend_location="lower right", |
| 69 | + show_legend='show', |
| 70 | + ) |
| 71 | + |
| 72 | + ax = fig.axes[0] |
| 73 | + fdsplotlib.add_version_string(ax, chid, plot_type='linear', scale_x=0.05, scale_y=0.9, font_size=plot_style['Label_Font_Size']) |
| 74 | + |
| 75 | + #fig.supertitle(chid) |
| 76 | + fig.savefig(fig_file, backend='pdf') |
78 | 77 | plt.close() |
79 | 78 |
|
80 | 79 | # write table for dataplot |
81 | | - test['R_FDS'] = R_FDS |
| 80 | + tests.loc[tests['Test'].index[ti],'R_FDS'] = R_FDS |
| 81 | + test = tests.iloc[ti] |
82 | 82 | test = test.drop('Test') |
83 | 83 | out_file = os.path.join(base_path,f"{chid}_FDS.csv") |
84 | 84 | pd.DataFrame([test]).to_csv(out_file,index=False) |
85 | 85 |
|
86 | 86 | # add fds data to full table for summary plotting |
87 | 87 | tests.loc[ti,'R_FDS'] = R_FDS |
88 | 88 |
|
89 | | - |
90 | 89 | ##### Create summary plots |
91 | 90 |
|
92 | 91 | # variables of interest |
|
97 | 96 |
|
98 | 97 | # fuel labels for filtering data |
99 | 98 | fuel_labels=["MF","EXSC","PPMC","EX"] |
100 | | - |
101 | 99 | for dvar in dep_variables: |
102 | | - |
| 100 | + plt.rcParams['mathtext.fontset'] = 'stix' #'dejavuserif' |
| 101 | + plt.rcParams['mathtext.default'] = 'rm' |
| 102 | + plt.rcParams['axes.formatter.use_mathtext'] = False |
103 | 103 | fig_file = os.path.join(fig_path, f"Catchpole_R_v_{dvar}.pdf") |
104 | | - fig, ax = plt.subplots(figsize=(plot_style["Paper_Width"], plot_style["Paper_Height"])) |
105 | 104 |
|
106 | 105 | # show +/- 20% relative error |
107 | 106 | [xmin,xmax] = [tests[dvar].min(),tests[dvar].max()] |
108 | | - ax.semilogy([xmin,xmax],[0.8,0.8],'k--') |
109 | | - ax.semilogy([xmin,xmax],[1.2,1.2],'k--') |
110 | | - |
111 | | - for fuel in fuel_labels: |
| 107 | + colors = ['b','g','r','c','m','y','k'] # matlab defauls |
| 108 | + fig = fdsplotlib.plot_to_fig(x_data=[xmin, xmax], y_data=[0.8,0.8], |
| 109 | + plot_type='semilogy', marker_style='k--',) |
| 110 | + for i in range(0, len(fuel_labels)): |
| 111 | + fuel = fuel_labels[i] |
112 | 112 | filtered_data = tests[tests['Test'].str.startswith(fuel)] |
| 113 | + color = colors[i] |
113 | 114 | if fuel=='EX': |
114 | 115 | filtered_data = tests[ |
115 | 116 | (tests['Test'].str.startswith(fuel))&(~tests['Test'].str.startswith('EXSC'))] |
116 | | - |
117 | | - ax.semilogy(filtered_data[dvar],filtered_data['R_FDS']/filtered_data['R'], |
118 | | - '.',label=fuel) |
119 | | - |
120 | | - # plot attributes |
121 | | - ax.set_xlabel(dep_variables[dvar], |
122 | | - fontdict={"fontname": plot_style["Font_Name"], |
123 | | - "fontsize": plot_style["Label_Font_Size"]}) |
124 | | - ax.set_ylabel("$R_{FDS}/R_{Exp}$ (-)", |
125 | | - fontdict={"fontname": plot_style["Font_Name"], |
126 | | - "fontsize": plot_style["Label_Font_Size"]}) |
127 | | - plt.legend(fontsize=plot_style["Key_Font_Size"], |
128 | | - framealpha=1,frameon=True) |
129 | | - ax.set_xlim([xmin,xmax]) |
| 117 | + fig = fdsplotlib.plot_to_fig(x_data=filtered_data[dvar], y_data=filtered_data['R_FDS']/filtered_data['R'], |
| 118 | + data_label=fuel, plot_type='semilogy', marker_style=colors[i]+'o', figure_handle=fig) |
| 119 | + fig = fdsplotlib.plot_to_fig(x_data=[xmin, xmax], y_data=[1.2,1.2], |
| 120 | + plot_type='semilogy', marker_style='k--', figure_handle=fig, |
| 121 | + x_min=xmin, x_max=xmax, y_min=3e-3, y_max=1.1e1, |
| 122 | + x_label=dep_variables[dvar],y_label=r"$\mathrm{R_{FDS}/R_{Exp}}$ $\mathrm{(-)}$", |
| 123 | + show_legend='show', legend_framealpha=1.0, legend_location=2) |
| 124 | + plt.gca().yaxis.set_major_formatter(ScalarFormatter()) |
130 | 125 |
|
131 | 126 | # add version sting |
132 | 127 | version_str = fdsplotlib.get_version_string(git_file) |
|
137 | 132 | plt.close() |
138 | 133 |
|
139 | 134 |
|
| 135 | + |
| 136 | + |
| 137 | + |
140 | 138 | # plot no-spread conditions |
141 | 139 |
|
142 | 140 | fig_file = os.path.join(fig_path, "Catchpole_no_spread.pdf") |
|
0 commit comments