Skip to content

Commit

Permalink
Fix various small bugs (OGGM#1686)
Browse files Browse the repository at this point in the history
* Fix various small bugs

* Fix the fix
  • Loading branch information
fmaussion committed Feb 4, 2024
1 parent 5313d54 commit 7a06570
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions oggm/core/centerlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -2430,6 +2430,8 @@ def fixed_dx_elevation_band_flowline(gdir, bin_variables=None,
warnings.filterwarnings("ignore", category=RuntimeWarning)
interp *= in_total / out_total
odf[var] = interp
# Match how OGGM computes distance along flowline
odf.index = np.arange(nx) * dx_meter
odf.to_csv(gdir.get_filepath('elevation_band_flowline',
filesuffix='_fixed_dx'))

Expand Down
2 changes: 2 additions & 0 deletions oggm/core/flowline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4170,6 +4170,8 @@ def run_with_hydro(gdir, run_task=None, store_monthly_hydro=False,
ods[varname] = ('time', data)
for k, v in d.items():
ods[varname].attrs[k] = v
if store_monthly_hydro and (varname + '_monthly') in ods:
ods[varname + '_monthly'].attrs[k] = v

# Append the output to the existing diagnostics
fpath = gdir.get_filepath('model_diagnostics', filesuffix=suffix)
Expand Down
11 changes: 9 additions & 2 deletions oggm/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,16 @@ def test_init_present_time_glacier_obs_thick(self, hef_elev_gdir,
# test that if w0<0 it is converted to rectangular
# set some thickness to very large values to force it
df_fixed_dx = pd.read_csv(gdir.get_filepath('elevation_band_flowline',
filesuffix='_fixed_dx'))
filesuffix='_fixed_dx'),
index_col=0)

# Check consistency between csv and flowline object
fl_inv = gdir.read_pickle('inversion_flowlines')[0]
assert fl_inv.nx == len(df_fixed_dx)
assert fl_inv.dx_meter == (df_fixed_dx.index[1] - df_fixed_dx.index[0])
np.testing.assert_allclose(fl_inv.dx_meter * np.arange(fl_inv.nx), df_fixed_dx.index)
new_thick = df_fixed_dx['consensus_ice_thickness']
new_thick[-10:] = new_thick[-10:] + 1000
new_thick.iloc[-10:] = new_thick.iloc[-10:] + 1000
df_fixed_dx['consensus_ice_thickness'] = new_thick
ref_vol_rect = np.sum(df_fixed_dx['area_m2'] * new_thick)
df_fixed_dx.to_csv(gdir.get_filepath('elevation_band_flowline',
Expand Down
2 changes: 2 additions & 0 deletions oggm/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ def check_result(ds):
assert 'area_m2_min_h' in ds.data_vars
assert 'melt_on_glacier' in ds.data_vars
assert 'melt_on_glacier_monthly' in ds.data_vars
assert ds_1['melt_on_glacier'].unit == 'kg yr-1'
assert ds_1['melt_on_glacier_monthly'].unit == 'kg yr-1'
assert np.all(np.isnan(
ds.loc[{'rgi_id': gdirs[0].rgi_id}]['area_m2_min_h'].values))
assert np.all(np.isnan(
Expand Down
2 changes: 1 addition & 1 deletion oggm/utils/_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def _entity_task(gdir, *, reset=None, print_log=True,
raise

if self.fallback is not None:
self.fallback(gdir)
out = self.fallback(gdir)
if return_value:
return out

Expand Down

0 comments on commit 7a06570

Please sign in to comment.