Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip glb-only plots for hemispheric ts #460

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 46 additions & 22 deletions zppy/templates/coupled_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def get_ylim(standard_range, extreme_values):
# Plotting functions

# 1
def plot_net_toa_flux_restom(ax, xlim, exps):
def plot_net_toa_flux_restom(ax, xlim, exps, rgn):
param_dict = {
"2nd_var": False,
"axhline_y": 0,
Expand All @@ -144,6 +144,7 @@ def plot_net_toa_flux_restom(ax, xlim, exps):
"do_add_line": True,
"do_add_trend": True,
"format": "%4.2f",
"glb_only": False,
"lw": 1.0,
"ohc": False,
"set_axhline": True,
Expand All @@ -156,11 +157,19 @@ def plot_net_toa_flux_restom(ax, xlim, exps):
"vol": False,
"ylabel": "W m-2",
}
plot(ax, xlim, exps, param_dict)
plot(ax, xlim, exps, param_dict, rgn)


# 2
def plot_global_surface_air_temperature(ax, xlim, exps):
def plot_global_surface_air_temperature(ax, xlim, exps, rgn):
if rgn == "glb":
region_title = "Global"
elif rgn == "n":
region_title = "Northern Hemisphere"
elif rgn == "s":
region_title = "Southern Hemisphere"
else:
raise RuntimeError(f"Invalid rgn={rgn}")
param_dict = {
"2nd_var": False,
"axhline_y": None,
Expand All @@ -171,23 +180,24 @@ def plot_global_surface_air_temperature(ax, xlim, exps):
"do_add_line": True,
"do_add_trend": True,
"format": "%4.2f",
"glb_only": False,
"lw": 1.0,
"ohc": False,
"set_axhline": False,
"set_legend": False,
"shorten_year": False,
"title": "Global surface air temperature",
"title": f"{region_title} surface air temperature",
"use_getmoc": False,
"var": lambda exp: np.array(exp["annual"]["TREFHT"]) - 273.15,
"verbose": False,
"vol": False,
"ylabel": "degC",
}
plot(ax, xlim, exps, param_dict)
plot(ax, xlim, exps, param_dict, rgn)


# 3
def plot_toa_radiation(ax, xlim, exps):
def plot_toa_radiation(ax, xlim, exps, rgn):
param_dict = {
"2nd_var": True,
"axhline_y": None,
Expand All @@ -198,6 +208,7 @@ def plot_toa_radiation(ax, xlim, exps):
"do_add_line": False,
"do_add_trend": False,
"format": None,
"glb_only": False,
"lw": 1.0,
"ohc": False,
"set_axhline": False,
Expand All @@ -210,11 +221,11 @@ def plot_toa_radiation(ax, xlim, exps):
"vol": None,
"ylabel": "W m-2",
}
plot(ax, xlim, exps, param_dict)
plot(ax, xlim, exps, param_dict, rgn)


# 4
def plot_net_atm_energy_imbalance(ax, xlim, exps):
def plot_net_atm_energy_imbalance(ax, xlim, exps, rgn):
param_dict = {
"2nd_var": False,
"axhline_y": None,
Expand All @@ -225,6 +236,7 @@ def plot_net_atm_energy_imbalance(ax, xlim, exps):
"do_add_line": True,
"do_add_trend": False,
"format": "%4.2f",
"glb_only": False,
"lw": 1.0,
"ohc": False,
"set_axhline": False,
Expand All @@ -238,11 +250,11 @@ def plot_net_atm_energy_imbalance(ax, xlim, exps):
"vol": False,
"ylabel": "W m-2",
}
plot(ax, xlim, exps, param_dict)
plot(ax, xlim, exps, param_dict, rgn)


# 5
def plot_change_ohc(ax, xlim, exps):
def plot_change_ohc(ax, xlim, exps, rgn):
param_dict = {
"2nd_var": False,
"axhline_y": 0,
Expand All @@ -253,6 +265,7 @@ def plot_change_ohc(ax, xlim, exps):
"do_add_line": False,
"do_add_trend": True,
"format": "%4.2f",
"glb_only": True,
"lw": 1.5,
"ohc": True,
"set_axhline": True,
Expand All @@ -265,11 +278,11 @@ def plot_change_ohc(ax, xlim, exps):
"vol": False,
"ylabel": "J",
}
plot(ax, xlim, exps, param_dict)
plot(ax, xlim, exps, param_dict, rgn)


# 6
def plot_max_moc(ax, xlim, exps):
def plot_max_moc(ax, xlim, exps, rgn):
param_dict = {
"2nd_var": False,
"axhline_y": 10,
Expand All @@ -280,6 +293,7 @@ def plot_max_moc(ax, xlim, exps):
"do_add_line": False,
"do_add_trend": True,
"format": "%4.2f",
"glb_only": True,
"lw": 1.5,
"ohc": False,
"set_axhline": True,
Expand All @@ -292,11 +306,11 @@ def plot_max_moc(ax, xlim, exps):
"vol": None,
"ylabel": "Sv",
}
plot(ax, xlim, exps, param_dict)
plot(ax, xlim, exps, param_dict, rgn)


# 7
def plot_change_sea_level(ax, xlim, exps):
def plot_change_sea_level(ax, xlim, exps, rgn):
param_dict = {
"2nd_var": False,
"axhline_y": None,
Expand All @@ -307,6 +321,7 @@ def plot_change_sea_level(ax, xlim, exps):
"do_add_line": False,
"do_add_trend": True,
"format": "%5.3f",
"glb_only": True,
"lw": 1.5,
"ohc": False,
"set_axhline": False,
Expand All @@ -323,11 +338,11 @@ def plot_change_sea_level(ax, xlim, exps):
"vol": True,
"ylabel": "mm",
}
plot(ax, xlim, exps, param_dict)
plot(ax, xlim, exps, param_dict, rgn)


# 8
def plot_net_atm_water_imbalance(ax, xlim, exps):
def plot_net_atm_water_imbalance(ax, xlim, exps, rgn):
param_dict = {
"2nd_var": False,
"axhline_y": None,
Expand All @@ -338,6 +353,7 @@ def plot_net_atm_water_imbalance(ax, xlim, exps):
"do_add_line": True,
"do_add_trend": False,
"format": "%5.4f",
"glb_only": False,
"lw": 1.0,
"ohc": False,
"set_axhline": False,
Expand All @@ -358,10 +374,12 @@ def plot_net_atm_water_imbalance(ax, xlim, exps):
"vol": False,
"ylabel": "mm yr-1",
}
plot(ax, xlim, exps, param_dict)
plot(ax, xlim, exps, param_dict, rgn)


def plot(ax, xlim, exps, param_dict):
def plot(ax, xlim, exps, param_dict, rgn):
if param_dict["glb_only"] and (rgn != "glb"):
return
ax.set_xlim(xlim)
extreme_values = []
for exp in exps:
Expand Down Expand Up @@ -442,9 +460,9 @@ def plot(ax, xlim, exps, param_dict):
"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,
"change_ohc": plot_change_ohc, # only glb
"max_moc": plot_max_moc, # only glb
"change_sea_level": plot_change_sea_level, # only glb
"net_atm_water_imbalance": plot_net_atm_water_imbalance,
}

Expand Down Expand Up @@ -552,6 +570,12 @@ def run(parameters, rgn): # noqa: C901
else:
raise RuntimeError(f"Invalid rgn={rgn}")
v = v[:, n] # Just use nth column
elif rgn != "glb":
# v only has one dimension -- glb.
# Therefore it is not possible to get n or s plots.
raise RuntimeError(
f"var={var} only has global data. Cannot process rgn={rgn}"
)
exp["annual"][var] = v
if "year" not in exp["annual"]:
time = v.getTime()
Expand Down Expand Up @@ -593,7 +617,7 @@ def run(parameters, rgn): # noqa: C901
if i < num_plots:
ax = plt.subplot(nrows, ncols, j + 1)
try:
PLOT_DICT[plot_list[i]](ax, xlim, exps)
PLOT_DICT[plot_list[i]](ax, xlim, exps, rgn)
except KeyError:
raise KeyError(f"Invalid plot name: {plot_list[i]}")
i += 1
Expand Down