[GRASS-user] Multiple labels and r.series

Dear GRASS Users:

I am creating a raster map that essentially summarizes the intersection of a series of labeled rasters that each have values of either 1 or null (presence/absence data). I am using r.series like this to perform the summation across the rasters that are all named with a prefix of presence_:

r.series input=“g.mlist rast pattern='presence_*' sep=,” output=presence_sum method=sum --o

Can anyone think of a way to achieve this summation of intersections in a way that will also allow for each cell to have a label that concatenates all labels for the respective raster maps that are present at that cell? E.g., let’s say three of the rasters are present at a particular cell, and the labels for those rasters are ‘raster1’, ‘raster4’, and ‘raster7’. I would like the final map to have a label of ‘raster1, raster4, raster7’.

Any and all suggestions are greatly appreciated.

Regards,
John

On Tue, 2008-11-11 at 11:03 -0800, John C. Tull wrote:

Dear GRASS Users:

I am creating a raster map that essentially summarizes the
intersection of a series of labeled rasters that each have values of
either 1 or null (presence/absence data). I am using r.series like
this to perform the summation across the rasters that are all named
with a prefix of presence_:

r.series input="`g.mlist rast pattern='presence_*' sep=,`"
output=presence_sum method=sum --o

Can anyone think of a way to achieve this summation of intersections
in a way that will also allow for each cell to have a label that
concatenates all labels for the respective raster maps that are
present at that cell? E.g., let's say three of the rasters are present
at a particular cell, and the labels for those rasters are 'raster1',
'raster4', and 'raster7'. I would like the final map to have a label
of 'raster1, raster4, raster7'.

Any and all suggestions are greatly appreciated.

Regards,
John

John,

I don't have a solution really. I am also interested in this. My general
idea was to export labels from each raster of interest, create some
table (csv), import back and attach to the "final" raster... if this is
possible.

But it would be nice to know how to do what you ask.

Regards, Nikos

John wrote:

I am creating a raster map that essentially summarizes the
intersection of a series of labeled rasters that each have
values of either 1 or null (presence/absence data). I am
using r.series like this to perform the summation across the
rasters that are all named with a prefix of presence_:

r.series input="`g.mlist rast
pattern='presence_*' sep=,`"
output=presence_sum method=sum --o

Can anyone think of a way to achieve this summation of
intersections in a way that will also allow for each cell to
have a label that concatenates all labels for the respective
raster maps that are present at that cell? E.g., let's
say three of the rasters are present at a particular cell,
and the labels for those rasters are 'raster1',
'raster4', and 'raster7'. I would like the
final map to have a label of 'raster1, raster4,
raster7'.

Any and all suggestions are greatly appreciated.

the trick here is to r.reclass 0/1 absence/presence maps to be 0/2^n
before running the sum. So you then get a sum like 13, which would mean
the 8+2+1 maps were all present, or if the sum was 5 you'd know the 1+4
maps were present for that cell, and not others.

see also r.bitpattern and r.mapcalc bitwise operators. (sorry I don't
know the proper name/wikipedia link for this technique, I'm not a computer
scientist)

Hamish

On Nov 11, 2008, at 6:45 PM, Hamish wrote:

John wrote:

I am creating a raster map that essentially summarizes the
intersection of a series of labeled rasters that each have
values of either 1 or null (presence/absence data). I am
using r.series like this to perform the summation across the
rasters that are all named with a prefix of presence_:

r.series input="`g.mlist rast
pattern='presence_*' sep=,`"
output=presence_sum method=sum --o

Can anyone think of a way to achieve this summation of
intersections in a way that will also allow for each cell to
have a label that concatenates all labels for the respective
raster maps that are present at that cell? E.g., let's
say three of the rasters are present at a particular cell,
and the labels for those rasters are 'raster1',
'raster4', and 'raster7'. I would like the
final map to have a label of 'raster1, raster4,
raster7'.

Any and all suggestions are greatly appreciated.

the trick here is to r.reclass 0/1 absence/presence maps to be 0/2^n
before running the sum. So you then get a sum like 13, which would mean
the 8+2+1 maps were all present, or if the sum was 5 you'd know the 1+4
maps were present for that cell, and not others.

see also r.bitpattern and r.mapcalc bitwise operators. (sorry I don't
know the proper name/wikipedia link for this technique, I'm not a computer
scientist)

Hamish

On Nov 11, 2008, at 6:45 PM, Hamish wrote:

John wrote:

I am creating a raster map that essentially summarizes the
intersection of a series of labeled rasters that each have
values of either 1 or null (presence/absence data). I am
using r.series like this to perform the summation across the
rasters that are all named with a prefix of presence_:

r.series input="`g.mlist rast
pattern='presence_*' sep=,`"
output=presence_sum method=sum --o

Can anyone think of a way to achieve this summation of
intersections in a way that will also allow for each cell to
have a label that concatenates all labels for the respective
raster maps that are present at that cell? E.g., let's
say three of the rasters are present at a particular cell,
and the labels for those rasters are 'raster1',
'raster4', and 'raster7'. I would like the
final map to have a label of 'raster1, raster4,
raster7'.

Any and all suggestions are greatly appreciated.

the trick here is to r.reclass 0/1 absence/presence maps to be 0/2^n
before running the sum. So you then get a sum like 13, which would mean
the 8+2+1 maps were all present, or if the sum was 5 you'd know the 1+4
maps were present for that cell, and not others.

see also r.bitpattern and r.mapcalc bitwise operators. (sorry I don't
know the proper name/wikipedia link for this technique, I'm not a computer
scientist)

I follow your logic here. I am still hopeful that someone will have some sort of script or r.mapcalc magic to generate concatenated labels.

As I'm not a computer scientist either, I fear I would spend more time trying to decipher the bitwise values and meanings than would be practical. That is a good suggestion, nonetheless. I should have added that I am using about 96 raster layers.

(Apologies for the mis-post before.)

Thanks,
John

On Tue, 2008-11-11 at 19:34 -0800, John C. Tull wrote:

On Nov 11, 2008, at 6:45 PM, Hamish wrote:

> John wrote:
>> I am creating a raster map that essentially summarizes the
>> intersection of a series of labeled rasters that each have
>> values of either 1 or null (presence/absence data). I am
>> using r.series like this to perform the summation across the
>> rasters that are all named with a prefix of presence_:
>>
>> r.series input="`g.mlist rast
>> pattern='presence_*' sep=,`"
>> output=presence_sum method=sum --o
>>
>> Can anyone think of a way to achieve this summation of
>> intersections in a way that will also allow for each cell to
>> have a label that concatenates all labels for the respective
>> raster maps that are present at that cell? E.g., let's
>> say three of the rasters are present at a particular cell,
>> and the labels for those rasters are 'raster1',
>> 'raster4', and 'raster7'. I would like the
>> final map to have a label of 'raster1, raster4,
>> raster7'.
>>
>> Any and all suggestions are greatly appreciated.
>
>
> the trick here is to r.reclass 0/1 absence/presence maps to be 0/2^n
> before running the sum. So you then get a sum like 13, which would
> mean
> the 8+2+1 maps were all present, or if the sum was 5 you'd know the
> 1+4
> maps were present for that cell, and not others.
>
>
> see also r.bitpattern and r.mapcalc bitwise operators. (sorry I don't
> know the proper name/wikipedia link for this technique, I'm not a
> computer
> scientist)
>
>
> Hamish

That was my general idea... (well, more or less). But I did not think of
r.bitmap as a possibility. Maybe there is away to do reverse-r.bitmap
and "code"(=assign to) pixels with various values which will correspond
to different categories-combinations(of maps).

This is how the MODIS Quality Layers work more or less, right?

Regards, Nikos

John C. Tull wrote:

>> I am creating a raster map that essentially summarizes the
>> intersection of a series of labeled rasters that each have
>> values of either 1 or null (presence/absence data). I am
>> using r.series like this to perform the summation across the
>> rasters that are all named with a prefix of presence_:
>>
>> r.series input="`g.mlist rast
>> pattern='presence_*' sep=,`"
>> output=presence_sum method=sum --o
>>
>> Can anyone think of a way to achieve this summation of
>> intersections in a way that will also allow for each cell to
>> have a label that concatenates all labels for the respective
>> raster maps that are present at that cell? E.g., let's
>> say three of the rasters are present at a particular cell,
>> and the labels for those rasters are 'raster1',
>> 'raster4', and 'raster7'. I would like the
>> final map to have a label of 'raster1, raster4,
>> raster7'.
>>
>> Any and all suggestions are greatly appreciated.
>
>
> the trick here is to r.reclass 0/1 absence/presence maps to be 0/2^n
> before running the sum. So you then get a sum like 13, which would
> mean
> the 8+2+1 maps were all present, or if the sum was 5 you'd know the
> 1+4
> maps were present for that cell, and not others.
>
>
> see also r.bitpattern and r.mapcalc bitwise operators. (sorry I don't
> know the proper name/wikipedia link for this technique, I'm not a
> computer
> scientist)

I follow your logic here. I am still hopeful that someone will have
some sort of script or r.mapcalc magic to generate concatenated labels.

As I'm not a computer scientist either, I fear I would spend more time
trying to decipher the bitwise values and meanings than would be
practical. That is a good suggestion, nonetheless. I should have added
that I am using about 96 raster layers.

The main problem here is that labels are associated with categories,
not with individual cells.

r.cross will take a set of input maps, and generate a unique category
(and concatenated label) for each unique combination of categories.
Howver, it won't handle 96 maps (it is currently limited to 10 maps in
6.3.0, increased to 30 maps in 6.4 and 7.0).

My first suggestion is to try using r.cross on batches of 10 maps at a
time, then use r.cross again on the 10 intermediate results. This may
fail if the total number of combinations is large, or if any cell has
too many labels (there may be a limit on the length of a label), and
will probably be quite slow (possibly unacceptably so).

Ultimately, it may not even be possible to generate such a map, given
the 32-bit limit for category numbers. You could theoretically have up
to to 2^96 distinct categories, although in practice you would be
limited by the size of the map. But you could end up with each cell
having a distinct combination of labels.

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

On Nov 11, 2008, at 9:04 PM, Glynn Clements wrote:

John C. Tull wrote:

I am creating a raster map that essentially summarizes the
intersection of a series of labeled rasters that each have
values of either 1 or null (presence/absence data). I am
using r.series like this to perform the summation across the
rasters that are all named with a prefix of presence_:

r.series input="`g.mlist rast
pattern='presence_*' sep=,`"
output=presence_sum method=sum --o

Can anyone think of a way to achieve this summation of
intersections in a way that will also allow for each cell to
have a label that concatenates all labels for the respective
raster maps that are present at that cell? E.g., let's
say three of the rasters are present at a particular cell,
and the labels for those rasters are 'raster1',
'raster4', and 'raster7'. I would like the
final map to have a label of 'raster1, raster4,
raster7'.

Any and all suggestions are greatly appreciated.

the trick here is to r.reclass 0/1 absence/presence maps to be 0/2^n
before running the sum. So you then get a sum like 13, which would
mean
the 8+2+1 maps were all present, or if the sum was 5 you'd know the
1+4
maps were present for that cell, and not others.

see also r.bitpattern and r.mapcalc bitwise operators. (sorry I don't
know the proper name/wikipedia link for this technique, I'm not a
computer
scientist)

I follow your logic here. I am still hopeful that someone will have
some sort of script or r.mapcalc magic to generate concatenated labels.

As I'm not a computer scientist either, I fear I would spend more time
trying to decipher the bitwise values and meanings than would be
practical. That is a good suggestion, nonetheless. I should have added
that I am using about 96 raster layers.

The main problem here is that labels are associated with categories,
not with individual cells.

r.cross will take a set of input maps, and generate a unique category
(and concatenated label) for each unique combination of categories.
Howver, it won't handle 96 maps (it is currently limited to 10 maps in
6.3.0, increased to 30 maps in 6.4 and 7.0).

My first suggestion is to try using r.cross on batches of 10 maps at a
time, then use r.cross again on the 10 intermediate results. This may
fail if the total number of combinations is large, or if any cell has
too many labels (there may be a limit on the length of a label), and
will probably be quite slow (possibly unacceptably so).

Ultimately, it may not even be possible to generate such a map, given
the 32-bit limit for category numbers. You could theoretically have up
to to 2^96 distinct categories, although in practice you would be
limited by the size of the map. But you could end up with each cell
having a distinct combination of labels.

I will explore this option. I'm using 6.4 svn, so I can push the envelope a bit.

Thanks,
John

> Ultimately, it may not even be possible to generate such a map, given
> the 32-bit limit for category numbers. You could theoretically have up
> to to 2^96 distinct categories, although in practice you would be
> limited by the size of the map. But you could end up with each cell
> having a distinct combination of labels.

I will explore this option. I'm using 6.4 svn, so I can
push the envelope a bit.

Hi,

idea: do you really need a static output map? would on-demand calls to
r.what suffice? It can take >96 input maps.

(but mind possible 4096 char bash shell command limit [<43 chars/map name
on average])

   echo "x|y|`g.mlist rast sep='|'`"
   echo "$x $y" | r.what in=`g.mlist rast`

create "$x $y" from r.out.xyz if you want a table covering every cell.

Hamish

me:

idea: do you really need a static output map? would on-demand calls
to r.what suffice? It can take >96 input maps.

...

   echo "x|y|`g.mlist rast sep='|'`"
   echo "$x $y" | r.what in=`g.mlist rast`

oops, that should read:

    echo "$x $y" | r.what in=`g.mlist rast sep=,` null=""

Hamish

I'm traveling, so I cannot test right now. I did need a static map. Using a table would work. I might be able to make a vector with r.to.vector and join those outputs for queries.

Sorry for top reply. Mobile device and I realized too late.

John

On Nov 12, 2008, at 22:42, Hamish <hamish_b@yahoo.com> wrote:

Ultimately, it may not even be possible to generate such a map, given
the 32-bit limit for category numbers. You could theoretically have up
to to 2^96 distinct categories, although in practice you would be
limited by the size of the map. But you could end up with each cell
having a distinct combination of labels.

I will explore this option. I'm using 6.4 svn, so I can
push the envelope a bit.

Hi,

idea: do you really need a static output map? would on-demand calls to
r.what suffice? It can take >96 input maps.

(but mind possible 4096 char bash shell command limit [<43 chars/map name
on average])

  echo "x|y|`g.mlist rast sep='|'`"
  echo "$x $y" | r.what in=`g.mlist rast`

create "$x $y" from r.out.xyz if you want a table covering every cell.

Hamish