replace#

geowombat.replace(data, to_replace)#

Replace values given in to_replace with value.

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

  • 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

Return type:

DataArray

Returns:

xarray.DataArray

Example

>>> import geowombat as gw
>>>
>>> with gw.open('image.tif', chunks=512) as ds:
>>>     # Replace 1 with 5
>>>     res = gw.replace(ds, {1: 5})