Skip to content

Climatology function breaks with season == "ANN" and drivers silently ignores errors with fallback behavior #680

@tomvothecoder

Description

@tomvothecoder

What happened?

I was writing a new climo() function in #677 and found a bug in the existing climo() function. The existing climo() function does not have a conditional statement for season == "ANN", causing this function to break if this case is true.

# Compute climatology
if season == "ANNUALCYCLE":
cycle = [
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
"12",
]
elif season == "SEASONALCYCLE":
cycle = ["DJF", "MAM", "JJA", "SON"]
else:
cycle = [season]

Downstream in the lat_lon_driver.run_diag() function, there is a section of code to get the land_frac and ocean_frac.

# Get land/ocean fraction for masking.
try:
land_frac = test_data.get_climo_variable("LANDFRAC", season)
ocean_frac = test_data.get_climo_variable("OCNFRAC", season)
except Exception:
mask_path = os.path.join(
e3sm_diags.INSTALL_PATH, "acme_ne30_ocean_land_mask.nc"
)
with cdms2.open(mask_path) as f:
land_frac = f("LANDFRAC")
ocean_frac = f("OCNFRAC")

  • If we run with "ANN", this section of code silently ignores this error due to except Exception (which captures all possible exceptions).
  • As a result, the exception will open the default mask file (acme_ne30_ocean_land_mask.nc) in all cases even if the masking variables exist in the test data and the climatology can be calculated for them.

What did you expect to happen?

  1. climo() should support "ANN"
  2. lat_lon_driver.run_diag() should only capture specific exceptions (e.g,. RunTimeError) and produce a logger warning if captured
  3. Check all other drivers for similar cases as 2. and fix them

Minimal Complete Verifiable Example

Relevant log output

Anything else we need to know?

In PR #677 (work-in-progress), I wrote a new climo() function that resolves this issue:
https://github.com/E3SM-Project/e3sm_diags/pull/677/files#diff-682f63237e8473278ef0ba3c452382fd62c09bb5cd23a435c8397dfd1ae98487

Environment

Latest stable release and main branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug fix (will increment patch version)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions