[GRASS-user] r.mask: no MASK created when using many categories

Dear List,

I am using r.mask to create a new raster map that only contains certain categories given in 'maskcats'. Then, I use r.mapcalc to save the map under a new name and (to be on the save side) delete the MASK with r.mask flag '-r'. I do this in a loop and it works fine until a case when the number of categories to combine is 213 (trail and error lead to 106 as the maximum number that works fine). Flag 'verbose' gives the message that a MASK was created, but none is there. The problem arises in both cases when I directly use Grass or through R using execGrass.

Is there a limit in the number of categories that can be passed to r.mask? I did not find any hint about that. Additionally, I wonder why there is no error message but in the contrary one that tells me that a MASK was created even when it failed.

In case the details are important (or if anybody has a better idea how to achieve what I want): I have a raster map of subcatchemts belonging to stream segments created with r.stream.basins. For the endpoints of segments, I want to combine these subcatchments to a total catchment raster map containing all upstream catchments.

Thanks a lot,

Mira

--
Dr. Mira Kattwinkel
Quantitative Landscape Ecology
Institute for Environmental Sciences
University of Koblenz-Landau
Fortstraße 7
76829 Landau
Germany
Phone: + 49 6341 280-31553
Office: Building I, Room 2.02

If you have the endpoint of of the outlet segment, you might use that as the “coordinates” parameter to r.stream.basins to create a single large drainage basin. Then use that as the mask to get out the subcatchments.

···

On 04/05/2017 03:22 PM, Mira Kattwinkel wrote:

Dear List,

I am using r.mask to create a new raster map that only contains certain categories given in ‘maskcats’. Then, I use r.mapcalc to save the map under a new name and (to be on the save side) delete the MASK with r.mask flag ‘-r’. I do this in a loop and it works fine until a case when the number of categories to combine is 213 (trail and error lead to 106 as the maximum number that works fine). Flag ‘verbose’ gives the message that a MASK was created, but none is there. The problem arises in both cases when I directly use Grass or through R using execGrass.

Is there a limit in the number of categories that can be passed to r.mask? I did not find any hint about that. Additionally, I wonder why there is no error message but in the contrary one that tells me that a MASK was created even when it failed.

In case the details are important (or if anybody has a better idea how to achieve what I want): I have a raster map of subcatchemts belonging to stream segments created with r.stream.basins. For the endpoints of segments, I want to combine these subcatchments to a total catchment raster map containing all upstream catchments.

Thanks a lot,

Mira

-- 
Micha Silver
cell: +972-523-665918

Dear Micha

thanks for your suggestion.

Actually, that's is what I usually do. However, I am not really interested in the catchment of the endpoints of the edges but in sampling points lying at the streams. If a point lies within the dem cell of the outlet, which can be a confluence of two streams, the coordinate approach will result in the catchment of both confluences, although the point lies just at one of them. That's why I came up with the idea of summing up the subcatchments of only the relevant branch of the stream network.

Maybe there are other thoughts on that?

Mira

On 05/04/17 15:25, Micha Silver wrote:

On 04/05/2017 03:22 PM, Mira Kattwinkel wrote:

Dear List,

I am using r.mask to create a new raster map that only contains certain categories given in 'maskcats'. Then, I use r.mapcalc to save the map under a new name and (to be on the save side) delete the MASK with r.mask flag '-r'. I do this in a loop and it works fine until a case when the number of categories to combine is 213 (trail and error lead to 106 as the maximum number that works fine). Flag 'verbose' gives the message that a MASK was created, but none is there. The problem arises in both cases when I directly use Grass or through R using execGrass.

Is there a limit in the number of categories that can be passed to r.mask? I did not find any hint about that. Additionally, I wonder why there is no error message but in the contrary one that tells me that a MASK was created even when it failed.

In case the details are important (or if anybody has a better idea how to achieve what I want): I have a raster map of subcatchemts belonging to stream segments created with r.stream.basins. For the endpoints of segments, I want to combine these subcatchments to a total catchment raster map containing all upstream catchments.

If you have the endpoint of of the outlet segment, you might use that as the "coordinates" parameter to r.stream.basins to create a single large drainage basin. Then use that as the mask to get out the subcatchments.

Thanks a lot,

Mira

--
Micha Silver
cell: +972-523-665918

--
Dr. Mira Kattwinkel
Quantitative Landscape Ecology
Institute for Environmental Sciences
University of Koblenz-Landau
Fortstraße 7
76829 Landau
Germany
Phone: + 49 6341 280-31553
Office: Building I, Room 2.02

On Wed, Apr 5, 2017 at 8:22 AM, Mira Kattwinkel
<kattwinkel-mira@uni-landau.de> wrote:

Dear List,

I am using r.mask to create a new raster map that only contains certain
categories given in 'maskcats'. Then, I use r.mapcalc to save the map under
a new name and (to be on the save side) delete the MASK with r.mask flag
'-r'. I do this in a loop and it works fine until a case when the number of
categories to combine is 213 (trail and error lead to 106 as the maximum
number that works fine). Flag 'verbose' gives the message that a MASK was
created, but none is there. The problem arises in both cases when I directly
use Grass or through R using execGrass.

I tried it on landsat raster from NC sample dataset and it worked.
Perhaps you could try to replicate it with this sample dataset?

Anna

Is there a limit in the number of categories that can be passed to r.mask? I
did not find any hint about that. Additionally, I wonder why there is no
error message but in the contrary one that tells me that a MASK was created
even when it failed.

In case the details are important (or if anybody has a better idea how to
achieve what I want): I have a raster map of subcatchemts belonging to
stream segments created with r.stream.basins. For the endpoints of segments,
I want to combine these subcatchments to a total catchment raster map
containing all upstream catchments.

Thanks a lot,

Mira

--
Dr. Mira Kattwinkel
Quantitative Landscape Ecology
Institute for Environmental Sciences
University of Koblenz-Landau
Fortstraße 7
76829 Landau
Germany
Phone: + 49 6341 280-31553
Office: Building I, Room 2.02

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

Dear Anna, dear list

I used the NC basic sample data set to replicate my case. Unfortunately, I get the same problem. Can anybody give me a hint? Thanks a lot!

Here is what I did and the output:

r.watershed elevation=elevation@PERMANENT threshold=500 basin=basins_new
SECTION 1a (of 5): Initiating Memory.
SECTION 1b (of 5): Determining Offmap Flow.
SECTION 2: A* Search.
SECTION 3a: Accumulating Surface Flow with MFD.
SECTION 3b: Adjusting drainage directions.
SECTION 4: Watershed determination.
SECTION 5: Closing Maps.

## creating mask with 106 categories works fine
r.mask raster=basins_new@PERMANENT maskcats=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
All subsequent raster operations will be limited to the MASK area. Removing or renaming raster map named 'MASK' will restore raster operations to normal.

r.mapcalc expression=r106 = MASK

r.mask -r
Raster MASK removed

## creating mask with 107 categories seems to work without error but there is no MASK output
r.mask raster=basins_new@PERMANENT maskcats=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
All subsequent raster operations will be limited to the MASK area. Removing or renaming raster map named 'MASK' will restore raster operations to normal.

r.mapcalc expression=m107 = MASK
Invalid map <MASK>
Parse error
ERROR: parse error

g.list type=raster
basins
basins_new
elevation
elevation_shade
geology
lakes
landuse
r106
soils

On 06/04/17 05:06, Anna Petrášová wrote:

On Wed, Apr 5, 2017 at 8:22 AM, Mira Kattwinkel
<kattwinkel-mira@uni-landau.de> wrote:

Dear List,

I am using r.mask to create a new raster map that only contains certain
categories given in 'maskcats'. Then, I use r.mapcalc to save the map under
a new name and (to be on the save side) delete the MASK with r.mask flag
'-r'. I do this in a loop and it works fine until a case when the number of
categories to combine is 213 (trail and error lead to 106 as the maximum
number that works fine). Flag 'verbose' gives the message that a MASK was
created, but none is there. The problem arises in both cases when I directly
use Grass or through R using execGrass.

I tried it on landsat raster from NC sample dataset and it worked.
Perhaps you could try to replicate it with this sample dataset?

Anna

Is there a limit in the number of categories that can be passed to r.mask? I
did not find any hint about that. Additionally, I wonder why there is no
error message but in the contrary one that tells me that a MASK was created
even when it failed.

In case the details are important (or if anybody has a better idea how to
achieve what I want): I have a raster map of subcatchemts belonging to
stream segments created with r.stream.basins. For the endpoints of segments,
I want to combine these subcatchments to a total catchment raster map
containing all upstream catchments.

Thanks a lot,

Mira

--
Dr. Mira Kattwinkel
Quantitative Landscape Ecology
Institute for Environmental Sciences
University of Koblenz-Landau
Fortstraße 7
76829 Landau
Germany
Phone: + 49 6341 280-31553
Office: Building I, Room 2.02

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

--
Dr. Mira Kattwinkel
Quantitative Landscape Ecology
Institute for Environmental Sciences
University of Koblenz-Landau
Fortstraße 7
76829 Landau
Germany
Phone: + 49 6341 280-31553
Office: Building I, Room 2.02

Interesting…
I can duplicate the problem (but only up to 100 cats). Above that I get an error of “stack smashing”:

GRASS 7.2.0 (ITM):~ > r.mask raster=farm_bas maskcats="seq -s " " 1 100" --o
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.
[Raster MASK present]

GRASS 7.2.0 (ITM):~ > r.info -g MASK
north=530000
south=510000
east=185000
west=170000
nsres=4
ewres=4
rows=5000
cols=3750
cells=18750000
datatype=CELL
ncats=0
[Raster MASK present]

But with 103 cats…
GRASS 7.2.0 (ITM):~ > r.mask raster=farm_bas maskcats="seq -s " " 1 103" --o
WARNING: MASK already exists and will be overwritten
*** stack smashing detected ***: r.reclass terminated
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.
GRASS 7.2.0 (ITM):~ > r.info -g MASK
ERROR: Raster map <MASK> not found

···

On 04/06/2017 12:12 PM, Mira Kattwinkel wrote:

Dear Anna, dear list

I used the NC basic sample data set to replicate my case. Unfortunately, I get the same problem. Can anybody give me a hint? Thanks a lot!

Here is what I did and the output:

r.watershed elevation=elevation@PERMANENT threshold=500 basin=basins_new
SECTION 1a (of 5): Initiating Memory.
SECTION 1b (of 5): Determining Offmap Flow.
SECTION 2: A* Search.
SECTION 3a: Accumulating Surface Flow with MFD.
SECTION 3b: Adjusting drainage directions.
SECTION 4: Watershed determination.
SECTION 5: Closing Maps.

creating mask with 106 categories works fine

r.mask raster=basins_new@PERMANENT maskcats=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
All subsequent raster operations will be limited to the MASK area. Removing or renaming raster map named ‘MASK’ will restore raster operations to normal.

r.mapcalc expression=r106 = MASK

r.mask -r
Raster MASK removed

creating mask with 107 categories seems to work without error but there is no MASK output

r.mask raster=basins_new@PERMANENT maskcats=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
All subsequent raster operations will be limited to the MASK area. Removing or renaming raster map named ‘MASK’ will restore raster operations to normal.

r.mapcalc expression=m107 = MASK
Invalid map
Parse error
ERROR: parse error

g.list type=raster
basins
basins_new
elevation
elevation_shade
geology
lakes
landuse
r106
soils

On 06/04/17 05:06, Anna Petrášová wrote:

On Wed, Apr 5, 2017 at 8:22 AM, Mira Kattwinkel
kattwinkel-mira@uni-landau.de wrote:

Dear List,

I am using r.mask to create a new raster map that only contains certain
categories given in ‘maskcats’. Then, I use r.mapcalc to save the map under
a new name and (to be on the save side) delete the MASK with r.mask flag
‘-r’. I do this in a loop and it works fine until a case when the number of
categories to combine is 213 (trail and error lead to 106 as the maximum
number that works fine). Flag ‘verbose’ gives the message that a MASK was
created, but none is there. The problem arises in both cases when I directly
use Grass or through R using execGrass.

I tried it on landsat raster from NC sample dataset and it worked.
Perhaps you could try to replicate it with this sample dataset?

Anna

Is there a limit in the number of categories that can be passed to r.mask? I
did not find any hint about that. Additionally, I wonder why there is no
error message but in the contrary one that tells me that a MASK was created
even when it failed.

In case the details are important (or if anybody has a better idea how to
achieve what I want): I have a raster map of subcatchemts belonging to
stream segments created with r.stream.basins. For the endpoints of segments,
I want to combine these subcatchments to a total catchment raster map
containing all upstream catchments.

Thanks a lot,

Mira


Dr. Mira Kattwinkel
Quantitative Landscape Ecology
Institute for Environmental Sciences
University of Koblenz-Landau
Fortstraße 7
76829 Landau
Germany
Phone: + 49 6341 280-31553
Office: Building I, Room 2.02


grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

-- 
Micha Silver
cell: +972-523-665918

On Thu, Apr 6, 2017 at 5:47 AM, Micha Silver <tsvibar@gmail.com> wrote:

Interesting...
I can duplicate the problem (but only up to 100 cats). Above that I get an
error of "stack smashing":

I tried to fix it in r70847 (or at least allow longer sequences, the
arrays are still statically allocated). But in this case you can also
use "1 thru 106".

Anna

GRASS 7.2.0 (ITM):~ > r.mask raster=farm_bas maskcats="`seq -s " " 1 100`"
--o
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.
[Raster MASK present]

GRASS 7.2.0 (ITM):~ > r.info -g MASK
north=530000
south=510000
east=185000
west=170000
nsres=4
ewres=4
rows=5000
cols=3750
cells=18750000
datatype=CELL
ncats=0
[Raster MASK present]

But with 103 cats...
GRASS 7.2.0 (ITM):~ > r.mask raster=farm_bas maskcats="`seq -s " " 1 103`"
--o
WARNING: MASK already exists and will be overwritten
*** stack smashing detected ***: r.reclass terminated
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.
GRASS 7.2.0 (ITM):~ > r.info -g MASK
ERROR: Raster map <MASK> not found

On 04/06/2017 12:12 PM, Mira Kattwinkel wrote:

Dear Anna, dear list

I used the NC basic sample data set to replicate my case. Unfortunately, I
get the same problem. Can anybody give me a hint? Thanks a lot!

Here is what I did and the output:

r.watershed elevation=elevation@PERMANENT threshold=500 basin=basins_new
SECTION 1a (of 5): Initiating Memory.
SECTION 1b (of 5): Determining Offmap Flow.
SECTION 2: A* Search.
SECTION 3a: Accumulating Surface Flow with MFD.
SECTION 3b: Adjusting drainage directions.
SECTION 4: Watershed determination.
SECTION 5: Closing Maps.

## creating mask with 106 categories works fine
r.mask raster=basins_new@PERMANENT maskcats=1 2 3 4 5 6 7 8 9 10 11 12 13 14
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.

r.mapcalc expression=r106 = MASK

r.mask -r
Raster MASK removed

## creating mask with 107 categories seems to work without error but there
is no MASK output
r.mask raster=basins_new@PERMANENT maskcats=1 2 3 4 5 6 7 8 9 10 11 12 13 14
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.

r.mapcalc expression=m107 = MASK
Invalid map <MASK>
Parse error
ERROR: parse error

g.list type=raster
basins
basins_new
elevation
elevation_shade
geology
lakes
landuse
r106
soils

On 06/04/17 05:06, Anna Petrášová wrote:

On Wed, Apr 5, 2017 at 8:22 AM, Mira Kattwinkel
<kattwinkel-mira@uni-landau.de> wrote:

Dear List,

I am using r.mask to create a new raster map that only contains certain
categories given in 'maskcats'. Then, I use r.mapcalc to save the map under
a new name and (to be on the save side) delete the MASK with r.mask flag
'-r'. I do this in a loop and it works fine until a case when the number of
categories to combine is 213 (trail and error lead to 106 as the maximum
number that works fine). Flag 'verbose' gives the message that a MASK was
created, but none is there. The problem arises in both cases when I directly
use Grass or through R using execGrass.

I tried it on landsat raster from NC sample dataset and it worked.
Perhaps you could try to replicate it with this sample dataset?

Anna

Is there a limit in the number of categories that can be passed to r.mask? I
did not find any hint about that. Additionally, I wonder why there is no
error message but in the contrary one that tells me that a MASK was created
even when it failed.

In case the details are important (or if anybody has a better idea how to
achieve what I want): I have a raster map of subcatchemts belonging to
stream segments created with r.stream.basins. For the endpoints of segments,
I want to combine these subcatchments to a total catchment raster map
containing all upstream catchments.

Thanks a lot,

Mira

--
Dr. Mira Kattwinkel
Quantitative Landscape Ecology
Institute for Environmental Sciences
University of Koblenz-Landau
Fortstraße 7
76829 Landau
Germany
Phone: + 49 6341 280-31553
Office: Building I, Room 2.02

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

--
Micha Silver
cell: +972-523-665918

Dear Anna,

great! Thanks a lot. If I understand it correctly, the limit is now 1024.

Btw, how would I update such a single function? Updating Grass does not work (linux' apt-get upgrade does not see a new version)?

Mira

On 07/04/17 03:53, Anna Petrášová wrote:

On Thu, Apr 6, 2017 at 5:47 AM, Micha Silver <tsvibar@gmail.com> wrote:

Interesting...
I can duplicate the problem (but only up to 100 cats). Above that I get an
error of "stack smashing":

I tried to fix it in r70847 (or at least allow longer sequences, the
arrays are still statically allocated). But in this case you can also
use "1 thru 106".

Anna

GRASS 7.2.0 (ITM):~ > r.mask raster=farm_bas maskcats="`seq -s " " 1 100`"
--o
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.
[Raster MASK present]

GRASS 7.2.0 (ITM):~ > r.info -g MASK
north=530000
south=510000
east=185000
west=170000
nsres=4
ewres=4
rows=5000
cols=3750
cells=18750000
datatype=CELL
ncats=0
[Raster MASK present]

But with 103 cats...
GRASS 7.2.0 (ITM):~ > r.mask raster=farm_bas maskcats="`seq -s " " 1 103`"
--o
WARNING: MASK already exists and will be overwritten
*** stack smashing detected ***: r.reclass terminated
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.
GRASS 7.2.0 (ITM):~ > r.info -g MASK
ERROR: Raster map <MASK> not found

On 04/06/2017 12:12 PM, Mira Kattwinkel wrote:

Dear Anna, dear list

I used the NC basic sample data set to replicate my case. Unfortunately, I
get the same problem. Can anybody give me a hint? Thanks a lot!

Here is what I did and the output:

r.watershed elevation=elevation@PERMANENT threshold=500 basin=basins_new
SECTION 1a (of 5): Initiating Memory.
SECTION 1b (of 5): Determining Offmap Flow.
SECTION 2: A* Search.
SECTION 3a: Accumulating Surface Flow with MFD.
SECTION 3b: Adjusting drainage directions.
SECTION 4: Watershed determination.
SECTION 5: Closing Maps.

## creating mask with 106 categories works fine
r.mask raster=basins_new@PERMANENT maskcats=1 2 3 4 5 6 7 8 9 10 11 12 13 14
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.

r.mapcalc expression=r106 = MASK

r.mask -r
Raster MASK removed

## creating mask with 107 categories seems to work without error but there
is no MASK output
r.mask raster=basins_new@PERMANENT maskcats=1 2 3 4 5 6 7 8 9 10 11 12 13 14
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.

r.mapcalc expression=m107 = MASK
Invalid map <MASK>
Parse error
ERROR: parse error

g.list type=raster
basins
basins_new
elevation
elevation_shade
geology
lakes
landuse
r106
soils

On 06/04/17 05:06, Anna Petrášová wrote:

On Wed, Apr 5, 2017 at 8:22 AM, Mira Kattwinkel
<kattwinkel-mira@uni-landau.de> wrote:

Dear List,

I am using r.mask to create a new raster map that only contains certain
categories given in 'maskcats'. Then, I use r.mapcalc to save the map under
a new name and (to be on the save side) delete the MASK with r.mask flag
'-r'. I do this in a loop and it works fine until a case when the number of
categories to combine is 213 (trail and error lead to 106 as the maximum
number that works fine). Flag 'verbose' gives the message that a MASK was
created, but none is there. The problem arises in both cases when I directly
use Grass or through R using execGrass.

I tried it on landsat raster from NC sample dataset and it worked.
Perhaps you could try to replicate it with this sample dataset?

Anna

Is there a limit in the number of categories that can be passed to r.mask? I
did not find any hint about that. Additionally, I wonder why there is no
error message but in the contrary one that tells me that a MASK was created
even when it failed.

In case the details are important (or if anybody has a better idea how to
achieve what I want): I have a raster map of subcatchemts belonging to
stream segments created with r.stream.basins. For the endpoints of segments,
I want to combine these subcatchments to a total catchment raster map
containing all upstream catchments.

Thanks a lot,

Mira

--
Dr. Mira Kattwinkel
Quantitative Landscape Ecology
Institute for Environmental Sciences
University of Koblenz-Landau
Fortstraße 7
76829 Landau
Germany
Phone: + 49 6341 280-31553
Office: Building I, Room 2.02

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

--
Micha Silver
cell: +972-523-665918

--
Dr. Mira Kattwinkel
Quantitative Landscape Ecology
Institute for Environmental Sciences
University of Koblenz-Landau
Fortstraße 7
76829 Landau
Germany
Phone: + 49 6341 280-31553
Office: Building I, Room 2.02

Hi Mira,

I find a more elegant way to create a mask from an arbitrarily long list of raster categories would be to use r.reclass where you can use an input file:

r.reclass input=subcatchments output=MASK rules=mask.dat

and in mask.dat you list your categories:

12=1
23=1
10=1
...
1200=1

Might help, although the problem seems to have been solved.

Michel

···

On 04/05/2017 03:59 PM, Mira Kattwinkel wrote:

Dear Micha

thanks for your suggestion.

Actually, that’s is what I usually do. However, I am not really interested in the catchment of the endpoints of the edges but in sampling points lying at the streams. If a point lies within the dem cell of the outlet, which can be a confluence of two streams, the coordinate approach will result in the catchment of both confluences, although the point lies just at one of them. That’s why I came up with the idea of summing up the subcatchments of only the relevant branch of the stream network.

Maybe there are other thoughts on that?

Mira

On 05/04/17 15:25, Micha Silver wrote:

On 04/05/2017 03:22 PM, Mira Kattwinkel wrote:

Dear List,

I am using r.mask to create a new raster map that only contains certain categories given in ‘maskcats’. Then, I use r.mapcalc to save the map under a new name and (to be on the save side) delete the MASK with r.mask flag ‘-r’. I do this in a loop and it works fine until a case when the number of categories to combine is 213 (trail and error lead to 106 as the maximum number that works fine). Flag ‘verbose’ gives the message that a MASK was created, but none is there. The problem arises in both cases when I directly use Grass or through R using execGrass.

Is there a limit in the number of categories that can be passed to r.mask? I did not find any hint about that. Additionally, I wonder why there is no error message but in the contrary one that tells me that a MASK was created even when it failed.

In case the details are important (or if anybody has a better idea how to achieve what I want): I have a raster map of subcatchemts belonging to stream segments created with r.stream.basins. For the endpoints of segments, I want to combine these subcatchments to a total catchment raster map containing all upstream catchments.

If you have the endpoint of of the outlet segment, you might use that as the “coordinates” parameter to r.stream.basins to create a single large drainage basin. Then use that as the mask to get out the subcatchments.

Thanks a lot,

Mira


Micha Silver
cell: +972-523-665918

On 07/04/17 09:56, Mira Kattwinkel wrote:

Dear Anna,

great! Thanks a lot. If I understand it correctly, the limit is now 1024.

Btw, how would I update such a single function? Updating Grass does not
work (linux' apt-get upgrade does not see a new version)?

You have to compile GRASS yourself [1] or wait for the next release which will then show up in your distribution.

But as Anna mentioned, in your case you might not need this as you could formulate your list of cats more efficiently using 'thru', i.e.:

r.mask raster=basins_new@PERMANENT maskcats="1 thru 107"

instead of listing them all. Or, if the series is not continuous:

r.mask raster=basins_new@PERMANENT maskcats="1 thru 25 53 thru 75"

Moritz

[1] https://grasswiki.osgeo.org/wiki/Compile_and_Install

On 07/04/17 03:53, Anna Petrášová wrote:

On Thu, Apr 6, 2017 at 5:47 AM, Micha Silver <tsvibar@gmail.com> wrote:

Interesting...
I can duplicate the problem (but only up to 100 cats). Above that I get an
error of "stack smashing":

I tried to fix it in r70847 (or at least allow longer sequences, the
arrays are still statically allocated). But in this case you can also
use "1 thru 106".

Anna

GRASS 7.2.0 (ITM):~ > r.mask raster=farm_bas maskcats="`seq -s " " 1 100`"
--o
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.
[Raster MASK present]

GRASS 7.2.0 (ITM):~ > r.info -g MASK
north=530000
south=510000
east=185000
west=170000
nsres=4
ewres=4
rows=5000
cols=3750
cells=18750000
datatype=CELL
ncats=0
[Raster MASK present]

But with 103 cats...
GRASS 7.2.0 (ITM):~ > r.mask raster=farm_bas maskcats="`seq -s " " 1 103`"
--o
WARNING: MASK already exists and will be overwritten
*** stack smashing detected ***: r.reclass terminated
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.
GRASS 7.2.0 (ITM):~ > r.info -g MASK
ERROR: Raster map <MASK> not found

On 04/06/2017 12:12 PM, Mira Kattwinkel wrote:

Dear Anna, dear list

I used the NC basic sample data set to replicate my case. Unfortunately, I
get the same problem. Can anybody give me a hint? Thanks a lot!

Here is what I did and the output:

r.watershed elevation=elevation@PERMANENT threshold=500 basin=basins_new
SECTION 1a (of 5): Initiating Memory.
SECTION 1b (of 5): Determining Offmap Flow.
SECTION 2: A* Search.
SECTION 3a: Accumulating Surface Flow with MFD.
SECTION 3b: Adjusting drainage directions.
SECTION 4: Watershed determination.
SECTION 5: Closing Maps.

## creating mask with 106 categories works fine
r.mask raster=basins_new@PERMANENT maskcats=1 2 3 4 5 6 7 8 9 10 11 12 13 14
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.

r.mapcalc expression=r106 = MASK

r.mask -r
Raster MASK removed

## creating mask with 107 categories seems to work without error but there
is no MASK output
r.mask raster=basins_new@PERMANENT maskcats=1 2 3 4 5 6 7 8 9 10 11 12 13 14
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.

r.mapcalc expression=m107 = MASK
Invalid map <MASK>
Parse error
ERROR: parse error

g.list type=raster
basins
basins_new
elevation
elevation_shade
geology
lakes
landuse
r106
soils

On 06/04/17 05:06, Anna Petrášová wrote:

On Wed, Apr 5, 2017 at 8:22 AM, Mira Kattwinkel
<kattwinkel-mira@uni-landau.de> wrote:

Dear List,

I am using r.mask to create a new raster map that only contains certain
categories given in 'maskcats'. Then, I use r.mapcalc to save the map under
a new name and (to be on the save side) delete the MASK with r.mask flag
'-r'. I do this in a loop and it works fine until a case when the number of
categories to combine is 213 (trail and error lead to 106 as the maximum
number that works fine). Flag 'verbose' gives the message that a MASK was
created, but none is there. The problem arises in both cases when I directly
use Grass or through R using execGrass.

I tried it on landsat raster from NC sample dataset and it worked.
Perhaps you could try to replicate it with this sample dataset?

Anna

Is there a limit in the number of categories that can be passed to r.mask? I
did not find any hint about that. Additionally, I wonder why there is no
error message but in the contrary one that tells me that a MASK was created
even when it failed.

In case the details are important (or if anybody has a better idea how to
achieve what I want): I have a raster map of subcatchemts belonging to
stream segments created with r.stream.basins. For the endpoints of segments,
I want to combine these subcatchments to a total catchment raster map
containing all upstream catchments.

Thanks a lot,

Mira

--
Dr. Mira Kattwinkel
Quantitative Landscape Ecology
Institute for Environmental Sciences
University of Koblenz-Landau
Fortstraße 7
76829 Landau
Germany
Phone: + 49 6341 280-31553
Office: Building I, Room 2.02

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

--
Micha Silver
cell: +972-523-665918

Thanks for that.

So, the limitation is not the number of categories but the string that defines them?

The 1 to 106 was just an example. In reality, I have various numbers with no ordering, up to more than 100 different ones.

Mira

On 07/04/17 10:38, Moritz Lennert wrote:

On 07/04/17 09:56, Mira Kattwinkel wrote:

Dear Anna,

great! Thanks a lot. If I understand it correctly, the limit is now 1024.

Btw, how would I update such a single function? Updating Grass does not
work (linux' apt-get upgrade does not see a new version)?

You have to compile GRASS yourself [1] or wait for the next release which will then show up in your distribution.

But as Anna mentioned, in your case you might not need this as you could formulate your list of cats more efficiently using 'thru', i.e.:

r.mask raster=basins_new@PERMANENT maskcats="1 thru 107"

instead of listing them all. Or, if the series is not continuous:

r.mask raster=basins_new@PERMANENT maskcats="1 thru 25 53 thru 75"

Moritz

[1] https://grasswiki.osgeo.org/wiki/Compile_and_Install

On 07/04/17 03:53, Anna Petrášová wrote:

On Thu, Apr 6, 2017 at 5:47 AM, Micha Silver <tsvibar@gmail.com> wrote:

Interesting...
I can duplicate the problem (but only up to 100 cats). Above that I get an
error of "stack smashing":

I tried to fix it in r70847 (or at least allow longer sequences, the
arrays are still statically allocated). But in this case you can also
use "1 thru 106".

Anna

GRASS 7.2.0 (ITM):~ > r.mask raster=farm_bas maskcats="`seq -s " " 1 100`"
--o
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.
[Raster MASK present]

GRASS 7.2.0 (ITM):~ > r.info -g MASK
north=530000
south=510000
east=185000
west=170000
nsres=4
ewres=4
rows=5000
cols=3750
cells=18750000
datatype=CELL
ncats=0
[Raster MASK present]

But with 103 cats...
GRASS 7.2.0 (ITM):~ > r.mask raster=farm_bas maskcats="`seq -s " " 1 103`"
--o
WARNING: MASK already exists and will be overwritten
*** stack smashing detected ***: r.reclass terminated
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.
GRASS 7.2.0 (ITM):~ > r.info -g MASK
ERROR: Raster map <MASK> not found

On 04/06/2017 12:12 PM, Mira Kattwinkel wrote:

Dear Anna, dear list

I used the NC basic sample data set to replicate my case. Unfortunately, I
get the same problem. Can anybody give me a hint? Thanks a lot!

Here is what I did and the output:

r.watershed elevation=elevation@PERMANENT threshold=500 basin=basins_new
SECTION 1a (of 5): Initiating Memory.
SECTION 1b (of 5): Determining Offmap Flow.
SECTION 2: A* Search.
SECTION 3a: Accumulating Surface Flow with MFD.
SECTION 3b: Adjusting drainage directions.
SECTION 4: Watershed determination.
SECTION 5: Closing Maps.

## creating mask with 106 categories works fine
r.mask raster=basins_new@PERMANENT maskcats=1 2 3 4 5 6 7 8 9 10 11 12 13 14
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.

r.mapcalc expression=r106 = MASK

r.mask -r
Raster MASK removed

## creating mask with 107 categories seems to work without error but there
is no MASK output
r.mask raster=basins_new@PERMANENT maskcats=1 2 3 4 5 6 7 8 9 10 11 12 13 14
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.

r.mapcalc expression=m107 = MASK
Invalid map <MASK>
Parse error
ERROR: parse error

g.list type=raster
basins
basins_new
elevation
elevation_shade
geology
lakes
landuse
r106
soils

On 06/04/17 05:06, Anna Petrášová wrote:

On Wed, Apr 5, 2017 at 8:22 AM, Mira Kattwinkel
<kattwinkel-mira@uni-landau.de> wrote:

Dear List,

I am using r.mask to create a new raster map that only contains certain
categories given in 'maskcats'. Then, I use r.mapcalc to save the map under
a new name and (to be on the save side) delete the MASK with r.mask flag
'-r'. I do this in a loop and it works fine until a case when the number of
categories to combine is 213 (trail and error lead to 106 as the maximum
number that works fine). Flag 'verbose' gives the message that a MASK was
created, but none is there. The problem arises in both cases when I directly
use Grass or through R using execGrass.

I tried it on landsat raster from NC sample dataset and it worked.
Perhaps you could try to replicate it with this sample dataset?

Anna

Is there a limit in the number of categories that can be passed to r.mask? I
did not find any hint about that. Additionally, I wonder why there is no
error message but in the contrary one that tells me that a MASK was created
even when it failed.

In case the details are important (or if anybody has a better idea how to
achieve what I want): I have a raster map of subcatchemts belonging to
stream segments created with r.stream.basins. For the endpoints of segments,
I want to combine these subcatchments to a total catchment raster map
containing all upstream catchments.

Thanks a lot,

Mira

--
Dr. Mira Kattwinkel
Quantitative Landscape Ecology
Institute for Environmental Sciences
University of Koblenz-Landau
Fortstraße 7
76829 Landau
Germany
Phone: + 49 6341 280-31553
Office: Building I, Room 2.02

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

--
Micha Silver
cell: +972-523-665918

--
Dr. Mira Kattwinkel
Quantitative Landscape Ecology
Institute for Environmental Sciences
University of Koblenz-Landau
Fortstraße 7
76829 Landau
Germany
Phone: + 49 6341 280-31553
Office: Building I, Room 2.02

On 07/04/17 12:10, Mira Kattwinkel wrote:

Thanks for that.

So, the limitation is not the number of categories but the string that
defines them?

Yes.

The 1 to 106 was just an example. In reality, I have various numbers
with no ordering, up to more than 100 different ones.

You might want to look at the solution Michel suggested, i.e. use reclass with a reclass file.

Moritz

On Fri, Apr 7, 2017 at 3:53 AM, Anna Petrášová <kratochanna@gmail.com> wrote:

On Thu, Apr 6, 2017 at 5:47 AM, Micha Silver <tsvibar@gmail.com> wrote:

I can duplicate the problem (but only up to 100 cats). Above that I get an
error of "stack smashing":

I tried to fix it in r70847 (or at least allow longer sequences, the
arrays are still statically allocated).

(To explain r70847: that it change https://trac.osgeo.org/grass/changeset/70847
r.reclass: allow using more than 100 rules)

But in this case you can also use "1 thru 106".

I have backported that for the future 7.2.2 in
https://trac.osgeo.org/grass/changeset/71050

Markus