diff --git a/CHANGELOG.md b/CHANGELOG.md index ca52542a..c086eaa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - New functions in `benchmark.py` and `util.py` to facilitate printing of the species/emissions/inventories that differ between Dev & Ref versions. ### Changed -- Applied cleanup susggestions from pylint to `benchmark.py`, `util.py`, `plot.py` -- Replaced format with f-strings in `benchmark.py`, `util.py` +- Applied cleanup susggestions from pylint to `benchmark.py`, `util.py`, `plot.py`, `oh_metrics.py`, `ste_flux.py` +- Replaced format with f-strings in `benchmark.py`, `util.py`, `plot.py`, `oh_metrics.py`, `ste_flux.py` - Abstract some common in `benchmark.py` into functions - Replaced direct calls to `yaml.load` with `util.read_config.file` (mostly using `quiet=True`) diff --git a/gcpy/oh_metrics.py b/gcpy/oh_metrics.py index bc5c9b67..96d5d45b 100644 --- a/gcpy/oh_metrics.py +++ b/gcpy/oh_metrics.py @@ -375,7 +375,7 @@ def print_metrics(common_vars, dst): file=f ) print("#" * 79, file=f) - + # ============================================================== # Mean OH concentration [1e5 molec/cm3] # ============================================================== diff --git a/gcpy/ste_flux.py b/gcpy/ste_flux.py index 83ca7ce6..e24499b6 100644 --- a/gcpy/ste_flux.py +++ b/gcpy/ste_flux.py @@ -11,11 +11,12 @@ import os from calendar import monthrange, month_abbr import warnings +import gc import numpy as np import pandas as pd import xarray as xr import gcpy.constants as physconsts -import gc +from gcpy.util import make_directory # Suppress harmless run-time warnings (mostly about underflow in division) warnings.filterwarnings("ignore", category=RuntimeWarning) @@ -96,18 +97,18 @@ def __init__(self, devstr, files, dst, year, combine="nested", concat_dim="time" ) - except FileNotFoundError: + except FileNotFoundError as exc: msg = f"Could not find one or more files in {files}" - raise FileNotFoundError(msg) + raise FileNotFoundError(msg) from exc else: try: self.ds_flx = xr.open_mfdataset( files, drop_variables=physconsts.skip_these_vars, ) - except FileNotFoundError: + except FileNotFoundError as exc: msg = f"Could not find one or more files in {files}" - raise FileNotFoundError(msg) + raise FileNotFoundError(msg) from exc # Set a flag to denote if this data is from GCHP self.is_gchp = "nf" in self.ds_flx.dims.keys() @@ -135,8 +136,7 @@ def __init__(self, devstr, files, dst, year, # Month names self.mon_name = [] for t in range(self.N_MONTHS): - self.mon_name.append("{} {}".format( - month_abbr[t + 1], self.y0_str)) + self.mon_name.append(f"{ month_abbr[t + 1]} {self.y0_str}") self.mon_name.append("Annual Mean") # Days in the benchmark year @@ -154,8 +154,7 @@ def __init__(self, devstr, files, dst, year, self.d_per_mon = [monthrange(self.y0, self.month)[1] * 1.0] # Month name - self.mon_name = ["{} {}".format(month_abbr[self.month], - self.y0_str)] + self.mon_name = [f"{month_abbr[self.month]} {self.y0_str}"] # Days in benchmark year self.d_per_yr = 0.0 @@ -248,12 +247,7 @@ def print_ste(globvars, df): Strat-trop exchange table """ # Create plot directory hierarchy if necessary - if os.path.isdir(globvars.dst) and not globvars.overwrite: - err_str = "Pass overwrite=True to overwrite files in that directory" - print(f"Directory {globvars.dst} exists. {err_str}") - return - elif not os.path.isdir(globvars.dst): - os.makedirs(globvars.dst) + make_directory(globvars.dst, globvars.overwrite) # Save the file in the Tables folder of dst filename = f"{globvars.dst}/Strat_trop_exchange.txt"