def run_random_task(tupel,gdir,y0): seed = tupel[0] temp_bias = tupel[1] fls = gdir.read_pickle('model_flowlines') suffix = str(y0)+'_random_'+str(seed)+'_'+ str(temp_bias) # test if file already exist: path = gdir.get_filepath('model_run', filesuffix=suffix) # does file already exists? if not os.path.exists(path): try: tasks.run_random_climate(gdir, nyears=400, y0=y0, bias=0, seed=seed, temperature_bias=temp_bias, init_model_fls=copy.deepcopy(fls), output_filesuffix=suffix) return path # oggm failed --> probaly "glacier exeeds boundaries" except: return None else: # does file contain a model? try: fmod = FileModel(path) return path except: return None
def _run_random_task(tupel, gdir, y0, bias): """ Run random model to create lots of possible states """ seed = tupel[0] temp_bias = tupel[1] fls = gdir.read_pickle('model_flowlines') suffix = str(y0) + '_random_' + str(seed) + '_' + str(temp_bias) #path = gdir.get_filepath('model_run', filesuffix=suffix) path = os.path.join(gdir.dir, str(y0), 'model_run' + suffix + '.nc') # does file already exists? if not os.path.exists(path): try: tasks.run_random_climate(gdir, nyears=600, y0=y0, bias=bias, seed=seed, temperature_bias=temp_bias, init_model_fls=copy.deepcopy(fls), output_filesuffix=suffix) return path # oggm failed --> probaly "glacier exeeds boundaries" except: return None else: # does file contain a model? try: fmod = FileModel(path) return path except: return None
def _single_calibration_run(gdir, mb_offset, ys, ye): """ Creates the synthetic experiment for one glacier. model_geometry_experiment.nc will be saved in working directory. """ # check, if this model_geometry already exists try: rp = gdir.get_filepath('model_geometry', filesuffix='_calibration_past_' + str(mb_offset)) model = FileModel(rp) # otherwise create calibration_run with mb_offset except: try: fls = gdir.read_pickle('model_flowlines') # run a 600 years random run with mb_offset tasks.run_random_climate(gdir, nyears=600, y0=ys, bias=mb_offset, seed=1, init_model_fls=fls, output_filesuffix='_calibration_random_' + str(mb_offset)) # construct s_OGGM --> previous glacier will be run forward from # ys - ye with past climate file tasks.run_from_climate_data( gdir, ys=ys, ye=ye, init_model_filesuffix='_calibration_random_' + str(mb_offset), bias=mb_offset, init_model_yr=600, output_filesuffix='_calibration_past_' + str(mb_offset)) # return FileModel rp = gdir.get_filepath('model_geometry', filesuffix='_calibration_past_' + str(mb_offset)) model = FileModel(rp) except: with open(os.path.join(gdir.dir, 'log.txt')) as log: error = list(log)[-1].split(';')[-1] return error return model
def _run_parallel_experiment(gdir, t0, te): """ Creates the synthetic experiment for one glacier. model_run_experiment.nc will be saved in working directory. """ try: fls = gdir.read_pickle('model_flowlines') # try to run random climate with temperature bias -1 model = tasks.run_random_climate(gdir, nyears=600, y0=t0, bias=0, seed=1, temperature_bias=-1, init_model_fls=fls) # construct observed glacier, previous glacier will be run forward from # 1850 - 2000 with past climate file b = fls[-1].bed_h fls = copy.deepcopy(model.fls) model = tasks.run_from_climate_data(gdir, ys=t0, ye=te, init_model_fls=fls, output_filesuffix='_experiment') except: print('experiment failed : ' + str(gdir.rgi_id))
def _run_experiment(gdir, temp_bias, bias, ys, ye): """ Creates the synthetic experiment for one glacier. model_run_experiment.nc will be saved in working directory. """ # check, if this experiment already exists try: rp = gdir.get_filepath('model_run', filesuffix='_advanced_experiment_' + str(temp_bias) + '_' + str(bias)) model = FileModel(rp) # otherwise create experiment except: try: fls = gdir.read_pickle('model_flowlines') model = tasks.run_random_climate( gdir, nyears=600, y0=ys, bias=bias, seed=1, temperature_bias=temp_bias, init_model_fls=fls, output_filesuffix='_random_experiment_' + str(temp_bias) + '_' + str(bias)) # construct observed glacier, previous glacier will be run forward from # 1917 - rgi_date with past climate file fls = copy.deepcopy(model.fls) tasks.run_from_climate_data( gdir, ys=ys, ye=ye, init_model_fls=fls, bias=bias, output_filesuffix='_advanced_experiment_' + str(temp_bias) + '_' + str(bias)) # to return FileModel rp = gdir.get_filepath('model_run', filesuffix='_advanced_experiment_' + str(temp_bias) + '_' + str(bias)) model = FileModel(rp) except: with open(os.path.join(gdir.dir, 'log.txt')) as log: error = list(log)[-1].split(';')[-1] return error return model
def _run_parallel_experiment(gdir, t0, te): """ Creates the synthetic experiment for one glacier. model_geometry_synthetic_experiment.nc will be saved in working directory. """ try: fls = gdir.read_pickle('model_flowlines') # try to run random climate with temperature bias -1 tasks.run_random_climate( gdir, nyears=600, y0=t0, bias=0, seed=1, temperature_bias=-1, init_model_fls=fls, output_filesuffix='_random_synthetic_experiment') # construct observed glacier, previous glacier will be run forward from # t0 - te with past climate file tasks.run_from_climate_data( gdir, ys=t0, ye=te, init_model_filesuffix='_random_synthetic_experiment', init_model_yr=600, output_filesuffix='_synthetic_experiment') # remove output file from random run os.remove( gdir.get_filepath('model_geometry', filesuffix='_random_synthetic_experiment')) os.remove( gdir.get_filepath('model_diagnostics', filesuffix='_random_synthetic_experiment')) except: print('experiment failed : ' + str(gdir.rgi_id))
def _run_experiment(gdir, temp_bias, bias, ys, ye): """ Creates the synthetic experiment for one glacier. model_run_experiment.nc will be saved in working directory. """ # check, if this experiment already exists try: rp = gdir.get_filepath('model_run', filesuffix='_advanced_experiment_' + str(temp_bias) + '_' + str(bias)) model = FileModel(rp) # otherwise create experiment except: fls = gdir.read_pickle('model_flowlines') try: model = tasks.run_random_climate(gdir, nyears=400, y0=ys, bias=bias, seed=1, temperature_bias=temp_bias, init_model_fls=fls) # construct observed glacier, previous glacier will be run forward from # 1917 - 2000 with past climate file fls = deepcopy(model.fls) model = tasks.run_from_climate_data( gdir, ys=ys, ye=ye, init_model_fls=fls, bias=bias, output_filesuffix='_advanced_experiment_' + str(temp_bias) + '_' + str(bias)) except: pass return model
tasks.catchment_width_geom(gdir) tasks.catchment_width_correction(gdir) tasks.process_cru_data(gdir) tasks.local_t_star(gdir) tasks.mu_star_calibration(gdir) glen_a = cfg.PARAMS['glen_a'] tasks.prepare_for_inversion(gdir) tasks.mass_conservation_inversion(gdir, glen_a=glen_a, fs=0) tasks.filter_inversion_output(gdir) # run tasks.init_present_time_glacier(gdir) tasks.run_random_climate(gdir, bias=0., temperature_bias=-1, nyears=120, glen_a=glen_a, check_for_boundaries=False) f = 0.9 f = plt.figure(figsize=(7, 10)) from mpl_toolkits.axes_grid1 import ImageGrid axs = ImageGrid( f, 111, # as in plt.subplot(111) nrows_ncols=(3, 2), axes_pad=0.15, share_all=True, cbar_location="right", cbar_mode="edge",
tasks.catchment_width_geom(gdir) tasks.catchment_width_correction(gdir) tasks.process_cru_data(gdir) tasks.local_t_star(gdir) tasks.mu_star_calibration(gdir) tasks.prepare_for_inversion(gdir) tasks.mass_conservation_inversion(gdir) tasks.filter_inversion_output(gdir) tasks.init_present_time_glacier(gdir) df = utils.compile_glacier_statistics([gdir], path=False) reset = False seed = 0 tasks.run_random_climate(gdir, nyears=800, seed=0, y0=2000, output_filesuffix='_2000_def', reset=reset) tasks.run_random_climate(gdir, nyears=800, seed=0, y0=1920, output_filesuffix='_1920_def', reset=reset) f = gdir.get_filepath('model_diagnostics', filesuffix='_2000_def') ds1 = xr.open_dataset(f) f = gdir.get_filepath('model_diagnostics', filesuffix='_1920_def') ds2 = xr.open_dataset(f) f = 0.9 f = plt.figure(figsize=(9*f, 6*f)) from mpl_toolkits.axes_grid1 import ImageGrid axs = ImageGrid(f, 111, # as in plt.subplot(111) nrows_ncols=(2, 2),
tasks.mu_star_calibration(gdir) tasks.prepare_for_inversion(gdir) tasks.mass_conservation_inversion(gdir) tasks.filter_inversion_output(gdir) tasks.init_present_time_glacier(gdir) df = utils.compile_glacier_statistics([gdir], path=False) reset = False seed = 0 glen_a = cfg.PARAMS['glen_a'] fs = 5.7e-20 nyears = 800 tasks.run_random_climate(gdir, nyears=nyears, bias=0, seed=seed, output_filesuffix='_fromzero_def', reset=reset, zero_initial_glacier=True) tasks.run_constant_climate(gdir, nyears=nyears, bias=0, output_filesuffix='_fromzero_ct', reset=reset, zero_initial_glacier=True) cfg.PARAMS['fs'] = fs * 0.5 tasks.run_random_climate(gdir, nyears=nyears, bias=0, seed=seed, output_filesuffix='_fromzero_fs', reset=reset, zero_initial_glacier=True) cfg.PARAMS['fs'] = 0 cfg.PARAMS['glen_a'] = glen_a*2 tasks.run_random_climate(gdir, nyears=nyears, bias=0, seed=seed, output_filesuffix='_fromzero_2A', reset=reset,