Skip to content

Commit

Permalink
example: rename more variables and rename config file (MESMER-group#279)
Browse files Browse the repository at this point in the history
* add test to train and emulate (legacy)

* linting

* use create_seed_dict function

* update

* mention path updates

* update comments

* rename config file

* rename more vars

* remove test file again
  • Loading branch information
mathause authored Sep 4, 2023
1 parent ed71fdf commit e6013a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
Configuration file for tests
Example configuration file
"""
import os.path

Expand Down Expand Up @@ -59,14 +58,14 @@
# members)
wgt_scen_tr_eq = True

# number of created emulations (small number for testing purposes)
# number of created emulations (small number for example)
nr_emus_v = 5

# seed offset for scenarios (0 meaning same emulations drawn for each scen, other
# numbers will have different ones for each scen)
scen_seed_offset_v = 0

# max. nr of iterations in cross validation (small for testing purposes)
# max. nr of iterations in cross validation (small for example)
max_iter_cv = 15

# predictors (for global module)
Expand Down
23 changes: 12 additions & 11 deletions examples/train_create_emus_automated.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
from mesmer.utils import convert_dict_to_arr, extract_land, separate_hist_future


def main():

# load in configurations used in this script
import config_across_scen_T_cmip6ng_test as cfg
def main(cfg):

# specify the target variable
targ = cfg.targs[0]
Expand Down Expand Up @@ -88,12 +85,12 @@ def main():
"- Prepare predictors for global variability, local trends and variability"
)

GSAT_s, time_s = separate_hist_future(gsat[esm], time[esm], cfg)
gsat_s, _ = separate_hist_future(gsat[esm], time[esm], cfg)
gv_novolc_tas_s = {}
for scen in gt_tas_s.keys():
gv_novolc_tas_s[scen] = GSAT_s[scen] - gt_tas_s[scen]
gv_novolc_tas_s[scen] = gsat_s[scen] - gt_tas_s[scen]

tas_s, time_s = separate_hist_future(tas[esm], time[esm], cfg)
tas_s, _ = separate_hist_future(tas[esm], time[esm], cfg)

print("- Start with global variability module")

Expand All @@ -103,12 +100,12 @@ def main():
scen = list(gt_tas.keys())[0]
time_v["all"] = time[esm][scen]
preds_gv = {"time": time_v}
emus_gv_T = create_emus_gv(params_gv_tas, preds_gv, cfg, save_emus=True)
emus_gv_tas = create_emus_gv(params_gv_tas, preds_gv, cfg, save_emus=True)

# create and save full global emulations
print("- Merge the global trend and the global variability.")
create_emus_g(
gt_tas, emus_gv_T, params_gt_tas, params_gv_tas, cfg, save_emus=True
gt_tas, emus_gv_tas, params_gt_tas, params_gv_tas, cfg, save_emus=True
)

print("- Start with local trends module")
Expand Down Expand Up @@ -154,7 +151,7 @@ def main():
)

# create full lv emulations
preds_lv = {"gvtas": emus_gv_T} # predictors_list
preds_lv = {"gvtas": emus_gv_tas} # predictors_list
emus_lv = create_emus_lv(params_lv, preds_lv, cfg, save_emus=True)

# create and save full emulations
Expand All @@ -163,4 +160,8 @@ def main():


if __name__ == "__main__":
main()

# load in configurations used in this script
import config_tas_cmip6ng_example as cfg

main(cfg)
10 changes: 3 additions & 7 deletions mesmer/io/load_mesmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,9 @@ def load_mesmer_output(
if esm_str != "_":
esm_str = esm_str + "_"

path_list = glob.glob(
os.path.join(
dir_mesmer,
mid_path,
f"{name}*{method_str}*{preds_str}*{targs_str}*{esm_str}*{scen_str}*.pkl",
)
)
filename = f"{name}*{method_str}*{preds_str}*{targs_str}*{esm_str}*{scen_str}*.pkl"
fullname = os.path.join(dir_mesmer, mid_path, filename)
path_list = glob.glob(fullname)

# load the requested output dictionary
if len(path_list) == 1:
Expand Down

0 comments on commit e6013a0

Please sign in to comment.