Re: [GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script
Anna Petrášová wrote: How? If we change the interface, I would like to be able to also pass env to write_command. Do you mean passing arbitrary environment variables through grass.script.mapcalc() down to the underlying r.mapcalc command? Which environment variables would be useful? For example when you want to parallelize multiple r.mapcalc calls with different region settings. You would copy the environment, change the region (e.g. set WIND_OVERRIDE) or even mapset or location and pass it to r.mapcalc without interfering with the current environment. I can do that now with run_command('r.mapcalc', ..., env=myEnv), it would be just more convenient to have it in the grass.script.mapcalc(). In fact, the same applies to other wrappers in grass.script, for example raster_what. Currently when querying raster in the gui, the GRASS_REGION is changed to match the raster before the query and restored afterwards. In my opinion, it would be just much more elegant (and would require less code) and less error prone, not to change the environment globally but just for the r.what module. Okay, done in r61428. -- Glynn Clements gl...@gclements.plus.com ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev
Re: [GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script
On Mon, Jul 28, 2014 at 11:59 AM, Glynn Clements gl...@gclements.plus.com wrote: Anna Petrášová wrote: How? If we change the interface, I would like to be able to also pass env to write_command. Do you mean passing arbitrary environment variables through grass.script.mapcalc() down to the underlying r.mapcalc command? Which environment variables would be useful? For example when you want to parallelize multiple r.mapcalc calls with different region settings. You would copy the environment, change the region (e.g. set WIND_OVERRIDE) or even mapset or location and pass it to r.mapcalc without interfering with the current environment. I can do that now with run_command('r.mapcalc', ..., env=myEnv), it would be just more convenient to have it in the grass.script.mapcalc(). In fact, the same applies to other wrappers in grass.script, for example raster_what. Currently when querying raster in the gui, the GRASS_REGION is changed to match the raster before the query and restored afterwards. In my opinion, it would be just much more elegant (and would require less code) and less error prone, not to change the environment globally but just for the r.what module. Okay, done in r61428. Thanks! Anna -- Glynn Clements gl...@gclements.plus.com ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev
Re: [GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script
On 26-07-14 07:58, Paulo van Breugel wrote: On 24-07-14 16:21, Glynn Clements wrote: Paulo van Breugel wrote: How do I use this new flag / seed parameter for r.mapcalc in python scripts? The grass.script.mapcalc() function has been updated to accept a seed= parameter, which should be either an integer or the string 'auto' for a random seed. Hi, after updating to the latest version, I tried: grass.script.mapcalc($tmp_map = rand(${minval},${maxval}), seed='auto', minval = minval, maxval = maxval, tmp_map = tmp_map) grass.script.mapcalc($tmp_map = rand(${minval},${maxval}), seed=1, minval = minval, maxval = maxval, tmp_map = tmp_map) In both cases I get the error. ERROR: Pseudo-random number generator not seeded Any idea what am I doing wrong here? Sorry, please ignore my message. I did a completely clean install of grass and now it works. Must have been some problem with old install or I was just too early with updating last time. In short, thanks Glynn for implementing the random seed options, great work! ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev
Re: [GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script
I am not familiar with how changes in the different version are handled, but will these changes to r.mapcalc and grass.script.mapcalc (now in grass 7.1) be implemented in grass 7.0? On 24-07-14 16:21, Glynn Clements wrote: Paulo van Breugel wrote: How do I use this new flag / seed parameter for r.mapcalc in python scripts? The grass.script.mapcalc() function has been updated to accept a seed= parameter, which should be either an integer or the string 'auto' for a random seed. ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev
Re: [GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script
On Sat, Jul 26, 2014 at 10:56 AM, Paulo van Breugel p.vanbreu...@gmail.com wrote: I am not familiar with how changes in the different version are handled, but will these changes to r.mapcalc and grass.script.mapcalc (now in grass 7.1) be implemented in grass 7.0? In my view this should be done once we have the remaining modules updated to use the new RNG. Thanks to Glynn for having implemented it! Markus ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev
Re: [GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script
Anna Petrášová wrote: How do I use this new flag / seed parameter for r.mapcalc in python scripts? I'll update the Python interface. How? If we change the interface, I would like to be able to also pass env to write_command. Do you mean passing arbitrary environment variables through grass.script.mapcalc() down to the underlying r.mapcalc command? Which environment variables would be useful? -- Glynn Clements gl...@gclements.plus.com ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev
Re: [GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script
Anna Petrášová wrote: How do I use this new flag / seed parameter for r.mapcalc in python scripts? The grass.script.mapcalc() function has been updated to accept a seed= parameter, which should be either an integer or the string 'auto' for a random seed. Just curious, why don't you use the s flag and instead create the seed in Python? It was simpler. Also, the Python version probably has better entropy. -- Glynn Clements gl...@gclements.plus.com ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev
Re: [GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script
On Sat, Jul 26, 2014 at 6:15 PM, Glynn Clements gl...@gclements.plus.com wrote: Anna Petrášová wrote: How do I use this new flag / seed parameter for r.mapcalc in python scripts? I'll update the Python interface. How? If we change the interface, I would like to be able to also pass env to write_command. Do you mean passing arbitrary environment variables through grass.script.mapcalc() down to the underlying r.mapcalc command? Which environment variables would be useful? For example when you want to parallelize multiple r.mapcalc calls with different region settings. You would copy the environment, change the region (e.g. set WIND_OVERRIDE) or even mapset or location and pass it to r.mapcalc without interfering with the current environment. I can do that now with run_command('r.mapcalc', ..., env=myEnv), it would be just more convenient to have it in the grass.script.mapcalc(). In fact, the same applies to other wrappers in grass.script, for example raster_what. Currently when querying raster in the gui, the GRASS_REGION is changed to match the raster before the query and restored afterwards. In my opinion, it would be just much more elegant (and would require less code) and less error prone, not to change the environment globally but just for the r.what module. Anna -- Glynn Clements gl...@gclements.plus.com ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev
Re: [GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script
On 24-07-14 16:21, Glynn Clements wrote: Paulo van Breugel wrote: How do I use this new flag / seed parameter for r.mapcalc in python scripts? The grass.script.mapcalc() function has been updated to accept a seed= parameter, which should be either an integer or the string 'auto' for a random seed. Hi, after updating to the latest version, I tried: grass.script.mapcalc($tmp_map = rand(${minval},${maxval}), seed='auto', minval = minval, maxval = maxval, tmp_map = tmp_map) grass.script.mapcalc($tmp_map = rand(${minval},${maxval}), seed=1, minval = minval, maxval = maxval, tmp_map = tmp_map) In both cases I get the error. ERROR: Pseudo-random number generator not seeded Any idea what am I doing wrong here? ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev
[GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script
How do I use this new flag / seed parameter for r.mapcalc in python scripts? I have for example a script where I can define the seed, or if left empty I want to set the 's' flag: if seed == : grass.mapcalc($tmp_map = rand(${minval},${maxval}), minval = minval, maxval = maxval, tmp_map = tmp_map) else: grass.mapcalc($tmp_map = rand(${minval},${maxval}), minval = minval, maxval = maxval, tmp_map = tmp_map) Where I need to set the flag='s' in the first instance or the seed= in the second instance On 23-07-14 02:14, Glynn Clements wrote: Glynn Clements wrote: I'm inclined to add both an option (to specify a seed, replacing the environment variable) and a flag (to seed from the system clock or whatever), and having the PRNG generate a fatal error if neither of those are used. This is now done. r61350 adds the lrand48/mrand48/drand48 equivalents to lib/gis. Brief testing suggests that the results are identical to those generated by GNU libc (which should be identical to any other POSIX implementation). r61352 changes it to generate a fatal error if used prior to seeding. r61353 changes r.mapcalc so that seeding is performed via seed= or -s. The seed (whether specified by seed= or generated for -s) is added to the history (for r.mapcalc; r3.mapcalc's create_history() function is a stub; do 3D rasters have history?) Note that GRASS_RND_SEED is no longer supported. That was a hack from the time before r.mapcalc used G_parser(). As I write this, it has occurred to me that the behaviour of rand() may be non-deterministic in the presence of certain forms of parallelism, e.g. multiple occurences of rand() in the expression(s) in conjunction with pthreads. Ultimately we may need to expand the PRNG to support explicit state (as per erand48, nrand48 and jrand48). ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev
Re: [GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script
Paulo van Breugel wrote: How do I use this new flag / seed parameter for r.mapcalc in python scripts? I'll update the Python interface. -- Glynn Clements gl...@gclements.plus.com ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev
Re: [GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script
On Thu, Jul 24, 2014 at 10:00 AM, Glynn Clements gl...@gclements.plus.com wrote: Paulo van Breugel wrote: How do I use this new flag / seed parameter for r.mapcalc in python scripts? I'll update the Python interface. How? If we change the interface, I would like to be able to also pass env to write_command. -- Glynn Clements gl...@gclements.plus.com ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev
Re: [GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script
Paulo van Breugel wrote: How do I use this new flag / seed parameter for r.mapcalc in python scripts? The grass.script.mapcalc() function has been updated to accept a seed= parameter, which should be either an integer or the string 'auto' for a random seed. -- Glynn Clements gl...@gclements.plus.com ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev
Re: [GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script
On Thu, Jul 24, 2014 at 10:21 AM, Glynn Clements gl...@gclements.plus.com wrote: Paulo van Breugel wrote: How do I use this new flag / seed parameter for r.mapcalc in python scripts? The grass.script.mapcalc() function has been updated to accept a seed= parameter, which should be either an integer or the string 'auto' for a random seed. Just curious, why don't you use the s flag and instead create the seed in Python? Anna -- Glynn Clements gl...@gclements.plus.com ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev ___ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev