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":
tasmin — calculate_monthly_minimum
tasmax — calculate_monthly_maximum
areacello — calculate_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.
Bug:
KeyError: 'operation'when processingAmon.tasmin(and related variables)Description
Processing
Amon.tasminfails with the following error:Error processing Amon.tasmin: 'operation'
This is a
KeyErrorraised inevaluate_expression()when it tries to accessexpr["operation"]on a calculation dict that uses"formula"as the function-name key instead.Affected Variables
The following variables in
ACCESS-ESM1.6_mappings.jsonuse"formula"instead of"operation":tasmin—calculate_monthly_minimumtasmax—calculate_monthly_maximumareacello—calculate_areacello(ocean variable)—calculate_global_ave_oceanRoot Cause
In
src/access_moppy/derivations/__init__.py,evaluate_expression()unconditionally accessesexpr["operation"]:However, some mapping entries use
"formula"as the key for the function name:While others correctly use
"operation":This inconsistency in
ACCESS-ESM1.6_mappings.jsoncausesevaluate_expression()to raise aKeyErrorfor the affected variables.Fix
Update
evaluate_expression()to accept either"operation"or"formula"as the function-name key:or make the handling consistent in
ACCESS-ESM1.6_mappings.jsonby using theoperation.