recode#

geowombat.recode(data, polygon, to_replace, num_workers=1)#

Recodes a DataArray with polygon mappings.

Parameters:
  • data (DataArray) – The xarray.DataArray to recode.

  • polygon (GeoDataFrame | str) – The geopandas.DataFrame or file with polygon geometry.

  • to_replace (dict) –

    How to find the values to replace. Dictionary mappings should be given as {from: to} pairs. If to_replace is an integer/string mapping, the to string should be ‘mode’.

    {1: 5}:

    recode values of 1 to 5

    {1: ‘mode’}:

    recode values of 1 to the polygon mode

  • num_workers (Optional[int]) – The number of parallel Dask workers (only used if to_replace has a ‘mode’ mapping).

Return type:

DataArray

Returns:

xarray.DataArray

Example

>>> import geowombat as gw
>>>
>>> with gw.open('image.tif', chunks=512) as ds:
>>>     # Recode 1 with 5 within a polygon
>>>     res = gw.recode(ds, 'poly.gpkg', {1: 5})