[GRASS-user] r.rescale - float instead of integer?

Hello,

I try to rescale a rastermap with category values ranging from 1 to 16.
I want to rescale them by dividing the values by the maximum value, like
1 --> 1/16, 10-->10/16 and 16 --> 1). I tried to do that with the r.rescale tool with setting the output range to 0,1 like:

r.rescale input=input output=output to=0.0,1.0

but it I don't get float values as a results, only 0 and 1 as integers. Does r.rescale handle floats and how do I have to rescale it? Or is there any other simple way to divide the single raster values by the maximum value and get a float value as result?

thank you

/johannes
--
GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit
gratis Handy-Flat! http://portal.gmx.net/de/go/dsl

On Tue, 22 Mar 2011, Johannes Radinger wrote:

but it I don't get float values as a results, only 0 and 1 as integers.
Does r.rescale handle floats and how do I have to rescale it? Or is there
any other simple way to divide the single raster values by the maximum
value and get a float value as result?

johannes,

   Have you considered r.mapcalc?

Rich

Johannes Radinger wrote:

I try to rescale a rastermap with category values ranging from 1 to 16.
I want to rescale them by dividing the values by the maximum value, like
1 --> 1/16, 10-->10/16 and 16 --> 1). I tried to do that with the r.rescale tool with setting the output range to 0,1 like:

r.rescale input=input output=output to=0.0,1.0

but it I don't get float values as a results, only 0 and 1 as
integers. Does r.rescale handle floats

No. r.rescale is a front-end to r.reclass, which only handles
integers.

r.recode provides similar functionality to r.reclass for
floating-point data (but it creates an entirely new map; reclass maps
only support integer data).

Or is there any other simple way to divide the single raster values
by the maximum value and get a float value as result?

  r.mapcalc "output = input / 16.0"

--
Glynn Clements <glynn@gclements.plus.com>

Am 23.03.2011 um 05:29 schrieb Glynn Clements:

Johannes Radinger wrote:

I try to rescale a rastermap with category values ranging from 1 to 16.

I want to rescale them by dividing the values by the maximum value, like

1 → 1/16, 10–>10/16 and 16 → 1). I tried to do that with the r.rescale tool with setting the output range to 0,1 like:

r.rescale input=input output=output to=0.0,1.0

but it I don’t get float values as a results, only 0 and 1 as

integers. Does r.rescale handle floats

No. r.rescale is a front-end to r.reclass, which only handles

integers.

r.recode provides similar functionality to r.reclass for

floating-point data (but it creates an entirely new map; reclass maps

only support integer data).

I looked at it but with r.code, I’ve to provide the input data range values as
fixed values (at least one) rather then saying use all values from min to max
as it is possible in rescale…

Or is there any other simple way to divide the single raster values

by the maximum value and get a float value as result?

r.mapcalc “output = input / 16.0”

I think r.mapcalc is probably the best solution, but as I don’t know the maximum
value in every case (I’ve to process several maps), I wanted to automatize.
Probably I’ve to write a script to read the max value and parse it to the mapcalc function.
My problem: First, I don’t know how to do that, Second there is this python-script issue
on my mac (see other thread)…

Glynn Clements <glynn@gclements.plus.com>


grass-user mailing list

grass-user@lists.osgeo.org

http://lists.osgeo.org/mailman/listinfo/grass-user

Johannes Radinger wrote:

I think r.mapcalc is probably the best solution, but as I don't know the maximum
value in every case (I've to process several maps), I wanted to automatize.
Probably I've to write a script to read the max value and parse it to the mapcalc function.
My problem: First, I don't know how to do that, Second there is this python-script issue
on my mac (see other thread)...

"r.info -r ..." will output the minimum and maximum values.

For a shell script, you can use e.g.:

  eval `r.info -r $inmap`
  r.mapcalc "$outmap = float($inmap) / $max"

For a Python script, you can use grass.script.raster_info(), e.g.:

  import grass.script as grass

  max = grass.raster_info(inmap)['max']
  grass.mapcalc("$outmap = $inmap / $max",
                inmap = inmap, outmap = outmap, max = max)

--
Glynn Clements <glynn@gclements.plus.com>

On Thu, Mar 24, 2011 at 6:07 PM, Glynn Clements
<glynn@gclements.plus.com> wrote:

Johannes Radinger wrote:

I think r.mapcalc is probably the best solution, but as I don't know the maximum
value in every case (I've to process several maps), I wanted to automatize.
Probably I've to write a script to read the max value and parse it to the mapcalc function.
My problem: First, I don't know how to do that, Second there is this python-script issue
on my mac (see other thread)...

"r.info -r ..." will output the minimum and maximum values.

For a shell script, you can use e.g.:

   eval \`r\.info \-r $inmap\`
   r\.mapcalc &quot;$outmap = float\($inmap\) / $max&quot;

Added here:
http://grass.osgeo.org/wiki/GRASS_and_Shell#Using_output_from_GRASS_modules_in_the_script

For a Python script, you can use grass.script.raster_info(), e.g.:

   import grass\.script as grass

   max = grass\.raster\_info\(inmap\)\[&#39;max&#39;\]
   grass\.mapcalc\(&quot;$outmap = $inmap / $max&quot;,
                 inmap = inmap, outmap = outmap, max = max\)

Added here:
http://grass.osgeo.org/wiki/GRASS_and_Python#Using_output_from_GRASS_modules_in_the_script

Markus