<div dir="ltr"><div><div><div>Thanks again Daniel for your help.<br><br></div>When I do the calculation in the GUI instead of in the Python shell I get these results:<br></div>r.mapcalc sun = global1@temp+ global2@temp<br>

(Fri Dec 28 12:26:10 2012) Command finished (1 sec)<br>r.mapcalc sun = sun@temp+ global3@temp<br>ERROR: Unable to close raster map<br><br></div>When I Google on the error message I find this post from 2010 <a href="http://lists.osgeo.org/pipermail/grass-user/2010-October/058463.html">http://lists.osgeo.org/pipermail/grass-user/2010-October/058463.html</a> saying:<br>

<pre>><i> Why am I obtaining this error? and How can I avoid it?
</i>
Because you're using the same map as both input and output, which
won't work. Either use a temporary name for the intermediate map, or
replace the second grass.mapcalc call with r.null.<br></pre><div class="gmail_extra">I'll have a look in using a temp file. This will make my script more complicated ;)<br clear="all"></div><div class="gmail_extra"><div>

<br>
Thanks,<br><br>
Paul<br>
<br>
<div style="font-size:13.3px;font-family:Verdana,Arial,Helvetica,sans-serif"><div style="border:1px solid #e5e5e5;background-color:#f8f8f8;padding:0.8em 0.8em 0.3em 0.8em"><div style="margin:0 0 8px 0"><p style="margin:0">

<span><b><img style="float:left;margin-left:5px;margin-right:5px" src="http://www.bontepaarden.nl/bontepaarden/images/newButton.png" alt="" height="120" width="160">Paul Meems </b><br><span>Release manager, configuration manager</span><br>

<span>and forum moderator of MapWindow GIS.</span><br><a href="http://www.mapwindow.org/" target="_blank"><span>www.mapwindow.org</span></a><br><br><span>Owner of MapWindow.nl - Support for</span><br><span>Dutch speaking users.</span><br>

<a href="http://www.mapwindow.nl/" target="_blank"><span>www.mapwindow.nl</span></a><br></span></p>
<p style="margin:0"><b><br></b></p></div></div><img src="http://p1.wisestamp.com/pixel.png?p=mozilla&v=3.9.12&t=1322134056890&u=482737fd0c4ca423" height="1" width="1"></div>
</div>
<br><br><div class="gmail_quote">2012/12/28 Daniel Lee <span dir="ltr"><<a href="mailto:lee@isi-solutions.org" target="_blank">lee@isi-solutions.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hi there,<br><div class="gmail_extra"><br><div class="gmail_quote"><div class="im"><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><div><br>I believe you overwrite by setting:<br>flags="s, o"<br> </div><div><div class="h5"><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></div><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>
</blockquote></div><br></div></div>