def test_ice_cap(): testdir = os.path.join(cfg.PATHS['test_dir'], 'tmp_icecap') utils.mkdir(testdir) cfg.initialize() cfg.PATHS['dem_file'] = get_demo_file('dem_RGI50-05.08389.tif') cfg.PARAMS['border'] = 20 cfg.set_divides_db(get_demo_file('divides_RGI50-05.08389.shp')) hef_file = get_demo_file('RGI50-05.08389.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) centerlines.compute_downstream_lines(gdir) geometry.initialize_flowlines(gdir) # We should have five groups lines = gdir.read_pickle('downstream_lines', div_id=0) assert len(np.unique(lines.group))==5 # This just checks that it works geometry.catchment_area(gdir) geometry.catchment_intersections(gdir) geometry.catchment_width_geom(gdir) geometry.catchment_width_correction(gdir) fig, ax = plt.subplots() graphics.plot_catchment_width(gdir, ax=ax, add_intersects=True, add_touches=True) fig.tight_layout() return fig
def test_intersects_borders(): fig, ax = plt.subplots() gdir = init_hef() graphics.plot_catchment_width(gdir, ax=ax, add_intersects=True, add_touches=True) fig.tight_layout() return fig
def test_nodivide_corrected(): # 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_RGI5.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) geometry.initialize_flowlines(gdir) geometry.catchment_area(gdir) geometry.catchment_intersections(gdir) geometry.catchment_width_geom(gdir) geometry.catchment_width_correction(gdir) fig, ax = plt.subplots() graphics.plot_catchment_width(gdir, ax=ax, corrected=True, add_intersects=True, add_touches=True) fig.tight_layout() shutil.rmtree(testdir) return fig
def test_ice_cap(): testdir = os.path.join(get_test_dir(), 'tmp_icecap') utils.mkdir(testdir, reset=True) cfg.initialize() cfg.PARAMS['use_intersects'] = False cfg.PATHS['dem_file'] = get_demo_file('dem_RGI50-05.08389.tif') cfg.PARAMS['border'] = 60 cfg.PATHS['working_dir'] = testdir df = gpd.read_file(get_demo_file('divides_RGI50-05.08389.shp')) df['Area'] = df.Area * 1e-6 # cause it was in m2 df['RGIId'] = ['RGI50-05.08389_d{:02d}'.format(d + 1) for d in df.index] gdirs = workflow.init_glacier_regions(df) workflow.gis_prepro_tasks(gdirs) from salem import mercator_grid, Map smap = mercator_grid((gdirs[0].cenlon, gdirs[0].cenlat), extent=[20000, 23000]) smap = Map(smap) fig, ax = plt.subplots() graphics.plot_catchment_width(gdirs, ax=ax, add_intersects=True, add_touches=True, smap=smap) fig.tight_layout() shutil.rmtree(testdir) return fig
def test_width_corrected(): fig, ax = plt.subplots() gdir = init_hef() graphics.plot_catchment_width(gdir, ax=ax, corrected=True, add_intersects=True, add_touches=True) fig.tight_layout() return fig
def test_ice_cap(): testdir = os.path.join(cfg.PATHS['test_dir'], 'tmp_icecap') utils.mkdir(testdir) cfg.initialize() cfg.PATHS['dem_file'] = get_demo_file('dem_RGI50-05.08389.tif') cfg.PARAMS['border'] = 20 cfg.set_divides_db(get_demo_file('divides_RGI50-05.08389.shp')) hef_file = get_demo_file('RGI50-05.08389.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) centerlines.compute_downstream_lines(gdir) geometry.initialize_flowlines(gdir) # We should have five groups lines = gdir.read_pickle('downstream_lines', div_id=0) assert len(np.unique(lines.group)) == 5 # This just checks that it works geometry.catchment_area(gdir) geometry.catchment_intersections(gdir) geometry.catchment_width_geom(gdir) geometry.catchment_width_correction(gdir) fig, ax = plt.subplots() graphics.plot_catchment_width(gdir, ax=ax, add_intersects=True, add_touches=True) fig.tight_layout() return fig
def test_width(): fig, ax = plt.subplots() gdir = init_hef() graphics.plot_catchment_width(gdir, ax=ax) fig.tight_layout() return fig
def test_width(): gdir = init_hef() graphics.plot_catchment_width(gdir) graphics.plot_catchment_width(gdir, corrected=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
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) plt.savefig(fn) plt.close() fn = bname + '5_thick.png' if not os.path.exists(fn): fls = gd.read_pickle('model_flowlines') model = flowline.FlowlineModel(fls) graphics.plot_modeloutput_map(gd, model=model) plt.savefig(fn) plt.close()
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], title='', corrected=True, add_colorbar=False, lonlat_contours_kwargs=llkw, add_scalebar=False) axs[3].text(xt, yt, 'd', **letkm) f.delaxes(axs[3].cax)
# 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()
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() #workflow.execute_entity_task(tasks.local_t_star, gdirs); #workflow.execute_entity_task(tasks.mu_star_calibration, gdirs);
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) plt.savefig(fn) plt.close() fn = bname + '5_thick.png' if not os.path.exists(fn): fls = gd.read_pickle('model_flowlines') model = flowline.FlowlineModel(fls) graphics.plot_modeloutput_map(gd, model=model) plt.savefig(fn) plt.close()
xt, yt = 109, 2. im = graphics.plot_catchment_areas(gdir, ax=axs[0], title='', lonlat_contours_kwargs=llkw, add_scalebar=True, lines_cmap=LCMAP, mask_cmap=MCMAP) axs[0].text(xt, yt, 'a', **letkm) graphics.plot_catchment_width(gdir, ax=axs[1], title='', add_colorbar=False, lonlat_contours_kwargs=llkw, add_scalebar=False, lines_cmap=LCMAP) axs[1].text(xt, yt, 'b', **letkm) graphics.plot_catchment_width(gdir, ax=axs[2], title='', corrected=True, add_colorbar=False, lonlat_contours_kwargs=llkw, add_scalebar=False, add_touches=True, lines_cmap=LCMAP) axs[2].text(xt, yt, 'c', **letkm)