|
1 | | -import os |
2 | | - |
3 | 1 | import cartopy.crs as ccrs |
4 | 2 | import cartopy.feature as cfeature |
5 | 3 | import matplotlib |
6 | 4 | import numpy as np |
7 | 5 | import xcdat as xc |
8 | 6 | from cartopy.mpl.ticker import LatitudeFormatter, LongitudeFormatter |
9 | 7 |
|
10 | | -from e3sm_diags.driver.utils.io import _get_output_dir |
11 | 8 | from e3sm_diags.logger import _setup_child_logger |
12 | | -from e3sm_diags.plot.utils import MAIN_TITLE_FONTSIZE |
| 9 | +from e3sm_diags.plot.utils import MAIN_TITLE_FONTSIZE, _save_main_plot |
13 | 10 |
|
14 | 11 | matplotlib.use("agg") |
15 | 12 | import matplotlib.pyplot as plt # isort:skip # noqa: E402 |
@@ -103,16 +100,8 @@ def plot(test, ref, parameter, basin_dict): |
103 | 100 | y=0.99, |
104 | 101 | ) |
105 | 102 |
|
106 | | - output_file_name = "tc-intensity" |
107 | | - for f in parameter.output_format: |
108 | | - f = f.lower().split(".")[-1] |
109 | | - fnm = os.path.join( |
110 | | - _get_output_dir(parameter), |
111 | | - output_file_name + "." + f, |
112 | | - ) |
113 | | - plt.savefig(fnm) |
114 | | - logger.info(f"Plot saved in: {fnm}") |
115 | | - plt.close() |
| 103 | + parameter.output_file = "tc-intensity" |
| 104 | + _save_main_plot(parameter) |
116 | 105 |
|
117 | 106 | # TC frequency of each basins |
118 | 107 | fig = plt.figure(figsize=(12, 7)) |
@@ -150,16 +139,8 @@ def plot(test, ref, parameter, basin_dict): |
150 | 139 | ax.set_ylabel("Fraction") |
151 | 140 | ax.set_title("Relative frequency of TCs for each ocean basins") |
152 | 141 |
|
153 | | - output_file_name = "tc-frequency" |
154 | | - for f in parameter.output_format: |
155 | | - f = f.lower().split(".")[-1] |
156 | | - fnm = os.path.join( |
157 | | - _get_output_dir(parameter), |
158 | | - output_file_name + "." + f, |
159 | | - ) |
160 | | - plt.savefig(fnm) |
161 | | - logger.info(f"Plot saved in: {fnm}") |
162 | | - plt.close() |
| 142 | + parameter.output_file = "tc-frequency" |
| 143 | + _save_main_plot(parameter) |
163 | 144 |
|
164 | 145 | fig1 = plt.figure(figsize=(12, 6)) |
165 | 146 | ax = fig1.add_subplot(111) |
@@ -190,16 +171,9 @@ def plot(test, ref, parameter, basin_dict): |
190 | 171 | ax.set_title( |
191 | 172 | "Distribution of accumulated cyclone energy (ACE) among various ocean basins" |
192 | 173 | ) |
193 | | - output_file_name = "ace-distribution" |
194 | | - for f in parameter.output_format: |
195 | | - f = f.lower().split(".")[-1] |
196 | | - fnm = os.path.join( |
197 | | - _get_output_dir(parameter), |
198 | | - output_file_name + "." + f, |
199 | | - ) |
200 | | - plt.savefig(fnm) |
201 | | - logger.info(f"Plot saved in: {fnm}") |
202 | | - plt.close() |
| 174 | + |
| 175 | + parameter.output_file = "ace-distribution" |
| 176 | + _save_main_plot(parameter) |
203 | 177 |
|
204 | 178 | fig, axes = plt.subplots(2, 3, figsize=(12, 6), sharex=True, sharey=True) |
205 | 179 | fig.subplots_adjust(hspace=0.4, wspace=0.15) |
@@ -231,16 +205,8 @@ def plot(test, ref, parameter, basin_dict): |
231 | 205 | y=0.99, |
232 | 206 | ) |
233 | 207 |
|
234 | | - output_file_name = "tc-frequency-annual-cycle" |
235 | | - for f in parameter.output_format: |
236 | | - f = f.lower().split(".")[-1] |
237 | | - fnm = os.path.join( |
238 | | - _get_output_dir(parameter), |
239 | | - output_file_name + "." + f, |
240 | | - ) |
241 | | - plt.savefig(fnm) |
242 | | - logger.info(f"Plot saved in: {fnm}") |
243 | | - plt.close() |
| 208 | + parameter.output_file = "tc-frequency-annual-cycle" |
| 209 | + _save_main_plot(parameter) |
244 | 210 |
|
245 | 211 | ########################################################## |
246 | 212 | # Plot TC tracks density |
@@ -286,17 +252,9 @@ def plot_map(test_data, ref_data, region, parameter): |
286 | 252 |
|
287 | 253 | # Figure title |
288 | 254 | fig.suptitle(PLOT_INFO[region]["title"], x=0.5, y=0.9, fontsize=14) |
289 | | - output_file_name = "{}-density-map".format(region) |
| 255 | + parameter.output_file = "{}-density-map".format(region) |
290 | 256 |
|
291 | | - for f in parameter.output_format: |
292 | | - f = f.lower().split(".")[-1] |
293 | | - fnm = os.path.join( |
294 | | - _get_output_dir(parameter), |
295 | | - output_file_name + "." + f, |
296 | | - ) |
297 | | - plt.savefig(fnm) |
298 | | - logger.info(f"Plot saved in: {fnm}") |
299 | | - plt.close() |
| 257 | + _save_main_plot(parameter) |
300 | 258 |
|
301 | 259 |
|
302 | 260 | def plot_panel(n, fig, proj, var, var_num_years, region, title): |
|
0 commit comments