Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaussion committed Mar 1, 2023
1 parent ba035da commit 0a5b854
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
14 changes: 10 additions & 4 deletions oggm/core/massbalance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

# Built ins
import logging
import os
# External libs
import cftime
import numpy as np
import xarray as xr
import pandas as pd
import netCDF4
from scipy.interpolate import interp1d
from scipy import optimize
# Locals
Expand Down Expand Up @@ -517,6 +517,7 @@ def __init__(self, gdir,
grad = self.prcp * 0 + default_grad
self.grad = grad
self.ref_hgt = nc.ref_hgt
self.climate_source = nc.climate_source
self.ys = self.years[0]
self.ye = self.years[-1]

Expand All @@ -527,10 +528,15 @@ def __repr__(self):
summary += [' Attributes:']
# Add all scalar attributes
done = []
for k in ['hemisphere', 'melt_f', 'prcp_fac', 'temp_bias', 'bias']:
for k in ['hemisphere', 'climate_source', 'melt_f', 'prcp_fac', 'temp_bias', 'bias']:
done.append(k)
nbform = ' - {}: {}' if k == 'hemisphere' else ' - {}: {:.02f}'
summary += [nbform.format(k, self.__getattribute__(k))]
v = self.__getattribute__(k)
if k == 'climate_source':
if v.endswith('.nc'):
v = os.path.basename(v)
nofloat = ['hemisphere', 'climate_source']
nbform = ' - {}: {}' if k in nofloat else ' - {}: {:.02f}'
summary += [nbform.format(k, v)]
for k, v in self.__dict__.items():
if np.isscalar(v) and not k.startswith('_') and k not in done:
nbform = ' - {}: {}'
Expand Down
7 changes: 4 additions & 3 deletions oggm/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ def test_repr(self, hef_gdir):
Class: MonthlyTIModel
Attributes:
- hemisphere: nh
- melt_f: 200.59
- climate_source: histalp_merged_hef.nc
- melt_f: 6.59
- prcp_fac: 2.50
- temp_bias: 0.00
- bias: 0.00
Expand Down Expand Up @@ -3055,7 +3056,7 @@ def test_equilibrium_glacier_wide(self, hef_gdir, inversion_params):
after_area = model.area_km2
after_len = model.fls[-1].length_m

np.testing.assert_allclose(ref_vol, after_vol, rtol=0.08)
np.testing.assert_allclose(ref_vol, after_vol, rtol=0.1)
np.testing.assert_allclose(ref_area, after_area, rtol=0.01)
np.testing.assert_allclose(ref_len, after_len, atol=200.01)

Expand Down Expand Up @@ -3122,7 +3123,7 @@ def test_random(self, hef_gdir, inversion_params):
dfo = hef_gdir.read_json('mb_calib')
df = massbalance.mb_calibration_from_geodetic_mb(hef_gdir,
calibrate_param1='temp_bias',
monthly_melt_f_default=dfo['melt_f'],
melt_f_default=dfo['melt_f'],
ref_mb=0,
ref_mb_years=(1970, 2001),
write_to_gdir=False)
Expand Down
3 changes: 2 additions & 1 deletion oggm/tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ def test_some_characs(self):
assert np.all(dfc.inv_volume_km3 > 0)
assert np.all(dfc.bias == 0)
assert np.all(dfc.temp_bias == 0)
assert np.all(dfc.monthly_melt_f > 80)
assert np.all(dfc.melt_f > cfg.PARAMS['melt_f_min'])
assert np.all(dfc.melt_f < cfg.PARAMS['melt_f_max'])
dfc = utils.compile_climate_statistics(gdirs)
sel = ['flowline_mean_elev', '1980-2010_avg_temp_mean_elev']
cc = dfc[sel].corr().values[0, 1]
Expand Down

0 comments on commit 0a5b854

Please sign in to comment.