Skip to content

Commit

Permalink
Rename prcp_fac
Browse files Browse the repository at this point in the history
  • Loading branch information
fmaussion committed Mar 2, 2023
1 parent 760cfc1 commit 180a492
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 122 deletions.
4 changes: 2 additions & 2 deletions docs/_code/prepare_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
tasks.catchment_width_correction(gdir)
cfg.PARAMS['baseline_climate'] = 'HISTALP'
cfg.PARAMS['use_tstar_calibration'] = True
cfg.PARAMS['use_winter_prcp_factor'] = False
cfg.PARAMS['prcp_scaling_factor'] = 2.5
cfg.PARAMS['use_winter_prcp_fac'] = False
cfg.PARAMS['prcp_fac'] = 2.5
tasks.process_histalp_data(gdir)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=FutureWarning)
Expand Down
17 changes: 8 additions & 9 deletions oggm/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,11 @@ def initialize_minimal(file=None, logging_level='INFO', params=None,
PARAMS['hydro_month_nh'] = cp.as_int('hydro_month_nh')
PARAMS['hydro_month_sh'] = cp.as_int('hydro_month_sh')
PARAMS['geodetic_mb_period'] = cp['geodetic_mb_period']
PARAMS['use_winter_prcp_factor'] = cp.as_bool('use_winter_prcp_factor')
PARAMS['use_winter_prcp_fac'] = cp.as_bool('use_winter_prcp_fac')

k = 'winter_prcp_factor_ab'
k = 'winter_prcp_fac_ab'
PARAMS[k] = [float(vk) for vk in cp.as_list(k)]
k = 'winter_prcp_factor_range'
k = 'winter_prcp_fac_range'
PARAMS[k] = [float(vk) for vk in cp.as_list(k)]
k = 'ref_mb_valid_window'
PARAMS[k] = [int(vk) for vk in cp.as_list(k)]
Expand All @@ -561,9 +561,9 @@ def initialize_minimal(file=None, logging_level='INFO', params=None,

# Precip factor can be none
try:
PARAMS['prcp_scaling_factor'] = cp.as_float('prcp_scaling_factor')
PARAMS['prcp_fac'] = cp.as_float('prcp_fac')
except ValueError:
PARAMS['prcp_scaling_factor'] = None
PARAMS['prcp_fac'] = None

# Delete non-floats
ltr = ['working_dir', 'dem_file', 'climate_file', 'use_tar_shapefiles',
Expand All @@ -582,11 +582,10 @@ def initialize_minimal(file=None, logging_level='INFO', params=None,
'free_board_marine_terminating', 'use_kcalving_for_inversion',
'error_when_glacier_reaches_boundaries', 'glacier_length_method',
'use_inversion_params_for_run',
'tidewater_type', 'store_model_geometry', 'use_winter_prcp_factor',
'tidewater_type', 'store_model_geometry', 'use_winter_prcp_fac',
'store_diagnostic_variables', 'store_fl_diagnostic_variables',
'geodetic_mb_period', 'store_fl_diagnostics', 'winter_prcp_factor_ab',
'winter_prcp_factor_range', 'prcp_scaling_factor',
'downstream_line_shape']
'geodetic_mb_period', 'store_fl_diagnostics', 'winter_prcp_fac_ab',
'winter_prcp_fac_range', 'prcp_fac', 'downstream_line_shape']
for k in ltr:
cp.pop(k, None)

Expand Down
56 changes: 28 additions & 28 deletions oggm/core/massbalance.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def decide_winter_precip_factor(gdir):

# from MB sandbox calibration to winter MB
# using t_melt=-1, cte lapse rate, monthly resolution
a, b = cfg.PARAMS['winter_prcp_factor_ab']
a, b = cfg.PARAMS['winter_prcp_fac_ab']
prcp_fac = a * np.log(w_prcp) + b
# don't allow extremely low/high prcp. factors!!!
r0, r1 = cfg.PARAMS['winter_prcp_factor_range']
r0, r1 = cfg.PARAMS['winter_prcp_fac_range']
return clip_scalar(prcp_fac, r0, r1)


Expand Down Expand Up @@ -545,7 +545,7 @@ def monthly_melt_f(self):
# after instantiation with properly changing the prcp time series
@property
def prcp_fac(self):
"""Precipitation factor (default: cfg.PARAMS['prcp_scaling_factor'])
"""Precipitation factor (default: cfg.PARAMS['prcp_fac'])
Called factor to make clear that it is a multiplicative factor in
contrast to the additive temperature bias
Expand Down Expand Up @@ -1448,9 +1448,9 @@ def mb_calibration_from_scalar_mb(gdir,
melt_f=None,
melt_f_min=None,
melt_f_max=None,
prcp_scaling_factor=None,
prcp_scaling_factor_min=None,
prcp_scaling_factor_max=None,
prcp_fac=None,
prcp_fac_min=None,
prcp_fac_max=None,
temp_bias=0,
temp_bias_min=None,
temp_bias_max=None,
Expand Down Expand Up @@ -1539,16 +1539,16 @@ def mb_calibration_from_scalar_mb(gdir,
melt_f_max: float
the maximum accepted value for the melt factor during optimisation.
Defaults to cfg.PARAMS['melt_f_max'].
prcp_scaling_factor: float
prcp_fac: float
the default value to use as precipitation scaling factor
(or the starting value when optimizing MB). Defaults to the method
chosen in `params.cfg` (winter prcp or global factor).
prcp_scaling_factor_min: float
prcp_fac_min: float
the minimum accepted value for the precipitation scaling factor during
optimisation. Defaults to cfg.PARAMS['prcp_scaling_factor_min'].
prcp_scaling_factor_max: float
optimisation. Defaults to cfg.PARAMS['prcp_fac_min'].
prcp_fac_max: float
the maximum accepted value for the precipitation scaling factor during
optimisation. Defaults to cfg.PARAMS['prcp_scaling_factor_max'].
optimisation. Defaults to cfg.PARAMS['prcp_fac_max'].
temp_bias: float
the default value to use as temperature bias (or the starting value when
optimizing MB). Defaults to 0.
Expand All @@ -1565,10 +1565,10 @@ def mb_calibration_from_scalar_mb(gdir,
melt_f_min = cfg.PARAMS['melt_f_min']
if melt_f_max is None:
melt_f_max = cfg.PARAMS['melt_f_max']
if prcp_scaling_factor_min is None:
prcp_scaling_factor_min = cfg.PARAMS['prcp_scaling_factor_min']
if prcp_scaling_factor_max is None:
prcp_scaling_factor_max = cfg.PARAMS['prcp_scaling_factor_max']
if prcp_fac_min is None:
prcp_fac_min = cfg.PARAMS['prcp_fac_min']
if prcp_fac_max is None:
prcp_fac_max = cfg.PARAMS['prcp_fac_max']
if melt_f is None:
melt_f = cfg.PARAMS['melt_f']
if temp_bias_min is None:
Expand Down Expand Up @@ -1620,21 +1620,21 @@ def mb_calibration_from_scalar_mb(gdir,
'you posted!')

# Ok, regardless on how we want to calibrate, we start with defaults
if prcp_scaling_factor is None:
if cfg.PARAMS['use_winter_prcp_factor']:
if prcp_fac is None:
if cfg.PARAMS['use_winter_prcp_fac']:
# Some sanity check
if cfg.PARAMS['prcp_scaling_factor'] is not None:
raise InvalidWorkflowError("Set PARAMS['prcp_scaling_factor'] "
if cfg.PARAMS['prcp_fac'] is not None:
raise InvalidWorkflowError("Set PARAMS['prcp_fac'] "
"to None if using winter_prcp_factor")
prcp_fac = decide_winter_precip_factor(gdir)
else:
prcp_fac = cfg.PARAMS['prcp_scaling_factor']
prcp_fac = cfg.PARAMS['prcp_fac']
if prcp_fac is None:
raise InvalidWorkflowError("Set either PARAMS['use_winter_prcp_factor'] "
raise InvalidWorkflowError("Set either PARAMS['use_winter_prcp_fac'] "
"or PARAMS['winter_prcp_factor'].")
else:
# if a prcp_scaling_factor is set, we will use it instead of the default option
prcp_fac = prcp_scaling_factor
# if a prcp_fac is set, we will use it instead of the default option
prcp_fac = prcp_fac

# Create the MB model we will calibrate
mb_mod = mb_model_class(gdir,
Expand All @@ -1652,7 +1652,7 @@ def mb_calibration_from_scalar_mb(gdir,
if calibrate_param1 == 'melt_f':
min_range, max_range = melt_f_min, melt_f_max
elif calibrate_param1 == 'prcp_fac':
min_range, max_range = prcp_scaling_factor_min, prcp_scaling_factor_max
min_range, max_range = prcp_fac_min, prcp_fac_max
elif calibrate_param1 == 'temp_bias':
min_range, max_range = temp_bias_min, temp_bias_max
else:
Expand Down Expand Up @@ -1685,7 +1685,7 @@ def to_minimize(x, model_attr):
if calibrate_param2 == 'melt_f':
min_range, max_range = melt_f_min, melt_f_max
elif calibrate_param2 == 'prcp_fac':
min_range, max_range = prcp_scaling_factor_min, prcp_scaling_factor_max
min_range, max_range = prcp_fac_min, prcp_fac_max
elif calibrate_param2 == 'temp_bias':
min_range, max_range = temp_bias_min, temp_bias_max
else:
Expand All @@ -1712,7 +1712,7 @@ def to_minimize(x, model_attr):
if calibrate_param3 == 'melt_f':
min_range, max_range = melt_f_min, melt_f_max
elif calibrate_param3 == 'prcp_fac':
min_range, max_range = prcp_scaling_factor_min, prcp_scaling_factor_max
min_range, max_range = prcp_fac_min, prcp_fac_max
elif calibrate_param3 == 'temp_bias':
min_range, max_range = temp_bias_min, temp_bias_max
else:
Expand Down Expand Up @@ -1964,7 +1964,7 @@ def fixed_geometry_mass_balance(gdir, ys=None, ye=None, years=None,
precipitation_factor: float
multiply a factor to the precipitation time series
default is None and means that the precipitation factor from the
calibration is applied which is cfg.PARAMS['prcp_scaling_factor']
calibration is applied which is cfg.PARAMS['prcp_fac']
mb_model_class : MassBalanceModel class
the MassBalanceModel class to use, default is MonthlyTIModel
"""
Expand Down Expand Up @@ -2021,7 +2021,7 @@ def compute_ela(gdir, ys=None, ye=None, years=None, climate_filename='climate_hi
precipitation_factor: float
multiply a factor to the precipitation time series
default is None and means that the precipitation factor from the
calibration is applied which is cfg.PARAMS['prcp_scaling_factor']
calibration is applied which is cfg.PARAMS['prcp_fac']
mb_model_class : MassBalanceModel class
the MassBalanceModel class to use, default is MonthlyTIModel
"""
Expand Down
14 changes: 7 additions & 7 deletions oggm/params.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,19 @@ temp_bias_min = -10
temp_bias_max = 10

# precipitation correction: set to a float for a constant scaling factor
# Needs to be set empty if use_winter_prcp_factor is True
prcp_scaling_factor =
# Needs to be set empty if use_winter_prcp_fac is True
prcp_fac =
# For calibration - set a range
prcp_scaling_factor_min = 0.1
prcp_scaling_factor_max = 5
prcp_fac_min = 0.1
prcp_fac_max = 5

# Use a precipitation dependent factor (unique per glacier)
# The values below have been calibrated on W5E5 data - they will work
# less well on other datasets (but should be fine since it only corrects
# total precipitation and should be less affected by temperature).
use_winter_prcp_factor = True
winter_prcp_factor_ab = -1.0614, 3.9200
winter_prcp_factor_range = 0.1, 10
use_winter_prcp_fac = True
winter_prcp_fac_ab = -1.0614, 3.9200
winter_prcp_fac_range = 0.1, 10


# When matching geodetic MB on a glacier per glacier basis, which period
Expand Down
12 changes: 6 additions & 6 deletions oggm/tests/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ def init_hef(reset=False, border=40, logging_level='INFO', rgi_id=None,
cfg.PATHS['working_dir'] = testdir
cfg.PARAMS['trapezoid_lambdas'] = 1
cfg.PARAMS['border'] = border
cfg.PARAMS['use_winter_prcp_factor'] = False
cfg.PARAMS['prcp_scaling_factor'] = 2.5
cfg.PARAMS['use_winter_prcp_fac'] = False
cfg.PARAMS['prcp_fac'] = 2.5

hef_file = get_demo_file('Hintereisferner_RGI5.shp')
entity = gpd.read_file(hef_file).iloc[0]
Expand Down Expand Up @@ -503,8 +503,8 @@ def init_columbia(reset=False):
cfg.PARAMS['border'] = 10
cfg.PARAMS['use_kcalving_for_inversion'] = True
cfg.PARAMS['use_kcalving_for_run'] = True
cfg.PARAMS['use_winter_prcp_factor'] = False
cfg.PARAMS['prcp_scaling_factor'] = 2.5
cfg.PARAMS['use_winter_prcp_fac'] = False
cfg.PARAMS['prcp_fac'] = 2.5
cfg.PARAMS['baseline_climate'] = 'CRU'

entity = gpd.read_file(get_demo_file('01_rgi60_Columbia.shp')).iloc[0]
Expand Down Expand Up @@ -542,8 +542,8 @@ def init_columbia_eb(dir_name, reset=False):
cfg.PARAMS['border'] = 10
cfg.PARAMS['use_kcalving_for_inversion'] = True
cfg.PARAMS['use_kcalving_for_run'] = True
cfg.PARAMS['use_winter_prcp_factor'] = False
cfg.PARAMS['prcp_scaling_factor'] = 2.5
cfg.PARAMS['use_winter_prcp_fac'] = False
cfg.PARAMS['prcp_fac'] = 2.5
cfg.PARAMS['baseline_climate'] = 'CRU'

entity = gpd.read_file(get_demo_file('01_rgi60_Columbia.shp')).iloc[0]
Expand Down
8 changes: 4 additions & 4 deletions oggm/tests/test_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def setUp(self):
cfg.PATHS['working_dir'] = self.testdir
cfg.PATHS['dem_file'] = get_demo_file('dem_SouthGlacier.tif')
cfg.PARAMS['border'] = 10
cfg.PARAMS['use_winter_prcp_factor'] = False
cfg.PARAMS['prcp_scaling_factor'] = 2.5
cfg.PARAMS['use_winter_prcp_fac'] = False
cfg.PARAMS['prcp_fac'] = 2.5
cfg.PARAMS['baseline_climate'] = 'CRU'

self.tf = get_demo_file('cru_ts4.01.1901.2016.SouthGlacier.tmp.dat.nc')
Expand Down Expand Up @@ -474,8 +474,8 @@ def setUp(self):
cfg.PATHS['working_dir'] = self.testdir
cfg.PARAMS['use_kcalving_for_inversion'] = True
cfg.PARAMS['use_kcalving_for_run'] = True
cfg.PARAMS['use_winter_prcp_factor'] = False
cfg.PARAMS['prcp_scaling_factor'] = 2.5
cfg.PARAMS['use_winter_prcp_fac'] = False
cfg.PARAMS['prcp_fac'] = 2.5
cfg.PARAMS['baseline_climate'] = 'CRU'

def tearDown(self):
Expand Down
20 changes: 10 additions & 10 deletions oggm/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ def test_multiple_inversion():
cfg.PARAMS['border'] = 40
cfg.PARAMS['baseline_climate'] = 'CUSTOM'
cfg.PARAMS['trapezoid_lambdas'] = 1
cfg.PARAMS['use_winter_prcp_factor'] = False
cfg.PARAMS['prcp_scaling_factor'] = 2.5
cfg.PARAMS['use_winter_prcp_fac'] = False
cfg.PARAMS['prcp_fac'] = 2.5
cfg.PATHS['working_dir'] = testdir

# Get the RGI ID
Expand Down Expand Up @@ -262,8 +262,8 @@ def test_multiple_models():
cfg.PATHS['working_dir'] = testdir
cfg.PARAMS['baseline_climate'] = 'CUSTOM'
cfg.PARAMS['trapezoid_lambdas'] = 1
cfg.PARAMS['use_winter_prcp_factor'] = False
cfg.PARAMS['prcp_scaling_factor'] = 2.5
cfg.PARAMS['use_winter_prcp_fac'] = False
cfg.PARAMS['prcp_fac'] = 2.5
cfg.PARAMS['border'] = 40

# Get the RGI ID
Expand Down Expand Up @@ -352,8 +352,8 @@ def test_chhota_shigri():
cfg.PARAMS['use_intersects'] = False
cfg.PATHS['working_dir'] = testdir
cfg.PARAMS['trapezoid_lambdas'] = 1
cfg.PARAMS['use_winter_prcp_factor'] = False
cfg.PARAMS['prcp_scaling_factor'] = 2.5
cfg.PARAMS['use_winter_prcp_fac'] = False
cfg.PARAMS['prcp_fac'] = 2.5

hef_file = get_demo_file('divides_RGI50-14.15990.shp')
df = gpd.read_file(hef_file)
Expand Down Expand Up @@ -396,8 +396,8 @@ def test_ice_cap():
cfg.PARAMS['border'] = 60
cfg.PATHS['working_dir'] = testdir
cfg.PARAMS['trapezoid_lambdas'] = 1
cfg.PARAMS['use_winter_prcp_factor'] = False
cfg.PARAMS['prcp_scaling_factor'] = 2.5
cfg.PARAMS['use_winter_prcp_fac'] = False
cfg.PARAMS['prcp_fac'] = 2.5

df = gpd.read_file(get_demo_file('divides_RGI50-05.08389.shp'))
df['Area'] = df.Area * 1e-6 # cause it was in m2
Expand Down Expand Up @@ -438,8 +438,8 @@ def test_coxe():
cfg.PARAMS['use_kcalving_for_inversion'] = True
cfg.PARAMS['use_kcalving_for_run'] = True
cfg.PARAMS['trapezoid_lambdas'] = 1
cfg.PARAMS['use_winter_prcp_factor'] = False
cfg.PARAMS['prcp_scaling_factor'] = 2.5
cfg.PARAMS['use_winter_prcp_fac'] = False
cfg.PARAMS['prcp_fac'] = 2.5

hef_file = get_demo_file('rgi_RGI50-01.10299.shp')
entity = gpd.read_file(hef_file).iloc[0]
Expand Down
Loading

0 comments on commit 180a492

Please sign in to comment.