Skip to content

Commit

Permalink
Merge pull request #993 from PCMDI/lee1043-patch-1_pre-commit
Browse files Browse the repository at this point in the history
Catch up with pre-commit
  • Loading branch information
lee1043 committed Oct 26, 2023
2 parents 26bf28a + c098690 commit e133c6c
Show file tree
Hide file tree
Showing 89 changed files with 1,596 additions and 860 deletions.
4 changes: 1 addition & 3 deletions pcmdi_metrics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# put here the import calls to expose whatever we want to the user
import logging
import logging # noqa

LOG_LEVEL = logging.DEBUG
plog = logging.getLogger("pcmdi_metrics")
Expand All @@ -15,6 +15,4 @@
plog.addHandler(ch)
plog.setLevel(LOG_LEVEL)
from . import io # noqa
#from . import pcmdi # noqa
#from . import mean_climate # noqa
from .version import __git_sha1__, __git_tag_describe__, __version__ # noqa
41 changes: 31 additions & 10 deletions pcmdi_metrics/cloud_feedback/cloud_feedback_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@
with open(input_files_json) as f:
ncfiles = json.load(f)
else:
print('Warning: input files were not explicitly given. They will be searched from ', path)
print(
"Warning: input files were not explicitly given. They will be searched from ",
path,
)

for exp in exps:
filenames[exp] = dict()
Expand Down Expand Up @@ -169,15 +172,33 @@
output_dict["RESULTS"][model] = OrderedDict()
output_dict["RESULTS"][model][variant] = OrderedDict()
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"] = OrderedDict()
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"]["high_cloud_altitude"] = assessed_cld_fbk[0]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"]["tropical_marine_low_cloud"] = assessed_cld_fbk[1]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"]["tropical_anvil_cloud_area"] = assessed_cld_fbk[2]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"]["land_cloud_amount"] = assessed_cld_fbk[3]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"]["middle_latitude_marine_low_cloud_amount"] = assessed_cld_fbk[4]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"]["high_latitude_low_cloud_optical_depth"] = assessed_cld_fbk[5]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"]["implied_unassessed"] = assessed_cld_fbk[6]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"]["sum_of_assessed"] = assessed_cld_fbk[7]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"]["total_cloud_feedback"] = assessed_cld_fbk[8]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"][
"high_cloud_altitude"
] = assessed_cld_fbk[0]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"][
"tropical_marine_low_cloud"
] = assessed_cld_fbk[1]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"][
"tropical_anvil_cloud_area"
] = assessed_cld_fbk[2]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"][
"land_cloud_amount"
] = assessed_cld_fbk[3]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"][
"middle_latitude_marine_low_cloud_amount"
] = assessed_cld_fbk[4]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"][
"high_latitude_low_cloud_optical_depth"
] = assessed_cld_fbk[5]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"][
"implied_unassessed"
] = assessed_cld_fbk[6]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"][
"sum_of_assessed"
] = assessed_cld_fbk[7]
output_dict["RESULTS"][model][variant]["assessed_cloud_feedback"][
"total_cloud_feedback"
] = assessed_cld_fbk[8]
output_dict["RESULTS"][model][variant]["clim_cloud_rmse"] = climo_cld_rmse
output_dict["RESULTS"][model][variant]["cloud_feedback_rmse"] = cld_fbk_rmse
output_dict["RESULTS"][model][variant]["equilibrium_climate_sensitivity"] = ecs
Expand Down
1 change: 0 additions & 1 deletion pcmdi_metrics/cloud_feedback/lib/argparse_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


def AddParserArgument():

P = CDPParser(
default_args_file=[],
description="Cloud feedback metrics",
Expand Down
16 changes: 8 additions & 8 deletions pcmdi_metrics/cloud_feedback/lib/cal_CloudRadKernel_xr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
# to expert-assessed values from Sherwood et al (2020)
# =============================================

from datetime import date

# IMPORT STUFF:
import cftime
import numpy as np
import xarray as xr
import xcdat as xc
import numpy as np
from global_land_mask import globe
from datetime import date

# =============================================
# define necessary information
Expand Down Expand Up @@ -190,7 +190,7 @@ def get_CRK_data(filepath):
###########################################################################
def get_kernel_regrid(ctl):
# Read in data and map kernels to lat/lon

f = xc.open_mfdataset(datadir + "cloud_kernels2.nc", decode_times=False)
f = f.rename({"mo": "time", "tau_midpt": "tau", "p_midpt": "plev"})
f["time"] = ctl["time"].copy()
Expand Down Expand Up @@ -370,7 +370,7 @@ def bony_sorting_part2(OKwaps, data, OKland, WTS, binedges):
# Ensure that the area matrix has zeros rather than masked points
CNTS = CNTS.where(~np.isnan(CNTS), 0.0)

if np.allclose(0.5, np.sum(CNTS.values, 1)) == False:
if np.allclose(0.5, np.sum(CNTS.values, 1)) is False:
print(
"sum of fractional counts over all wapbins does not equal 0.5 (tropical fraction)"
)
Expand All @@ -385,7 +385,7 @@ def bony_sorting_part2(OKwaps, data, OKland, WTS, binedges):
v2b = (data * WTS).sum(dim=["lat", "lon"]).transpose("time", "tau", "plev")

# if np.allclose(v1.values,v2a.values)==False or np.allclose(v1.values,v2b.values)==False:
if np.allclose(v1.values, v2b.values) == False:
if np.allclose(v1.values, v2b.values) is False:
print("Cannot reconstruct tropical average via summing regimes")

return DATA, CNTS # [time,wapbin]
Expand Down Expand Up @@ -602,7 +602,7 @@ def obscuration_terms3(c1, c2):
L_R_bar = L_R_bar.where(L_R_bar >= 0, 0.0)
F_bar = F_bar.where(F_bar >= 0, 0.0)

rep_L_bar = tile_uneven(L_bar, L12)
# rep_L_bar = tile_uneven(L_bar, L12)
rep_L_R_bar = tile_uneven(L_R_bar, L_R12)
rep_F_bar = tile_uneven(F_bar, F12b)

Expand Down Expand Up @@ -873,7 +873,7 @@ def klein_metrics(obs_clisccp, gcm_clisccp, LWkern, SWkern, WTS):
# take only clouds with tau>3.6
clisccp_bias_CPM = clisccp_bias[:, 2:, :] # 4 tau bins
obs_clisccp_CPM = obs_clisccp[:, 2:, :] # 4 tau bins
gcm_clisccp_CPM = gcm_clisccp[:, 2:, :] # 4 tau bins
# gcm_clisccp_CPM = gcm_clisccp[:, 2:, :] # 4 tau bins
LWkernel_CPM = LWkern[:, 2:, :] # 4 tau bins
SWkernel_CPM = SWkern[:, 2:, :] # 4 tau bins
NETkernel_CPM = SWkernel_CPM + LWkernel_CPM
Expand Down
41 changes: 25 additions & 16 deletions pcmdi_metrics/cloud_feedback/lib/cld_fbks_ecs_assessment_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"""

import json
import string
import os
import string
from datetime import date

import matplotlib as mpl
Expand All @@ -17,7 +17,7 @@
HEIGHT = 0.45

# ######################################################
# DEFINE COLORS FOR ECS COLORBAR
# DEFINE COLORS FOR ECS COLORBAR
# ######################################################
cmap = plt.cm.RdBu_r # define the colormap
# extract all colors from the .jet map
Expand Down Expand Up @@ -75,7 +75,6 @@

# ######################################################
def get_expert_assessed_fbks():

# ######################################################
# ############# WCRP ASSESSMENT VALUES #################
# ######################################################
Expand Down Expand Up @@ -272,7 +271,6 @@ def get_fbks(cld_fbks, obsc_cld_fbks, cld_errs, ecs_dict):

# ######################################################
def get_gcm_assessed_fbks(fbk_dict, obsc_fbk_dict):

# dictionary is structured: [region][sfc][sec][name]

assessed = []
Expand Down Expand Up @@ -364,7 +362,6 @@ def get_gcm_assessed_fbks(fbk_dict, obsc_fbk_dict):

# ######################################################
def get_gcm_cld_errs(err_dict, name):

# dictionary is structured: [region][sfc][sec][name]

DATA = []
Expand Down Expand Up @@ -403,7 +400,6 @@ def get_gcm_cld_errs(err_dict, name):

# ######################################################
def get_unassessed_fbks(fbk_dict, obsc_fbk_dict):

# dictionary is structured: [region][sfc][sec][name]

fbk_names = []
Expand Down Expand Up @@ -651,7 +647,6 @@ def label_models(ax, models5, models6):

# ######################################################
def plot_expert():

(expert_cld_fbks, err_expert_cld_fbks, fbk_names) = get_expert_assessed_fbks()
LN = len(fbk_names)

Expand Down Expand Up @@ -880,10 +875,15 @@ def static_plot(assessed, ecs, models, fbk_names, gen, fig, gs):

# ######################################################
def make_all_figs(
cld_fbks6, obsc_cld_fbks6, cld_errs6, ecs_dict56, newmod,
figdir=None, datadir=None,
debug=False):

cld_fbks6,
obsc_cld_fbks6,
cld_errs6,
ecs_dict56,
newmod,
figdir=None,
datadir=None,
debug=False,
):
# Set a unique marker for your new model
MARK[newmod] = "<"

Expand Down Expand Up @@ -998,7 +998,9 @@ def make_all_figs(
# new axis for labeling all models
ax = plt.subplot(gs[:10, 10:12])
label_models(ax, models5, models6)
plt.savefig(os.path.join(figdir, "WCRP_assessed_cld_fbks_amip-p4K.png"), bbox_inches="tight")
plt.savefig(
os.path.join(figdir, "WCRP_assessed_cld_fbks_amip-p4K.png"), bbox_inches="tight"
)
if debug:
print("make_all_figs: WCRP_assessed_cld_fbks_amip-p4K.png done")

Expand Down Expand Up @@ -1030,7 +1032,10 @@ def make_all_figs(
# new axis for labeling all models
ax = plt.subplot(gs[:10, 10:12])
label_models(ax, models5, models6)
plt.savefig(os.path.join(figdir, "WCRP_unassessed_cld_fbks_amip-p4K.png"), bbox_inches="tight")
plt.savefig(
os.path.join(figdir, "WCRP_unassessed_cld_fbks_amip-p4K.png"),
bbox_inches="tight",
)
if debug:
print("make_all_figs: WCRP_unassessed_cld_fbks_amip-p4K.png done")

Expand Down Expand Up @@ -1277,8 +1282,9 @@ def make_all_figs(
)
cb.ax.tick_params(labelsize=14)
ax2.set_ylabel(r"$\mathrm{E_{NET}}$", size=14)
plt.savefig(os.path.join(
figdir, "WCRP_assessed_RMSE_v_cldfbk2_amip-p4K.png"), bbox_inches="tight"
plt.savefig(
os.path.join(figdir, "WCRP_assessed_RMSE_v_cldfbk2_amip-p4K.png"),
bbox_inches="tight",
)

# #####################################################
Expand Down Expand Up @@ -1402,7 +1408,10 @@ def make_all_figs(
plt.title("b", fontsize=16, loc="left")
plt.ylim(0.04, 0.15)
plt.xlim(0.60, 1.65)
plt.savefig(os.path.join(figdir, "WCRP_totcldfbks2_v_E_NET_amip-p4K.png"), bbox_inches="tight")
plt.savefig(
os.path.join(figdir, "WCRP_totcldfbks2_v_E_NET_amip-p4K.png"),
bbox_inches="tight",
)

# ######################################################
# PRINT OUT THE TABLE OF EVERYTHING:
Expand Down
Loading

0 comments on commit e133c6c

Please sign in to comment.