Skip to content

Commit

Permalink
Fix black and mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvothecoder committed Nov 29, 2023
1 parent 5e04584 commit c6c3adc
Show file tree
Hide file tree
Showing 23 changed files with 28 additions and 61 deletions.
3 changes: 2 additions & 1 deletion e3sm_diags/derivations/acme.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ def cosp_bin_sum(
tau_high0: Optional[float],
):
"""sum of cosp bins to calculate cloud fraction in specified cloud top pressure / height and
cloud thickness bins, input variable has dimension (cosp_prs,cosp_tau,lat,lon)/(cosp_ht,cosp_tau,lat,lon)"""
cloud thickness bins, input variable has dimension (cosp_prs,cosp_tau,lat,lon)/(cosp_ht,cosp_tau,lat,lon)
"""
prs: FileAxis = cld.getAxis(0)
tau: FileAxis = cld.getAxis(1)

Expand Down
3 changes: 0 additions & 3 deletions e3sm_diags/driver/arm_diags_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ def run_diag_aerosol_activation(parameter: ARMDiagsParameter) -> ARMDiagsParamet
logger.info("Selected region: {}".format(region))
# Possible variables are ccn01, ccn02, ccn05
for variable in variables:

test_data = utils.dataset.Dataset(parameter, test=True)

test_a_num = test_data.get_timeseries_variable("a_num", single_point=True)[
Expand All @@ -441,7 +440,6 @@ def run_diag_aerosol_activation(parameter: ARMDiagsParameter) -> ARMDiagsParamet
)

if "armdiags" in ref_name:

ref_file = os.path.join(
ref_path,
region[:3] + "armdiagsaciactivate" + region[3:5].upper() + ".c1.nc",
Expand Down Expand Up @@ -568,7 +566,6 @@ def run_diag_pdf_daily(parameter: ARMDiagsParameter):


def run_diag(parameter: ARMDiagsParameter) -> ARMDiagsParameter:

if parameter.diags_set == "annual_cycle":
return run_diag_annual_cycle(parameter)
elif parameter.diags_set == "diurnal_cycle":
Expand Down
6 changes: 5 additions & 1 deletion e3sm_diags/driver/enso_diags_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ def run_diag_map(parameter: EnsoDiagsParameter) -> EnsoDiagsParameter:
)

# Reference
(ref_domain, ref_reg_coe, ref_confidence_levels,) = perform_regression(
(
ref_domain,
ref_reg_coe,
ref_confidence_levels,
) = perform_regression(
ref_data,
parameter,
var,
Expand Down
8 changes: 2 additions & 6 deletions e3sm_diags/driver/lat_lon_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,8 @@ def run_diag(parameter: CoreParameter) -> CoreParameter: # noqa: C901

# Select plev.
for ilev in range(len(plev)):
mv1 = mv1_p[
ilev,
]
mv2 = mv2_p[
ilev,
]
mv1 = mv1_p[ilev,]
mv2 = mv2_p[ilev,]

for region in regions:
parameter.var_region = region
Expand Down
8 changes: 2 additions & 6 deletions e3sm_diags/driver/polar_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,8 @@ def run_diag(parameter: CoreParameter) -> CoreParameter:

# Select plev.
for ilev in range(len(plev)):
mv1 = mv1_p[
ilev,
]
mv2 = mv2_p[
ilev,
]
mv1 = mv1_p[ilev,]
mv2 = mv2_p[ilev,]

for region in regions:
logger.info("Selected region: {}".format(region))
Expand Down
9 changes: 4 additions & 5 deletions e3sm_diags/driver/tc_analysis_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ def _get_vars_from_te_stitch(
vars_dict["yearmc"][k - 1, index - 1] = float(line_split[6])
vars_dict["monthmc"][k - 1, index - 1] = float(line_split[7])

vars_dict["year_start"] = year_start
vars_dict["year_end"] = year_end
vars_dict["num_years"] = year_end - year_start + 1
vars_dict["year_start"] = year_start # type: ignore
vars_dict["year_end"] = year_end # type: ignore
vars_dict["num_years"] = year_end - year_start + 1 # type: ignore
logger.info(
f"TE Start Year: {vars_dict['year_start']}, TE End Year: {vars_dict['year_end']}, Total Years: {vars_dict['num_years']}"
)
Expand Down Expand Up @@ -340,7 +340,6 @@ def _derive_metrics_per_basin(
and lat[0] > basin_info[3]
and lat[0] < basin_info[4]
):

mod_num_ocn = mod_num_ocn + 1
mod_mon.append(mon[0])
mod_wnd.append(np.max(wind))
Expand Down Expand Up @@ -491,7 +490,7 @@ def _calc_mean_ace(vsmc: "MaskedArray", yearic: np.ndarray, num_rows: int) -> fl
wind_ts = wind[wind >= 35]
ace[i] = ace[i] + np.sum(wind_ts**2) / 1e4

return np.mean(ace)
return np.mean(ace) # type: ignore


def _calc_ts_intensity_dist(wind_speeds: List[int]) -> np.ndarray:
Expand Down
2 changes: 1 addition & 1 deletion e3sm_diags/driver/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def save_transient_variables_to_netcdf(set_num, variables_dict, label, parameter
Save the transient variables to nc file.
"""
if parameter.save_netcdf:
for (variable_name, variable) in variables_dict.items():
for variable_name, variable in variables_dict.items():
# Set cdms preferences - no compression, no shuffling, no complaining
cdms2.setNetcdfDeflateFlag(1)
# 1-9, min to max - Comes at heavy IO (read/write time cost)
Expand Down
8 changes: 2 additions & 6 deletions e3sm_diags/driver/zonal_mean_xy_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,8 @@ def run_diag(parameter: CoreParameter) -> CoreParameter:

# Select plev.
for ilev in range(len(plev)):
mv1 = mv1_p[
ilev,
]
mv2 = mv2_p[
ilev,
]
mv1 = mv1_p[ilev,]
mv2 = mv2_p[ilev,]

for region in regions:
logger.info(f"Selected region: {region}")
Expand Down
3 changes: 1 addition & 2 deletions e3sm_diags/plot/cartopy/annual_cycle_zonal_mean_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def get_ax_size(fig, ax):


def plot_panel(n, fig, var, clevels, cmap, title, parameters, stats=None):

mon = var.getTime()
lat = var.getLatitude()
var = np.transpose(var)
Expand Down Expand Up @@ -172,7 +171,7 @@ def plot(reference, test, diff, metrics_dict, parameter):
subpage = np.array(p).reshape(2, 2)
subpage[1, :] = subpage[0, :] + subpage[1, :]
subpage = subpage + np.array(border).reshape(2, 2)
subpage = list(((subpage) * page).flatten())
subpage = list(((subpage) * page).flatten()) # type: ignore
extent = matplotlib.transforms.Bbox.from_extents(*subpage)
# Save subplot
fname = fnm + ".%i." % (i) + f
Expand Down
4 changes: 1 addition & 3 deletions e3sm_diags/plot/cartopy/cosp_histogram_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def get_ax_size(fig, ax):


def plot_panel(n, fig, _, var, clevels, cmap, title, parameters, stats=None):

# Contour levels
levels = None
norm = None
Expand Down Expand Up @@ -170,7 +169,6 @@ def plot_panel(n, fig, _, var, clevels, cmap, title, parameters, stats=None):


def plot(reference, test, diff, _, parameter):

# Create figure, projection
fig = plt.figure(figsize=parameter.figsize, dpi=parameter.dpi)

Expand Down Expand Up @@ -251,7 +249,7 @@ def plot(reference, test, diff, _, parameter):
subpage = np.array(p).reshape(2, 2)
subpage[1, :] = subpage[0, :] + subpage[1, :]
subpage = subpage + np.array(border).reshape(2, 2)
subpage = list(((subpage) * page).flatten())
subpage = list(((subpage) * page).flatten()) # type: ignore
extent = matplotlib.transforms.Bbox.from_extents(*subpage)
# Save subplot
fname = fnm + ".%i." % (i) + f
Expand Down
5 changes: 2 additions & 3 deletions e3sm_diags/plot/cartopy/diurnal_cycle_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def determine_tick_step(degrees_covered):


def plot_panel(n, fig, proj, var, amp, amp_ref, title, parameter):

normalize_test_amp = parameter.normalize_test_amp
specified_max_amp = parameter.normalize_amp_int

Expand Down Expand Up @@ -129,7 +128,7 @@ def plot_panel(n, fig, proj, var, amp, amp_ref, title, parameter):
# If less than 0.50 is subtracted, then 0 W will overlap 0 E on the left side of the plot.
# If a number is added, then the value won't show up at all.
if global_domain or full_lon:
xticks = [0, 60, 120, 180, 240, 300, 359.99]
xticks = [0, 60, 120, 180, 240, 300, 359.99] # type: ignore
else:
xticks = np.append(xticks, lon_east)
proj = ccrs.PlateCarree()
Expand Down Expand Up @@ -309,7 +308,7 @@ def plot(test_tmax, test_amp, ref_tmax, ref_amp, parameter):
subpage = np.array(p).reshape(2, 2)
subpage[1, :] = subpage[0, :] + subpage[1, :]
subpage = subpage + np.array(border).reshape(2, 2)
subpage = list(((subpage) * page).flatten())
subpage = list(((subpage) * page).flatten()) # type: ignore
extent = matplotlib.transforms.Bbox.from_extents(*subpage)
# Save subplot
subplot_suffix = ".%i." % (i) + f
Expand Down
3 changes: 1 addition & 2 deletions e3sm_diags/plot/cartopy/enso_diags_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def determine_tick_step(degrees_covered):
def plot_panel_map(
n, fig, proj, var, clevels, cmap, title, parameter, conf=None, stats={}
):

var = add_cyclic(var)
lon = var.getLongitude()
lat = var.getLatitude()
Expand Down Expand Up @@ -330,7 +329,7 @@ def plot_map(
subpage = np.array(p).reshape(2, 2)
subpage[1, :] = subpage[0, :] + subpage[1, :]
subpage = subpage + np.array(border).reshape(2, 2)
subpage = list(((subpage) * page).flatten())
subpage = list(((subpage) * page).flatten()) # type: ignore
extent = matplotlib.transforms.Bbox.from_extents(*subpage)
# Save subplot
subplot_suffix = ".%i." % (i) + f
Expand Down
1 change: 0 additions & 1 deletion e3sm_diags/plot/cartopy/lat_lon_land_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@


def plot(reference, test, diff, metrics_dict, parameter):

return base_plot(reference, test, diff, metrics_dict, parameter)
4 changes: 1 addition & 3 deletions e3sm_diags/plot/cartopy/lat_lon_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def determine_tick_step(degrees_covered):
def plot_panel( # noqa: C901
n, fig, proj, var, clevels, cmap, title, parameters, stats=None
):

var = add_cyclic(var)
lon = var.getLongitude()
lat = var.getLatitude()
Expand Down Expand Up @@ -249,7 +248,6 @@ def plot_panel( # noqa: C901


def plot(reference, test, diff, metrics_dict, parameter):

# Create figure, projection
fig = plt.figure(figsize=parameter.figsize, dpi=parameter.dpi)
proj = ccrs.PlateCarree()
Expand Down Expand Up @@ -337,7 +335,7 @@ def plot(reference, test, diff, metrics_dict, parameter):
subpage = np.array(p).reshape(2, 2)
subpage[1, :] = subpage[0, :] + subpage[1, :]
subpage = subpage + np.array(border).reshape(2, 2)
subpage = list(((subpage) * page).flatten())
subpage = list(((subpage) * page).flatten()) # type: ignore
extent = matplotlib.transforms.Bbox.from_extents(*subpage)
# Save subplot
fname = fnm + ".%i." % (i) + f
Expand Down
1 change: 0 additions & 1 deletion e3sm_diags/plot/cartopy/lat_lon_river_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@


def plot(reference, test, diff, metrics_dict, parameter):

return base_plot(reference, test, diff, metrics_dict, parameter)
4 changes: 1 addition & 3 deletions e3sm_diags/plot/cartopy/meridional_mean_2d_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def get_ax_size(fig, ax):


def plot_panel(n, fig, proj, var, clevels, cmap, title, parameters, stats=None):

# var_min = float(var.min())
# var_max = float(var.max())
# var_mean = cdutil.averager(var, axis='xy', weights='generate')
Expand Down Expand Up @@ -167,7 +166,6 @@ def plot_panel(n, fig, proj, var, clevels, cmap, title, parameters, stats=None):


def plot(reference, test, diff, metrics_dict, parameter):

# Create figure, projection
fig = plt.figure(figsize=parameter.figsize, dpi=parameter.dpi)
# proj = ccrs.PlateCarree(central_longitude=180)
Expand Down Expand Up @@ -255,7 +253,7 @@ def plot(reference, test, diff, metrics_dict, parameter):
subpage = np.array(p).reshape(2, 2)
subpage[1, :] = subpage[0, :] + subpage[1, :]
subpage = subpage + np.array(border).reshape(2, 2)
subpage = list(((subpage) * page).flatten())
subpage = list(((subpage) * page).flatten()) # type: ignore
extent = matplotlib.transforms.Bbox.from_extents(*subpage)
# Save subplot
fname = fnm + ".%i." % (i) + f
Expand Down
4 changes: 1 addition & 3 deletions e3sm_diags/plot/cartopy/polar_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def get_ax_size(fig, ax):


def plot_panel(n, fig, proj, pole, var, clevels, cmap, title, parameters, stats=None):

var = add_cyclic(var)
lon = var.getLongitude()
lat = var.getLatitude()
Expand Down Expand Up @@ -158,7 +157,6 @@ def plot_panel(n, fig, proj, pole, var, clevels, cmap, title, parameters, stats=


def plot(reference, test, diff, metrics_dict, parameter):

# Create figure, projection
fig = plt.figure(figsize=parameter.figsize, dpi=parameter.dpi)

Expand Down Expand Up @@ -262,7 +260,7 @@ def plot(reference, test, diff, metrics_dict, parameter):
subpage = np.array(p).reshape(2, 2)
subpage[1, :] = subpage[0, :] + subpage[1, :]
subpage = subpage + np.array(border).reshape(2, 2)
subpage = list(((subpage) * page).flatten())
subpage = list(((subpage) * page).flatten()) # type: ignore
extent = matplotlib.transforms.Bbox.from_extents(*subpage)
# Save subplot
fname = fnm + ".%i." % (i) + f
Expand Down
1 change: 0 additions & 1 deletion e3sm_diags/plot/cartopy/tc_analysis_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def get_ax_size(fig, ax):


def plot_panel(n, fig, proj, var, var_num_years, region, title):

ax = fig.add_axes(panel[n], projection=proj)
ax.set_extent(plot_info[region][0], ccrs.PlateCarree())

Expand Down
4 changes: 1 addition & 3 deletions e3sm_diags/plot/cartopy/zonal_mean_2d_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def get_ax_size(fig, ax):


def plot_panel(n, fig, proj, var, clevels, cmap, title, parameters, stats=None):

# var_min = float(var.min())
# var_max = float(var.max())
# var_mean = cdutil.averager(var, axis='xy', weights='generate')
Expand Down Expand Up @@ -187,7 +186,6 @@ def plot_panel(n, fig, proj, var, clevels, cmap, title, parameters, stats=None):


def plot(reference, test, diff, metrics_dict, parameter):

# Create figure, projection
fig = plt.figure(figsize=parameter.figsize, dpi=parameter.dpi)
# proj = ccrs.PlateCarree(central_longitude=180)
Expand Down Expand Up @@ -277,7 +275,7 @@ def plot(reference, test, diff, metrics_dict, parameter):
subpage = np.array(p).reshape(2, 2)
subpage[1, :] = subpage[0, :] + subpage[1, :]
subpage = subpage + np.array(border).reshape(2, 2)
subpage = list(((subpage) * page).flatten())
subpage = list(((subpage) * page).flatten()) # type: ignore
extent = matplotlib.transforms.Bbox.from_extents(*subpage)
# Save subplot
fname = fnm + ".%i." % (i) + f
Expand Down
1 change: 0 additions & 1 deletion e3sm_diags/plot/cartopy/zonal_mean_2d_stratosphere_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@


def plot(reference, test, diff, metrics_dict, parameter):

return base_plot(reference, test, diff, metrics_dict, parameter)
3 changes: 1 addition & 2 deletions e3sm_diags/plot/cartopy/zonal_mean_xy_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def get_ax_size(fig, ax):


def plot(reference, test, diff, metrics_dict, parameter):

# Create figure
fig = plt.figure(figsize=parameter.figsize, dpi=parameter.dpi)

Expand Down Expand Up @@ -121,7 +120,7 @@ def plot(reference, test, diff, metrics_dict, parameter):
subpage = np.array(p).reshape(2, 2)
subpage[1, :] = subpage[0, :] + subpage[1, :]
subpage = subpage + np.array(border).reshape(2, 2)
subpage = list(((subpage) * page).flatten())
subpage = list(((subpage) * page).flatten()) # type: ignore
extent = matplotlib.transforms.Bbox.from_extents(*subpage)
# Save subplot
fname = fnm + ".%i." % (i) + f
Expand Down
3 changes: 0 additions & 3 deletions e3sm_diags/viewer/lat_lon_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ def _create_lat_lon_table_index(

# --- Function to read CMIP6 model metrics ---
def read_cmip6_metrics_from_csv(path, variables, seasons):

models = []

with open(path, "r") as fin:
Expand Down Expand Up @@ -292,7 +291,6 @@ def read_cmip6_metrics_from_csv(path, variables, seasons):

# --- Function to read E3SM Diags metrics ---
def read_e3sm_diags_metrics(path, variables, seasons, names=None):

# List of available models
models = []
paths = []
Expand Down Expand Up @@ -674,7 +672,6 @@ def _create_csv_from_dict_taylor_diag(
# Add samples for baseline simulation.

if run_type == "model_vs_obs":

# Read the control run data.
# Example base line csv file name: JJA_metrics_table_taylor_diag_historical_1985-2014_E3SMv1.csv
for ibase, base_line_csv_path in enumerate(base_line_csv_paths):
Expand Down
1 change: 0 additions & 1 deletion e3sm_diags/viewer/mean_2d_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def create_viewer(root_dir, parameters):
for var in param.variables:
for season in param.seasons:
for region in param.regions:

try:
viewer.set_group(param.case_id)
except RuntimeError:
Expand Down

0 comments on commit c6c3adc

Please sign in to comment.