I want to project the shadows from a DSM raster.
Is it possible to iterate the grass function r.sunmask.datetime over a list from a csv file composed with interest dates(month/day) and time (hours from 9:00 to 18:00) along the year?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityYes, of course.
Actually the power of GRASS really shines when you need to perform repetitive tasks in a loop. The specific answer depends on how your CSV is formatted, what operating system you're working on, and what command shell you prefer. For example: If I had a CSV that looks like:
day,month,year,hour,min
01,01,2019,10,30
02,01,2019,11,30
03,01,2019,13,30
and if I wanted to write a loop using the Linux bash shell:
while IFS=, read dy mo yr hr mn;
do output=`sunmask_$yr_$mn_$dy_$hr_$mn`;
r.sunmask elevation=<your DSM> year=$yr month=$mn day=$dy hour=$hr minute=$mn output=$output;
done
The above can be re-written also for a windows cmd shell, and could be easily ported to python. Pay attention to the timezone parameter. (Refer to the man page for details...)
I solved it by another way with earthpy library. You'll need a dataframe with daily and hourly azimut and altitude. Here's the script:
def hillshade (index):
altitude = df.altitude[index]
azimut = df.azimut[index]
return ep.plot_bands(
es.hillshade(elevation, azimuth = azimut, altitude = altitude),
)
plt.show()
for i in df.index:
hillshade(i)
That will print a raster for every date and time you have in your data frame.