geowombat.calc_area(data, values, op='eq', units='km2', row_chunks=None, col_chunks=None, n_workers=1, n_threads=1, scheduler='threads', n_chunks=100)#

Calculates the area of data values.

  • data (DataArray) – The xarray.DataArray to calculate area.

  • values (list) – A list of values.

  • op (Optional[str]) – The value sign. Choices are [‘gt’, ‘ge’, ‘lt’, ‘le’, ‘eq’].

  • units (Optional[str]) – The units to return. Choices are [‘km2’, ‘ha’].

  • row_chunks (Optional[int]) – The row chunk size to process in parallel.

  • col_chunks (Optional[int]) – The column chunk size to process in parallel.

  • n_workers (Optional[int]) – The number of parallel workers for scheduler.

  • n_threads (Optional[int]) – The number of parallel threads for dask.compute().

  • scheduler (Optional[str]) –

    The parallel task scheduler to use. Choices are [‘processes’, ‘threads’, ‘mpool’].

    mpool: process pool of workers using multiprocessing.Pool processes: process pool of workers using concurrent.futures threads: thread pool of workers using concurrent.futures

  • n_chunks (Optional[int]) – The chunk size of windows. If not given, equal to n_workers x 50.

Return type:





>>> import geowombat as gw
>>> # Read a land cover image with 512x512 chunks
>>> with'land_cover.tif', chunks=512) as src:
>>>     df = gw.calc_area(
>>>         src,
>>>         [1, 2, 5],        # calculate the area of classes 1, 2, and 5
>>>         units='km2',      # return area in kilometers squared
>>>         n_workers=4,
>>>         row_chunks=1024,  # iterate over larger chunks to use 512 chunks in parallel
>>>         col_chunks=1024
>>>     )