From 9b6ee2d83ce2ae5d049a7d6162ae7c1201611a7e Mon Sep 17 00:00:00 2001 From: Ryan Forsyth Date: Tue, 23 Jul 2024 15:20:22 -0500 Subject: [PATCH] Allow single variable global time series plots --- ...se_global_time_series_custom_chrysalis.cfg | 4 +- ...bal_time_series_single_plots_chrysalis.cfg | 46 +++++++++++ ...ate_min_case_global_time_series_custom.cfg | 4 +- ...n_case_global_time_series_single_plots.cfg | 46 +++++++++++ tests/integration/utils.py | 1 + zppy/templates/coupled_global.py | 81 ++++++++++++++++--- zppy/templates/default.ini | 4 + zppy/templates/global_time_series.bash | 2 +- 8 files changed, 171 insertions(+), 17 deletions(-) create mode 100644 tests/integration/generated/test_min_case_global_time_series_single_plots_chrysalis.cfg create mode 100644 tests/integration/template_min_case_global_time_series_single_plots.cfg diff --git a/tests/integration/generated/test_min_case_global_time_series_custom_chrysalis.cfg b/tests/integration/generated/test_min_case_global_time_series_custom_chrysalis.cfg index 3a648737..3204bde9 100644 --- a/tests/integration/generated/test_min_case_global_time_series_custom_chrysalis.cfg +++ b/tests/integration/generated/test_min_case_global_time_series_custom_chrysalis.cfg @@ -23,7 +23,7 @@ years = "1985:1995:5", input_files = "eam.h0" input_subdir = "archive/atm/hist" mapping_file = "glb" - vars = "TREFHT,AODDUST" + vars = "TREFHT" [[ lnd_monthly_glb ]] frequency = "monthly" @@ -37,7 +37,7 @@ active = True experiment_name = "v3.LR.historical_0051" figstr = "v3.LR.historical_0051" plots_original="" -plots_atm = "TREFHT,AODDUST" +plots_atm = "TREFHT" plots_lnd = "FSH,RH2M,LAISHA,LAISUN,QINTR,QOVER,QRUNOFF,QSOIL,QVEGE,QVEGT,SOILWATER_10CM,TSA,H2OSNO,TOTLITC,CWDC,SOIL1C,SOIL2C,SOIL3C,SOIL4C,WOOD_HARVESTC,TOTVEGC,NBP,GPP,AR,HR" ts_num_years = 5 walltime = "00:30:00" diff --git a/tests/integration/generated/test_min_case_global_time_series_single_plots_chrysalis.cfg b/tests/integration/generated/test_min_case_global_time_series_single_plots_chrysalis.cfg new file mode 100644 index 00000000..6c941dec --- /dev/null +++ b/tests/integration/generated/test_min_case_global_time_series_single_plots_chrysalis.cfg @@ -0,0 +1,46 @@ +[default] +case = "v3.LR.historical_0051" +constraint = "" +dry_run = "False" +environment_commands = "" +input = /lcrc/group/e3sm2/ac.wlin/E3SMv3/v3.LR.historical_0051 +input_subdir = archive/atm/hist +mapping_file = "map_ne30pg2_to_cmip6_180x360_aave.20200201.nc" +output = "/lcrc/group/e3sm/ac.forsyth2/zppy_min_case_global_time_series_single_plots_output/unique_id/v3.LR.historical_0051" +partition = "debug" +qos = "regular" +www = "/lcrc/group/e3sm/public_html/diagnostic_output/ac.forsyth2/zppy_min_case_global_time_series_single_plots_www/unique_id" + +[ts] +active = True +e3sm_to_cmip_environment_commands = "" +walltime = "00:30:00" +years = "1985:1995:5", + + [[ atm_monthly_glb ]] + # Note global average won't work for 3D variables. + frequency = "monthly" + input_files = "eam.h0" + input_subdir = "archive/atm/hist" + mapping_file = "glb" + vars = "TREFHT" + + [[ lnd_monthly_glb ]] + frequency = "monthly" + input_files = "elm.h0" + input_subdir = "archive/lnd/hist" + mapping_file = "glb" + vars = "FSH,RH2M,LAISHA" + +[global_time_series] +active = True +experiment_name = "v3.LR.historical_0051" +figstr = "v3.LR.historical_0051" +ncols = 1 +nrows = 1 +plots_original="" +plots_atm = "TREFHT" +plots_lnd = "FSH,RH2M,LAISHA" +ts_num_years = 5 +walltime = "00:30:00" +years = "1985-1995", diff --git a/tests/integration/template_min_case_global_time_series_custom.cfg b/tests/integration/template_min_case_global_time_series_custom.cfg index 538ac7ac..f35eb364 100644 --- a/tests/integration/template_min_case_global_time_series_custom.cfg +++ b/tests/integration/template_min_case_global_time_series_custom.cfg @@ -23,7 +23,7 @@ years = "1985:1995:5", input_files = "eam.h0" input_subdir = "archive/atm/hist" mapping_file = "glb" - vars = "TREFHT,AODDUST" + vars = "TREFHT" [[ lnd_monthly_glb ]] frequency = "monthly" @@ -37,7 +37,7 @@ active = True experiment_name = "#expand case_name#" figstr = "#expand case_name#" plots_original="" -plots_atm = "TREFHT,AODDUST" +plots_atm = "TREFHT" plots_lnd = "FSH,RH2M,LAISHA,LAISUN,QINTR,QOVER,QRUNOFF,QSOIL,QVEGE,QVEGT,SOILWATER_10CM,TSA,H2OSNO,TOTLITC,CWDC,SOIL1C,SOIL2C,SOIL3C,SOIL4C,WOOD_HARVESTC,TOTVEGC,NBP,GPP,AR,HR" ts_num_years = 5 walltime = "00:30:00" diff --git a/tests/integration/template_min_case_global_time_series_single_plots.cfg b/tests/integration/template_min_case_global_time_series_single_plots.cfg new file mode 100644 index 00000000..f28ff7df --- /dev/null +++ b/tests/integration/template_min_case_global_time_series_single_plots.cfg @@ -0,0 +1,46 @@ +[default] +case = "#expand case_name#" +constraint = "#expand constraint#" +dry_run = "#expand dry_run#" +environment_commands = "#expand environment_commands#" +input = /lcrc/group/e3sm2/ac.wlin/E3SMv3/#expand case_name# +input_subdir = archive/atm/hist +mapping_file = "map_ne30pg2_to_cmip6_180x360_aave.20200201.nc" +output = "#expand user_output#zppy_min_case_global_time_series_single_plots_output/#expand unique_id#/#expand case_name#" +partition = "#expand partition_short#" +qos = "#expand qos_short#" +www = "#expand user_www#zppy_min_case_global_time_series_single_plots_www/#expand unique_id#" + +[ts] +active = True +e3sm_to_cmip_environment_commands = "#expand e3sm_to_cmip_environment_commands#" +walltime = "00:30:00" +years = "1985:1995:5", + + [[ atm_monthly_glb ]] + # Note global average won't work for 3D variables. + frequency = "monthly" + input_files = "eam.h0" + input_subdir = "archive/atm/hist" + mapping_file = "glb" + vars = "TREFHT" + + [[ lnd_monthly_glb ]] + frequency = "monthly" + input_files = "elm.h0" + input_subdir = "archive/lnd/hist" + mapping_file = "glb" + vars = "FSH,RH2M,LAISHA" + +[global_time_series] +active = True +experiment_name = "#expand case_name#" +figstr = "#expand case_name#" +ncols = 1 +nrows = 1 +plots_original="" +plots_atm = "TREFHT" +plots_lnd = "FSH,RH2M,LAISHA" +ts_num_years = 5 +walltime = "00:30:00" +years = "1985-1995", diff --git a/tests/integration/utils.py b/tests/integration/utils.py index 9a65b059..050a1edb 100644 --- a/tests/integration/utils.py +++ b/tests/integration/utils.py @@ -292,6 +292,7 @@ def generate_cfgs(unified_testing=False, dry_run=False): "min_case_global_time_series_custom", "min_case_global_time_series_original_8_no_ocn", "min_case_global_time_series_original_8", + "min_case_global_time_series_single_plots", "min_case_ilamb_land_only", "min_case_ilamb", "min_case_mpas_analysis", diff --git a/zppy/templates/coupled_global.py b/zppy/templates/coupled_global.py index 762e7724..5b6c819d 100644 --- a/zppy/templates/coupled_global.py +++ b/zppy/templates/coupled_global.py @@ -599,14 +599,22 @@ def set_var( del ts -def make_plot_pdfs( - figstr, rgn, component, xlim, exps, plot_list, valid_plots, invalid_plots +# FIXME: C901 'main' is too complex (19) +def make_plot_pdfs( # noqa: C901 + figstr, + rgn, + component, + xlim, + exps, + plot_list, + valid_plots, + invalid_plots, + nrows, + ncols, ): num_plots = len(plot_list) if num_plots == 0: return - nrows = 4 - ncols = 2 plots_per_page = nrows * ncols num_pages = math.ceil(num_plots / plots_per_page) @@ -614,7 +622,7 @@ def make_plot_pdfs( # https://stackoverflow.com/questions/58738992/save-multiple-figures-with-subplots-into-a-pdf-with-multiple-pages pdf = matplotlib.backends.backend_pdf.PdfPages(f"{figstr}_{rgn}_{component}.pdf") for page in range(num_pages): - fig = plt.figure(1, figsize=[13.5, 16.5]) + fig = plt.figure(1, figsize=[13.5 / 2, 16.5 / 4]) fig.suptitle(f"{figstr}_{rgn}_{component}") for j in range(plots_per_page): # The final page doesn't need to be filled out with plots. @@ -661,7 +669,9 @@ def make_plot_pdfs( fig.tight_layout() pdf.savefig(1) - if num_pages > 1: + if plots_per_page == 1: + fig.savefig(f"{figstr}_{rgn}_{component}_{plot_name}.png", dpi=150) + elif num_pages > 1: fig.savefig(f"{figstr}_{rgn}_{component}_{page}.png", dpi=150) else: fig.savefig(f"{figstr}_{rgn}_{component}.png", dpi=150) @@ -725,6 +735,8 @@ def run(parameters, rgn): # noqa: C901 plots_ice = param_get_list(parameters[11]) plots_lnd = param_get_list(parameters[12]) plots_ocn = param_get_list(parameters[13]) + nrows = int(parameters[14]) + ncols = int(parameters[15]) vars_original = [] if "net_toa_flux_restom" or "net_atm_energy_imbalance" in plots_original: vars_original.append("RESTOM") @@ -820,19 +832,64 @@ def run(parameters, rgn): # noqa: C901 invalid_plots: List[str] = [] make_plot_pdfs( - figstr, rgn, "original", xlim, exps, plots_original, valid_plots, invalid_plots + figstr, + rgn, + "original", + xlim, + exps, + plots_original, + valid_plots, + invalid_plots, + nrows, + ncols, ) make_plot_pdfs( - figstr, rgn, "atm", xlim, exps, plots_atm, valid_plots, invalid_plots + figstr, + rgn, + "atm", + xlim, + exps, + plots_atm, + valid_plots, + invalid_plots, + nrows, + ncols, ) make_plot_pdfs( - figstr, rgn, "ice", xlim, exps, plots_ice, valid_plots, invalid_plots + figstr, + rgn, + "ice", + xlim, + exps, + plots_ice, + valid_plots, + invalid_plots, + nrows, + ncols, ) make_plot_pdfs( - figstr, rgn, "lnd", xlim, exps, plots_lnd, valid_plots, invalid_plots + figstr, + rgn, + "lnd", + xlim, + exps, + plots_lnd, + valid_plots, + invalid_plots, + nrows, + ncols, ) make_plot_pdfs( - figstr, rgn, "ocn", xlim, exps, plots_ocn, valid_plots, invalid_plots + figstr, + rgn, + "ocn", + xlim, + exps, + plots_ocn, + valid_plots, + invalid_plots, + nrows, + ncols, ) print(f"These {rgn} region plots generated successfully: {valid_plots}") @@ -842,7 +899,7 @@ def run(parameters, rgn): # noqa: C901 def run_by_region(parameters): - regions = parameters[14].split(",") + regions = parameters[16].split(",") for rgn in regions: if rgn.lower() in ["glb", "global"]: rgn = "glb" diff --git a/zppy/templates/default.ini b/zppy/templates/default.ini index 1e456999..99f486ea 100644 --- a/zppy/templates/default.ini +++ b/zppy/templates/default.ini @@ -304,6 +304,10 @@ figstr = string(default="") # NOTE: always overrides value in [default] input_subdir = string(default="archive/ocn/hist") moc_file = string(default="") +# Number of columns per page +ncols = integer(default=2) +# Number of rows per page +nrows = integer(default=4) # Deprecated; legacy name for plots_original; kept for backwards compatibility # plots_original replaces it with the same default. # So, if a cfg used the default value before, the behavior will remain the same. diff --git a/zppy/templates/global_time_series.bash b/zppy/templates/global_time_series.bash index 22dee4d7..d5278cca 100644 --- a/zppy/templates/global_time_series.bash +++ b/zppy/templates/global_time_series.bash @@ -68,7 +68,7 @@ fi echo 'Update time series figures' cd ${global_ts_dir} atmosphere_only={{ atmosphere_only }} -python coupled_global.py ${case_dir} ${experiment_name} ${figstr} ${start_yr} ${end_yr} {{ color }} ${ts_num_years} {{ plots_original }} ${atmosphere_only,,} {{ plots_atm }} {{ plots_ice }} {{ plots_lnd }} {{ plots_ocn }} {{ regions }} +python coupled_global.py ${case_dir} ${experiment_name} ${figstr} ${start_yr} ${end_yr} {{ color }} ${ts_num_years} {{ plots_original }} ${atmosphere_only,,} {{ plots_atm }} {{ plots_ice }} {{ plots_lnd }} {{ plots_ocn }} {{ nrows }} {{ ncols }} {{ regions }} if [ $? != 0 ]; then cd {{ scriptDir }} echo 'ERROR (6)' > {{ prefix }}.status