Cog Worker

Scalable geospatial analysis on Cloud Optimized GeoTIFFs (COGs).

cog_worker is a simple python library to help write and chunk analyses of gridded data for applications including GIS, remote sensing, and machine learning.

It provides two things:

  1. A pattern for writing projection- and scale-agnostic analyses of COGs, and

  2. Methods for previewing the results of these analyses and executing them in managable chunks.

Under the hood, cog_worker is just a wrapper around rio-tiler. It does dynamic reprojection and rescaling of input data, enabling you to combine data sources in different projections, and surfaces this data as Numpy arrays that work with the familiar scientific python tools.

Example

import numpy as np
from cog_worker import Manager

# Write your analysis as a function that takes a cog_worker.Worker
# as its first parameter
def my_analysis(worker):
   arr = worker.read('example-cog.tif')
   # calculations ...
   return arr

# Run the function in chunks in a given scale and projection
manager = Manager(proj='wgs84', scale=0.00083333)
manager.chunk_save('output.tif', my_analysis, chunksize=512)

Installation

Install from PyPI.

pip install cog_worker

If you want to use the cog_worker.distributed module to execute functions in a Dask cluster, you will also need to install dask.distributed.

pip install dask[distributed]

Getting started

Follow the quick start notebook.

See also

Other tools:

  • rio-cogeo Cloud Optimized GeoTIFF (COG) creation and validation plugin for Rasterio. (Need to turn your data into COGs?)

  • titiler - A modern dynamic tile server built on top of FastAPI and Rasterio/GDAL. (Need to serve COGs as tiles for a webmap?)

  • stackstac - Easier cloud-native geoprocessing. (Leverage the full power of xarray and stac)

Dependencies: