Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
gname = os.path.basename(dgn)
print(gname)
ifile = find_path(os.path.join(DATA_DIR, 'itmix', 'glaciers_sorted'),
'02_surface_' + gname + '*.asc')
ds = salem.EsriITMIX(ifile)
itmix_topo = ds.get_vardata()
ifiles = find_path(ITMIX_ODIR, '*' + gname + '*.asc', allow_more=True)
for ifile in ifiles:
ds2 = salem.EsriITMIX(ifile)
oggm_topo = ds2.get_vardata()
thick = itmix_topo - oggm_topo
cm = salem.Map(ds.grid)
cm.set_plot_params(nlevels=256)
cm.set_cmap(plt.get_cmap('viridis'))
cm.set_data(thick)
cm.visualize()
pname = os.path.basename(ifile).split('.')[0]
plt.savefig(os.path.join(pdir, pname) + '.png')
plt.close()
filesuffix='_tbias')
utils.compile_run_output(gdirs, filesuffix='_defaults')
utils.compile_run_output(gdirs, filesuffix='_tbias')
# ds = xr.open_dataset(os.path.join(base_dir, 'run_output_defaults.nc'))
# (ds.volume.sum(dim='rgi_id') * 1e-9).plot()
# plt.show()
# exit()
# We prepare for the plot, which needs our own map to proceed.
# Lets do a local mercator grid
g = salem.mercator_grid(center_ll=(-19.61, 63.63),
extent=(18000, 14500))
# And a map accordingly
sm = salem.Map(g, countries=False)
# sm.set_lonlat_contours(add_xtick_labels=False, yinterval=0.05, xinterval=0.1)
sm.set_lonlat_contours(interval=0)
z = sm.set_topography('/home/mowglie/disk/OGGM_INPUT/tmp/ISL.tif')
sm.set_data(z)
# Figs
f = 0.75
f, axs = plt.subplots(2, 1, figsize=(7 * f, 10 * f))
graphics.plot_domain(gdirs, ax=axs[0], smap=sm)
sm.set_data()
# sm.set_lonlat_contours(yinterval=0.05, xinterval=0.1)
sm.set_lonlat_contours(interval=0)
sm.set_geometry()
sm.set_text()
# read the shapefile and use its extent to define a ideally sized map
shp = salem.read_shapefile(get_demo_file('rgi_kesselwand.shp'))
# I you need to do a lot of maps you might want
# to use an API key and set it here with key='YOUR_API_KEY'
g = GoogleVisibleMap(x=[shp.min_x, shp.max_x], y=[shp.min_y, shp.max_y],
scale=2, # scale is for more details
maptype='satellite') # try out also: 'terrain'
# the google static image is a standard rgb image
ggl_img = g.get_vardata()
ax1.imshow(ggl_img)
ax1.set_title('Google static map')
# make a map of the same size as the image (no country borders)
sm = Map(g.grid, factor=1, countries=False)
sm.set_shapefile(shp) # add the glacier outlines
sm.set_rgb(ggl_img) # add the background rgb image
sm.set_scale_bar(location=(0.88, 0.94)) # add scale
sm.visualize(ax=ax2) # plot it
ax2.set_title('GPR measurements')
# read the point GPR data and add them to the plot
df = pd.read_csv(get_demo_file('gtd_ttt_kesselwand.csv'))
dl = DataLevels(df.THICKNESS, levels=np.arange(10, 201, 10), extend='both')
x, y = sm.grid.transform(df.POINT_LON.values, df.POINT_LAT.values)
ax2.scatter(x, y, color=dl.to_rgb(), s=50, edgecolors='k', linewidths=1)
dl.append_colorbar(ax2, label='Ice thickness (m)')
# make it nice
plt.tight_layout()
plt.show()
maptype='satellite', scale=2,
size_x=400, size_y=400)
ggl_img = g.get_vardata()
# Get each level draining into the lake, then into the last level, and so on
gds = []
prev_id = [gdf.iloc[0].MAIN_BAS]
while True:
gd = gdf.loc[gdf.NEXT_DOWN.isin(prev_id)]
if len(gd) == 0:
break
gds.append(gd)
prev_id = gd.HYBAS_ID.unique()
# make a map of the same size as the image
sm = salem.Map(g.grid, factor=1)
sm.set_rgb(ggl_img) # add the background rgb image
# add all the draining basins
cmap = plt.get_cmap('Blues')
for i, gd in enumerate(gds):
# here we use a trick. set_shapefile uses PatchCollections internally,
# which is fast but does not support legend labels.
# so we use set_geometry instead:
for g, geo in enumerate(gd.geometry):
# we don't want more than one label per level
label = 'Level {:02d}'.format(i+1) if g == 0 else None
sm.set_geometry(geo, facecolor=cmap(i/(len(gds)-1)),
alpha=0.8, label=label)
# Get the polygon of the last sink (i.e. the lake) and plot it
gds_0 = gdf.loc[gdf.HYBAS_ID == gdf.iloc[0].MAIN_BAS]
sm.set_shapefile(gds_0, linewidth=2)
lonlat_contours_kwargs=None, cbar_ax=None, autosave=False,
add_scalebar=True, figsize=None, savefig=None,
savefig_kwargs=None,
**kwargs):
dofig = False
if ax is None:
fig = plt.figure(figsize=figsize)
ax = fig.add_subplot(111)
dofig = True
# Cast to list
gdirs = utils.tolist(gdirs)
if smap is None:
mp = salem.Map(gdirs[0].grid, countries=False,
nx=gdirs[0].grid.nx)
else:
mp = smap
if lonlat_contours_kwargs is not None:
mp.set_lonlat_contours(**lonlat_contours_kwargs)
if add_scalebar:
mp.set_scale_bar()
out = plotfunc(gdirs, ax=ax, smap=mp, **kwargs)
if add_colorbar and 'cbar_label' in out:
cbprim = out.get('cbar_primitive', mp)
if cbar_ax:
cb = cbprim.colorbarbase(cbar_ax)
else:
fig = plt.figure(figsize=figsize)
ax = fig.add_subplot(111)
dofig = True
gdirs = utils.tolist(gdirs)
xx, yy = [], []
for gdir in gdirs:
xx.extend(gdir.extent_ll[0])
yy.extend(gdir.extent_ll[1])
gm = salem.GoogleVisibleMap(xx, yy,
key='AIzaSyDWG_aTgfU7CeErtIzWfdGxpStTlvDXV_o')
img = gm.get_vardata()
cmap = salem.Map(gm.grid, countries=False, nx=gm.grid.nx)
cmap.set_rgb(img)
for gdir in gdirs:
cmap.set_shapefile(gdir.read_shapefile('outlines'))
cmap.plot(ax)
title = ''
if len(gdirs) == 1:
title = gdir.rgi_id
if gdir.name is not None and gdir.name != '':
title += ': ' + gdir.name
ax.set_title(title)
if dofig:
plt.tight_layout()
# Create extend of map [W, E, S, N]
extent = [ds['longitude'].values.min(), ds['longitude'].values.max(),
ds['latitude'].values.min(), ds['latitude'].values.max()]
# Setup colors
colors = cm.nipy_spectral(np.linspace(0,1,len(ds['gyms'])))
# Get google map. Scale is for more details. Mapytype can have
# 'terrain' or 'satellite'
g = GoogleVisibleMap(x=[extent[0], extent[1]], y=[extent[2],
extent[3]], scale=4, maptype='terrain')
ggl_img = g.get_vardata()
# Plot map
fig, ax = plt.subplots(1, 1, figsize=(20,20))
sm = Map(g.grid, factor=1, countries=False)
sm.set_rgb(ggl_img)
sm.visualize(ax=ax)
# Plot gym points
for i in range(0, len(ds['gyms'])):
# Create label
self.regcount = i
self._rank() # Add self.rank
_label = self.rank+' '+ds['gyms'].values[i]+': '+\
ds['athlete_names'].values[i]+' ('+str(ds[self.how].values[i])+')'
x, y = sm.grid.transform(ds['longitude'].values[i],
ds['latitude'].values[i])
ax.scatter(x, y, color=colors[i], s=400, label=_label)
plt.title(self.fname+' | '+self.city+' | '+self.column+' | '+self.how)
# Shrink current axis by 20% to make room for legend
box = ax.get_position()