def test_nodivide(): # test directory testdir = TESTDIR_BASE + '_nodiv' if not os.path.exists(testdir): os.makedirs(testdir) # Init cfg.initialize() cfg.set_divides_db() cfg.PATHS['dem_file'] = get_demo_file('hef_srtm.tif') cfg.PATHS['climate_file'] = get_demo_file('histalp_merged_hef.nc') cfg.PARAMS['border'] = 40 # loop because for some reason indexing wont work hef_file = get_demo_file('Hintereisferner.shp') rgidf = gpd.GeoDataFrame.from_file(hef_file) for index, entity in rgidf.iterrows(): gdir = oggm.GlacierDirectory(entity, base_dir=testdir, reset=True) gis.define_glacier_region(gdir, entity=entity) gis.glacier_masks(gdir) centerlines.compute_centerlines(gdir) graphics.plot_centerlines(gdir)
def test_nodivide(): # test directory testdir = TESTDIR_BASE + '_nodiv' if not os.path.exists(testdir): os.makedirs(testdir) # Init cfg.initialize() cfg.set_divides_db() cfg.PATHS['dem_file'] = get_demo_file('hef_srtm.tif') cfg.PATHS['climate_file'] = get_demo_file('histalp_merged_hef.nc') cfg.PARAMS['border'] = 40 hef_file = get_demo_file('Hintereisferner.shp') entity = gpd.GeoDataFrame.from_file(hef_file).iloc[0] gdir = oggm.GlacierDirectory(entity, base_dir=testdir, reset=True) gis.define_glacier_region(gdir, entity=entity) gis.glacier_masks(gdir) centerlines.compute_centerlines(gdir) fig, ax = plt.subplots() graphics.plot_centerlines(gdir, ax=ax) fig.tight_layout() return fig
def test_downstream(): fig, ax = plt.subplots() gdir = init_hef() graphics.plot_centerlines(gdir, ax=ax, add_downstream=True, use_flowlines=True) fig.tight_layout() return fig
def test_nodivide(): # test directory testdir = os.path.join(cfg.PATHS['test_dir'], 'tmp_nodiv') if not os.path.exists(testdir): os.makedirs(testdir) # Init cfg.initialize() cfg.set_divides_db() cfg.PATHS['dem_file'] = get_demo_file('hef_srtm.tif') cfg.PATHS['climate_file'] = get_demo_file('histalp_merged_hef.nc') cfg.PARAMS['border'] = 40 hef_file = get_demo_file('Hintereisferner.shp') entity = gpd.GeoDataFrame.from_file(hef_file).iloc[0] gdir = oggm.GlacierDirectory(entity, base_dir=testdir, reset=True) gis.define_glacier_region(gdir, entity=entity) gis.glacier_masks(gdir) centerlines.compute_centerlines(gdir) fig, ax = plt.subplots() graphics.plot_centerlines(gdir, ax=ax) fig.tight_layout() shutil.rmtree(testdir) return fig
def test_centerlines(): gdir = init_hef() graphics.plot_centerlines(gdir) graphics.plot_centerlines(gdir, use_flowlines=True) graphics.plot_centerlines(gdir, add_downstream=True, use_flowlines=True) graphics.plot_centerlines(gdir, add_downstream=True)
def test_nodivide(): # test directory testdir = TESTDIR_BASE + "_nodiv" if not os.path.exists(testdir): os.makedirs(testdir) # Init cfg.initialize() cfg.set_divides_db() cfg.PATHS["dem_file"] = get_demo_file("hef_srtm.tif") cfg.PATHS["climate_file"] = get_demo_file("histalp_merged_hef.nc") cfg.PARAMS["border"] = 40 hef_file = get_demo_file("Hintereisferner.shp") entity = gpd.GeoDataFrame.from_file(hef_file).iloc[0] gdir = oggm.GlacierDirectory(entity, base_dir=testdir, reset=True) gis.define_glacier_region(gdir, entity=entity) gis.glacier_masks(gdir) centerlines.compute_centerlines(gdir) graphics.plot_centerlines(gdir)
def test_centerlines(): fig, ax = plt.subplots() gdir = init_hef() graphics.plot_centerlines(gdir, ax=ax) fig.tight_layout() return fig
fn = bname + '0_ggl.png' if not os.path.exists(fn): graphics.plot_googlemap(gd) plt.savefig(fn) plt.close() fn = bname + '1_dom.png' if not os.path.exists(fn): graphics.plot_domain(gd, title_comment=demsource) plt.savefig(fn) plt.close() plt.close() fn = bname + '2_cls.png' if not os.path.exists(fn): graphics.plot_centerlines(gd, title_comment=demsource) plt.savefig(fn) plt.close() fn = bname + '3_fls.png' if not os.path.exists(fn): graphics.plot_centerlines(gd, title_comment=demsource, use_flowlines=True, add_downstream=True) plt.savefig(fn) plt.close() fn = bname + '4_widths.png' if not os.path.exists(fn): graphics.plot_catchment_width(gd, corrected=True, add_intersects=True, add_touches=True)
for gd in gdirs: itmix.write_itmix_ascii(gd, 2) graphics.plot_distributed_thickness(gd) plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_d2.png') plt.close() pdir = PLOTS_DIR if not os.path.exists(pdir): os.makedirs(pdir) for gd in gdirs: # graphics.plot_googlemap(gd) # plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_ggl.png') # plt.close() # graphics.plot_domain(gd) # plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_dom.png') # plt.close() graphics.plot_centerlines(gd) plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_cls.png') plt.close() graphics.plot_catchment_width(gd, corrected=True) plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_w.png') plt.close() graphics.plot_inversion(gd) plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_inv.png') plt.close() # graphics.plot_distributed_thickness(gd, how='per_altitude') # plt.savefig(pdir + gd.name + '_' + gd.rgi_id + '_dis1.png') # plt.close() pass
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)
va='top', fontsize=20, bbox=dict(facecolor='white', edgecolor='black')) graphics.plot_domain(gdir, ax=axs[0], title='', add_colorbar=False, lonlat_contours_kwargs=llkw) xt, yt = 4.5, 4.5 axs[0].text(xt, yt, 'a', **letkm) im = graphics.plot_centerlines(gdir, ax=axs[1], title='', add_colorbar=True, lonlat_contours_kwargs=llkw, cbar_ax=axs[1].cax, add_scalebar=False) axs[1].text(xt, yt, 'b', **letkm) graphics.plot_catchment_width(gdir, ax=axs[2], title='', add_colorbar=False, lonlat_contours_kwargs=llkw, add_scalebar=False) axs[2].text(xt, yt, 'c', **letkm) graphics.plot_catchment_width(gdir, ax=axs[3],
# While the above should work always, this here is no piece of fun execute_entity_task(tasks.random_glacier_evolution, gdirs) # Write out glacier statistics df = utils.glacier_characteristics(gdirs) fpath = os.path.join(cfg.PATHS['working_dir'], 'glacier_char.csv') df.to_csv(fpath) # Plots (if you want) if PLOTS_DIR == '': exit() utils.mkdir(PLOTS_DIR) for gd in gdirs: bname = os.path.join(PLOTS_DIR, gd.name + '_' + gd.rgi_id + '_') graphics.plot_googlemap(gd) plt.savefig(bname + 'ggl.png') plt.close() graphics.plot_domain(gd) plt.savefig(bname + 'dom.png') plt.close() graphics.plot_centerlines(gd) plt.savefig(bname + 'cls.png') plt.close() graphics.plot_catchment_width(gd, corrected=True) plt.savefig(bname + 'w.png') plt.close() graphics.plot_inversion(gd) plt.savefig(bname + 'inv.png') plt.close()
# Apply several tasks sequentially (i.e. one after an other) on our glacier list list_talks = [ tasks.compute_centerlines, #Compute the centerlines following Kienholz et al., (2014). tasks.initialize_flowlines, #Computes more physical Inversion Flowlines from geometrical Centerlines tasks.compute_downstream_line, #Computes the Flowline along the unglaciated downstream topography tasks.catchment_area, #Compute the catchment areas of each tributary line. tasks.catchment_width_geom, #Compute geometrical catchment widths for each point of the flowlines tasks.catchment_width_correction, #Corrects for NaNs and inconsistencies in the geometrical widths. tasks.compute_downstream_bedshape #The bedshape obtained by fitting a parabola to the line's normals and downstream altitude ] for task in list_talks: workflow.execute_entity_task(task, gdirs) for agdir in gdirs: graphics.plot_centerlines(agdir, figsize=(8, 7), use_flowlines=True, add_downstream=True) graphics.plot_catchment_areas(agdir, figsize=(8, 7)) graphics.plot_catchment_width(agdir, corrected=True, figsize=(8, 7)) # Location of Monthly Climate Data for the Glacier #fpath = gdir.get_filepath('climate_monthly') #print(fpath) #ds = xr.open_dataset(fpath) #print(ds) # Data is in hydrological years # -> let's just ignore the first and last calendar years #ds.temp.resample(time='AS').mean()[1:-1].plot() plt.show()
cfg.PARAMS['fixed_dx'] = 40 cfg.PARAMS['border'] = 10 entity = gpd.read_file(get_demo_file('Hintereisferner.shp')) hef = workflow.init_glacier_regions(entity, reset=False)[0] input_shp = hef.get_filepath('outlines', div_id=0) input_dem = hef.get_filepath('dem', div_id=0) # filter options f_area = False f_alt_range = True f_perc_alt_range = True # set paths to python 2.7 and to the partitioning package python = 'path to python 2.7' project = 'path to the partitioning package' script = os.path.join(project, 'partitioning/examples/run_divides.py') os.system(python + ' ' + script + ' ' + input_shp + ' ' + input_dem + ' ' + str(f_area) + ' ' + str(f_alt_range) + ' ' + str(f_perc_alt_range)) print('Hintereisferner is divided into', hef.n_divides, 'parts.') tasks.glacier_masks(hef) tasks.compute_centerlines(hef) graphics.plot_centerlines(hef) plt.show()
ax0.scatter(x_conect, y_conect, s=80, marker="o", color='red') ax0.text(x_conect, y_conect, s=gdir.rgi_id, color=sns.xkcd_rgb["white"], weight='black', fontsize=12) sm.visualize(ax=ax0, addcbar=False) # cbar_title='Velocity \n m/yr') at = AnchoredText('a', prop=dict(size=14), frameon=True, loc=2) ax0.add_artist(at) llkw = {'interval': 1} ax2 = fig1.add_subplot(spec[0, 1]) graphics.plot_centerlines(gdirs[0], ax=ax2, title='', add_colorbar=False, lonlat_contours_kwargs=llkw, add_scalebar=False) at = AnchoredText('b', prop=dict(size=10), frameon=True, loc=2) ax2.add_artist(at) ax3 = fig1.add_subplot(spec[0, 2]) graphics.plot_catchment_width(gdirs[0], ax=ax3, title='', corrected=True, lonlat_contours_kwargs=llkw, add_colorbar=False, add_scalebar=False) at = AnchoredText('d', prop=dict(size=14), frameon=True, loc=2) ax3.add_artist(at)
###################### Plotting scripts ####################################### if Plotting: # Plotting things before the calving for all glaciers PLOTS_DIR = '/home/beatriz/Documents/OGGM_Alaska_run/plots/' # PLOTS_DIR = '' # if PLOTS_DIR == '': # exit() # utils.mkdir(PLOTS_DIR) for gd in gdirs: bname = os.path.join(PLOTS_DIR, gd.name + '_' + gd.rgi_id + '_') graphics.plot_googlemap(gd) plt.savefig(bname + 'ggl.png') plt.close() graphics.plot_centerlines(gd, add_downstream=False) plt.savefig(bname + 'cls.png') plt.close() graphics.plot_catchment_width(gd, corrected=True) plt.savefig(bname + 'w.png') plt.close() graphics.plot_inversion(gd) plt.savefig(bname + 'inv.png') plt.close() graphics.plot_distributed_thickness(gd) plt.savefig(bname + 'inv_cor.png') plt.close() ################### Making a regional thickness plot ######################### # dem = utils.get_topo_file([-149.5,-146],[60, 62]) # dem = salem.GeoTiff(dem[0])
nrows_ncols = (1, 2), axes_pad=1.5, share_all=True, cbar_location="left", cbar_mode="single", cbar_size="7%", cbar_pad=0.05, aspect = True ) llkw = {'interval': 0} letkm = dict(color='black', ha='left', va='top', fontsize=20, bbox=dict(facecolor='white', edgecolor='black')) graphics.plot_centerlines(gdirs[0], ax=grid1[0], title='', add_colorbar=True, lonlat_contours_kwargs=llkw, cbar_ax=grid1[0].cax, add_scalebar=True) xt, yt = 2.45, 2.45 grid1[0].text(xt, yt, 'a', **letkm) graphics.plot_catchment_width(gdirs[0], ax=grid1[1], title='', corrected=True, add_colorbar=False, lonlat_contours_kwargs=llkw, add_scalebar=False) grid1[1].text(xt, yt, 'c', **letkm) grid1.axes_all
fn = bname + '0_ggl.png' if not os.path.exists(fn): graphics.plot_googlemap(gd) plt.savefig(fn) plt.close() fn = bname + '1_dom.png' if not os.path.exists(fn): graphics.plot_domain(gd, title_comment=demsource) plt.savefig(fn) plt.close() plt.close() fn = bname + '2_cls.png' if not os.path.exists(fn): graphics.plot_centerlines(gd, title_comment=demsource) plt.savefig(fn) plt.close() fn = bname + '3_fls.png' if not os.path.exists(fn): graphics.plot_centerlines(gd, title_comment=demsource, use_flowlines=True, add_downstream=True) plt.savefig(fn) plt.close() fn = bname + '4_widths.png' if not os.path.exists(fn): graphics.plot_catchment_width(gd,