Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raster: Read raster for mask from env variable #2392

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

wenzeslaus
Copy link
Member

@wenzeslaus wenzeslaus commented May 21, 2022

Use environment variable GRASS_MASK to obtain the name of the raster map to use as raster map for auto-masking.

Mask can be in another mapset. If it does not exist, mask is not applied. The direct masking rules for values (zero and null is masked out) apply (as when using g.copy raster=xxx,MASK).

This will be implemented to work with r.mask, i.e., r.mask will get the name from the environment variable. While setting and unsetting can be done only by manipulating the environment variable, r.mask will use whatever is the mask name set by the environment variable or the default name. This allows to fully use the r.mask capabilities without a need to reimplement them somewhere else. It will also keep the workflows with and without the variable same, so all the r.mask documentation applies to the advanced case of using the variable. If the mask set by the environment is in a different mapset, r.mask will fail.

An alternative would be to implement this without r.mask, i.e., r.mask does not get the name from the environment variable. Setting and unsetting this mask would be done only by manipulating the environment variable. This would be analogous to GRASS_REGION which cannot be manipulated by g.region and similar to g.copy used for MASK which cannot be mixed with r.mask -r. However, while GRASS_REGION says what the computational region should be, GRASS_MASK merely says what the mask name is regardless of its presence. We could fail if the raster is not present, but it seems more natural to behave the same as with the default name (MASK). This then leads to the implementation where r.mask respects whatever GRASS_MASK says.

Review code:

  • raster/r.kappa/mask.c (mask to text including categories)
  • raster/r.report/maskinfo.c (mask to text including categories)
  • raster/r.random.cells/init.c (opens by name)
  • raster/r.random.surface/init.c (opens by name)
  • raster/r.surf.contour/main.c (opens by name)
  • raster/r.volume/main.c (opens by name)

Use variable:

  • testsuite/raster/raster_md5test.sh (in this PR)
  • raster/r.mapcalc/testsuite/const_map_test.sh (in this PR)

Use r.mask.status tool:

  • python/grass/grassdb/history.py
  • gui/wxpython/core/gconsole.py

Update doc:

  • raster/rasterintro.html
  • vector/vectorintro.html
  • raster3d/raster3dintro.html
  • raster/r.mapcalc/r.mapcalc.html
  • raster/r.mapcalc/r3.mapcalc.html
  • raster/r.watershed/front/r.watershed.html
  • doc/notebooks/parallelization_tutorial.ipynb
  • doc/development/style_guide.md
  • imagery/i.smap/i.smap.html
  • imagery/i.pca/main.c
  • raster/r.resamp.bspline/r.resamp.bspline.html
  • raster/r.out.gdal/r.out.gdal.html

Use environment variable GRASS_MASK to obtain the name of the raster map to use as raster map for auto-masking.

Mask can be in another mapset. If it does not exist, mask is not applied. The direct masking rules for values (zero and null is masked out) apply (as when using `g.copy raster=xxx,MASK`).

This is implemented as an alternative to using r.mask, i.e., r.mask does not get the name from the environment variable. Setting and unsetting is done by manipulating the environment variable. This is analogous to GRASS_REGION which cannot be manipulated by g.region and similar to g.copy used for MASK which cannot be mixed with r.mask -r.
@wenzeslaus wenzeslaus added this to the 8.4.0 milestone May 24, 2022
@wenzeslaus wenzeslaus added enhancement New feature or request C Related code is in C labels May 25, 2022
@wenzeslaus wenzeslaus modified the milestones: 8.3.0, 8.4.0 Feb 10, 2023
@landam
Copy link
Member

landam commented Nov 20, 2023

@wenzeslaus Please provide details on what is missing in order to review this PR?

@wenzeslaus wenzeslaus modified the milestones: 8.4.0, 8.5.0 Apr 26, 2024
wenzeslaus added a commit to wenzeslaus/grass that referenced this pull request Sep 27, 2024
On many places (more than covered here), 2D raster mask is called MASK conflating the concept (mask) and the implementation (MASK raster). Users using the r.mask tool may not interact with the underlying raster directly, so there is no reason to use MASK over mask.

This is leaving many places as they are with MASK. Some will be better revisited with or after OSGeo#2390 and OSGeo#2392 when a more comprehensive solution is available.

This fixes and keeps in sync wording r.null and r.external, and moves r.circle comment documenting the interface to a flag description.
wenzeslaus added a commit to wenzeslaus/grass that referenced this pull request Sep 27, 2024
To avoid asking about presence of the MASK raster, add a library function which checks for presence of the raster hiding its name in the library.

This prepares way for OSGeo#2392.

This also changes the message from using MASK to simply mask. I'm open to suggestion on wording of 'mask is present' versus 'mask is active' etc.
wenzeslaus added a commit that referenced this pull request Oct 11, 2024
On many places (more than covered here), 2D raster mask is called MASK conflating the concept (mask) and the implementation (MASK raster). Users using the r.mask tool may not interact with the underlying raster directly, so there is no reason to use MASK over mask.

This is changing MASK to mask and modifies related wording. However, this is also leaving many places as they are with MASK. Some will be better revisited with or after #2390 and #2392 when a more comprehensive solution is available.

This fixes and keeps in sync wording in r.null and r.external, and moves r.circle comment documenting the interface to a flag description.
@github-actions github-actions bot added raster Related to raster data processing HTML Related code is in HTML libraries module docs labels Oct 11, 2024
@github-actions github-actions bot added the tests Related to Test Suite label Oct 14, 2024
lib/raster/auto_mask.c Outdated Show resolved Hide resolved
@github-actions github-actions bot added the Python Related code is in Python label Oct 15, 2024
@wenzeslaus
Copy link
Member Author

I'm taking suggestions on wording of "mask present" versus "mask active". A possible take:

  • mask present: Raster which is identified as mask exists. (Typically, that would be a raster called MASK in the current mapset.)
  • mask active: Masking is enabled (i.e., used) in the C library.

This would be distinction for the library, esp. the C library. I think we can have more loose rules for the user interface and documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C docs enhancement New feature or request HTML Related code is in HTML libraries module Python Related code is in Python raster Related to raster data processing tests Related to Test Suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants