2

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?

3

Yes, 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...)

3
  • Hi Micha, I'm working in windows environment. Is the script you wrote suitable to it? – Rodrigo Vargas Feb 6 '20 at 7:13
  • Hint: if r.sunmask is too slow in computing shadows, consider r.sun (grass.osgeo.org/grass78/manuals/…) – markusN Feb 6 '20 at 21:05
  • Indeed it's very slow but I solved it by another way with earthpy library. – Rodrigo Vargas Feb 7 '20 at 7:30
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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