Skip to content

Commit 4be2186

Browse files
authored
Remove assertion that bias adjustment precipitation factor be between 0.5 and 2
Closes #118. This PR returns the GCM precipitation bias adjustment factors to `run_simulation.py` and removed previous assertions that the bias-adjusted GCM precipitation divided by the reference climate precipitation not differ by a factor >2 for the same time period. A warning is now raised in `run_simulation.py` if the factor differs by >2x, but the simulation will still run. Also cleaned up relict variable naming that was in place to handle `ref_spinupyears` and `gcm_spinupyears`.
1 parent 484cec5 commit 4be2186

5 files changed

Lines changed: 68 additions & 107 deletions

File tree

pygem/bin/op/compress_gdirs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
from oggm import utils, workflow
1717

1818
# pygem imports
19-
import pygem.setup.config as config
19+
from pygem.setup.config import ConfigManager
2020

21-
# check for config
22-
config.ensure_config()
21+
# instantiate ConfigManager
22+
config_manager = ConfigManager()
2323
# read the config
24-
pygem_prms = config.read_config()
24+
pygem_prms = config_manager.read_config()
2525

2626
# Initialize OGGM subprocess
2727
cfg.initialize(logging_level='WARNING')

pygem/bin/run/run_inversion.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import pandas as pd
77

88
# pygem imports
9-
import pygem.setup.config as config
9+
from pygem.setup.config import ConfigManager
1010

11-
# check for config
12-
config.ensure_config()
11+
# instantiate ConfigManager
12+
config_manager = ConfigManager()
1313
# read the config
14-
pygem_prms = config.read_config()
14+
pygem_prms = config_manager.read_config()
1515
from oggm import cfg, tasks, workflow
1616

1717
import pygem.pygem_modelsetup as modelsetup

pygem/bin/run/run_simulation.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import os
2424
import sys
2525
import time
26+
import warnings
2627

2728
import matplotlib.pyplot as plt
2829
import numpy as np
@@ -457,6 +458,7 @@ def run(list_packed_vars):
457458
gcm_elev_adj = gcm_elev
458459
gcm_temp_adj = gcm_temp[:, sim_idx_start:]
459460
gcm_prec_adj = gcm_prec[:, sim_idx_start:]
461+
gcm_prec_biasadj_frac = np.ones(gcm_prec_adj.shape[0])
460462
# Bias correct based on reference climate data
461463
else:
462464
# OPTION 1: Adjust temp using Huss and Hock (2015), prec similar but addresses for variance and outliers
@@ -472,14 +474,16 @@ def run(list_packed_vars):
472474
args.ref_startyear,
473475
)
474476
# Precipitation bias correction
475-
gcm_prec_adj, gcm_elev_adj = gcmbiasadj.prec_biasadj_opt1(
476-
ref_prec,
477-
ref_elev,
478-
gcm_prec,
479-
dates_table_ref,
480-
dates_table_full,
481-
args.sim_startyear,
482-
args.ref_startyear,
477+
gcm_prec_adj, gcm_elev_adj, gcm_prec_biasadj_frac = (
478+
gcmbiasadj.prec_biasadj_opt1(
479+
ref_prec,
480+
ref_elev,
481+
gcm_prec,
482+
dates_table_ref,
483+
dates_table_full,
484+
args.sim_startyear,
485+
args.ref_startyear,
486+
)
483487
)
484488
# OPTION 2: Adjust temp and prec using Huss and Hock (2015)
485489
elif args.option_bias_adjustment == 2:
@@ -494,12 +498,14 @@ def run(list_packed_vars):
494498
args.ref_startyear,
495499
)
496500
# Precipitation bias correction
497-
gcm_prec_adj, gcm_elev_adj = gcmbiasadj.prec_biasadj_HH2015(
498-
ref_prec,
499-
ref_elev,
500-
gcm_prec,
501-
dates_table_ref,
502-
dates_table_full,
501+
gcm_prec_adj, gcm_elev_adj, gcm_prec_biasadj_frac = (
502+
gcmbiasadj.prec_biasadj_HH2015(
503+
ref_prec,
504+
ref_elev,
505+
gcm_prec,
506+
dates_table_ref,
507+
dates_table_full,
508+
)
503509
)
504510
# OPTION 3: Adjust temp and prec using quantile delta mapping, Cannon et al. (2015)
505511
elif args.option_bias_adjustment == 3:
@@ -524,6 +530,7 @@ def run(list_packed_vars):
524530
args.sim_startyear,
525531
args.ref_startyear,
526532
)
533+
gcm_prec_biasadj_frac = np.ones(gcm_prec_adj.shape[0])
527534

528535
# assert that the gcm_elev_adj is not None
529536
assert gcm_elev_adj is not None, 'No GCM elevation data'
@@ -640,6 +647,13 @@ def run(list_packed_vars):
640647
'prec': gcm_prec_adj[glac, :],
641648
'lr': gcm_lr[glac, :],
642649
}
650+
fact = gcm_prec_biasadj_frac[glac]
651+
if fact < 0.5 or fact > 2:
652+
warnings.warn(
653+
f'Bias-adjusted GCM precipitation for {glacier_str} differs from that of the refernce climate data by a factor greater than 2x ({round(fact, 2)})',
654+
Warning,
655+
stacklevel=2,
656+
)
643657
gdir.dates_table = dates_table
644658

645659
glacier_area_km2 = fls[0].widths_m * fls[0].dx_meter / 1e6

pygem/bin/run/run_spinup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import pandas as pd
88

99
# pygem imports
10-
import pygem.setup.config as config
10+
from pygem.setup.config import ConfigManager
1111

12-
# check for config
13-
config.ensure_config()
12+
# instantiate ConfigManager
13+
config_manager = ConfigManager()
1414
# read the config
15-
pygem_prms = config.read_config()
15+
pygem_prms = config_manager.read_config()
1616
from oggm import tasks, workflow
1717

1818
import pygem.pygem_modelsetup as modelsetup

0 commit comments

Comments
 (0)