Skip to contents

This function creates a water mask for a map, typically the light likelihood map computed by geolight_map(). The mask is based on country polygons from Natural Earth and is stored as map$mask_water as a logical matrix where TRUE indicates water and FALSE indicates land.

A pixel is marked as water when the fraction of its area covered by land is at or below land_threshold. With the default land_threshold = 0, a pixel is land if any land exists within it, which is important for detecting small islands.

Usage

map_add_mask_water(map, ne_scale = "medium", land_threshold = 0)

Arguments

map

a GeoPressureR map object, e.g. tag$map_light from geolight_map().

ne_scale

Natural Earth resolution passed to rnaturalearth::ne_countries(scale = ...). Valid values are "small", "medium", "large" or c(110, 50, 10). Default is "medium".

land_threshold

Numeric threshold used to classify pixels as water from the rasterized land fraction. Pixels with land fraction at or below land_threshold are marked as water. Use 0 for a conservative mask where any land in a pixel makes it land.

Value

A map object with mask_water added as a logical matrix.

Details

The land polygons are rasterized to match the map's grid (defined by extent and scale from the map). land_threshold controls how much land can be present in a pixel before it is treated as land in map$mask_water. For "large"/10 resolution, rnaturalearthhires is used by rnaturalearth when available.

See also

Examples

if (FALSE) {
withr::with_dir(system.file("extdata", package = "GeoPressureR"), {
  tag <- tag_create("18LX", quiet = TRUE) |>
    tag_label(quiet = TRUE) |>
    tag_set_map(
      extent = c(-16, 23, 0, 50),
      scale = 4,
      known = data.frame(
        stap_id = 1,
        known_lon = 17.05,
        known_lat = 48.9
      )
    ) |>
    twilight_create() |>
    twilight_label_read() |>
    geolight_map(quiet = TRUE)

  # Create water mask
  tag$map_light <- map_add_mask_water(tag$map_light)

  # View the mask
  image(tag$map_light$mask_water)
})
}