Skip to content

Commit 12efa16

Browse files
authored
Merge pull request #14461 from johodges/master
improvement to catchpole plotting script
2 parents 92e2750 + c474581 commit 12efa16

1 file changed

Lines changed: 59 additions & 61 deletions

File tree

Utilities/Python/scripts/catchpole_spread_rates.py

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
import numpy as np
22
import matplotlib.pyplot as plt
3-
import os
3+
import os, sys
44
import pandas as pd
5+
from matplotlib.ticker import ScalarFormatter
56

67
# 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)
711
import fdsplotlib
812

13+
914
# Get plot style parameters
15+
plt.rcParams["pdf.use14corefonts"] = True # forces matplotlib to write native pdf fonts rather then embed
1016
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"]
1517

1618
# 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')
1922

2023
# 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"))
2225

2326
for ti,test in tests.iterrows():
24-
chid = test['Test']
27+
R = tests['R'].iloc[ti]
28+
chid = tests['Test'].iloc[ti]
2529
fds_file = os.path.join(base_path, f"{chid}_devc.csv")
2630
git_file = os.path.join(base_path, f"{chid}_git.txt")
2731
fig_file = os.path.join(fig_path, f"{chid}.pdf")
@@ -44,49 +48,44 @@
4448
if R_FDS<0:
4549
R_FDS=0
4650

47-
fig, ax = plt.subplots(figsize=(plot_style["Paper_Width"], plot_style["Paper_Height"]))
48-
4951
# Exp results
5052
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')
7877
plt.close()
7978

8079
# 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]
8282
test = test.drop('Test')
8383
out_file = os.path.join(base_path,f"{chid}_FDS.csv")
8484
pd.DataFrame([test]).to_csv(out_file,index=False)
8585

8686
# add fds data to full table for summary plotting
8787
tests.loc[ti,'R_FDS'] = R_FDS
8888

89-
9089
##### Create summary plots
9190

9291
# variables of interest
@@ -97,36 +96,32 @@
9796

9897
# fuel labels for filtering data
9998
fuel_labels=["MF","EXSC","PPMC","EX"]
100-
10199
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
103103
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"]))
105104

106105
# show +/- 20% relative error
107106
[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]
112112
filtered_data = tests[tests['Test'].str.startswith(fuel)]
113+
color = colors[i]
113114
if fuel=='EX':
114115
filtered_data = tests[
115116
(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())
130125

131126
# add version sting
132127
version_str = fdsplotlib.get_version_string(git_file)
@@ -137,6 +132,9 @@
137132
plt.close()
138133

139134

135+
136+
137+
140138
# plot no-spread conditions
141139

142140
fig_file = os.path.join(fig_path, "Catchpole_no_spread.pdf")

0 commit comments

Comments
 (0)