<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>We really need a cookbook way to set up GRASS for Windows so that Python scripts run. </div><div><br></div><div>A couple students and I have struggled with this for the past 9 months. Although we've managed to get Python recognized by WinGRASS by running in a Windows terminal rather than Msys, we still can't run scripts that call GRASS libraries or the parser. </div><div><br class="webkit-block-placeholder"></div><div>Michael</div>
<div><br><div>Begin forwarded message:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><span class="Apple-style-span" style="font-family: monospace; ">Date: Tue, 4 May 2010 22:17:16 -0700 (PDT)<br>From: LeeDaniel <<a href="mailto:Lee.Daniel.1986@gmail.com">Lee.Daniel.1986@gmail.com</a>><br>Subject: [GRASS-user] Problem with running Python script in GRASS<br>To:<span class="Apple-converted-space"> </span><a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><br>Message-ID: <<a href="mailto:1273036636062-5007296.post@n2.nabble.com">1273036636062-5007296.post@n2.nabble.com</a>><br>Content-Type: text/plain; charset=us-ascii<br><br><br>Hello fellow GRASS users!<br><br>I'm sure this is a very simple problem but I'm having a really difficult<br>time with it... After searching for the solution for several days I'm on the<br>end of my whits and am really needing this script to get working. This is<br>the problem:<br><br>I've written a Python script, doing my best to use the Python I know and<br>reverse engineer the python scripts I found in the Internet. As far as I can<br>tell, the script should be fine, although I naturally can't execute it<br>independently. My goal is to run it as a command from inside GRASS so that<br>the user can input the parameters through the GUI. I think GRASS recognizes<br>that the script is there but isn't able to generate the GUI.<br><br>Here's the script:<br><br>__________________________________<br><br>############################################################################<br>#<br># MODULE: r.solar<br># AUTHOR(S): Daniel Lee<br># PURPOSE: Runs r.sun for a year using different inputs for each month<br># COPYRIGHT: (C) 2010 by Daniel Lee<br>#<br># This program is free software under the GNU General Public<br># License (>=v2). Read the file COPYING that comes with GRASS<br># for details.<br>#<br>#############################################################################<br><br>#%Module<br>#% label: Solar modeling tool.<br>#% description: Conducts a solar analysis for a year using empirical inputs<br>for each month.<br>#% keywords: raster<br>#%End<br>#%Option<br>#% key: elevin<br>#% type: string<br>#% gisprompt: old,cell,raster<br>#% description: Name of input elevation map (unit = meters)<br>#% required : yes<br>#% guisection: Required inputs<br>#%End<br>#%Option<br>#% key: aspect<br>#% type: string<br>#% gisprompt: old,cell,raster<br>#% description: Name of input aspect map (decimal degrees)<br>#% required : yes<br>#% guisection: Required inputs<br>#%End<br>#%Option<br>#% key: slopein<br>#% type: string<br>#% gisprompt: old,cell,raster<br>#% description: Name of input slope map (decimal degrees)<br>#% required : yes<br>#% guisection: Required inputs<br>#%End<br>#%Option<br>#% key: linkein<br>#% type: string<br>#% gisprompt: old,cell,raster<br>#% description: Name of input Linke atmospheric turbidity coefficient map<br>#% required : no<br>#% guisection: Optional inputs<br>#%End<br>#%Option<br>#% key: albedo<br>#% type: string<br>#% gisprompt: old,cell,raster<br>#% description: Name of input albedo coefficient map<br>#% required : no<br>#% guisection: Optional inputs<br>#%End<br>#%Option<br>#% key: mapset<br>#% type: string<br>#% description: Name of the mapset containing solar data<br>#% required : yes<br>#% guisection: Required inputs<br>#%End<br>#%Flag<br>#% key: z<br>#% description: Generate map of sunlight insolation time (h)<br>#% guisection: Output options<br>#%End<br>#%Flag<br>#% key: y<br>#% description: Generate map of reflected radiation (Wh/m2)<br>#% guisection: Output options<br>#%End<br><br>import sys<br>import os<br>import string<br>import grass.script as grass<br><br>def main():<br> elevin = options['elevin']<br> aspect = options['aspect']<br> slopein = options['slopein']<br> linkein = options['linkein']<br> albedo = options['albedo']<br> mapset = "@" + options['mapset']<br> reflected = flags['y']<br> duration = flags['z']<br> step = 0.16<br><br> for day in range(365):<br> day += 1<br> # Define month<br> if day == 1:<br> month = "01" + mapset<br> elif day == 32:<br> month = "02" + mapset<br> elif day == 60:<br> month = "03" + mapset<br> elif day == 91:<br> month = "04" + mapset<br> elif day == 121:<br> month = "05" + mapset<br> elif day == 152:<br> month = "06" + mapset<br> elif day == 182:<br> month = "07" + mapset<br> elif day == 213:<br> month = "08" + mapset<br> elif day == 244:<br> month = "09" + mapset<br> elif day == 274:<br> month = "10" + mapset<br> elif day == 305:<br> month = "11" + mapset<br> elif day == 335:<br> month = "12" + mapset<br><br> # Define coefficients!<br> coefbh = 'coefbh' + month<br> coefdh = 'coefdh' + month<br> if not grass.find_file(elevin)['file'] or not<br>grass.find_file(aspect)['file'] or not grass.find_file(slopein)['file'] or<br>not grass.find_file(coefbh)['file'] or not grass.find_file(coefdh)['file']:<br> grass.fatal(_("Raster map <%a> not found.") % input<br><br> # Define outputs!<br> beam_rad = 'beam' + str(day)<br> diff_rad = 'diffuse' + str(day)<br> glob_rad = 'global' + str(day)<br> if duration and reflected:<br> insol_time = 'insol_time' + str(day)<br> refl_rad = 'reflected' + str(day)<br> grass.run_command('r.sun', flags = 's', elevin = elevin, aspin =<br>aspin, slopein = slopein, linkein = linkein, albedo = albedo, coefbh =<br>coefbh, coefdh = coefdh, beam_rad = beam_rad, insol_time = insol_time,<br>diff_rad = diff_rad, refl_rad = refl_rad, glob_rad = glob_rad, day = day,<br>step = step)<br> elif duration and not reflected:<br> insol_time = 'insol_time' + str(day)<br> grass.run_command('r.sun', flags = 's', elevin = elevin, aspin =<br>aspin, slopein = slopein, linkein = linkein, albedo = albedo, coefbh =<br>coefbh, coefdh = coefdh, beam_rad = beam_rad, insol_time = insol_time,<br>diff_rad = diff_rad, glob_rad = glob_rad, day = day, step = step)<br> elif reflected and not duration:<br> refl_rad = 'reflected' + str(day)<br> grass.run_command('r.sun', flags = 's', elevin = elevin, aspin =<br>aspin, slopein = slopein, linkein = linkein, albedo = albedo, coefbh =<br>coefbh, coefdh = coefdh, beam_rad = beam_rad, diff_rad = diff_rad, refl_rad<br>= refl_rad, glob_rad = glob_rad, day = day, step = step)<br> else:<br> grass.run_command('r.sun', flags = 's', elevin = elevin, aspin =<br>aspin, slopein = slopein, linkein = linkein, albedo = albedo, coefbh =<br>coefbh, coefdh = coefdh, beam_rad = beam_rad, diff_rad = diff_rad, glob_rad<br>= glob_rad, day = day, step = step)<br><br>if __name__ == "__main__":<br> options, flags = grass.parser()<br> main()<br><br>__________________________________<br><br>After loading that into the appropriate directory:<br>C:\GRASS-64\scripts<br>and restarting GRASS, I enter the command "r.solar" into the command line.<br><br>The result is the following message:<br><br><<br><br>Traceback (most recent call last):<br> File "C:/GRASS-64/etc/wxpython/wxgui.py", line 473, in<br>OnRunCmd<br><br>self.goutput.RunCmd(cmd, switchPage=False)<br> File "C:\GRASS-64\etc\wxpython\gui_modules\goutput.py",<br>line 354, in RunCmd<br><br>menuform.GUI().ParseCommand(cmdlist, parentframe=self)<br> File "C:\GRASS-64\etc\wxpython\gui_modules\menuform.py",<br>line 1825, in ParseCommand<br><br>xml.sax.parseString(getInterfaceDescription(cmd[0]).decode(e<br>nc).split('\n',1)[1].replace('', '<?xml version="1.0"<br>encoding="utf-8"?>\n', 1).encode("utf-8"),<br> File "C:\GRASS-64\etc\wxpython\gui_modules\menuform.py",<br>line 1764, in getInterfaceDescription<br><br>raise IOError, _("Unable to fetch interface description for<br>command '%s'.") % cmd<br>IOError<br>:<br>Unable to fetch interface description for command 'r.solar'.<br><br>__________________________________<br><br>I've tried this on two different computers, both with Windows 7. My belief<br>as to what the problem could be:<br>- I've put the file in the wrong directory<br>- I've got to somehow compile it before I can run it<br>- It's got to be imported somehow into the GRASS interface first<br>- My syntax is somehow all wrong<br>- I'm missing some component needed to initiate the GUI<br><br>Can somebody help me? I really need this for my thesis and, as always,<br>there's a lot of time pressure. I'd be immensely grateful to anyone who can<br>help me further. Thanks a lot!<br><br>Best regards,<br>Daniel Lee<br>--<br>View this message in context:<span class="Apple-converted-space"> </span><a href="http://osgeo-org.1803224.n2.nabble.com/Problem-with-running-Python-script-in-GRASS-tp5007296p5007296.html">http://osgeo-org.1803224.n2.nabble.com/Problem-with-running-Python-script-in-GRASS-tp5007296p5007296.html</a><br>Sent from the Grass - Users mailing list archive at<span class="Apple-converted-space"> </span><a href="http://Nabble.com/">Nabble.com</a>.<br></span></span></blockquote></div><br></body></html>