Skip to content

Commit

Permalink
Revert back some inversion checks from pr #1089 and small bugfix in i…
Browse files Browse the repository at this point in the history
…tslive (#1094)

* New attempt

* pep8
  • Loading branch information
fmaussion authored Nov 12, 2020
1 parent b87ffda commit f71fe7d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions oggm/core/centerlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ def set_apparent_mb(self, mb, mu_star=None):
flux_needs_correction = False
flux = np.cumsum(self.flux + mb * self.widths * self.dx)

# We filter only lines with two negative grid points, the
# rest we can cope with
# We filter only lines with two negative grid points,
# the rest we can cope with
if flux[-2] < 0:
flux_needs_correction = True

Expand Down
21 changes: 21 additions & 0 deletions oggm/core/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,27 @@ def local_t_star(gdir, *, ref_df=None, tstar=None, bias=None):
gdir.write_json(df, 'local_mustar')


def _check_terminus_mass_flux(gdir, fls, cmb):
# Avoid code duplication

rho = cfg.PARAMS['ice_density']

# This variable is in "sensible" units normalized by width
flux = fls[-1].flux[-1]
aflux = flux * (gdir.grid.dx ** 2) / rho # m3 ice per year

# If not marine and a bit far from zero, warning
if cmb == 0 and flux > 0 and not np.allclose(flux, 0, atol=0.01):
log.info('(%s) flux should be zero, but is: '
'%.4f m3 ice yr-1', gdir.rgi_id, aflux)

# If not marine and quite far from zero, error
if cmb == 0 and flux > 0 and not np.allclose(flux, 0, atol=1):
msg = ('({}) flux should be zero, but is: {:.4f} m3 ice yr-1'
.format(gdir.rgi_id, aflux))
raise MassBalanceCalibrationError(msg)


def _mu_star_per_minimization(x, fls, cmb, temp, prcp, widths):

# Get the corresponding mu
Expand Down
2 changes: 1 addition & 1 deletion oggm/core/inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def prepare_for_inversion(gdir, add_debug_var=False,
log.info('(%s) has negative flux somewhere', gdir.rgi_id)
utils.clip_min(flux, 0, out=flux)

if np.sum(flux <= 0) > 1:
if np.sum(flux <= 0) > 1 and len(fls) == 1:
raise RuntimeError("More than one grid point has zero or "
"negative flux: this should not happen.")

Expand Down
2 changes: 1 addition & 1 deletion oggm/params.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ max_mu_star = 10000.
clip_mu_star = False
# For some glacier geometries, having one mu* for the entire glacier implies
# that some tributaries should not exist and have a negative mass flux
# somewhere along their flowline.
# at the terminus of their flowline.
# This problem can be solved by computing a different mu* for these
# tributaries (recommended)
correct_for_neg_flux = True
Expand Down
4 changes: 2 additions & 2 deletions oggm/shop/its_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _reproject_and_scale(gdir, do_error=False):
if do_error:
ln = 'Uncertainty of ' + ln
v.long_name = ln
v[:] = vx
v[:] = vx.filled(np.nan)

vn = 'obs_icevel_y'
if do_error:
Expand All @@ -178,7 +178,7 @@ def _reproject_and_scale(gdir, do_error=False):
if do_error:
ln = 'Uncertainty of ' + ln
v.long_name = ln
v[:] = vy
v[:] = vy.filled(np.nan)


@utils.entity_task(log, writes=['gridded_data'])
Expand Down

0 comments on commit f71fe7d

Please sign in to comment.