Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add capability to reset the "state" of the mass balance model #1757

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions docs/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ Enhancements
``dis_from_border``, ...) to define this ranking, providing greater flexibility
and control over how the melting sequence is visualized (:pull:`1746`).
By `Patrick Schmitt <https://github.com/pat-schmitt>`_
- Added "reset_state()" function to ``MassBalanceModel`` to signal any state-dependent
mass balance model to "reset its state" at the start of the period. This function
does nothing in the parent class and would only be implemented by a state-ful
mass balance model. Done mainly to address that ``apparent_mb_from_any_mb()`` calls
``get_specific_mb()`` twice, leading to nonzero terminal flux (potentially) with a
state-dependent mass balance model. `apparent_mb_from_any_mb()` also changed
accordingly.

Bug fixes
~~~~~~~~~
Expand Down
17 changes: 16 additions & 1 deletion oggm/core/massbalance.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def __repr__(self):
summary += [nbform.format(k, v)]
return '\n'.join(summary) + '\n'

def reset_state(self):
"""Reset any internal state of the model.
This might not be needed by most models, but some models have an
internal state (e.g. a snow cover history) which can be reset
this way.
"""
pass

def get_monthly_mb(self, heights, year=None, fl_id=None, fls=None):
"""Monthly mass balance at given altitude(s) for a moment in time.

Expand Down Expand Up @@ -2087,7 +2095,7 @@ def to_minimize(ela_h):
@entity_task(log, writes=['inversion_flowlines'])
def apparent_mb_from_any_mb(gdir, mb_model=None,
mb_model_class=MonthlyTIModel,
mb_years=None):
mb_years=None, reset_state=False):
"""Compute apparent mb from an arbitrary mass balance profile.

This searches for a mass balance residual to add to the mass balance
Expand All @@ -2110,6 +2118,10 @@ def apparent_mb_from_any_mb(gdir, mb_model=None,
geodetic MB period, i.e. PARAMS['geodetic_mb_period'].
It does not matter much for the final result, but it should be a
period long enough to have a representative MB gradient.
reset_state : bool
if True, the mass balance model will be reset at each mass-balance year.
This is useful if the model has an internal state that might
affect the results.
"""

# Do we have a calving glacier?
Expand Down Expand Up @@ -2141,6 +2153,9 @@ def to_minimize(residual_to_opt):

residual = optimize.brentq(to_minimize, -1e5, 1e5)

if (reset_state):
mb_model.reset_state()

# Reset flux
for fl in fls:
fl.reset_flux()
Expand Down
Loading