Skip to content

Commit 1b31f69

Browse files
committed
more flexbility
1 parent c0b6969 commit 1b31f69

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

oggm/cfg.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,16 @@ def set_logging_config(logging_level='INFO'):
312312
Print confirmation that things are working as expected, e.g. when
313313
each task is run correctly (this is the default).
314314
WARNING
315-
Indication that something unexpected happened on a glacier,
316-
but that OGGM is still working on this glacier.
315+
Do not print INFO or DEBUG but print WARNING (which indicate that
316+
something unexpected happened on a glacier but that OGGM is
317+
still working on this glacier).
317318
ERROR
318319
Print workflow messages and errors only, e.g. when a glacier cannot
319320
run properly.
320321
WORKFLOW
321322
Print only high level, workflow information (typically, one message
322-
per task). Errors and warnings will NOT be printed.
323+
per task). Errors and warnings will NOT be printed. This is the level
324+
we recommend for operational large-scale runs.
323325
CRITICAL
324326
Print nothing but fatal errors.
325327

oggm/core/massbalance.py

+35-11
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ class MonthlyTIModel(MassBalanceModel):
320320
def __init__(self, gdir,
321321
filename='climate_historical',
322322
input_filesuffix='',
323+
mb_params_filesuffix='',
323324
fl_id=None,
324325
melt_f=None,
325326
temp_bias=None,
@@ -340,7 +341,10 @@ def __init__(self, gdir,
340341
set to a different BASENAME if you want to use alternative climate
341342
data. Default is 'climate_historical'
342343
input_filesuffix : str, optional
343-
append a suffix to the filename (useful for GCM runs).
344+
append a suffix to the climate input filename (useful for GCM runs).
345+
mb_params_filesuffix : str, optional
346+
append a suffix to the mb params calibration file (useful for
347+
sensitivity runs).
344348
fl_id : int, optional
345349
if this flowline has been calibrated alone and has specific
346350
model parameters.
@@ -378,6 +382,7 @@ def __init__(self, gdir,
378382
super(MonthlyTIModel, self).__init__()
379383
self.valid_bounds = [-1e4, 2e4] # in m
380384
self.fl_id = fl_id # which flowline are we the model of?
385+
self.mb_params_filesuffix = mb_params_filesuffix # which mb params?
381386
self.gdir = gdir
382387

383388
if melt_f is None:
@@ -543,13 +548,16 @@ def temp_bias(self, new_temp_bias):
543548
@lazy_property
544549
def calib_params(self):
545550
if self.fl_id is None:
546-
return self.gdir.read_json('mb_calib')
551+
return self.gdir.read_json('mb_calib', self.mb_params_filesuffix)
547552
else:
548553
try:
549-
return self.gdir.read_json('mb_calib',
550-
filesuffix=f'_fl{self.fl_id}')
554+
out = self.gdir.read_json('mb_calib', filesuffix=f'_fl{self.fl_id}')
555+
if self.mb_params_filesuffix:
556+
raise InvalidWorkflowError('mb_params_filesuffix cannot be '
557+
'used with multiple flowlines')
558+
return out
551559
except FileNotFoundError:
552-
return self.gdir.read_json('mb_calib')
560+
return self.gdir.read_json('mb_calib', self.mb_params_filesuffix)
553561

554562
def is_year_valid(self, year):
555563
return self.ys <= year <= self.ye
@@ -1403,6 +1411,7 @@ def mb_calibration_from_wgms_mb(gdir, **kwargs):
14031411
Parameters
14041412
----------
14051413
**kwargs : any kwarg accepted by mb_calibration_from_scalar_mb
1414+
except `ref_mb` and `ref_mb_years`
14061415
"""
14071416

14081417
# Note that this currently does not work for hydro years (WGMS uses hydro)
@@ -1428,12 +1437,15 @@ def mb_calibration_from_geodetic_mb(gdir, *,
14281437
calibrate_param2=None,
14291438
calibrate_param3=None,
14301439
mb_model_class=MonthlyTIModel,
1440+
filesuffix='',
14311441
):
14321442
"""Calibrate for geodetic MB data from Hugonnet et al., 2021.
14331443
14341444
The data table can be obtained with utils.get_geodetic_mb_dataframe().
14351445
It is equivalent to the original data from Hugonnet, but has some outlier
1436-
values filtered. See `this notebook` for more details.
1446+
values filtered. See [this notebook](https://nbviewer.org/urls/
1447+
cluster.klima.uni-bremen.de/~oggm/geodetic_ref_mb/convert_vold1.ipynb)
1448+
for more details.
14371449
14381450
The problem of calibrating many unknown parameters on geodetic data is
14391451
currently unsolved. This is OGGM's current take, based on trial and
@@ -1480,6 +1492,10 @@ def mb_calibration_from_geodetic_mb(gdir, *,
14801492
the MassBalanceModel to use for the calibration. Needs to use the
14811493
same parameters as MonthlyTIModel (the default): melt_f,
14821494
temp_bias, prcp_fac.
1495+
filesuffix: str
1496+
add a filesuffix to mb_params.json. This could be useful for sensitivity
1497+
analyses with MB models, if they need to fetch other sets of params for
1498+
example.
14831499
14841500
Returns
14851501
-------
@@ -1551,6 +1567,7 @@ def mb_calibration_from_geodetic_mb(gdir, *,
15511567
prcp_fac_max=prcp_fac_max,
15521568
temp_bias=temp_bias,
15531569
mb_model_class=mb_model_class,
1570+
filesuffix=filesuffix,
15541571
)
15551572

15561573
else:
@@ -1565,6 +1582,7 @@ def mb_calibration_from_geodetic_mb(gdir, *,
15651582
calibrate_param3=calibrate_param3,
15661583
temp_bias=temp_bias,
15671584
mb_model_class=mb_model_class,
1585+
filesuffix=filesuffix,
15681586
)
15691587

15701588

@@ -1896,7 +1914,7 @@ def to_minimize(x, model_attr):
18961914

18971915

18981916
@entity_task(log, writes=['mb_calib'])
1899-
def perturbate_mb_params(gdir, perturbation=None, reset_default=False):
1917+
def perturbate_mb_params(gdir, perturbation=None, reset_default=False, filesuffix=''):
19001918
"""Replaces pre-calibrated MB params with perturbed ones for this glacier.
19011919
19021920
It simply replaces the existing `mb_calib.json` file with an
@@ -1923,9 +1941,15 @@ def perturbate_mb_params(gdir, perturbation=None, reset_default=False):
19231941
perturbation : dict
19241942
the parameters to change and the associated value (see doc above)
19251943
reset_default : bool
1926-
reset the parameters to their original value
1944+
reset the parameters to their original value. This might be
1945+
unnecessary if using the filesuffix mechanism.
1946+
filesuffix : str
1947+
write the modified parameters in a separate mb_calib.json file
1948+
with the filesuffix appended. This can then be read by the
1949+
MassBalanceModel for example instead of the default one.
1950+
Note that it's always the default, precalibrated params
1951+
file which is read to start with.
19271952
"""
1928-
19291953
df = gdir.read_json('mb_calib')
19301954

19311955
# Save original params if not there
@@ -1936,7 +1960,7 @@ def perturbate_mb_params(gdir, perturbation=None, reset_default=False):
19361960
if reset_default:
19371961
for k in ['bias', 'melt_f', 'prcp_fac', 'temp_bias']:
19381962
df[k] = df[k + '_orig']
1939-
gdir.write_json(df, 'mb_calib')
1963+
gdir.write_json(df, 'mb_calib', filesuffix=filesuffix)
19401964
return df
19411965

19421966
for k, v in perturbation.items():
@@ -1947,7 +1971,7 @@ def perturbate_mb_params(gdir, perturbation=None, reset_default=False):
19471971
else:
19481972
raise InvalidParamsError(f'Perturbation not valid: {k}')
19491973

1950-
gdir.write_json(df, 'mb_calib')
1974+
gdir.write_json(df, 'mb_calib', filesuffix=filesuffix)
19511975
return df
19521976

19531977

oggm/tasks.py

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from oggm.core.massbalance import mb_calibration_from_wgms_mb
3333
from oggm.core.massbalance import apparent_mb_from_linear_mb
3434
from oggm.core.massbalance import apparent_mb_from_any_mb
35+
from oggm.core.massbalance import perturbate_mb_params
3536
from oggm.core.massbalance import fixed_geometry_mass_balance
3637
from oggm.core.massbalance import compute_ela
3738
from oggm.shop.w5e5 import process_w5e5_data

0 commit comments

Comments
 (0)