Quickstart
This guide shows the two main ways to use OmniCloudMask: processing numpy arrays directly, or processing satellite scene files.
Predict from a numpy array
Use predict_from_array when you already have image data loaded as a numpy array with Red, Green, and NIR bands:
import numpy as np
from omnicloudmask import predict_from_array
# Load your data as (3, height, width) array: Red, Green, NIR bands
input_array = np.random.rand(3, 1024, 1024).astype(np.float32)
# Run prediction
mask = predict_from_array(input_array)
# mask shape: (1, height, width)
# Values: 0=Clear, 1=Thick Cloud, 2=Thin Cloud, 3=Cloud Shadow
Tip
Don’t have a NIR band? You can pass an array of zeros in its place and still get good predictions. See Spectral Channels for details.
Predict from scene files
Use predict_from_load_func to process satellite scene files directly. The library includes loaders for Sentinel-2, Landsat 8, and multiband GeoTIFFs:
Sentinel-2
from pathlib import Path
from omnicloudmask import predict_from_load_func, load_s2
scene_paths = [
Path("path/to/scene1.SAFE"),
Path("path/to/scene2.SAFE"),
]
# Predictions saved as GeoTIFFs alongside input scenes
pred_paths = predict_from_load_func(scene_paths, load_s2)
Landsat 8
from pathlib import Path
from omnicloudmask import predict_from_load_func, load_ls8
scene_paths = [
Path("path/to/LC08_scene1"),
Path("path/to/LC08_scene2"),
]
pred_paths = predict_from_load_func(scene_paths, load_ls8)
Multiband GeoTIFF
from functools import partial
from pathlib import Path
from omnicloudmask import predict_from_load_func, load_multiband
scene_paths = [Path("path/to/image.tif")]
# Specify band order: [Red, Green, NIR] (1-indexed)
loader = partial(load_multiband, band_order=[4, 3, 5])
pred_paths = predict_from_load_func(scene_paths, loader)