def test_run(self): entity = gpd.read_file(self.rgi_file).iloc[0] gdir = oggm.GlacierDirectory(entity, base_dir=self.testdir) gis.define_glacier_region(gdir) gis.glacier_masks(gdir) centerlines.compute_centerlines(gdir) centerlines.initialize_flowlines(gdir) centerlines.compute_downstream_line(gdir) centerlines.compute_downstream_bedshape(gdir) centerlines.catchment_area(gdir) centerlines.catchment_intersections(gdir) centerlines.catchment_width_geom(gdir) centerlines.catchment_width_correction(gdir) # Climate tasks -- only data IO and tstar interpolation! tasks.process_dummy_cru_file(gdir, seed=0) tasks.local_t_star(gdir) tasks.mu_star_calibration(gdir) # Inversion tasks tasks.find_inversion_calving(gdir) # Final preparation for the run tasks.init_present_time_glacier(gdir) # check that calving happens in the real context as well tasks.run_constant_climate(gdir, bias=0, nyears=200, temperature_bias=-0.5) with xr.open_dataset(gdir.get_filepath('model_diagnostics')) as ds: assert ds.calving_m3[-1] > 10
def run_and_plot_merged_montmine(pout): # Set-up cfg.initialize(logging_level='WORKFLOW') cfg.PATHS['working_dir'] = utils.gettempdir(dirname='OGGM-merging', reset=True) # Use a suitable border size for your domain cfg.PARAMS['border'] = 80 cfg.PARAMS['use_intersects'] = False montmine = workflow.init_glacier_directories(['RGI60-11.02709'], from_prepro_level=3)[0] gdirs = workflow.init_glacier_directories(['RGI60-11.02709', 'RGI60-11.02715'], from_prepro_level=3) workflow.execute_entity_task(tasks.init_present_time_glacier, gdirs) gdirs_merged = workflow.merge_glacier_tasks(gdirs, 'RGI60-11.02709', return_all=False, filename='climate_monthly', buffer=2.5) # plot centerlines fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[20, 10]) plot_centerlines(montmine, ax=ax1, use_flowlines=True) xt = ax1.get_xticks() ax1.set_xticks(xt[::2]) ax1.tick_params(axis='both', which='major', labelsize=20) ax1.set_title('entity glacier', fontsize=24) plot_centerlines(gdirs_merged, ax=ax2, use_model_flowlines=True) ax2.tick_params(axis='both', which='major', labelsize=20) ax2.set_title('merged with Glacier de Ferpecle', fontsize=24) axs = fig.get_axes() axs[3].remove() axs[2].tick_params(axis='y', labelsize=16) axs[2].set_ylabel('Altitude [m]', fontsize=18) fig.suptitle('Glacier du Mont Mine', fontsize=24) fig.subplots_adjust(left=0.04, right=0.99, bottom=0.08, top=0.89, wspace=0.3) fn = os.path.join(pout, 'merged_montmine.png') fig.savefig(fn) # run glaciers with negative t bias # some model settings years = 125 tbias = -1.5 # model Mont Mine glacier as entity and complile the output tasks.run_constant_climate(montmine, nyears=years, output_filesuffix='_entity', temperature_bias=tbias) ds_entity = utils.compile_run_output([montmine], path=False, filesuffix='_entity') # model the merged glacier and complile the output tasks.run_constant_climate(gdirs_merged, nyears=years, output_filesuffix='_merged', temperature_bias=tbias, climate_filename='climate_monthly') ds_merged = utils.compile_run_output([gdirs_merged], path=False, filesuffix='_merged') # # bring them to same size again tbias = -2.2 years = 125 tasks.run_constant_climate(montmine, nyears=years, output_filesuffix='_entity1', temperature_bias=tbias) ds_entity1 = utils.compile_run_output([montmine], path=False, filesuffix='_entity1') # and let them shrink again # some model settings tbias = -0.5 years = 100 # load the previous entity run tmp_mine = FileModel( montmine.get_filepath('model_run', filesuffix='_entity1')) tmp_mine.run_until(years) tasks.run_constant_climate(montmine, nyears=years, output_filesuffix='_entity2', init_model_fls=tmp_mine.fls, temperature_bias=tbias) ds_entity2 = utils.compile_run_output([montmine], path=False, filesuffix='_entity2') # model the merged glacier and complile the output tmp_merged = FileModel( gdirs_merged.get_filepath('model_run', filesuffix='_merged')) tmp_merged.run_until(years) tasks.run_constant_climate(gdirs_merged, nyears=years, output_filesuffix='_merged2', init_model_fls=tmp_merged.fls, temperature_bias=tbias, climate_filename='climate_monthly') ds_merged2 = utils.compile_run_output([gdirs_merged], path=False, filesuffix='_merged2') fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[20, 7]) dse = ds_entity.length.to_series().rolling(5, center=True).mean() dsm = ds_merged.length.to_series().rolling(5, center=True).mean() ax1.plot(dse.values, 'C1', label='Entity glacier', linewidth=3) ax1.plot(dsm.values, 'C2', label='Merged glacier', linewidth=3) ax1.set_xlabel('Simulation time [yr]', fontsize=20) ax1.set_ylabel('Glacier length[m]', fontsize=20) ax1.grid(True) ax1.legend(loc=2, fontsize=18) dse2 = ds_entity2.length.to_series().rolling(5, center=True).mean() dsm2 = ds_merged2.length.to_series().rolling(5, center=True).mean() ax2.plot(dse2.values, 'C1', label='Entity glacier', linewidth=3) ax2.plot(dsm2.values, 'C2', label='Merged glacier', linewidth=3) ax2.set_xlabel('Simulation time [yr]', fontsize=22) ax2.set_ylabel('Glacier length [m]', fontsize=22) ax2.grid(True) ax2.legend(loc=1, fontsize=18) ax1.set_xlim([0, 120]) ax2.set_xlim([0, 100]) ax1.set_ylim([7500, 12000]) ax2.set_ylim([7500, 12000]) ax1.tick_params(axis='both', which='major', labelsize=20) ax2.tick_params(axis='both', which='major', labelsize=20) fig.subplots_adjust(left=0.08, right=0.96, bottom=0.11, top=0.93, wspace=0.3) fn = os.path.join(pout, 'merged_montmine_timeseries.png') fig.savefig(fn)
### Ice thickness ### list_talks = [ tasks.prepare_for_inversion, # This is a preprocessing task tasks.mass_conservation_inversion, # This does the actual job tasks. filter_inversion_output # This smoothes the thicknesses at the tongue a little ] for task in list_talks: workflow.execute_entity_task(task, gdirs) # plot #graphics.plot_inversion(gdirs, figsize=(8, 7)) # from tutorial tasks.init_present_time_glacier(gdir) tasks.run_constant_climate(gdir, nyears=100, y0=2000) fmod = flowline.FileModel(gdir.get_filepath('model_run')) fmod.run_until(0) #graphics.plot_modeloutput_map(gdir, model=fmod) # plot # get glacier flowline and bed elevation # Main flowline from FlowlineMassBalance fl = fmod.fls[-1] i, j = fl.line.xy # xy flowline on grid lons, lats = gdir.grid.ij_to_crs(i, j, crs='EPSG:4326') # to WGS84 df_coords = pd.DataFrame(index=fl.dis_on_line * gdir.grid.dx) df_coords.index.name = 'Distance along flowline' df_coords['lon'] = lons df_coords['lat'] = lats
df = utils.glacier_characteristics([gdir], path=False) reset = False seed = 5 seed = 0 tasks.random_glacier_evolution(gdir, nyears=800, bias=0, seed=seed, filesuffix='_fromzero_def', reset=reset, zero_initial_glacier=True) tasks.run_constant_climate(gdir, nyears=800, bias=0, filesuffix='_fromzero_ct', reset=reset, zero_initial_glacier=True) cfg.PARAMS['flowline_fs'] = 5.7e-20 * 0.5 tasks.random_glacier_evolution(gdir, nyears=800, bias=0, seed=seed, filesuffix='_fromzero_fs', reset=reset, zero_initial_glacier=True) cfg.PARAMS['flowline_fs'] = 0 cfg.PARAMS['flowline_glen_a'] = cfg.A * 2 tasks.random_glacier_evolution(gdir,