Skip to content

[BUG] KeyError: 'operation' when processing Amon.tasmin (and related variables) #241

@rhaegar325

Description

@rhaegar325

Bug: KeyError: 'operation' when processing Amon.tasmin (and related variables)

Description

Processing Amon.tasmin fails with the following error:

Error processing Amon.tasmin: 'operation'

This is a KeyError raised in evaluate_expression() when it tries to access expr["operation"] on a calculation dict that uses "formula" as the function-name key instead.

Affected Variables

The following variables in ACCESS-ESM1.6_mappings.json use "formula" instead of "operation":

  • tasmincalculate_monthly_minimum
  • tasmaxcalculate_monthly_maximum
  • areacellocalculate_areacello
  • (ocean variable)calculate_global_ave_ocean

Root Cause

In src/access_moppy/derivations/__init__.py, evaluate_expression() unconditionally accesses expr["operation"]:

# line 113 (before fix)
op = expr["operation"]

However, some mapping entries use "formula" as the key for the function name:

"calculation": {
    "type": "formula",
    "formula": "calculate_monthly_minimum",
    "operands": ["fld_s03i236"]
}

While others correctly use "operation":

"calculation": {
    "type": "formula",
    "operation": "add",
    "operands": ["fld_s30i405", "fld_s30i406"]
}

This inconsistency in ACCESS-ESM1.6_mappings.json causes evaluate_expression() to raise a KeyError for the affected variables.

Fix

Update evaluate_expression() to accept either "operation" or "formula" as the function-name key:

# src/access_moppy/derivations/__init__.py, line 113
op = expr.get("operation") or expr.get("formula")

or make the handling consistent in ACCESS-ESM1.6_mappings.json by using the operation.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions