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

Mira Kattwinkel kattwinkel-mira at uni-landau.de
Fri Apr 7 03:10:28 PDT 2017


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 at PERMANENT maskcats="1 thru 107"
>
> instead of listing them all. Or, if the series is not continuous:
>
> r.mask raster=basins_new at 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 at 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 at 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 at 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 at 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 at 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 at 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



More information about the grass-user mailing list