[GRASS-user] r.rescale categories definition

Dear GRASS Users and Developers,

I'm having some problem in understanding the categories resulting from
r.rescale

With:

r.rescale in=elevation.dem from=1200,1500 to=1,2 out=elev.resc

I have this result:

1 1200 thru 1349

2 1350 thru 1500

Two categories with a range of 150 meters each.

But with a new three categories subdivision:

r.rescale in=elevation.dem from=1200,1500 to=1,3 out=elev.resc

the result is:

1 1200 thru 1274

2 1275 thru 1424

3 1425 thru 1500

The first and last categories have a range of 75 meters and the second one
of 150 meters.

Similar result with a four categories subdivision:

r.rescale in=elevation.dem from=1200,1500 to=1,4 out=elev.resc

1 1200 thru 1250

2 1251 thru 1350

3 1351 thru 1450

4 1451 thru 1500

Categories 1 and 4 have a range of 50 meters, 2 and 3 a range of 100 meters.

It seems that the first and last categories have the half range of all the
others ones. Is this correct? Shouldn't the range be the same for all
categories?

(same results with GRASS6.4, GRASS6.3 and GRASS6.2).

Many thanks in advance

A. Clerici

Parma University

Italy

On Saturday 12 December 2009 11:03:35 Aldo Clerici wrote:

Dear GRASS Users and Developers,

I'm having some problem in understanding the categories resulting from
r.rescale

With:

r.rescale in=elevation.dem from=1200,1500 to=1,2 out=elev.resc

I have this result:

1 1200 thru 1349

2 1350 thru 1500

Two categories with a range of 150 meters each.

But with a new three categories subdivision:

r.rescale in=elevation.dem from=1200,1500 to=1,3 out=elev.resc

the result is:

1 1200 thru 1274

2 1275 thru 1424

3 1425 thru 1500

The first and last categories have a range of 75 meters and the second one
of 150 meters.

Similar result with a four categories subdivision:

r.rescale in=elevation.dem from=1200,1500 to=1,4 out=elev.resc

1 1200 thru 1250

2 1251 thru 1350

3 1351 thru 1450

4 1451 thru 1500

Categories 1 and 4 have a range of 50 meters, 2 and 3 a range of 100
meters.

It seems that the first and last categories have the half range of all the
others ones. Is this correct? Shouldn't the range be the same for all
categories?

(same results with GRASS6.4, GRASS6.3 and GRASS6.2).

Many thanks in advance

A. Clerici

Parma University

Italy

Hi, I have not used r.rescale (perhaps it uses some form of ratio on the
amount of points in given categories it assigns, hence the middle categories
being larger ranges). I think r.reclass would be a better option so you can
classify exactly what the categories would be.

John

John,
tanks for your quick answer.
A correct reclassification can be easily obtained with r.reclass or
r.mapcalc, but I would like to know if the behaviour of r.rescale is correct
and in this case what's the way it uses to define categories (just to
explain it to students working with GRASS).

Thanks again.

A. Clerici

-----Messaggio originale-----
Da: grass-user-bounces@lists.osgeo.org
[mailto:grass-user-bounces@lists.osgeo.org] Per conto di John Tate
Inviato: sabato 12 dicembre 2009 12.20
A: grass-user@lists.osgeo.org
Oggetto: Re: [GRASS-user] r.rescale categories definition

On Saturday 12 December 2009 11:03:35 Aldo Clerici wrote:

Dear GRASS Users and Developers,

I'm having some problem in understanding the categories resulting from
r.rescale

With:

r.rescale in=elevation.dem from=1200,1500 to=1,2 out=elev.resc

I have this result:

1 1200 thru 1349

2 1350 thru 1500

Two categories with a range of 150 meters each.

But with a new three categories subdivision:

r.rescale in=elevation.dem from=1200,1500 to=1,3 out=elev.resc

the result is:

1 1200 thru 1274

2 1275 thru 1424

3 1425 thru 1500

The first and last categories have a range of 75 meters and the second one
of 150 meters.

Similar result with a four categories subdivision:

r.rescale in=elevation.dem from=1200,1500 to=1,4 out=elev.resc

1 1200 thru 1250

2 1251 thru 1350

3 1351 thru 1450

4 1451 thru 1500

Categories 1 and 4 have a range of 50 meters, 2 and 3 a range of 100
meters.

It seems that the first and last categories have the half range of all the
others ones. Is this correct? Shouldn't the range be the same for all
categories?

(same results with GRASS6.4, GRASS6.3 and GRASS6.2).

Many thanks in advance

A. Clerici

Parma University

Italy

Hi, I have not used r.rescale (perhaps it uses some form of ratio on the
amount of points in given categories it assigns, hence the middle categories

being larger ranges). I think r.reclass would be a better option so you can
classify exactly what the categories would be.

John
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Aldo Clerici wrote:

Dear GRASS Users and Developers,
I'm having some problem in understanding the categories resulting from
r.rescale

With:
r.rescale in=elevation.dem from=1200,1500 to=1,2 out=elev.resc

I have this result:
1 1200 thru 1349
2 1350 thru 1500

Two categories with a range of 150 meters each.

But with a new three categories subdivision:
r.rescale in=elevation.dem from=1200,1500 to=1,3 out=elev.resc
the result is:
1 1200 thru 1274
2 1275 thru 1424
3 1425 thru 1500

The first and last categories have a range of 75 meters and the second one
of 150 meters.

Similar result with a four categories subdivision:
r.rescale in=elevation.dem from=1200,1500 to=1,4 out=elev.resc

1 1200 thru 1250
2 1251 thru 1350
3 1351 thru 1450
4 1451 thru 1500
  
Categories 1 and 4 have a range of 50 meters, 2 and 3 a range of 100 meters.

It seems that the first and last categories have the half range of all the
others ones. Is this correct? Shouldn't the range be the same for all
categories?

This is a result of r.rescale rounding rather than truncating, so the
minimum and maximum input values are the midpoints of the first and
last intervals:

    old_delta = old_max - old_min;
    new_delta = new_max - new_min;
    divisor = (float)new_delta / (float)old_delta;
  ...
    for (cat = old_min; cat <= old_max; cat++) {
  value = (int)(divisor * (cat - old_min) + new_min + .5);

You can get balanced intervals with:

#!/bin/sh
inmap=$1
outmap=$2
to_min=$3
to_max=$4
eval `r.info -r $inmap`
awk -vold_min=$min -vold_max=$max -vnew_min=$to_min -vnew_max=$to_max '
BEGIN {
  new_delta = new_max - new_min + 1
  old_delta = old_max - old_min + 1
  for (i = 0; i < new_delta; i++) {
    lo = old_min + i * old_delta / new_delta
    hi = old_min + (i+1) * old_delta / new_delta - 1
    new = new_min + i
    printf("%d thru %d = %d %d\n", lo, hi, new, lo)
  }
}' | r.reclass in=$inmap out=$outmap

E.g.:

  ./rescale.sh elevation.dem elev.resc 1 4

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

Glynn,
tanks for your detailed explanations. As an ordinary user I was a bit
confused in looking the command results and trying to find an explanation in
the manual pages.
For my purposes I would prefer an equal classes subdivision but probably
there is some effective reason for such kind of classes definition. I'm not
able to evaluate it.
If the current computation is necessary (or not modifiable) couldn't be
useful to warn the user about the specific (and probably unexpected) way the
categories are computed (may be in the manual)?

Best regards
A.Clerici

-----Messaggio originale-----
Da: Glynn Clements [mailto:glynn@gclements.plus.com]
Inviato: sabato 12 dicembre 2009 17.59
A: Aldo Clerici
Cc: grass-user@lists.osgeo.org
Oggetto: Re: [GRASS-user] r.rescale categories definition

Aldo Clerici wrote:

Dear GRASS Users and Developers,
I'm having some problem in understanding the categories resulting from
r.rescale

With:
r.rescale in=elevation.dem from=1200,1500 to=1,2 out=elev.resc

I have this result:
1 1200 thru 1349
2 1350 thru 1500

Two categories with a range of 150 meters each.

But with a new three categories subdivision:
r.rescale in=elevation.dem from=1200,1500 to=1,3 out=elev.resc
the result is:
1 1200 thru 1274
2 1275 thru 1424
3 1425 thru 1500

The first and last categories have a range of 75 meters and the second one
of 150 meters.

Similar result with a four categories subdivision:
r.rescale in=elevation.dem from=1200,1500 to=1,4 out=elev.resc

1 1200 thru 1250
2 1251 thru 1350
3 1351 thru 1450
4 1451 thru 1500
  
Categories 1 and 4 have a range of 50 meters, 2 and 3 a range of 100

meters.

It seems that the first and last categories have the half range of all the
others ones. Is this correct? Shouldn't the range be the same for all
categories?

This is a result of r.rescale rounding rather than truncating, so the
minimum and maximum input values are the midpoints of the first and
last intervals:

    old_delta = old_max - old_min;
    new_delta = new_max - new_min;
    divisor = (float)new_delta / (float)old_delta;
  ...
    for (cat = old_min; cat <= old_max; cat++) {
  value = (int)(divisor * (cat - old_min) + new_min + .5);

You can get balanced intervals with:

#!/bin/sh
inmap=$1
outmap=$2
to_min=$3
to_max=$4
eval `r.info -r $inmap`
awk -vold_min=$min -vold_max=$max -vnew_min=$to_min -vnew_max=$to_max '
BEGIN {
  new_delta = new_max - new_min + 1
  old_delta = old_max - old_min + 1
  for (i = 0; i < new_delta; i++) {
    lo = old_min + i * old_delta / new_delta
    hi = old_min + (i+1) * old_delta / new_delta - 1
    new = new_min + i
    printf("%d thru %d = %d %d\n", lo, hi, new, lo)
  }
}' | r.reclass in=$inmap out=$outmap

E.g.:

  ./rescale.sh elevation.dem elev.resc 1 4

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

Glynn,
tanks for your detailed explanations. As an ordinary user I was a bit
confused in looking the command results and trying to find an explanation in
the manual pages.
For my purposes I would prefer an equal classes subdivision but probably
there is some effective reason for such kind of classes definition. I'm not
able to evaluate it.
If the current computation is necessary (or not modifiable) couldn't be
useful to warn the user about the specific (and probably unexpected) way the
categories are computed (may be in the manual)?

Best regards
A.Clerici

-----Messaggio originale-----
Da: Glynn Clements [mailto:glynn@gclements.plus.com]
Inviato: sabato 12 dicembre 2009 17.59
A: Aldo Clerici
Cc: grass-user@lists.osgeo.org
Oggetto: Re: [GRASS-user] r.rescale categories definition

Aldo Clerici wrote:

Dear GRASS Users and Developers,
I'm having some problem in understanding the categories resulting from
r.rescale

With:
r.rescale in=elevation.dem from=1200,1500 to=1,2 out=elev.resc

I have this result:
1 1200 thru 1349
2 1350 thru 1500

Two categories with a range of 150 meters each.

But with a new three categories subdivision:
r.rescale in=elevation.dem from=1200,1500 to=1,3 out=elev.resc
the result is:
1 1200 thru 1274
2 1275 thru 1424
3 1425 thru 1500

The first and last categories have a range of 75 meters and the second one
of 150 meters.

Similar result with a four categories subdivision:
r.rescale in=elevation.dem from=1200,1500 to=1,4 out=elev.resc

1 1200 thru 1250
2 1251 thru 1350
3 1351 thru 1450
4 1451 thru 1500
  
Categories 1 and 4 have a range of 50 meters, 2 and 3 a range of 100

meters.

It seems that the first and last categories have the half range of all the
others ones. Is this correct? Shouldn't the range be the same for all
categories?

This is a result of r.rescale rounding rather than truncating, so the
minimum and maximum input values are the midpoints of the first and
last intervals:

    old_delta = old_max - old_min;
    new_delta = new_max - new_min;
    divisor = (float)new_delta / (float)old_delta;
  ...
    for (cat = old_min; cat <= old_max; cat++) {
  value = (int)(divisor * (cat - old_min) + new_min + .5);

You can get balanced intervals with:

#!/bin/sh
inmap=$1
outmap=$2
to_min=$3
to_max=$4
eval `r.info -r $inmap`
awk -vold_min=$min -vold_max=$max -vnew_min=$to_min -vnew_max=$to_max '
BEGIN {
  new_delta = new_max - new_min + 1
  old_delta = old_max - old_min + 1
  for (i = 0; i < new_delta; i++) {
    lo = old_min + i * old_delta / new_delta
    hi = old_min + (i+1) * old_delta / new_delta - 1
    new = new_min + i
    printf("%d thru %d = %d %d\n", lo, hi, new, lo)
  }
}' | r.reclass in=$inmap out=$outmap

E.g.:

  ./rescale.sh elevation.dem elev.resc 1 4

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

Glynn Clements wrote:

You can get balanced intervals with:

#!/bin/sh
inmap=$1
outmap=$2
to_min=$3
to_max=$4
eval `r.info -r $inmap`
awk -vold_min=$min -vold_max=$max -vnew_min=$to_min -vnew_max=$to_max '
BEGIN {
  new_delta = new_max - new_min + 1
  old_delta = old_max - old_min + 1
  for (i = 0; i < new_delta; i++) {
    lo = old_min + i * old_delta / new_delta
    hi = old_min + (i+1) * old_delta / new_delta - 1
    new = new_min + i
    printf("%d thru %d = %d %d\n", lo, hi, new, lo)
  }
}' | r.reclass in=$inmap out=$outmap

E.g.:

  ./rescale.sh elevation.dem elev.resc 1 4

Hello Glynn Clements,

thanks for the nice shell-script you posted. It was very helpful.
But perhaps you can give me an answer to the following issue.
Is it possible to apply the script just to a small range of the attribute
values? I thought about an option like there is in modul r.rescale
("from=").

Cheers
Christoph
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/r-rescale-categories-definition-tp4155847p5959222.html
Sent from the Grass - Users mailing list archive at Nabble.com.

-C.R- wrote:

Is it possible to apply the script just to a small range of the attribute
values? I thought about an option like there is in modul r.rescale
("from=").

I think I solved the problem on my own changing Glynns script like this:

#!/bin/sh
inmap=$1
outmap=$2
to_min=$3
to_max=$4
min=$5
max=$6
awk -vold_min=$min -vold_max=$max -vnew_min=$to_min -vnew_max=$to_max '
BEGIN {
  new_delta = new_max - new_min + 1
  old_delta = old_max - old_min + 1
  for (i = 0; i < new_delta; i++) {
    lo = old_min + i * old_delta / new_delta
    hi = old_min + (i+1) * old_delta / new_delta - 1
    new = new_min + i
    printf("%d thru %d = %d %d\n", lo, hi, new, lo)
  }
}' | r.reclass in=$inmap out=$outmap

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/r-rescale-categories-definition-tp4155847p5959296.html
Sent from the Grass - Users mailing list archive at Nabble.com.