[GRASS-user] Question regarding grass.mapcalc
Greetings I'm doing a Python script to calibrate a raster image. Since I need to do 3 different calculations I'm using a tempfile (tempL) This is the code: tempL = grass.read_command(g.tempfile, pid = 1) grass.mapcalc($L=$lmin+ (($lmax-$lmin)/($QCALmax-$QCALmin))* ($raster_file-$QCALmin), L=tempL, lmin=lmin, lmax=lmax, QCALmax=QCALmax, QCALmin=QCALmin, raster_file=raster_file) Where tempL is a temporary, (lmin,lmax) are floats, QCALmax and QCALmin are int and raster_file is a raster map used as input. And I get this: syntax error, unexpected '/', expecting NAME or STRING Parse error ERROR: An error occurred while running r.mapcalc What is happening? I believe it has something to do with tempL. Maybe I'm not doing this right. Can anyone help me on this? Thanks Kim ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Question regarding grass.mapcalc
Kim Besson wrote: I'm doing a Python script to calibrate a raster image. Since I need to do 3 different calculations I'm using a tempfile (tempL) This is the code: tempL = grass.read_command(g.tempfile, pid = 1) grass.mapcalc($L=$lmin+ (($lmax-$lmin)/($QCALmax-$QCALmin))* ($raster_file-$QCALmin), L=tempL, lmin=lmin, lmax=lmax, QCALmax=QCALmax, QCALmin=QCALmin, raster_file=raster_file) Where tempL is a temporary, (lmin,lmax) are floats, QCALmax and QCALmin are int and raster_file is a raster map used as input. And I get this: syntax error, unexpected '/', expecting NAME or STRING Parse error ERROR: An error occurred while running r.mapcalc What is happening? I believe it has something to do with tempL. Maybe I'm not doing this right. Can anyone help me on this? g.tempfile returns the full pathname to a temporary file, not a map name. There isn't a module to generate temporary map names. A common approach is to use the name of the script followed by .tmp. -- Glynn Clements gl...@gclements.plus.com ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Question regarding grass.mapcalc
Kim Besson wrote: So your suggestion would be rass.mapcalc($L=$lmin+ (($lmax-$lmin)/($QCALmax-$QCALmin)) ($raster_file-$QCALmin), L=tempL, lmin=lmin, lmax=lmax, QCALmax=QCALmax, QCALmin=QCALmin, raster_file=raster_file) and at the end delete L file? My suggestion would be to replace: tempL = grass.read_command(g.tempfile, pid = 1) with: tempL = myscript.tmp Any temporary maps should be deleted upon termination. Use atexit.register() to register a function which deletes any temporary maps (if they exist). This will ensure that the maps get deleted regardless of whether the script terminates normally or due to an exception. Look at the scripts in 7.0 for examples. -- Glynn Clements gl...@gclements.plus.com ___ grass-user mailing list grass-user@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-user