Skip to content

Commit

Permalink
Allow single variable global time series plots
Browse files Browse the repository at this point in the history
  • Loading branch information
forsyth2 committed Jul 30, 2024
1 parent 8e1b02c commit d982e7c
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
1 change: 1 addition & 0 deletions tests/integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,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",
Expand Down
84 changes: 72 additions & 12 deletions zppy/templates/coupled_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,22 +599,33 @@ 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)

counter = 0
# 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])
if plots_per_page == 1:
fig = plt.figure(1, figsize=[13.5 / 2, 16.5 / 4])
else:
fig = plt.figure(1, figsize=[13.5, 16.5])
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.
Expand Down Expand Up @@ -661,7 +672,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)
Expand Down Expand Up @@ -725,6 +738,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")
Expand Down Expand Up @@ -820,19 +835,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}")
Expand All @@ -842,7 +902,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"
Expand Down
4 changes: 4 additions & 0 deletions zppy/templates/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion zppy/templates/global_time_series.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d982e7c

Please sign in to comment.