diff --git a/tests/integration/generated/directions_chrysalis.md b/tests/integration/generated/directions_chrysalis.md index 395999a1..d7abb870 100644 --- a/tests/integration/generated/directions_chrysalis.md +++ b/tests/integration/generated/directions_chrysalis.md @@ -11,7 +11,7 @@ rm -rf /lcrc/group/e3sm/ac.forsyth2/zppy_test_bundles_output/v2.LR.historical_02 python tests/integration/utils.py zppy -c tests/integration/generated/test_bundles.cfg # bundle1 and bundle2 should run. After they finish, invoke zppy again to resolve remaining dependencies: -zppy -c tests/integration/test_bundles.cfg +zppy -c tests/integration/generated/test_bundles.cfg # bundle3 and ilamb should run ``` @@ -48,7 +48,7 @@ rm -rf /lcrc/group/e3sm/public_html/zppy_test_resources/expected_bundles cp -r /lcrc/group/e3sm/public_html/diagnostic_output/ac.forsyth2/zppy_test_bundles_www/v2.LR.historical_0201 /lcrc/group/e3sm/public_html/zppy_test_resources/expected_bundles mkdir -p /lcrc/group/e3sm/public_html/zppy_test_resources/expected_bundles/bundle_files cp -r /lcrc/group/e3sm/ac.forsyth2/zppy_test_bundles_output/v2.LR.historical_0201/post/scripts/bundle*.bash /lcrc/group/e3sm/public_html/zppy_test_resources/expected_bundles/bundle_files -cd #expected_bundles +cd /lcrc/group/e3sm/public_html/zppy_test_resources/expected_bundles # This file will list all the expected images. find . -type f -name '*.png' > ../image_list_expected_bundles.txt cd @@ -60,8 +60,16 @@ python -u -m unittest tests/integration/test_bundles.py ``` cd +chmod u+x tests/integration/generated/update_campaign_expected_files_chrysalis.sh ./tests/integration/generated/update_campaign_expected_files_chrysalis.sh ``` +This command also runs the test again. +If the test fails on `test_campaign_high_res_v1`, try running the lines of the loop manually: +``` +rm -rf /lcrc/group/e3sm/public_html/zppy_test_resources/test_campaign_high_res_v1_expected_files +mkdir -p /lcrc/group/e3sm/public_html/zppy_test_resources/test_campaign_high_res_v1_expected_files +mv test_campaign_high_res_v1_output/post/scripts/*.settings /lcrc/group/e3sm/public_html/zppy_test_resources/test_campaign_high_res_v1_expected_files +``` ### test_complete_run diff --git a/tests/integration/generated/update_campaign_expected_files_chrysalis.sh b/tests/integration/generated/update_campaign_expected_files_chrysalis.sh old mode 100644 new mode 100755 diff --git a/tests/integration/template_directions.md b/tests/integration/template_directions.md index 4f8175e7..cc023d11 100644 --- a/tests/integration/template_directions.md +++ b/tests/integration/template_directions.md @@ -60,8 +60,16 @@ python -u -m unittest tests/integration/test_bundles.py ``` cd +chmod u+x tests/integration/generated/update_campaign_expected_files_#expand machine#.sh ./tests/integration/generated/update_campaign_expected_files_#expand machine#.sh ``` +This command also runs the test again. +If the test fails on `test_campaign_high_res_v1`, try running the lines of the loop manually: +``` +rm -rf #expand expected_dir#test_campaign_high_res_v1_expected_files +mkdir -p #expand expected_dir#test_campaign_high_res_v1_expected_files +mv test_campaign_high_res_v1_output/post/scripts/*.settings #expand expected_dir#test_campaign_high_res_v1_expected_files +``` ### test_complete_run diff --git a/zppy/templates/coupled_global.py b/zppy/templates/coupled_global.py index 9524b680..705ba188 100644 --- a/zppy/templates/coupled_global.py +++ b/zppy/templates/coupled_global.py @@ -109,123 +109,7 @@ def add_trend( # ----------------------------------------------------------------------------- -# These are the "Tableau 20" colors as RGB. -t20: List[Tuple[float, float, float]] = [ - (31, 119, 180), - (174, 199, 232), - (255, 127, 14), - (255, 187, 120), - (44, 160, 44), - (152, 223, 138), - (214, 39, 40), - (255, 152, 150), - (148, 103, 189), - (197, 176, 213), - (140, 86, 75), - (196, 156, 148), - (227, 119, 194), - (247, 182, 210), - (127, 127, 127), - (199, 199, 199), - (188, 189, 34), - (219, 219, 141), - (23, 190, 207), - (158, 218, 229), -] -# Scale the RGB values to the [0, 1] range, which is the format matplotlib accepts. -for i in range(len(t20)): - r, g, b = t20[i] - t20[i] = (r / 255.0, g / 255.0, b / 255.0) - -# "Tableau 10" uses every other color -t10 = [] -for i in range(0, len(t20), 2): - t10.append(t20[i]) - -# ----------------------------------------------------------------------------- -# --- Atmos data --- - -# Experiments -case_dir = sys.argv[1] -experiment_name = sys.argv[2] -figstr = sys.argv[3] -year1 = sys.argv[4] -year2 = sys.argv[5] -color = sys.argv[6] -ts_num_years = sys.argv[7] -if sys.argv[8].lower() == "false": - atmosphere_only = False -else: - atmosphere_only = True -exps = [ - { - "atmos": "{}/post/atm/glb/ts/monthly/{}yr/glb.xml".format( - case_dir, ts_num_years - ), - "ocean": None - if atmosphere_only - else "{}/post/ocn/glb/ts/monthly/{}yr/glb.xml".format(case_dir, ts_num_years), - "moc": None - if atmosphere_only - else "{}/post/ocn/glb/ts/monthly/{}yr/".format(case_dir, ts_num_years), - "vol": None - if atmosphere_only - else "{}/post/ocn/glb/ts/monthly/{}yr/glb.xml".format(case_dir, ts_num_years), - "name": experiment_name, - "yoffset": 0.0, - "yr": ([{{year1}}, {{year2}}],), - "color": "{{ color }}", - } -] - -# Variables to extract -vars = ["RESTOM", "RESSURF", "TREFHT", "FSNTOA", "FLUT", "PRECC", "PRECL", "QFLX"] - -# Read data -exp: Any -for exp in exps: - print(exp["atmos"]) - ts = TS(exp["atmos"]) - exp["annual"] = {} - for var in vars: - print(var) - v = ts.globalAnnual(var) - exp["annual"][var] = v - if "year" not in exp["annual"]: - time = v.getTime() - exp["annual"]["year"] = [x.year for x in time.asComponentTime()] - del ts - - # Optionally read ohc - if exp["ocean"] is not None: - ts = TS(exp["ocean"]) - exp["annual"]["ohc"] = ts.globalAnnual("ohc") - # annomalies with respect to first year - exp["annual"]["ohc"][:] = exp["annual"]["ohc"][:] - exp["annual"]["ohc"][0] - - if exp["vol"] is not None: - ts = TS(exp["vol"]) - exp["annual"]["volume"] = ts.globalAnnual("volume") - # annomalies with respect to first year - exp["annual"]["volume"][:] = ( - exp["annual"]["volume"][:] - exp["annual"]["volume"][0] - ) - -# ----------------------------------------------------------------------------- -# --- Generate plots --- - -xlim = [float(year1), float(year2)] - -fig = plt.figure(figsize=[13.5, 16.5]) -nrows = 4 -ncols = 2 - -# xlim = [0., 31.] -# fig = plt.figure(figsize=[13.5, 9.0]) -# nrows = 2 -# ncols = 2 - - +# Function to get ylim def get_ylim(standard_range, extreme_values): standard_min = standard_range[0] standard_max = standard_range[1] @@ -244,301 +128,424 @@ def get_ylim(standard_range, extreme_values): return [ylim_min, ylim_max] -# ----------- -# First panel -# ----------- -ax = plt.subplot(nrows, ncols, 1) -ax.set_xlim(xlim) - -extreme_values = [] -for exp in exps: - year = np.array(exp["annual"]["year"]) + exp["yoffset"] - var = np.array(exp["annual"]["RESTOM"]) - extreme_values.append(np.amax(var)) - extreme_values.append(np.amin(var)) - # ax.plot(year,var,lw=1.5,marker='o',c=exp['color'],label=exp['name']) - ax.plot(year, var, lw=1.0, marker=None, c=exp["color"], label=exp["name"]) - if exp["yr"] is not None: - print(exp["name"]) - for yrs in exp["yr"]: - add_line( - year, - var, - yrs[0], - yrs[1], - format="%4.2f", - ax=ax, - lw=2, - color=exp["color"], - ) - add_trend( - year, - var, - yrs[0], - yrs[1], - format="%4.2f", - ax=ax, - lw=2, - color=exp["color"], - ) +# ----------------------------------------------------------------------------- +# Plotting functions -ax.set_ylim(get_ylim([-1.5, 1.5], extreme_values)) -ax.axhline(y=0, lw=1, c="0.5") -ax.set_title("Net TOA flux (restom)") -ax.set_xlabel("Year") -ax.set_ylabel("W m-2") -ax.legend(loc="best") - -# ------------ -# Second panel -# ------------ -ax = plt.subplot(nrows, ncols, 2) -ax.set_xlim(xlim) - -extreme_values = [] -for exp in exps: - year = np.array(exp["annual"]["year"]) + exp["yoffset"] - var = np.array(exp["annual"]["TREFHT"]) - 273.15 - extreme_values.append(np.amax(var)) - extreme_values.append(np.amin(var)) - # ax.plot(year,var,lw=1.5,marker='o',c=exp['color'],label=exp['name']) - ax.plot(year, var, lw=1.0, marker=None, c=exp["color"], label=exp["name"]) - if exp["yr"] is not None: - print(exp["name"]) - for yrs in exp["yr"]: - add_line( - year, - var, - yrs[0], - yrs[1], - format="%4.2f", - ax=ax, - lw=2, - color=exp["color"], - ) - add_trend( - year, - var, - yrs[0], - yrs[1], - format="%4.2f", - ax=ax, - lw=2, - color=exp["color"], - ) +# Net TOA flux (restom) +def plot_net_toa_flux_restom(ax, xlim, exps): + ax.set_xlim(xlim) + extreme_values = [] + for exp in exps: + year = np.array(exp["annual"]["year"]) + exp["yoffset"] + var = np.array(exp["annual"]["RESTOM"]) + extreme_values.append(np.amax(var)) + extreme_values.append(np.amin(var)) + ax.plot(year, var, lw=1.0, marker=None, c=exp["color"], label=exp["name"]) + if exp["yr"] is not None: + print(exp["name"]) + for yrs in exp["yr"]: + add_line( + year, + var, + yrs[0], + yrs[1], + format="%4.2f", + ax=ax, + lw=2, + color=exp["color"], + ) + add_trend( + year, + var, + yrs[0], + yrs[1], + format="%4.2f", + ax=ax, + lw=2, + color=exp["color"], + ) + + ax.set_ylim(get_ylim([-1.5, 1.5], extreme_values)) + ax.axhline(y=0, lw=1, c="0.5") + ax.set_title("Net TOA flux (restom)") + ax.set_xlabel("Year") + ax.set_ylabel("W m-2") + ax.legend(loc="best") -ax.set_ylim(get_ylim([13, 15.5], extreme_values)) -ax.set_title("Global surface air temperature") -ax.set_xlabel("Year") -ax.set_ylabel("degC") -# ax.legend(loc="upper left") - -# ------------ -# Third panel -# ------------ -ax = plt.subplot(nrows, ncols, 3) -ax.set_xlim(xlim) - -extreme_values = [] -for exp in exps: - year = np.array(exp["annual"]["year"]) + exp["yoffset"] - var = np.array(exp["annual"]["FSNTOA"]) - extreme_values.append(np.amax(var)) - extreme_values.append(np.amin(var)) - # ax.plot(year,var,lw=1.5,marker='o',c=exp['color'],label=exp['name']) - ax.plot(year, var, lw=1.0, marker=None, c=exp["color"], label=exp["name"]) - var = np.array(exp["annual"]["FLUT"]) - # ax.plot(year,var,lw=1.5,marker='o',ls=':',c=exp['color']) - ax.plot(year, var, lw=1.0, marker=None, ls=":", c=exp["color"]) - -ax.set_ylim(get_ylim([235, 245], extreme_values)) -ax.set_title("TOA radiation: SW (solid), LW (dashed)") -ax.set_xlabel("Year") -ax.set_ylabel("W m-2") -# ax.legend(loc="lower left") - -# ------------ -# Fourth panel -# ------------ -ax = plt.subplot(nrows, ncols, 4) -ax.set_xlim(xlim) - -extreme_values = [] -for exp in exps: - year = np.array(exp["annual"]["year"]) + exp["yoffset"] - var = np.array(exp["annual"]["RESTOM"]) - np.array(exp["annual"]["RESSURF"]) - extreme_values.append(np.amax(var)) - extreme_values.append(np.amin(var)) - # ax.plot(year,var,lw=1.5,marker='o',c=exp['color'],label=exp['name']) - ax.plot(year, var, lw=1.0, marker=None, c=exp["color"], label=exp["name"]) - if exp["yr"] is not None: - print(exp["name"]) - for yrs in exp["yr"]: - add_line( - year, - var, - yrs[0], - yrs[1], - format="%4.2f", - ax=ax, - lw=2, - color=exp["color"], - ) -ax.set_ylim(get_ylim([-0.3, 0.3], extreme_values)) -ax.set_title("Net atm energy imbalance (restom-ressurf)") -ax.set_xlabel("Year") -ax.set_ylabel("W m-2") -# ax.legend(loc="lower left") - -# ----------- -# Fifth panel -# ----------- -ax = plt.subplot(nrows, ncols, 5) -ax.set_xlim(xlim) - -extreme_values = [] -for exp in exps: - if exp["ocean"] is not None: +def plot_global_surface_air_temperature(ax, xlim, exps): + ax.set_xlim(xlim) + + extreme_values = [] + for exp in exps: year = np.array(exp["annual"]["year"]) + exp["yoffset"] - var = np.array(exp["annual"]["ohc"]) + var = np.array(exp["annual"]["TREFHT"]) - 273.15 extreme_values.append(np.amax(var)) extreme_values.append(np.amin(var)) - ax.plot(year, var, lw=1.5, marker=None, c=exp["color"], label=exp["name"]) - for yrs in exp["yr"]: - add_trend( - year, - var, - yrs[0], - yrs[1], - format="%4.2f", - ax=ax, - lw=3, - color=exp["color"], - ohc=True, - ) + ax.plot(year, var, lw=1.0, marker=None, c=exp["color"], label=exp["name"]) + if exp["yr"] is not None: + print(exp["name"]) + for yrs in exp["yr"]: + add_line( + year, + var, + yrs[0], + yrs[1], + format="%4.2f", + ax=ax, + lw=2, + color=exp["color"], + ) + add_trend( + year, + var, + yrs[0], + yrs[1], + format="%4.2f", + ax=ax, + lw=2, + color=exp["color"], + ) + + ax.set_ylim(get_ylim([13, 15.5], extreme_values)) + ax.set_title("Global surface air temperature") + ax.set_xlabel("Year") + ax.set_ylabel("degC") + + +def plot_toa_radiation(ax, xlim, exps): + ax.set_xlim(xlim) + + extreme_values = [] + for exp in exps: + year = np.array(exp["annual"]["year"]) + exp["yoffset"] + var = np.array(exp["annual"]["FSNTOA"]) + extreme_values.append(np.amax(var)) + extreme_values.append(np.amin(var)) + ax.plot(year, var, lw=1.0, marker=None, c=exp["color"], label=exp["name"]) + var = np.array(exp["annual"]["FLUT"]) + ax.plot(year, var, lw=1.0, marker=None, ls=":", c=exp["color"]) + + ax.set_ylim(get_ylim([235, 245], extreme_values)) + ax.set_title("TOA radiation: SW (solid), LW (dashed)") + ax.set_xlabel("Year") + ax.set_ylabel("W m-2") -ax.set_ylim(get_ylim([-0.3e24, 0.9e24], extreme_values)) -ax.axhline(y=0, lw=1, c="0.5") -ax.set_title("Change in ocean heat content") -ax.set_xlabel("Year") -ax.set_ylabel("J") -ax.legend(loc="best") - -# ----------- -# Sixth panel -# ----------- -ax = plt.subplot(nrows, ncols, 6) -ax.set_xlim(xlim) - -extreme_values = [] -for exp in exps: - if exp["moc"] is not None: - [year_moc, var] = getmoc(exp["moc"]) - ax.plot(year_moc, var, lw=1.5, marker=None, c=exp["color"], label=exp["name"]) + +def plot_net_atm_energy_imbalance(ax, xlim, exps): + ax.set_xlim(xlim) + + extreme_values = [] + for exp in exps: + year = np.array(exp["annual"]["year"]) + exp["yoffset"] + var = np.array(exp["annual"]["RESTOM"]) - np.array(exp["annual"]["RESSURF"]) extreme_values.append(np.amax(var)) extreme_values.append(np.amin(var)) - for yrs in exp["yr"]: - add_trend( - year_moc, - var, - yrs[0], - yrs[1], - format="%4.2f", - ax=ax, - lw=3, - color=exp["color"], - verbose=True, + ax.plot(year, var, lw=1.0, marker=None, c=exp["color"], label=exp["name"]) + if exp["yr"] is not None: + print(exp["name"]) + for yrs in exp["yr"]: + add_line( + year, + var, + yrs[0], + yrs[1], + format="%4.2f", + ax=ax, + lw=2, + color=exp["color"], + ) + + ax.set_ylim(get_ylim([-0.3, 0.3], extreme_values)) + ax.set_title("Net atm energy imbalance (restom-ressurf)") + ax.set_xlabel("Year") + ax.set_ylabel("W m-2") + + +def plot_change_ohc(ax, xlim, exps): + ax.set_xlim(xlim) + + extreme_values = [] + for exp in exps: + if exp["ocean"] is not None: + year = np.array(exp["annual"]["year"]) + exp["yoffset"] + var = np.array(exp["annual"]["ohc"]) + extreme_values.append(np.amax(var)) + extreme_values.append(np.amin(var)) + ax.plot(year, var, lw=1.5, marker=None, c=exp["color"], label=exp["name"]) + for yrs in exp["yr"]: + add_trend( + year, + var, + yrs[0], + yrs[1], + format="%4.2f", + ax=ax, + lw=3, + color=exp["color"], + ohc=True, + ) + + ax.set_ylim(get_ylim([-0.3e24, 0.9e24], extreme_values)) + ax.axhline(y=0, lw=1, c="0.5") + ax.set_title("Change in ocean heat content") + ax.set_xlabel("Year") + ax.set_ylabel("J") + ax.legend(loc="best") + + +def plot_max_moc(ax, xlim, exps): + ax.set_xlim(xlim) + + extreme_values = [] + for exp in exps: + if exp["moc"] is not None: + [year_moc, var] = getmoc(exp["moc"]) + ax.plot( + year_moc, var, lw=1.5, marker=None, c=exp["color"], label=exp["name"] + ) + extreme_values.append(np.amax(var)) + extreme_values.append(np.amin(var)) + for yrs in exp["yr"]: + add_trend( + year_moc, + var, + yrs[0], + yrs[1], + format="%4.2f", + ax=ax, + lw=3, + color=exp["color"], + verbose=True, + ) + + ax.set_ylim(get_ylim([4, 22], extreme_values)) + ax.axhline(y=10, lw=1, c="0.5") + ax.set_title("Max MOC Atlantic streamfunction at 26.5N") + ax.set_xlabel("Year") + ax.set_ylabel("Sv") + ax.legend(loc="best") + + +def plot_change_sea_level(ax, xlim, exps): + ax.set_xlim(xlim) + + extreme_values = [] + for exp in exps: + if exp["vol"] is not None: + year_vol = np.array(exp["annual"]["year"]) + exp["yoffset"] + var = ( + 1e3 + * np.array(exp["annual"]["volume"]) + / (4.0 * math.pi * (6371229.0) ** 2 * 0.7) ) + extreme_values.append(np.amax(var)) + extreme_values.append(np.amin(var)) + ax.plot( + year_vol, var, lw=1.5, marker=None, c=exp["color"], label=exp["name"] + ) + for yrs in exp["yr"]: + add_trend( + year_vol, + var, + yrs[0], + yrs[1], + format="%5.3f", + ax=ax, + lw=3, + color=exp["color"], + verbose=True, + vol=True, + ) + + ax.set_ylim(get_ylim([4, 22], extreme_values)) + ax.set_title("Change in sea level") + ax.set_xlabel("Year") + ax.set_ylabel("mm") + ax.legend(loc="best") + -ax.set_ylim(get_ylim([4, 22], extreme_values)) -ax.axhline(y=10, lw=1, c="0.5") -ax.set_title("Max MOC Atlantic streamfunction at 26.5N") -ax.set_xlabel("Year") -ax.set_ylabel("Sv") -ax.legend(loc="best") - -# ----------- -# Seventh panel -# ----------- -ax = plt.subplot(nrows, ncols, 7) -ax.set_xlim(xlim) - -extreme_values = [] -for exp in exps: - if exp["vol"] is not None: - year_vol = np.array(exp["annual"]["year"]) + exp["yoffset"] +def plot_net_atm_water_imbalance(ax, xlim, exps): + ax.set_xlim(xlim) + + extreme_values = [] + for exp in exps: + year = np.array(exp["annual"]["year"]) + exp["yoffset"] var = ( - 1e3 - * np.array(exp["annual"]["volume"]) - / (4.0 * math.pi * (6371229.0) ** 2 * 0.7) + 365 + * 86400 + * ( + np.array(exp["annual"]["QFLX"]) + - 1e3 + * (np.array(exp["annual"]["PRECC"]) + np.array(exp["annual"]["PRECL"])) + ) ) extreme_values.append(np.amax(var)) extreme_values.append(np.amin(var)) - ax.plot(year_vol, var, lw=1.5, marker=None, c=exp["color"], label=exp["name"]) - for yrs in exp["yr"]: - add_trend( - year_vol, - var, - yrs[0], - yrs[1], - format="%5.3f", - ax=ax, - lw=3, - color=exp["color"], - verbose=True, - vol=True, - ) + ax.plot(year, var, lw=1.0, marker=None, c=exp["color"], label=exp["name"]) + if exp["yr"] is not None: + print(exp["name"]) + for yrs in exp["yr"]: + add_line( + year, + var, + yrs[0], + yrs[1], + format="%5.4f", + ax=ax, + lw=2, + color=exp["color"], + ) -ax.set_ylim(get_ylim([4, 22], extreme_values)) -# ax.axhline(y=10,lw=1,c='0.5') -ax.set_title("Change in sea level") -ax.set_xlabel("Year") -ax.set_ylabel("mm") -ax.legend(loc="best") - -# ------------ -# Eighth panel -# ------------ -ax = plt.subplot(nrows, ncols, 8) -ax.set_xlim(xlim) - -extreme_values = [] -for exp in exps: - year = np.array(exp["annual"]["year"]) + exp["yoffset"] - var = ( - 365 - * 86400 - * ( - np.array(exp["annual"]["QFLX"]) - - 1e3 - * (np.array(exp["annual"]["PRECC"]) + np.array(exp["annual"]["PRECL"])) - ) - ) - extreme_values.append(np.amax(var)) - extreme_values.append(np.amin(var)) - ax.plot(year, var, lw=1.0, marker=None, c=exp["color"], label=exp["name"]) - if exp["yr"] is not None: - print(exp["name"]) - for yrs in exp["yr"]: - add_line( - year, - var, - yrs[0], - yrs[1], - format="%5.4f", - ax=ax, - lw=2, - color=exp["color"], + ax.set_ylim(get_ylim([-1, 1], extreme_values)) + ax.set_title("Net atm water imbalance (evap-prec)") + ax.set_xlabel("Year") + ax.set_ylabel("mm yr-1") + + +PLOT_DICT = { + "net_toa_flux_restom": plot_net_toa_flux_restom, + "global_surface_air_temperature": plot_global_surface_air_temperature, + "toa_radiation": plot_toa_radiation, + "net_atm_energy_imbalance": plot_net_atm_energy_imbalance, + "change_ohc": plot_change_ohc, + "max_moc": plot_max_moc, + "change_sea_level": plot_change_sea_level, + "net_atm_water_imbalance": plot_net_atm_water_imbalance, +} + + +# ----------------------------------------------------------------------------- +def run(parameters): + # These are the "Tableau 20" colors as RGB. + t20: List[Tuple[float, float, float]] = [ + (31, 119, 180), + (174, 199, 232), + (255, 127, 14), + (255, 187, 120), + (44, 160, 44), + (152, 223, 138), + (214, 39, 40), + (255, 152, 150), + (148, 103, 189), + (197, 176, 213), + (140, 86, 75), + (196, 156, 148), + (227, 119, 194), + (247, 182, 210), + (127, 127, 127), + (199, 199, 199), + (188, 189, 34), + (219, 219, 141), + (23, 190, 207), + (158, 218, 229), + ] + # Scale the RGB values to the [0, 1] range, which is the format matplotlib accepts. + for i in range(len(t20)): + r, g, b = t20[i] + t20[i] = (r / 255.0, g / 255.0, b / 255.0) + + # "Tableau 10" uses every other color + t10 = [] + for i in range(0, len(t20), 2): + t10.append(t20[i]) + + # ----------------------------------------------------------------------------- + # --- Atmos data --- + + # Experiments + case_dir = parameters[1] + experiment_name = parameters[2] + figstr = parameters[3] + year1 = int(parameters[4]) + year2 = int(parameters[5]) + color = parameters[6] + ts_num_years = parameters[7] + if parameters[8].lower() == "false": + atmosphere_only = False + else: + atmosphere_only = True + plot_list = parameters[9].split(",") + exps = [ + { + "atmos": "{}/post/atm/glb/ts/monthly/{}yr/glb.xml".format( + case_dir, ts_num_years + ), + "ocean": None + if atmosphere_only + else "{}/post/ocn/glb/ts/monthly/{}yr/glb.xml".format( + case_dir, ts_num_years + ), + "moc": None + if atmosphere_only + else "{}/post/ocn/glb/ts/monthly/{}yr/".format(case_dir, ts_num_years), + "vol": None + if atmosphere_only + else "{}/post/ocn/glb/ts/monthly/{}yr/glb.xml".format( + case_dir, ts_num_years + ), + "name": experiment_name, + "yoffset": 0.0, + "yr": ([year1, year2],), + "color": f"{color}", + } + ] + + # Variables to extract + vars = ["RESTOM", "RESSURF", "TREFHT", "FSNTOA", "FLUT", "PRECC", "PRECL", "QFLX"] + + # Read data + exp: Any + for exp in exps: + print(exp["atmos"]) + ts = TS(exp["atmos"]) + exp["annual"] = {} + for var in vars: + print(var) + v = ts.globalAnnual(var) + exp["annual"][var] = v + if "year" not in exp["annual"]: + time = v.getTime() + exp["annual"]["year"] = [x.year for x in time.asComponentTime()] + del ts + + # Optionally read ohc + if exp["ocean"] is not None: + ts = TS(exp["ocean"]) + exp["annual"]["ohc"] = ts.globalAnnual("ohc") + # annomalies with respect to first year + exp["annual"]["ohc"][:] = exp["annual"]["ohc"][:] - exp["annual"]["ohc"][0] + + if exp["vol"] is not None: + ts = TS(exp["vol"]) + exp["annual"]["volume"] = ts.globalAnnual("volume") + # annomalies with respect to first year + exp["annual"]["volume"][:] = ( + exp["annual"]["volume"][:] - exp["annual"]["volume"][0] ) -ax.set_ylim(get_ylim([-1, 1], extreme_values)) -ax.set_title("Net atm water imbalance (evap-prec)") -ax.set_xlabel("Year") -ax.set_ylabel("mm yr-1") -# ax.legend(loc="lower left") + # ----------------------------------------------------------------------------- + # --- Generate plots --- + + xlim = [float(year1), float(year2)] + + fig = plt.figure(figsize=[13.5, 16.5]) + num_plots = len(plot_list) + nrows = math.ceil(num_plots / 2) + ncols = 2 + + for i in range(num_plots): + ax = plt.subplot(nrows, ncols, i + 1) + try: + PLOT_DICT[plot_list[i]](ax, xlim, exps) + except KeyError: + raise KeyError(f"Invalid plot name: {plot_list[i]}") + + fig.tight_layout() + fig.savefig(figstr + ".pdf") + fig.savefig(figstr + ".png", dpi=150) + plt.clf() + -fig.tight_layout() -fig.savefig(figstr + ".pdf") -fig.savefig(figstr + ".png", dpi=150) -plt.clf() +if __name__ == "__main__": + run(sys.argv) diff --git a/zppy/templates/default.ini b/zppy/templates/default.ini index 15222cf4..9bdf3925 100644 --- a/zppy/templates/default.ini +++ b/zppy/templates/default.ini @@ -270,6 +270,8 @@ figstr = string(default="") # NOTE: always overrides value in [default] input_subdir = string(default="archive/ocn/hist") moc_file = string(default="") +# The names of the plots you want displayed +plot_names = string(default="net_toa_flux_restom,global_surface_air_temperature,toa_radiation,net_atm_energy_imbalance,change_ohc,max_moc,change_sea_level,net_atm_water_imbalance") # The number of years in a time-series file ts_num_years = integer(default=10) ts_years = string_list(default=list("")) diff --git a/zppy/templates/global_time_series.bash b/zppy/templates/global_time_series.bash index a29546ba..60629d03 100644 --- a/zppy/templates/global_time_series.bash +++ b/zppy/templates/global_time_series.bash @@ -87,7 +87,7 @@ fi echo 'Update time series figures' cd ${global_ts_dir} -python coupled_global.py ${case_dir} ${experiment_name} ${figstr} ${start_yr} ${end_yr} {{ color }} ${ts_num_years} ${atmosphere_only} +python coupled_global.py ${case_dir} ${experiment_name} ${figstr} ${start_yr} ${end_yr} {{ color }} ${ts_num_years} ${atmosphere_only} "{{ plot_names }}" if [ $? != 0 ]; then cd {{ scriptDir }} echo 'ERROR (5)' > {{ prefix }}.status