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

rsaga.wetness.index() issues #18

Open
jannes-m opened this issue Sep 7, 2018 · 2 comments
Open

rsaga.wetness.index() issues #18

jannes-m opened this issue Sep 7, 2018 · 2 comments

Comments

@jannes-m
Copy link
Contributor

jannes-m commented Sep 7, 2018

@be-marc I have two, ok, in fact three issues/recommendations:

  1. Why is it not possible to post an issue on r-spatial/RSAGA?
  2. The rsaga.wetness.index() documentation claims that out.wetness is optional when it isn't (see code below).
  3. Specifying a wrong parameter name results in an uninformative error message (see code below). Wouldn't it be possible to parse the function parameters and check if the correct ones were provided? Probably in the way how @stevenpawley is doing it in Rsagacmd.
library("RSAGA")
#> Loading required package: gstat
#> Loading required package: shapefiles
#> Loading required package: foreign
#> 
#> Attaching package: 'shapefiles'
#> The following objects are masked from 'package:foreign':
#> 
#>     read.dbf, write.dbf
#> Loading required package: plyr
data("dem", package = "RQGIS")
raster::writeRaster(dem, filename = file.path(tempdir(), "dem.sdat"),
                    format = "SAGA")
#> class       : RasterLayer 
#> dimensions  : 117, 117, 13689  (nrow, ncol, ncell)
#> resolution  : 30.85, 30.85  (x, y)
#> extent      : 794599.1, 798208.6, 8931775, 8935384  (xmin, xmax, ymin, ymax)
#> coord. ref. : NA 
#> data source : /tmp/Rtmp50WDWm/dem.sgrd 
#> names       : dem 
#> values      : 238, 1094  (min, max)

#**********************************************************
# 1. rsaga.wetness.index-----------------------------------
#**********************************************************

# this does not work
rsaga.wetness.index(in.dem = file.path(tempdir(), "dem.sgrd"),
                    # out.wetness.index = file.path(tempdir(), "twi.sdat"),
                    out.carea = file.path(tempdir(), "carea.sdat"),
                    out.cslope = file.path(tempdir(), "cslope.sdat"),
                    area.type = 0,
                    slope.type = 1)
#> Error in default.file.extension(out.wetness.index, ".sgrd"): argument "out.wetness.index" is missing, with no default


# Specifying out.wetness.index makes it work but in the docu it says this is
# optional
rsaga.wetness.index(in.dem = file.path(tempdir(), "dem.sgrd"),
                    out.wetness.index = file.path(tempdir(), "twi.sdat"),
                    out.carea = file.path(tempdir(), "carea.sdat"),
                    out.cslope = file.path(tempdir(), "cslope.sdat"),
                    area.type = 0,
                    slope.type = 1)
#> Search for SAGA command line program and modules... 
#> Done
#> 
#> 
#> SAGA Version: 2.3.1
#> 
#> library path: /usr/lib/saga/
#> library name: libta_hydrology
#> library     : Hydrology
#> tool        : SAGA Wetness Index
#> author      : (c) 2001 by J.Boehner, O.Conrad
#> processors  : 8 [8]
#> 
#> Load grid: /tmp/Rtmp50WDWm/dem.sgrd...
#> 
#> 
#> Parameters
#> 
#> 
#> Grid system: 30.85; 117x 117y; 794614.532615x 8931790.299603y
#> Elevation: dem
#> Weights: <not set>
#> Catchment area: Catchment area
#> Catchment slope: Catchment slope
#> Modified Catchment Area: Modified Catchment Area
#> Topographic Wetness Index: Topographic Wetness Index
#> Suction: 10.000000
#> Type of Area: absolute catchment area
#> Type of Slope: catchment slope
#> Minimum Slope: 0.000000
#> Offset Slope: 0.100000
#> Slope Weighting: 1.000000
#> 
#> Create index: dem
#> catchment area and slope...
#> pass 1 (1453 > 0)
#> pass 2 (556 > 0)
#> pass 3 (294 > 0)
#> pass 4 (134 > 0)
#> pass 5 (75 > 0)
#> pass 6 (38 > 0)
#> pass 7 (10 > 0)
#> pass 8 (3 > 0)
#> pass 9 (0 > 0)
#> post-processing...
#> topographic wetness index...
#> Save grid: /tmp/Rtmp50WDWm/carea.sdat...
#> Save grid: /tmp/Rtmp50WDWm/cslope.sdat...
#> Save grid: /tmp/Rtmp50WDWm/file2db918af8413...
#> Save grid: /tmp/Rtmp50WDWm/twi.sdat...

#**********************************************************
# 2. Uninformative error messages--------------------------
#**********************************************************

# let's run rsaga.geoprocessor with a wrongly specified parameter, e.g., we 
# have written SLOP_TYPE instead of SLOPE_TYPE
# The resulting error message is not very informative, would it be possible to
# check if the user has specified the correct parameter names
params = list(DEM = file.path(tempdir(), "dem.sgrd"),
              AREA = file.path(tempdir(), "carea.sdat"),
              SLOPE = file.path(tempdir(), "cslope.sdata"),
              AREA_TYPE = 0,
              SLOP_TYPE = 1)
rsaga.geoprocessor(lib = "ta_hydrology", module = "SAGA Wetness Index",
                   param = params)
#> Search for SAGA command line program and modules... 
#> Done
#> Warning in system(command, intern = intern, ...): running command ''/usr/
#> bin/saga_cmd' -f=q ta_hydrology 'SAGA Wetness Index' -DEM '/tmp/Rtmp50WDWm/
#> dem.sgrd' -AREA '/tmp/Rtmp50WDWm/carea.sdat' -SLOPE '/tmp/Rtmp50WDWm/
#> cslope.sdata' -AREA_TYPE '0' -SLOP_TYPE '1'' had status 1
#> 
#> 
#> SAGA Version: 2.3.1
#> 
#> library path: /usr/lib/saga/
#> library name: libta_hydrology
#> library     : Hydrology
#> tool        : SAGA Wetness Index
#> author      : (c) 2001 by J.Boehner, O.Conrad
#> processors  : 8 [8]
#> 
#> 
#> Usage: saga_cmd ta_hydrology 15 [-DEM <str>] [-WEIGHT <str>] [-AREA <str>] [-SLOPE <str>] [-AREA_MOD <str>] [-TWI <str>] [-SUCTION <double>] [-AREA_TYPE <str>] [-SLOPE_TYPE <str>] [-SLOPE_MIN <double>] [-SLOPE_OFF <double>] [-SLOPE_WEIGHT <double>]
#>   -DEM:<str>             Elevation
#>  Grid (input)
#>   -WEIGHT:<str>          Weights
#>  Grid (optional input)
#>   -AREA:<str>            Catchment area
#>  Grid (output)
#>   -SLOPE:<str>           Catchment slope
#>  Grid (output)
#>   -AREA_MOD:<str>        Modified Catchment Area
#>  Grid (output)
#>   -TWI:<str>             Topographic Wetness Index
#>  Grid (output)
#>   -SUCTION:<double>      Suction
#>  Floating point
#>  Minimum: 0.000000
#>  Default: 10.000000
#>   -AREA_TYPE:<str>       Type of Area
#>  Choice
#>  Available Choices:
#>  [0] absolute catchment area
#>  [1] square root of catchment area
#>  [2] specific catchment area
#>  Default: 1
#>   -SLOPE_TYPE:<str>      Type of Slope
#>  Choice
#>  Available Choices:
#>  [0] local slope
#>  [1] catchment slope
#>  Default: 1
#>   -SLOPE_MIN:<double>    Minimum Slope
#>  Floating point
#>  Minimum: 0.000000
#>  Default: 0.000000
#>   -SLOPE_OFF:<double>    Offset Slope
#>  Floating point
#>  Minimum: 0.000000
#>  Default: 0.100000
#>   -SLOPE_WEIGHT:<double> Slope Weighting
#>  Floating point
#>  Minimum: 0.000000
#>  Default: 1.000000

Created on 2018-09-07 by the reprex package (v0.2.0).

@be-marc
Copy link

be-marc commented Oct 1, 2018

  1. Why is it not possible to post an issue on r-spatial/RSAGA?

Should be possible soon. I have sent a message to owner of r-spatial

  1. The rsaga.wetness.index() documentation claims that out.wetness is optional when it isn't (see code below).

out.wetness is now optional r-spatial/RSAGA@66ea4e9

  1. Specifying a wrong parameter name results in an uninformative error message (see code below). Wouldn't it be possible to parse the function parameters and check if the correct ones were provided? Probably in the way how @stevenpawley is doing it in Rsagacmd.

I added this as a new feature r-spatial/RSAGA@86e1957

@jannes-m
Copy link
Contributor Author

jannes-m commented Oct 1, 2018

@be-marc Excellent!! Thanks for all the hard work!! Will give it a try soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants