Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gallery example for grdgradient #1428

Merged
Merged
Changes from 30 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
e4dbdaa
add myself 'Yohai Magen' to authers
yohaimagen Aug 6, 2021
9ac4a6c
Merge branch 'GenericMappingTools:main' into add_myself_to_AUTHORS.md
yohaimagen Aug 7, 2021
a546150
Update AUTHORS.md
yohaimagen Aug 7, 2021
c5ecf3a
adding a gallery example to gedgradient
yohaimagen Aug 10, 2021
f5f495c
changing figure size
yohaimagen Aug 10, 2021
519ad80
reformat
yohaimagen Aug 10, 2021
51a1397
corecting typos
yohaimagen Aug 11, 2021
7922d5a
Merge branch 'main' into grdgradient_gallery_example
michaelgrund Aug 30, 2021
fb5a71b
Update examples/gallery/images/grdgradient.py
yohaimagen Sep 4, 2021
e5338be
Update examples/gallery/images/grdgradient.py
yohaimagen Sep 4, 2021
2db53ea
Update examples/gallery/images/grdgradient.py
yohaimagen Sep 4, 2021
490fe5d
Update examples/gallery/images/grdgradient.py
yohaimagen Sep 4, 2021
bc75bff
Update examples/gallery/images/grdgradient.py
yohaimagen Sep 4, 2021
485093f
Update examples/gallery/images/grdgradient.py
yohaimagen Sep 4, 2021
77814bf
Merge branch 'main' into grdgradient_gallery_example
yohaimagen Sep 4, 2021
75ad23c
swaping places of original and grdient data
yohaimagen Sep 4, 2021
8824389
add changes to exampeels instad of gallery
yohaimagen Sep 12, 2021
f052e94
Merge branch 'main' into grdgradient_gallery_example
yohaimagen Sep 12, 2021
b8cdb48
reformat
yohaimagen Sep 12, 2021
c141255
reformat
yohaimagen Sep 12, 2021
becddc8
add segustion manually
yohaimagen Sep 12, 2021
61b713f
Update examples/gallery/images/grdgradient.py
yohaimagen Sep 12, 2021
6373482
Update examples/gallery/images/grdgradient.py
yohaimagen Sep 12, 2021
bd1bc47
Update examples/gallery/images/grdgradient.py
yohaimagen Sep 12, 2021
238af9a
Update examples/gallery/images/grdgradient.py
yohaimagen Sep 12, 2021
1c6d02a
Update examples/gallery/images/grdgradient.py
yohaimagen Sep 12, 2021
92f4409
update doc
yohaimagen Sep 12, 2021
9c7dd30
reformat
yohaimagen Sep 12, 2021
87781d5
Update examples/gallery/images/grdgradient.py
yohaimagen Sep 12, 2021
103eeca
reformat
yohaimagen Sep 12, 2021
90f2129
Update examples/gallery/images/grdgradient.py
yohaimagen Sep 12, 2021
8a46b2e
Apply suggestions from code review
yohaimagen Sep 14, 2021
9390f94
Merge branch 'main' into grdgradient_gallery_example
yohaimagen Sep 14, 2021
0cd367c
edit the doc
yohaimagen Sep 15, 2021
0f67bea
add N37W120.earth_relief_03s tile to chach
yohaimagen Sep 15, 2021
8b4d5c5
add @ prefix
yohaimagen Sep 15, 2021
e06dcd9
Update .github/workflows/cache_data.yaml
yohaimagen Sep 15, 2021
e98808a
recommenting pull_request
yohaimagen Sep 15, 2021
391b1dd
Merge branch 'main' into grdgradient_gallery_example
yohaimagen Sep 15, 2021
0c6e53d
Apply suggestions from code review
yohaimagen Sep 16, 2021
b061927
change title
yohaimagen Sep 16, 2021
2b9bddb
Merge branch 'grdgradient_gallery_example' of https://github.com/yoha…
yohaimagen Sep 16, 2021
5fecb09
Merge branch 'main' into grdgradient_gallery_example
yohaimagen Sep 16, 2021
b931683
Update examples/gallery/images/grdgradient.py
yohaimagen Sep 16, 2021
a27c700
add sugestion manually
yohaimagen Sep 16, 2021
90a7dff
Apply suggestions from code review
yohaimagen Sep 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions examples/gallery/images/grdgradient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
Calculating the gradient of a grid file
--------------------
yohaimagen marked this conversation as resolved.
Show resolved Hide resolved
The :meth:`pygmt.grgradient` method calculates the gradient of a grid file.
yohaimagen marked this conversation as resolved.
Show resolved Hide resolved
In the example shown below we will see how to calculate a hillshade map based
on a Data Elevation Model(DEM). As input :meth:`pygmt.grdgradient` gets
yohaimagen marked this conversation as resolved.
Show resolved Hide resolved
a :class:`xarray.DataArray` object or a path string to a grid file. We will use
the ``radiance`` parameter in order to set the illumination source direction
and altitude.
"""

import pygmt

fig = pygmt.Figure()

yohaimagen marked this conversation as resolved.
Show resolved Hide resolved
# Define region of interest around Yosemite valley
region = [-119.825, -119.4, 37.6, 37.825]

# Load sample grid (3 arc second global relief) in target area
grid = pygmt.datasets.load_earth_relief(resolution="03s", region=region)
seisman marked this conversation as resolved.
Show resolved Hide resolved

# calculate the reflection of a light source projecting from west to east
# (azimuth of 270 degrees) and at a latitude of 30 degrees from the horizon
dgrid = pygmt.grdgradient(grid=grid, radiance=[270, 30])

fig = pygmt.Figure()
# define figure configuration
pygmt.config(FORMAT_GEO_MAP="ddd.x", MAP_FRAME_TYPE="plain")

# --------------- plotting the original Data Elevation Model -----------

pygmt.makecpt(cmap="gray", series=[200, 4000, 10])
fig.grdimage(
grid=grid,
projection="M12c",
frame=['WSrt+t"Original Data Elevation Model"', "xa0.1", "ya0.1"],
cmap=True,
region=region,
yohaimagen marked this conversation as resolved.
Show resolved Hide resolved
)

fig.colorbar(position="JML+o1.4c/0c+w7c/0.5c", frame=["xa1000f500+lElevation", "y+lm"])

# --------------- plotting the hillshade map -----------

# Shift plot origin of the second map by "width of the first map + 0.5 cm"
yohaimagen marked this conversation as resolved.
Show resolved Hide resolved
# in x direction
yohaimagen marked this conversation as resolved.
Show resolved Hide resolved
fig.shift_origin(xshift="12.5c")

pygmt.makecpt(cmap="gray", series=[-1.5, 0.3, 0.01])
fig.grdimage(
grid=dgrid,
projection="M12c",
frame=['lSEt+t"Hillshade Map"', "xa0.1", "ya0.1"],
cmap=True,
region=region,
yohaimagen marked this conversation as resolved.
Show resolved Hide resolved
)


yohaimagen marked this conversation as resolved.
Show resolved Hide resolved
fig.show()