-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
206 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
=========================== | ||
Plot on a google static map | ||
=========================== | ||
In this script, we use `motionless <https://github.com/ryancox/motionless>`_ | ||
to download an image from the `google static map API <http://code.google.com/apis/maps/documentation/staticmaps/>`_ | ||
and plot it on a :py:class:`~salem.Map`. We then add information to the map | ||
such as a glacier outline (from the `RGI <http://www.glims.org/RGI/>`_), | ||
and ground penetrating radar measurements (GPR, from the | ||
`GlaThiDa <http://www.gtn-g.ch/data_catalogue_glathida/>`_ database). | ||
The GPR measurements were realized in 1997, the glacier outlines are from | ||
2003, and the map background is from 2016. This illustrates the retreat of | ||
the Kesselwandferner glacier. | ||
""" | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import salem | ||
from salem import get_demo_file, DataLevels, GoogleVisibleMap, Map | ||
import matplotlib.pyplot as plt | ||
|
||
# prepare the figure | ||
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5)) | ||
|
||
# read the shapefile and use its extent to define a ideally sized map | ||
shp = salem.read_shapefile(get_demo_file('rgi_kesselwand.shp')) | ||
g = GoogleVisibleMap(x=[shp.min_x, shp.max_x], y=[shp.min_y, shp.max_y], | ||
maptype='satellite') # try out: '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 | ||
sm = Map(g.grid, factor=1) | ||
sm.set_shapefile(shp) # add the glacier outlines | ||
sm.set_rgb(ggl_img) # add the background rgb image | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,44 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
============== | ||
Add topography | ||
============== | ||
=================== | ||
Topographic shading | ||
=================== | ||
Here we add topography to the plot. | ||
How to add topographic shading to a plot. | ||
""" | ||
|
||
from salem import mercator_grid, Map, get_demo_file | ||
import matplotlib.pyplot as plt | ||
|
||
grid = mercator_grid(center_ll=(10.76, 46.798444), | ||
extent=(10000, 7000)) | ||
c = Map(grid, countries=False) | ||
c.set_lonlat_contours(interval=10) | ||
c.set_shapefile(get_demo_file('Hintereisferner_UTM.shp')) | ||
c.set_topography(get_demo_file('hef_srtm.tif')) | ||
# prepare the figure | ||
|
||
fig, ax = plt.subplots(1, 1) | ||
c.visualize(ax=ax, addcbar=False, title='Default: spline deg 3') | ||
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(8, 7)) | ||
|
||
# map extent | ||
grid = mercator_grid(center_ll=(10.76, 46.79), extent=(18000, 14000)) | ||
sm = Map(grid, countries=False) | ||
sm.set_lonlat_contours(interval=0) | ||
|
||
# add topography | ||
fpath = get_demo_file('hef_srtm.tif') | ||
sm.set_topography(fpath) | ||
sm.visualize(ax=ax1, addcbar=False, title='relief_factor=0.7 (default)') | ||
|
||
# stronger shading | ||
sm.set_topography(fpath, relief_factor=1.4) | ||
sm.visualize(ax=ax2, addcbar=False, title='relief_factor=1.4') | ||
|
||
# add color shading | ||
z = sm.set_topography(fpath) | ||
sm.set_data(z) | ||
sm.set_cmap('topo') | ||
sm.visualize(ax=ax3, title='Color with shading', addcbar=False) | ||
|
||
# color without topo shading | ||
sm.set_topography() | ||
sm.visualize(ax=ax4, title='Color without shading', addcbar=False) | ||
|
||
# make it nice | ||
plt.tight_layout() | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.