@@ -320,6 +320,7 @@ class MonthlyTIModel(MassBalanceModel):
320
320
def __init__ (self , gdir ,
321
321
filename = 'climate_historical' ,
322
322
input_filesuffix = '' ,
323
+ mb_params_filesuffix = '' ,
323
324
fl_id = None ,
324
325
melt_f = None ,
325
326
temp_bias = None ,
@@ -340,7 +341,10 @@ def __init__(self, gdir,
340
341
set to a different BASENAME if you want to use alternative climate
341
342
data. Default is 'climate_historical'
342
343
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).
344
348
fl_id : int, optional
345
349
if this flowline has been calibrated alone and has specific
346
350
model parameters.
@@ -378,6 +382,7 @@ def __init__(self, gdir,
378
382
super (MonthlyTIModel , self ).__init__ ()
379
383
self .valid_bounds = [- 1e4 , 2e4 ] # in m
380
384
self .fl_id = fl_id # which flowline are we the model of?
385
+ self .mb_params_filesuffix = mb_params_filesuffix # which mb params?
381
386
self .gdir = gdir
382
387
383
388
if melt_f is None :
@@ -543,13 +548,16 @@ def temp_bias(self, new_temp_bias):
543
548
@lazy_property
544
549
def calib_params (self ):
545
550
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 )
547
552
else :
548
553
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
551
559
except FileNotFoundError :
552
- return self .gdir .read_json ('mb_calib' )
560
+ return self .gdir .read_json ('mb_calib' , self . mb_params_filesuffix )
553
561
554
562
def is_year_valid (self , year ):
555
563
return self .ys <= year <= self .ye
@@ -1403,6 +1411,7 @@ def mb_calibration_from_wgms_mb(gdir, **kwargs):
1403
1411
Parameters
1404
1412
----------
1405
1413
**kwargs : any kwarg accepted by mb_calibration_from_scalar_mb
1414
+ except `ref_mb` and `ref_mb_years`
1406
1415
"""
1407
1416
1408
1417
# Note that this currently does not work for hydro years (WGMS uses hydro)
@@ -1428,12 +1437,15 @@ def mb_calibration_from_geodetic_mb(gdir, *,
1428
1437
calibrate_param2 = None ,
1429
1438
calibrate_param3 = None ,
1430
1439
mb_model_class = MonthlyTIModel ,
1440
+ filesuffix = '' ,
1431
1441
):
1432
1442
"""Calibrate for geodetic MB data from Hugonnet et al., 2021.
1433
1443
1434
1444
The data table can be obtained with utils.get_geodetic_mb_dataframe().
1435
1445
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.
1437
1449
1438
1450
The problem of calibrating many unknown parameters on geodetic data is
1439
1451
currently unsolved. This is OGGM's current take, based on trial and
@@ -1480,6 +1492,10 @@ def mb_calibration_from_geodetic_mb(gdir, *,
1480
1492
the MassBalanceModel to use for the calibration. Needs to use the
1481
1493
same parameters as MonthlyTIModel (the default): melt_f,
1482
1494
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.
1483
1499
1484
1500
Returns
1485
1501
-------
@@ -1551,6 +1567,7 @@ def mb_calibration_from_geodetic_mb(gdir, *,
1551
1567
prcp_fac_max = prcp_fac_max ,
1552
1568
temp_bias = temp_bias ,
1553
1569
mb_model_class = mb_model_class ,
1570
+ filesuffix = filesuffix ,
1554
1571
)
1555
1572
1556
1573
else :
@@ -1565,6 +1582,7 @@ def mb_calibration_from_geodetic_mb(gdir, *,
1565
1582
calibrate_param3 = calibrate_param3 ,
1566
1583
temp_bias = temp_bias ,
1567
1584
mb_model_class = mb_model_class ,
1585
+ filesuffix = filesuffix ,
1568
1586
)
1569
1587
1570
1588
@@ -1896,7 +1914,7 @@ def to_minimize(x, model_attr):
1896
1914
1897
1915
1898
1916
@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 = '' ):
1900
1918
"""Replaces pre-calibrated MB params with perturbed ones for this glacier.
1901
1919
1902
1920
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):
1923
1941
perturbation : dict
1924
1942
the parameters to change and the associated value (see doc above)
1925
1943
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.
1927
1952
"""
1928
-
1929
1953
df = gdir .read_json ('mb_calib' )
1930
1954
1931
1955
# Save original params if not there
@@ -1936,7 +1960,7 @@ def perturbate_mb_params(gdir, perturbation=None, reset_default=False):
1936
1960
if reset_default :
1937
1961
for k in ['bias' , 'melt_f' , 'prcp_fac' , 'temp_bias' ]:
1938
1962
df [k ] = df [k + '_orig' ]
1939
- gdir .write_json (df , 'mb_calib' )
1963
+ gdir .write_json (df , 'mb_calib' , filesuffix = filesuffix )
1940
1964
return df
1941
1965
1942
1966
for k , v in perturbation .items ():
@@ -1947,7 +1971,7 @@ def perturbate_mb_params(gdir, perturbation=None, reset_default=False):
1947
1971
else :
1948
1972
raise InvalidParamsError (f'Perturbation not valid: { k } ' )
1949
1973
1950
- gdir .write_json (df , 'mb_calib' )
1974
+ gdir .write_json (df , 'mb_calib' , filesuffix = filesuffix )
1951
1975
return df
1952
1976
1953
1977
0 commit comments