Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Added sunset calculation to daily_solar. Addresses #90
Browse files Browse the repository at this point in the history
  • Loading branch information
qjhart committed Sep 30, 2019
1 parent 66c23b2 commit 7a517f6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 7 additions & 1 deletion g.cimis/g.cimis/etc/daily_solar.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ifndef DD
$(error MAPSET ${MAPSET} is not YYYYMMDD)
endif

rasters:=$(shell g.list type=rast pattern=????PST-B2)
rasters:=$(shell g.list type=rast pattern=????PST-B2 | sort)

info::
@echo daily_solar.mk
Expand All @@ -33,3 +33,9 @@ info::
# This is for redoing a complete day, not calculating data instantly.
$(eval $(call mapset_targets,${MAPSET}))
$(foreach f,${rasters},$(info B2:$f@${MAPSET}) $(eval $(call next_solar_calc,$f,${MAPSET})))

# Sometimes we have no rasters that are in the evening. In that case, we need to add in the sunset
# calculation. This is when the last raster is still in daylight.
last_daynight:=$(shell g.solar_time cmd=daynight rast=$(lastword ${rasters}))
ssetr_phony:=$(shell g.solar_time cmd=ssetr)PST-B2
$(if $(filter day,${last_daynight}),$(eval $(call next_solar_calc,${ssetr_phony},${MAPSET})))
19 changes: 18 additions & 1 deletion g.cimis/g.solar_time/g.solar_time
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,23 @@ function prev() {
echo $prev
}

function next() {
local t1=$(fn2t $1)
local ti
local next
local suffix=${1#????}

for i in $(g.list type=rast pattern="????${suffix}" | sort -r); do
ti=${i%${suffix}}
if [[ $ti > $t1 ]]; then
next=$i
else
break
fi
done
echo $next
}

function risedayset() {
local dn
local pdn
Expand Down Expand Up @@ -179,7 +196,7 @@ case $CMD in
day_parms | sretr_parms | ssetr_parms ) # Grass helpers
$CMD;
;;
daynight | prev | risedayset ) # Identifiers
daynight | prev | next | risedayset ) # Identifiers
if [[ -z ${GIS_OPT_RAST} ]]; then
g.message "$CMD requires raster"
exit 1;
Expand Down

0 comments on commit 7a517f6

Please sign in to comment.