Last active
May 11, 2021 04:12
-
-
Save perrygeo/11350017 to your computer and use it in GitHub Desktop.
PyGRASS
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
import os | |
import sys | |
outdir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'output')) | |
if not os.path.exists(outdir): | |
os.mkdir(outdir) | |
input_elevation = "dem.img" | |
gisbase = os.environ['GISBASE'] = "/usr/local/grass-7.0.0svn" | |
# putting $GISBASE/lib (with $GISBASE replaced by its actual value) | |
# into /etc/ld.so.conf then running ldconfig). | |
# os.environ['LD_LIBRARY_PATH'] = os.path.join(gisbase, 'lib') | |
# print os.environ['LD_LIBRARY_PATH'] | |
gisdbase = os.path.join('.') | |
# TODO create these with correct projection info for the input raster(s) | |
location = "bigsur" | |
mapset = "PERMANENT" | |
sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "python")) | |
import grass.script.setup as gsetup | |
gsetup.init(gisbase, gisdbase, location, mapset) | |
############################################################################### | |
from grass.pygrass.modules.shortcuts import raster as rast | |
from grass.pygrass.modules.shortcuts import general | |
general.mremove(rast="*", f=True) | |
elev = "dem" | |
slope = "slope.img" | |
aspect = "aspect.img" | |
rast.external(input=input_elevation, output=elev, overwrite=True) | |
rast.external_out(directory=outdir, format="HFA") | |
rast.slope_aspect(elevation=elev, slope=slope, aspect=aspect, format='percent', overwrite=True) | |
rast.topidx(input=elev, output="topidx.img") | |
rast.sun (elev_in=elev, asp_in=aspect, slope_in=slope, | |
lin=2.5, alb=0.2, day=172, | |
#beam_rad=b172b diff_rad=d172b, refl_rad=r172b insol_time=it172b, glob_rad=g172b | |
insol_time='insoltime_172.img', glob_rad='globalrad_172.img') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some other useful terrain commands in GRASS 7