Use slope as shading

Using the slope file generated with grdgradient -S gives a very mild and pleasing shading effect (and I think this method is used by a couple of software packages as default to give a sense of depth).
It’s not made to be used as a way of shading (or?), so it demands some processing. E.g. the slope file needs to fit the -1/1 range that grdimage expects for an illumination file. See example script and figure below:

# make grid
gmt grdcut -RIHO6 -Giho06.nc @earth_relief_02m

# create slope
gmt grdgradient iho06.nc -D -Sslope.nc
# manipulate slope to be 'centered' around 0 as grdimage requires
gmt grdmath 0.5 slope.nc SUB = slope-norm.nc

gmt begin iho06 png
gmt set GMT_THEME minimal

# plot default shading
gmt grdimage -I+d iho06.nc -JM8c -Baf -B+t"grdimage -I+d"

# plot own slope-style shade
gmt grdimage -X10c -Islope-norm.nc iho06.nc -Baf -B+t"Slope file shading"
gmt end show

# clean up
rm iho06.nc slope.nc slope-norm.nc gmt.history

Resulting figure.

So my question is;

  • does this way of doing it hold water?
  • are there better ways to normalize the slope file? gmt grdmath 0.5 slope.nc SUB = slope-norm.nc seems a bit… primitive. And, the ‘shade’ effect is only visible where the slope is significant.

It looks pretty clean this way, what’s the problem ?
Maybe grdgradient can scale your file directly via -N (and -Q?)

Thanks @PlanetGus. It looks ok, but I can’t think that subtracting the slope grid from 0.5 is a solid way of doing it.

-N and -Q applies to output with -G I think; not the grid produced with -S.

Here’s an improved script where you can give a ‘vertical exaggeration’ effect.

# make grid
gmt grdcut -RIHO6 -Giho06.nc @earth_relief_02m

# create slope
gmt grdgradient iho06.nc -D -Sslope.nc
# manipulate slope, add 'vertical exaggeration' (2 MUL). Increase this number if you want a bigger effect
gmt grdmath 0.5 slope.nc 2 MUL SUB = slope.nc

gmt begin iho06 png
gmt set GMT_THEME minimal

# plot default shading
gmt grdimage -Islope.nc iho06.nc -JM8c -Baf -B+t"Slope shade"

gmt end show

# clean up
rm iho06.nc slope.nc gmt.history

VE = 2

VE = 5

How do you come up with 0.5 to shift to zero. I thought the slopes are in units of data values per distance values. Are the values signed (I cannot recall and cannot test right now)? We could probably implement some modifier etc to convert the slope grid to an intensity grid of sorts if there was a simple recipe to use,

I have no idea what I’m doing.

$ gmt grdcut -RIHO6 -Giho06.nc @earth_relief_02m

$ gmt grdgradient iho06.nc -D -Sslope.nc

$ gmt grdinfo slope.nc 
slope.nc: Title: Produced by grdgradient
slope.nc: Command: gmt grdgradient iho06.nc -D -Sslope.nc
[...]
slope.nc: v_min: 0 v_max: 0.617982804775 name: z
[...]

So gmt grdmath 0.5 slope.nc SUB = slope-norm.nc gives v_min: -0.117982804775 v_max: 0.5 which “feels” more like -1/1 and looks OK. Again, this is just trial and error. My second script includes this 2 MUL part which makes the slopes a bit more pronounced.

The philosphical question here is; what physical meaning does this have? Nothing?, just eye candy? A hillshade is intuitive (at least in the simple case); the sun shines and topography will cast shadows, depending on its height and azimut.

And, a modifier to easily use slope for intensity would be great. I often find slopes as a way of shading to be a very easy (…) and good for presenting the terrain.

Confess that I’ve not payed close attention to the script contents, though this is one of those things on on my (head)backyard list to look one day. The reason for it is that MB auto-scripts (in …perl) use slopes for shading. You may want to look at those scripts for inspiration.

1 Like

My advisor (Adam Soule) taught me in grad school to use grdhisteq after grdgradient for visually appealing maps with illumination derived from slope. The ‘intensity’ of the trick is similarly manipulated using grdmath.

# make grid
gmt grdcut -RIHO6 -Giho06.nc @earth_relief_02m

# create slope
gmt grdgradient iho06.nc -Da -Sslope.nc
gmt grdhisteq slope.nc -Gslope-norm.nc -N
gmt grdmath slope-norm.nc -0.15 MUL = illum.nc

gmt begin iho06 png
gmt set GMT_THEME minimal

# plot default shading
gmt grdimage -I+d iho06.nc -JM8c -Baf -B+t"grdimage -I+d"

# plot own slope-style shade
gmt grdimage -X10c -Iillum.nc iho06.nc -Baf -B+t"Slope file shading"
gmt end show

1 Like

Thank you @Joaquim and @maxrjones for great tips. grdhisteq is one of the tools I’ve never spent time on, so maybe this is a good opportunity to do so.