[GRASS-user] r.shade python issues
Hi – I’m having issues with r.shade module in grass 7.0.3 when trying to interact with data via python. r.shade runs absolutely fine through the UI, however, when I run the syntax through the python console, I get a syntax error. I have tried a variety of different datasets and syntax but it keeps coming back with the syntax error, I went back to manual for the basics but I still get the following: *r.shade shade=aspect color=elevation output=elevation_aspect_shaded* * File "", line 1* *r.shade(shade=aspect color=elevation output=elevation_aspect_shaded)* * ^* *SyntaxError: invalid syntax* Other modules (r.in.gdal, r.relief, r.slope.aspect, g.region etc) all run fine through python, I am only having issues with r.shade. Does anybody have any idea what might be going wrong? Cheers, Gareth ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] r.shade python issues
Hei, Maybe the issue is missing commas? r.shade(shade=aspect, color=elevation, output=elevation_aspect_shaded) Cheers Stefan From: grass-user [mailto:grass-user-boun...@lists.osgeo.org] On Behalf Of Gareth Grewcock Sent: 23. mai 2016 11:49 To: grass-user@lists.osgeo.org Subject: [GRASS-user] r.shade python issues Hi – I’m having issues with r.shade module in grass 7.0.3 when trying to interact with data via python. r.shade runs absolutely fine through the UI, however, when I run the syntax through the python console, I get a syntax error. I have tried a variety of different datasets and syntax but it keeps coming back with the syntax error, I went back to manual for the basics but I still get the following: r.shade shade=aspect color=elevation output=elevation_aspect_shaded File "", line 1 r.shade(shade=aspect color=elevation output=elevation_aspect_shaded) ^ SyntaxError: invalid syntax Other modules (r.in.gdal, r.relief, r.slope.aspect, g.region etc) all run fine through python, I am only having issues with r.shade. Does anybody have any idea what might be going wrong? Cheers, Gareth ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] r.shade python issues
Hi Stefan - thanks for getting back to me. I had tried that before but still got issues, this time returning: 'NameError: name 'r' is not defined' *r.shade(shade=aspect, color=elevation, output=elevation_aspect_shaded)* *Traceback (most recent call last):* * File "", line 1, in * *NameError: name 'r' is not defined* Any ideas what might be causing that? Cheers, Gareth On Mon, May 23, 2016 at 12:47 PM, Blumentrath, Stefan < stefan.blumentr...@nina.no> wrote: > Hei, > > > > Maybe the issue is missing commas? > > > > r.shade(shade=aspect, color=elevation, output=elevation_aspect_shaded) > > > > Cheers > > Stefan > > > > *From:* grass-user [mailto:grass-user-boun...@lists.osgeo.org] *On Behalf > Of *Gareth Grewcock > *Sent:* 23. mai 2016 11:49 > *To:* grass-user@lists.osgeo.org > *Subject:* [GRASS-user] r.shade python issues > > > > Hi – I’m having issues with r.shade module in grass 7.0.3 when trying to > interact with data via python. > > > > r.shade runs absolutely fine through the UI, however, when I run the > syntax through the python console, I get a syntax error. > > > > I have tried a variety of different datasets and syntax but it keeps > coming back with the syntax error, I went back to manual for the basics but > I still get the following: > > > > *r.shade shade=aspect color=elevation output=elevation_aspect_shaded* > > * File "", line 1* > > *r.shade(shade=aspect color=elevation output=elevation_aspect_shaded)* > > * ^* > > *SyntaxError: invalid syntax* > > > > Other modules (r.in.gdal, r.relief, r.slope.aspect, g.region etc) all run > fine through python, I am only having issues with r.shade. > > > > Does anybody have any idea what might be going wrong? > > > > Cheers, > > Gareth > > > ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] r.shade python issues
Hello, I answered off-list by mistake. Normally, when "non-zero return code1" occurs, you can see the error generated by the module on the terminal. Alternatively, you can try the solution given in the wiki to retrieve the error: def read2_command(*args, **kwargs): kwargs['stdout'] = grass.PIPE kwargs['stderr'] = grass.PIPE ps = grass.start_command(*args, **kwargs) return ps.communicate() Could you check this out and post the result here? Regards, Laurent 2016-05-23 9:58 GMT-05:00 Gareth Grewcock : > Thanks for getting in touch Laurent. > > I have been working on a data processing script written in python which I > want to use Grass modules in. So I have actually been using > gscript.run_command() already. I was doing this externally and not actually > loading Grass explicitly. I can do this successfully as follows: > > grass.run_command('r.in.gdal',input = ffile, output = name, quiet = 'True', > overwrite = 'True', flags = 'o') > > grass.run_command('r.relief',input = name,output = hillshade_output,altitude > = '20', azimuth = '315', zscale = '6', overwrite = 'True') > > grass.run_command('r.slope.aspect',elevation = name, slope = "dem_slope", > aspect = "dem_aspect", overwrite = 'True') > > However, when I come to use r.shade, I get the 'non-zero return code1', so I > have since gone back into the Grass UI to try and simply run python snippets > but can't get r.shade to work with Python either externally or through the > UI, I really have no idea what the problem is as all of the other modules > work fine. > > Cheers, > > Gareth > > On Mon, May 23, 2016 at 3:38 PM, Laurent C. wrote: >> >> Hello, >> >> Try this: >> >> import grass.script as gscript >> gscript.run_command("r.shade", shade=aspect, color=elevation, >> output=elevation_aspect_shaded) >> >> Have a look at the wiki: >> https://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library >> >> Laurent >> >> 2016-05-23 8:01 GMT-05:00 Gareth Grewcock : >> > Hi Stefan - thanks for getting back to me. >> > >> > I had tried that before but still got issues, this time returning: >> > 'NameError: name 'r' is not defined' >> > >> > r.shade(shade=aspect, color=elevation, output=elevation_aspect_shaded) >> > Traceback (most recent call last): >> > File "", line 1, in >> > NameError: name 'r' is not defined >> > >> > Any ideas what might be causing that? >> > >> > Cheers, >> > Gareth >> > >> > On Mon, May 23, 2016 at 12:47 PM, Blumentrath, Stefan >> > wrote: >> >> >> >> Hei, >> >> >> >> >> >> >> >> Maybe the issue is missing commas? >> >> >> >> >> >> >> >> r.shade(shade=aspect, color=elevation, output=elevation_aspect_shaded) >> >> >> >> >> >> >> >> Cheers >> >> >> >> Stefan >> >> >> >> >> >> >> >> From: grass-user [mailto:grass-user-boun...@lists.osgeo.org] On Behalf >> >> Of >> >> Gareth Grewcock >> >> Sent: 23. mai 2016 11:49 >> >> To: grass-user@lists.osgeo.org >> >> Subject: [GRASS-user] r.shade python issues >> >> >> >> >> >> >> >> Hi – I’m having issues with r.shade module in grass 7.0.3 when trying >> >> to >> >> interact with data via python. >> >> >> >> >> >> >> >> r.shade runs absolutely fine through the UI, however, when I run the >> >> syntax through the python console, I get a syntax error. >> >> >> >> >> >> >> >> I have tried a variety of different datasets and syntax but it keeps >> >> coming back with the syntax error, I went back to manual for the basics >> >> but >> >> I still get the following: >> >> >> >> >> >> >> >> r.shade shade=aspect color=elevation output=elevation_aspect_shaded >> >> >> >> File "", line 1 >> >> >> >> r.shade(shade=aspect color=elevation >> >> output=elevation_aspect_shaded) >> >> >> >> ^ >> >> >> >> SyntaxError: invalid syntax >> >> >> >> >> >> >> >> Other modules (r.in.gdal, r.relief, r.slope.aspect, g.region etc) all >> >> run >> >> fine through python, I am only having issues with r.shade. >> >> >> >> >> >> >> >> Does anybody have any idea what might be going wrong? >> >> >> >> >> >> >> >> Cheers, >> >> >> >> Gareth >> >> >> >> >> > >> > >> > >> > ___ >> > grass-user mailing list >> > grass-user@lists.osgeo.org >> > http://lists.osgeo.org/mailman/listinfo/grass-user > > ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] r.shade python issues
On 23/05/16 15:01, Gareth Grewcock wrote: Hi Stefan - thanks for getting back to me. I had tried that before but still got issues, this time returning: 'NameError: name 'r' is not defined' /r.shade(shade=aspect, color=elevation, output=elevation_aspect_shaded)/ /Traceback (most recent call last):/ / File "", line 1, in / /NameError: name 'r' is not defined/ / / Any ideas what might be causing that? If you are using pygrass, you have to create the r.shade module object before using it. See [1]. If you are not using pygrass, please give us more information about what happens in your script before the call that fails. Moritz [1] https://grass.osgeo.org/grass70/manuals/libpython/pygrass_modules.html ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user