2

I just downloaded SAGA and the RSAGA package for R. I would like to use the rsaga.pisr2 function to compute solar radiation for my region of interest. I am currently getting errors related to proj4 (see below) which I don't know how to resolve.

I set the rsaga environment as follows (for some reason specifying version the first time doesn't work, so I had to do it separately):

rse <- rsaga.env(path='/usr/local/Cellar/saga-gis-lts/2.3.2_2/bin/',
                 modules='/usr/local/Cellar/saga-gis-lts/2.3.2_2/lib/saga',
                 version = '2.3.2')
rse$version <- '2.3.2'

I converted a raster DEM layer to sgrd format using the RSAGA function rsaga.esri.to.sgrd:

dem_sgrd <- rsaga.esri.to.sgrd(in.grids='Documents/IGERT/RockGlacierModeling/GlacierNP/GlacierNP_DEM.asc',
                               out.sgrds=paste0(pisr_folder,'GlacierNP_DEM.sgrd'),env=rse)
dem_sgrd_fn <- paste0(pisr_folder,'GlacierNP_DEM')

The original projection of the DEM raster was:

 "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"

I then input the sgrd DEM to the rsaga.pisr2 function as follows:

pisr <- rsaga.pisr2(in.dem = dem_sgrd_fn, in.svf.grid = NULL, in.vapour.grid = NULL, in.linke.grid = NULL, out.direct.grid=out_direct_grid_fn, out.diffuse.grid=out_diffuse_grid_fn, out.total.grid=out_total_grid_fn, out.ratio.grid = out_ratio_grid_fn, out.duration = out_duration_fn, out.sunrise=out_sunrise_fn, out.sunset=out_sunset_fn, local.svf = TRUE, location = "grid", latitude = 48.5, unit = "kWh/m2", solconst = 1367, method = "height", hgt.atmosphere = 12000, cmp.pressure = 1013, cmp.water.content = 1.68, cmp.dust = 100, lmp.transmittance = 70, time.range = c(0, 24), time.step = 0.5, start.date = list(day = 1, month = 2, year = 2015), end.date = list(day = 2, month = 2, year = 2015), day.step = 5, env = rse)

When I run this function I don't get any output files and I get the following output in the console in R:

Error: Proj4 [initialization]: no arguments in initialization list
Error: Could not initialize grid projection.
Error: could not execute tool [pj_proj4].[Geographic Coordinate Grids]
Error: executing tool [Potential Incoming Solar Radiation]


SAGA Version: 2.3.2

library path: /usr/local/Cellar/saga-gis-lts/2.3.2_2/lib/saga/
library name: libta_lighting
library     : Lighting, Visibility
tool        : Potential Incoming Solar Radiation
author      : O.Conrad (c) 2010

Load grid: Documents/IGERT/RockGlacierModeling/GlacierNP/rsaga_pisr/GlacierNP_DEM.sgrd...


Parameters


Grid system: 0.000833; 1719x 1161y; -114.574167x 48.134167y
Elevation: GlacierNP_DEM
Sky View Factor: <not set>
Water Vapour Pressure [mbar]: <not set>
Default: 10.000000
Direct Insolation: Direct Insolation
Diffuse Insolation: Diffuse Insolation
Total Insolation: Total Insolation
Direct to Diffuse Ratio: Direct to Diffuse Ratio
Solar Constant [W / m²]: 1367.000000
Local Sky View Factor: yes
Units: kWh / m2
Shadow: fat
Location: calculate from grid system
Time Period: range of days
Day: 01/01/2015
Last Day: 02/01/2015
Resolution [d]: 5
Time Span [h]: 0.000000; 24.000000
Resolution [h]: 0.500000
Atmospheric Effects: Height of Atmosphere and Vapour Pressure
Height of Atmosphere [m]: 12000.000000

Geographic Coordinate Grids


Parameters


Grid system: 0.000833; 1719x 1161y; -114.574167x 48.134167y
Grid: GlacierNP_DEM
Longitude: Longitude
Latitude: Latitude


source: 
Warning message:
running command ''/usr/local/Cellar/saga-gis-lts/2.3.2_2/bin/saga_cmd' -f=q ta_lighting 'Potential Incoming Solar Radiation' -GRD_DEM 'Documents/IGERT/RockGlacierModeling/GlacierNP/rsaga_pisr/GlacierNP_DEM.sgrd' -GRD_DIRECT 'Documents/IGERT/RockGlacierModeling/GlacierNP/rsaga_pisr/GlacierNP_out_direct_grid.sgrd' -GRD_DIFFUS 'Documents/IGERT/RockGlacierModeling/GlacierNP/rsaga_pisr/GlacierNP_out_diffuse_grid.sgrd' -GRD_TOTAL 'Documents/IGERT/RockGlacierModeling/GlacierNP/rsaga_pisr/GlacierNP_out_total_grid.sgrd' -GRD_RATIO 'Documents/IGERT/RockGlacierModeling/GlacierNP/rsaga_pisr/GlacierNP_out_ratio_grid.sgrd' -GRD_DURATION 'Documents/IGERT/RockGlacierModeling/GlacierNP/rsaga_pisr/GlacierNP_out_duration.sgrd' -GRD_SUNRISE 'Documents/IGERT/RockGlacierModeling/GlacierNP/rsaga_pisr/GlacierNP_out_sunrise.sgrd' -GRD_SUNSET 'Documents/IGERT/RockGlacierModeling/GlacierNP/rsaga_pisr/GlacierNP_out_sunset.sgrd' -UNITS '0' -SOLARCONST '1367' -LOCALSVF 'true' -METHOD '0' -HOUR_STEP '0.5' -LOCATION ... <truncated>

I'm running R version 3.40 on a Mac (OS 10.14) with SAGA version 2.3.2. I have no experience with SAGA or RSAGA. I ran the code in terminal and was able to successfully output the files I wanted.

  • Why do you think it is a problem with proj4? can you run the command directly from the console? The strangest thing I see there is the double bar in bin//saga_cmd. You can try specifying the arguments for the rsaga.env function. – Gabriel De Luca Jan 6 at 4:36
  • @GabrielDeLuca Thanks for your ideas. I've edited my original post to reflect answers to your suggestions. I deleted a second version of SAGA I had and that removed the double bar you mentioned. Specifying rsaga.env does not resolve the issue. I can run the program in terminal, but still no luck in R. If this can't be easily resolved I may settle for running in terminal, but I would prefer to resolve the issue. I suspected a problem with proj4 due to the first few errors in the output. – lutecel Jan 6 at 19:23
  • Sorry, I do not have experience in RSAGA. It seems that you need to assign a CRS to the grid? Could you try running before saga_cmd pj_proj4 0 -CRS_METHOD 0 -CRS_PROJ4 "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" -GRIDS "GlacierNP_DEM.sgrd" through a rsaga.geoprocessor function? – Gabriel De Luca Jan 6 at 21:43
  • @GabrielDeLuca Good idea. I was able to assign the CRS in R using: rsaga.geoprocessor("pj_proj4", 0, list(CRS_METHOD=0, CRS_PROJ4="+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0", GRIDS=paste0(pisr_folder,'GlacierNP_DEM.sgrd')),env=rse) I was then able to run the rsaga.pisr2 function without error. If you create an answer I would be happy to accept it. – lutecel Jan 7 at 17:40
  • I'm glad to know that it worked well. I would prefer if you can add the answer yourself, with the correct code in RSAGA, and accept it. I just thought about how to solve it from SAGA. – Gabriel De Luca Jan 7 at 17:52
1

Following the suggestions of Gabriel De Luca, the problem was solved by assigning a CRS to the input DEM. In R:

rsaga.geoprocessor("pj_proj4", 0, list(CRS_METHOD=0, CRS_PROJ4="+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0", GRIDS=paste0(pisr_folder,'GlacierNP_DEM.sgrd')),env=rse)

I was then able to run the rsaga.pisr2 function to calculate solar radiation. For this to work, I also had to make sure to define the rsaga environment, not using the default rsaga.env().

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.