Skip to content

polygon: Masks from polygons drawn on results (CLI)

Commands of moraine.cli.polygon (source); the same functions are called in Python as mc.<name>(...) with import moraine.cli as mc. The help below is generated from the docstrings, like moraine COMMAND --help.

command summary
polygon-mask Mask of the pixels or points inside (or outside) the polygons of a GeoJSON file

polygon-mask

Mask of the pixels or points inside (or outside) the polygons of a GeoJSON file. The polygons come from the tile viewer (TileView.save_polygons) or any GeoJSON file. Give the positions of the data in the coordinates of the file in one of three ways: x and y (longitude / latitude for 'lonlat' files, range / azimuth for 'radar_grid' files), gix (point clouds on the radar grid) or shape (a whole raster on the radar grid, pixel (i, j) at range j, azimuth i). Apply the mask with e.g. math (where(mask, a, nan)) or pc-logic-pc.

moraine polygon-mask --polygons STR --mask STR [--x STR] [--y STR] [--gix STR] [--shape INT INT] [--keep STR] [--chunks INT INT]
argument type default description
--polygons str required input GeoJSON file with the polygons
--mask str required output bool mask, True for the data to keep; same shape as x / y, (n_points,) for gix, (nlines, width) for shape
--x str None input x coordinate of the data (longitude or range), any shape; with y
--y str None input y coordinate of the data (latitude or azimuth), same shape as x
--gix str None input grid index (azimuth, range) of a point cloud, shape (n_points, 2); 'radar_grid' polygons only
--shape tuple[int, int] None raster shape (nlines, width); 'radar_grid' polygons only
--keep str 'inside' 'inside' keeps the data inside any polygon (True there), 'outside' keeps the data outside all polygons
--chunks tuple[int, int], 1000) (1000, 1000) output chunk size for shape; the other outputs are chunked like their input

Global options: --json, --traceback, --log FILE, -q / --quiet (conventions).

In a pipeline (not used by the example pipelines; required arguments only):

[[step]]
name = "polygon_mask"
run = "polygon-mask"
polygons = "..."
mask = "..."

In Python:

import moraine.cli as mc
mc.polygon_mask(polygons, mask, x=None, y=None, gix=None, shape=None, keep='inside', chunks=(1000, 1000))