r.sunangle GRASS GIS python script

PURPOSE
r.sunangle is a GRASS GIS module which computes sun angles for each point in given text file, from day of beginning to end day with given time increment. Input file must contain IDs and positions of the points (latitude and longitude), time increment, starting and ending days for computations. Values of slope inclination, aspect and elevation can be specified as well ("s" flag), by default they will be taken from raster layers specified as input parameters.

DESCRIPTION
The algorithm employs the equations and terminology from:
Hofierka, J., Suri, M. (2002, september 11). The solar radiation model for Open source GIS: implementation and applications. Trento, Italy.

Module is based on R script originally written by Michal Gallay (michal.gallay (at) gmail.com) for Institute of Botany Slovak Academy of Sciences in Bratislava, Slovakia. Inputs require a text file, which is read by this script and the values contained enter the algorithm.
The format of the input file should be:

point;latitude;longitude;increment;day_start;day_end;slope_value;aspect_value;elevation_value

point - ID of the point (number or text string)
latitude - latitude of the point in decimal degrees
longtitude of the point in decimal degrees
increment - time increment in decimal hours (24.0 for one day)
day_start - day of of the beginning (1 for January 1, 365 for December 31)
day_end - day of of the end (1 for January 1, 365 for December 31)
slope_value - slope inclination value in degrees
aspect_value - aspect (orientation) in degrees (0 = north, 90 = east, 180 = south, 270 = west)
elevation_value - elevation above sea level in m (
Values must be separated with ";" (semicolon).

If output file is not specified by user, then the results are saved in a new file_solar_incidence_angle.csv text file.
The format of the output file is:
1;point;latitude;slope_angle;aspect_angle;day;time;inclined_sun_angle;inclined_sunset_time;horiz_sun_angle;horiz_sunset_time;sun_azimuth

Output text file contains header and computed values in one line per point and time step separated by ";" (semicolon).
Output variables:
point - point ID
latitude - latitude in decimal degrees
longitude - longitude in decimal degrees
elevation - elevation in m above sea level
slope_angle - slope inclination in degrees
aspect_angle - aspect (orientation) in degrees (0 = north, 90 = east, 180 = south, 270 = west)
day - day of year (1 for January 1, 365 for December 31)
time - time in decimal hours
inclined_sun_angle - sun angle above inclined surface in degrees
inclined_sunset_time - local sunset time on inclined surface in decimal hours
horiz_sun_angle - sun angle above horizontal surface in degrees, negative value when sun is below horizon (at night)
horiz_sunset_time - local sunset time (astronomic) in decimal hours
sun_azimuth - sun azimuth in degrees (0 = north, 90 = east, 180 = south, 270 = west)
max_sun_angle - maximal sun angle above inclined surface in degrees
delta_sun_angle - delta of the sun angle from maximal sun angle above inclined surface in degrees



KNOWN ISSUES
The inclined_sunset_time can return NaN (no value) if (-C_33/C_31) 
returns value out of <-1;1>, e.g. arccos(-1.2) does not exist, 
This problem needs a closer look, but other variables are safe and reliable.


USAGE
r.sunangle
r.sunangle help
r.sunangle [-s] input_file=string [elev=name] [slope=name] [aspect=name] [output_file=name] [--help] [--verbose] [--quiet]

Flags:

-s
    Use terrain parameters from input file instead of raster maps
--help
    Print usage summary
--verbose
    Verbose module output
--quiet
    Quiet module output

Parameters:

input_file=string [required]
    Input txt file with points coordinates and time data
elev=name
    Name of elevation raster map
slope=name
    Name of slope raster map
aspect=name
    Name of aspect raster map
output_file=string
    Output txt file with results

INSTALLATION

Script requires working installation of GRASS GIS 7.0 (http://grass.osgeo.org)

Linux/Unix
Put the file bin/linux/r.sunangle into directory $USER/.grass7/addons/scripts
Put the file bin/linux/r.sunangle.html into directory $USER/.grass7/addons/docs/html
Put the file bin/linux/r.sunangle.1 into directory $USER/.grass7/addons/docs/man/man1

Windows
Put the file bin/windows/r.sunangle.bat into c:\Users\user_name\AppData\Roaming\GRASS7\addons\bin
Put the file bin/windows/r.sunangle.html into c:\Users\user_name\AppData\Roaming\GRASS7\addons\docs\html
Put the file bin/windows/r.sunangle.1 into c:\Users\user_name\AppData\Roaming\GRASS7\addons\bin\man\man1
Put the file bin/windows/r.sunangle.py into c:\Users\user_name\AppData\Roaming\GRASS7\addons\scripts

Compilation from sources
1. compile Grass GIS 7.0 from sources
2. unpack sources into grass_source_directory/scripts
3. cd grass_source_directory/scripts/r.sunangle
4. run make & make install


AUTHOR of GRASS GIS version:
Ivan Barka (ivan.barka (at) gmail.com, National Forest Centre Zvolen, Slovakia) in cooperation with Dusan Senko (Institute of Botany, Slovak Academy of Sciences).

Script citation:
Barka, I. Gallay, M., Senko, D. r.sunangle Python script in the GRASS GIS environment for calculation of solar radiation parameters. In: Merea P. et al. 2016: Ecological niche differentiation between tetra- and octoploids of Jacobaea vulgaris (Asteraceae). Preslia 88: 113-136.