Hi team — small heads-up on what looks like an unintended no-op in the fertiliser N loss-rate calculation.
In SALCAfield/SALCAfield_field.py, inside the if fert_kgN != 0: / if fert_kgTAN != 0: blocks:
857 if fert_kgN != 0:
858 # calculate loss rate through NH3, N2O (only direct) and NOx
859 loss_rate_N_frac = (e_fert_kg_NH3_N+e_direct_kgN2O_N+e_fert_kgNOx_N) / \
860 fert_kgN # [kg N/kg N]
861 min(1.0, loss_rate_N_frac) # cannot be >1
...
866 if fert_kgTAN != 0:
867 # calculate loss rate through NH3, N2O and NOx
868 loss_rate_TAN_frac = (e_fert_kg_NH3_N+e_direct_kgN2O_N+e_fert_kgNOx_N) / \
869 fert_kgTAN # [kg TAN/kg TAN]
870 min(1.0, loss_rate_TAN_frac) # cannot be >1
On lines 861 and 870 the return value of min(1.0, ...) is computed but never assigned, so the statement has no effect. The comment (# cannot be >1) states the intent is to clamp the loss rate to 1.0, but because the result is discarded, loss_rate_N_frac and loss_rate_TAN_frac keep their raw values — which can exceed 1.0 — and are then passed uncapped into SALCAnitrate.
Why it's a bug: when the summed N losses (NH3 + direct N2O + NOx) exceed the applied N (or TAN), the fraction is > 1.0 and the intended clamp silently fails, propagating a physically impossible loss rate downstream.
One-line fix — assign the result:
loss_rate_N_frac = min(1.0, loss_rate_N_frac) # line 861
loss_rate_TAN_frac = min(1.0, loss_rate_TAN_frac) # line 870
Thanks!
Hi team — small heads-up on what looks like an unintended no-op in the fertiliser N loss-rate calculation.
In
SALCAfield/SALCAfield_field.py, inside theif fert_kgN != 0:/if fert_kgTAN != 0:blocks:On lines 861 and 870 the return value of
min(1.0, ...)is computed but never assigned, so the statement has no effect. The comment (# cannot be >1) states the intent is to clamp the loss rate to 1.0, but because the result is discarded,loss_rate_N_fracandloss_rate_TAN_frackeep their raw values — which can exceed 1.0 — and are then passed uncapped into SALCAnitrate.Why it's a bug: when the summed N losses (NH3 + direct N2O + NOx) exceed the applied N (or TAN), the fraction is > 1.0 and the intended clamp silently fails, propagating a physically impossible loss rate downstream.
One-line fix — assign the result:
Thanks!