Skip to content

Commit

Permalink
More warnings fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaussion committed Aug 25, 2023
1 parent b55aa49 commit fd4f1b2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
17 changes: 9 additions & 8 deletions oggm/core/dynamic_spinup.py
Expand Up @@ -1206,8 +1206,8 @@ def dynamic_melt_f_run_with_dynamic_spinup(
with utils.DisableLogger():
ds = utils.compile_run_output(gdir, input_filesuffix=output_filesuffix,
path=False)
dmdtda_mdl = ((ds.volume.loc[yr1_ref_mb].values -
ds.volume.loc[yr0_ref_mb].values) /
dmdtda_mdl = ((ds.volume.loc[yr1_ref_mb].values[0] -
ds.volume.loc[yr0_ref_mb].values[0]) /
gdir.rgi_area_m2 /
(yr1_ref_mb - yr0_ref_mb) *
cfg.PARAMS['ice_density'])
Expand Down Expand Up @@ -1785,14 +1785,13 @@ def run_dynamic_melt_f_calibration(
# Get the reference geodetic mb and error if not given
if ref_dmdtda is None:
df_ref_dmdtda = utils.get_geodetic_mb_dataframe().loc[gdir.rgi_id]
sel = df_ref_dmdtda.loc[df_ref_dmdtda['period'] == ref_period].iloc[0]
# reference geodetic mass balance from Hugonnet 2021
ref_dmdtda = float(
df_ref_dmdtda.loc[df_ref_dmdtda['period'] == ref_period]['dmdtda'])
ref_dmdtda = float(sel['dmdtda'])
# dmdtda: in meters water-equivalent per year -> we convert
ref_dmdtda *= 1000 # kg m-2 yr-1
# error of reference geodetic mass balance from Hugonnet 2021
err_ref_dmdtda = float(df_ref_dmdtda.loc[df_ref_dmdtda['period'] ==
ref_period]['err_dmdtda'])
err_ref_dmdtda = float(sel['err_dmdtda'])
err_ref_dmdtda *= 1000 # kg m-2 yr-1
err_ref_dmdtda *= err_dmdtda_scaling_factor

Expand Down Expand Up @@ -1957,8 +1956,10 @@ def cost_fct(melt_f, model_dynamic_spinup_end):
model_dynamic_spinup_end.append(copy.deepcopy(model_dynamic_spinup))

# calculate the mismatch of dmdtda
cost = float(dmdtda_mdl - ref_dmdtda)

try:
cost = float(dmdtda_mdl - ref_dmdtda)
except:
t = 1
return cost

def init_cost_fun():
Expand Down
6 changes: 4 additions & 2 deletions oggm/shop/cru.py
Expand Up @@ -176,8 +176,10 @@ def process_cru_data(gdir, tmp_file=None, pre_file=None, y0=None, y1=None,
assert len(hgt_f) > 0.

# maybe this will throw out of bounds warnings
nc_ts_tmp.set_subset(corners=((lon, lat), (lon, lat)), margin=1)
nc_ts_pre.set_subset(corners=((lon, lat), (lon, lat)), margin=1)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=RuntimeWarning)
nc_ts_tmp.set_subset(corners=((lon, lat), (lon, lat)), margin=1)
nc_ts_pre.set_subset(corners=((lon, lat), (lon, lat)), margin=1)

# compute monthly anomalies
# of temp
Expand Down
28 changes: 12 additions & 16 deletions oggm/tests/test_models.py
Expand Up @@ -3606,11 +3606,10 @@ def reset_melt_f():
yr1_ref_dmdtda = int(yr1_ref_dmdtda.split('-')[0])

df_ref_dmdtda = utils.get_geodetic_mb_dataframe().loc[gdir.rgi_id]
ref_dmdtda = float(
df_ref_dmdtda.loc[df_ref_dmdtda['period'] == ref_period]['dmdtda'])
sel = df_ref_dmdtda.loc[df_ref_dmdtda['period'] == ref_period].iloc[0]
ref_dmdtda = float(sel['dmdtda'])
ref_dmdtda *= 1000 # kg m-2 yr-1
err_ref_dmdtda = float(df_ref_dmdtda.loc[df_ref_dmdtda['period'] ==
ref_period]['err_dmdtda'])
err_ref_dmdtda = float(sel['err_dmdtda'])
err_ref_dmdtda *= 1000 # kg m-2 yr-1

if do_inversion:
Expand Down Expand Up @@ -3795,11 +3794,10 @@ def reset_melt_f():
yr1_ref_dmdtda = int(yr1_ref_dmdtda.split('-')[0])

df_ref_dmdtda = utils.get_geodetic_mb_dataframe().loc[gdir.rgi_id]
ref_dmdtda = float(
df_ref_dmdtda.loc[df_ref_dmdtda['period'] == ref_period]['dmdtda'])
sel = df_ref_dmdtda.loc[df_ref_dmdtda['period'] == ref_period]
ref_dmdtda = float(sel['dmdtda'])
ref_dmdtda *= 1000 # kg m-2 yr-1
err_ref_dmdtda = float(df_ref_dmdtda.loc[df_ref_dmdtda['period'] ==
ref_period]['err_dmdtda'])
err_ref_dmdtda = float(sel['err_dmdtda'])
err_ref_dmdtda *= 1000 # kg m-2 yr-1

melt_f_max = 1000 * 12 / 365
Expand Down Expand Up @@ -4038,11 +4036,10 @@ def reset_melt_f():
'oggm_v1.6/L3-L5_files/2023.1/elev_bands/W5E5/')[0]

df_ref_dmdtda = utils.get_geodetic_mb_dataframe().loc[gdir.rgi_id]
ref_dmdtda = float(
df_ref_dmdtda.loc[df_ref_dmdtda['period'] == ref_period]['dmdtda'])
sel = df_ref_dmdtda.loc[df_ref_dmdtda['period'] == ref_period].iloc[0]
ref_dmdtda = float(sel['dmdtda'])
ref_dmdtda *= 1000 # kg m-2 yr-1
err_ref_dmdtda = float(df_ref_dmdtda.loc[df_ref_dmdtda['period'] ==
ref_period]['err_dmdtda'])
err_ref_dmdtda = float(sel['err_dmdtda'])
err_ref_dmdtda *= 1000 # kg m-2 yr-1
delta_ref_dmdtda = 100
delta_err_ref_dmdtda = -50
Expand Down Expand Up @@ -4172,11 +4169,10 @@ def reset_melt_f():
yr1_ref_dmdtda = int(yr1_ref_dmdtda.split('-')[0])

df_ref_dmdtda = utils.get_geodetic_mb_dataframe().loc[gdir.rgi_id]
ref_dmdtda = float(
df_ref_dmdtda.loc[df_ref_dmdtda['period'] == ref_period]['dmdtda'])
sel = df_ref_dmdtda.loc[df_ref_dmdtda['period'] == ref_period].iloc[0]
ref_dmdtda = float(sel['dmdtda'])
ref_dmdtda *= 1000 # kg m-2 yr-1
err_ref_dmdtda = float(df_ref_dmdtda.loc[df_ref_dmdtda['period'] ==
ref_period]['err_dmdtda'])
err_ref_dmdtda = float(sel['err_dmdtda'])
err_ref_dmdtda *= 1000 # kg m-2 yr-1

# conduct the run
Expand Down
1 change: 1 addition & 0 deletions oggm/tests/test_utils.py
Expand Up @@ -1397,6 +1397,7 @@ def test_elev_bands_and_spinup_run_with_different_evolution_models(self):
dynamic_spinup='area/dmdtda', test_rgidf=rgidf,
test_intersects_file=inter,
store_fl_diagnostics=True,
continue_on_error=False,
mb_calibration_strategy='melt_temp',
test_topofile=topof, elev_bands=True,
override_params={'geodetic_mb_period': ref_period,
Expand Down
4 changes: 4 additions & 0 deletions oggm/tests/test_workflow.py
Expand Up @@ -382,6 +382,8 @@ def test_random(self):
@mpl_image_compare(remove_text=True, multi=True)
def test_plot_region_inversion():

pytest.importorskip('pytest_mpl')

gdirs = up_to_inversion()

# We prepare for the plot, which needs our own map to proceed.
Expand Down Expand Up @@ -409,6 +411,8 @@ def test_plot_region_inversion():
@mpl_image_compare(remove_text=True, multi=True)
def test_plot_region_model():

pytest.importorskip('pytest_mpl')

gdirs = random_for_plot()

dfc = utils.compile_task_log(gdirs,
Expand Down

0 comments on commit fd4f1b2

Please sign in to comment.