Hi there,<br><div class="gmail_extra"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div></div>I'm now trying to use r.sun and r.mapcalc with Python to create my annual solar radiation map.<br clear="all">
<div><div><div><div>I'm using the Python shell inside GRASS.<br>
<br></div><div>For testing purposes I start with 9 days.<br></div><div>The r.sun part seems to be working:<span style="font-family:courier new,monospace"><br>for x in range(1, 10, 1):<br> print "Working on day %d" % (x)<br>
glob_rad = 'global' + str(x)<br> grass.run_command('r.sun', flags = 's', elevin = 'w001001@temp', aspin = 'aspect@temp', slopein = 'slope@temp', glob_rad = glob_rad, day = x)</span><br>
</div><div>I do have a question about parsing the --overwrite flag. How to do that. Adding <span style="font-family:courier new,monospace">flags='s, --overwrite</span>' or <span style="font-family:courier new,monospace">flags='s, -overwrite'</span> gives a compile error.<br>
</div></div></div></div></div></blockquote><div><br>I believe you overwrite by setting:<br>flags="s, o"<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr"><div><div><div><div>
</div><div><br></div><div>Now I try to combine the results of r.sun into 1 raster.<br></div><div>This is working:<br></div><div><span style="font-family:courier new,monospace">for x in range(1, 10, 1): <br> if x == 2:<br>
exp = 'sun = global1@temp + global2@temp'<br> print exp<br> grass.mapcalc(exp, quiet=False, verbose=False, overwrite=True)</span><br><br></div><div>This is also working:<br></div><div><span style="font-family:courier new,monospace">for x in range(1, 10, 1): <br>
if x == 2:<br> exp = 'sun = global1@temp + global2@temp'<br> print exp<br> grass.mapcalc(exp, quiet=False, verbose=False, overwrite=True)<br> elif x > 2: <br> exp = 'sun = sun@temp + global' + str(x) + '@temp'<br>
print exp</span><br></div><div>and produces this output:<br><span style="font-family:courier new,monospace">sun = sun@temp + global3@temp <br>sun = sun@temp + global4@temp <br>sun = sun@temp + global5@temp <br>sun = sun@temp + global6@temp <br>
sun = sun@temp + global7@temp <br>sun = sun@temp + global8@temp <br>sun = sun@temp + global9@temp</span><br></div><div>But when I execute this using <br></div><div><span style="font-family:courier new,monospace">grass.mapcalc(exp, quiet=False, verbose=False, overwrite=True)<br>
</span></div><div><span style="font-family:courier new,monospace"></span></div><div>
Grass crashes completely.<br><br></div><div>Has this something to do with having the output file is the input file as well?<br></div><div>If this is not allowed how can I combine all output files from r.sun into 1 raster?<br>
</div></div></div></div></div></blockquote><div><br>GRASS doesn't care what you're combining, when you use the map calculator it just sees numbers so that shouldn't be a problem.<br>I don't know why the map calculator to overwrite the input map would be a problem either. I'm not familiar with your syntax though. What happens when you just enter the expression on the "normal" command line?<br>
<br>r.mapcalc "sun = sun + global3"<br><br>That should work.<br><br>Best,<br>Daniel<br></div></div><br></div>