Skip to content

Commit a004f26

Browse files
committed
Spinup bug fix
1 parent e313d89 commit a004f26

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pygem/bin/run/run_spinup.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,6 @@ def _objective(**kwargs):
399399

400400
# get true spinup period (note, if initial fails, oggm tries period/2)
401401
spinup_period_ = gd.rgi_date + 1 - fls[0].y0
402-
if spinup_period_ in results.keys():
403-
return None
404402

405403
# create lookup dict (timestamp → index)
406404
dtable = modelsetup.datesmodelrun(startyear=fls[0].y0, endyear=kwargs['ye'])
@@ -431,8 +429,12 @@ def _objective(**kwargs):
431429
if p in results.keys():
432430
continue
433431
kwargs['spinup_period'] = p
434-
p_, mismatch, model = _objective(**kwargs)
435-
results[p_] = (mismatch, model)
432+
out = _objective(**kwargs)
433+
if isinstance(out, tuple):
434+
p_, mismatch, model = out
435+
results[out[0]] = (out[1], out[2])
436+
else:
437+
continue
436438

437439
# find best
438440
best_period = min(results, key=lambda k: results[k][0])
@@ -441,8 +443,7 @@ def _objective(**kwargs):
441443
kwargs['spinup_period'] = best_period
442444
# ensure spinup start year <= min_start_yr
443445
if gd.rgi_date + 1 - best_period > min_start_yr:
444-
kwargs['spinup_start_yr'] = min_start_yr
445-
kwargs.pop('spinup_period')
446+
kwargs['spinup_period'] = gd.rgi_date + 1 - min_start_yr
446447
p_, best_value, best_model = _objective(**kwargs)
447448
results[p_] = (mismatch, model)
448449
best_period = gd.rgi_date + 1 - min_start_yr

0 commit comments

Comments
 (0)