Satellite-based kelp classification from Sentinel-2 using semantic segmentation
Reason this release was yanked:
Broken dependency resolution
Project description
SKeMa
Satellite-based Kelp Mapping using Semantic Segmentation on Sentinel-2 imagery
skema is a Python tool for classifying kelp in Sentinel-2 satellite images using a deep learning segmentation model (PyTorch). It provides a command-line interface (CLI) for easy, reproducible inference. To run the tool you would need to download Sentinel-2 images from the Copernicus Browser. More detailed instruction on how to download these images can be found in Section Usage. The following instructions are provided for anyone with no knowledge of what a command line is, no knowledge of Python or virtual environments, etc. Just follow along step by step.
Model available on Hugging Face: m5ghanba/SKeMa
DOI: 10.57967/hf/6790
Table of Contents
- Quick Start (Experienced Users)
- Citation
- Installation
- Usage
- Static Files
- GPU Support
- Project Structure
- License
Quick Start (Experienced Users)
pip install skema-kelp
# Download static files (for model_full only) from sources listed below
# Download Sentinel-2 imagery from https://dataspace.copernicus.eu/browser/
skema --input-dir "path/to/S2_scene.SAFE" --output-filename output.tif
# For help and all options
skema --help
For detailed installation instructions (beginner-friendly), see Installation below.
Citation
If you use SKeMa in your research or work, please cite:
@software{skema_2025,
author = {Mohsen Ghanbari, Neil Ernst, Taylor A. Denouden, Luba Y. Reshitnyk, Piper Steffen, Alena Wachmann, Alejandra Mora-Sotoa, Eduardo Loos, Margot Hessing-Lewis, Nic Dedeluke, Maycira Costa},
title = {SKeMa: Satellite-based Kelp Mapping using Semantic Segmentation on Sentinel-2 imagery},
year = 2026,
publisher = {Hugging Face},
doi = {10.57967/hf/6790},
url = {https://huggingface.co/m5ghanba/SKeMa}
}
Installation
Before you can set up SKeMa, you'll need Python (version 3.8 to 3.12) installed on your computer. Python is a free tool, and no accounts or sign-ups are required to install it. We'll install it using your terminal (command line) where possible for simplicity. If you're on Windows, ensure you're using PowerShell or Command Prompt as Administrator (right-click and select "Run as administrator") for some steps. In some cases, however, you may need to use Command Prompt instead of PowerShell because PowerShell can handle command resolution and PATH variables differently, which may prevent it from recognizing Python even if it is installed. Additionally, if Python was installed only for your user account (and not system-wide), it may only be accessible from a normal Command Prompt session rather than one opened as Administrator, since elevated terminals can use a different set of environment variables.
Step 1: Install Python
Checking Your Current Python Version:
Before proceeding, check if you already have Python between versions 3.8 and 3.12 on your computer. Open a terminal (PowerShell, Command Prompt, or macOS/Linux terminal).
Run:
python --version
or, on macOS/Linux, try:
python3 --version
If the version shown is between 3.8 and 3.12 (e.g., Python 3.9.13, Python 3.11.5, Python 3.12.7), you already meet the requirement and can skip the installation steps below. Otherwise, follow the instructions below to install Python.
On Windows
-
Download the Python 3.12.7 installer directly from the Python website:
-
Run the installer:
- IMPORTANT: At the very first screen, check the box that says "Add Python to PATH". This option is unchecked by default โ if you miss it, Python will not be recognised by your terminal.
- Click "Install Now" and follow the prompts.
-
Verify the installation:
- Open Command Prompt (search for
cmdin the Start menu). Use Command Prompt, not PowerShell, as PowerShell can sometimes fail to recognise Python even if it is installed. - Run
python --version. It should outputPython 3.12.7. - If you see an error, close and reopen Command Prompt and try again. If it still fails, search online for "add Python to PATH Windows".
- Open Command Prompt (search for
On macOS
-
Install Homebrew (a package manager for CLI installations, if you don't have it):
- Open Terminal (search for it in Spotlight with Cmd+Space).
- Run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - Follow any on-screen prompts (it may ask for your password; this is normal). No account needed.
- After installation, run the commands it suggests to add Homebrew to your PATH (e.g.,
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofileand theneval "$(/opt/homebrew/bin/brew shellenv)"). - Verify: Run
brew --version. It should show a version like "4.3.0".
-
Install Python 3.12:
- Run:
brew install python@3.12 - This installs Python and adds it to PATH.
- Verify: Run
python3 --version(note: usepython3on macOS). It should output "Python 3.12.7".
Alternative: Download the official installer from python.org using your browser, run it, and follow GUI steps. Make sure Python is added to your PATH during installation.
- Run:
On Linux (e.g., Ubuntu/Debian; adjust for other distros like Fedora)
-
Update your package list:
- Open your terminal.
- Run:
sudo apt update - Enter your password when prompted (sudo is for admin privileges; no account needed beyond your user login).
-
Install Python 3.12:
- Run:
sudo apt install python3.12 python3.12-venv python3-pip - This installs Python, the venv module, and pip.
- Verify: Run
python3 --version. It should output "Python 3.12.x". - For Fedora/RHEL: Use
sudo dnf install python3.12instead.
Note: If your distro's repositories don't have Python 3.12, add a PPA (e.g., for Ubuntu:
sudo add-apt-repository ppa:deadsnakes/ppathen update and install). - Run:
Once Python is installed and verified, proceed to the next section. If you encounter errors (e.g., "command not found"), search online for the exact error message + your OS.
Step 2: Install SKeMa
Open your terminal:
- On Windows, you can use Command Prompt or PowerShell.
- On macOS, open the Terminal app.
- On Linux, open your terminal emulator of choice.
When you open a terminal, you start inside a directory (folder). You can move to another directory with the command cd. For example:
cd C:\Users\YourName\Documents
On macOS/Linux:
cd /Users/yourname/Documents
๐ The easiest way to navigate is to open your file explorer, go to the folder you want, then copy its full path and paste it after cd on the command line. For more details, look up "basic terminal navigation" online.
Now, navigate to a directory where you want to work with SKeMa, then run:
Option 1: Install with pip (Recommended)
# Create a virtual environment
python -m venv skema_env
# Activate the virtual environment
# On Windows:
skema_env\Scripts\activate
# On macOS/Linux:
source skema_env/bin/activate
# Install SKeMa
pip install skema-kelp
โ ๏ธ Windows only โ "Access Denied" when activating the environment
This is caused by PowerShell's execution policy, which blocks scripts from running by default on many Windows systems. Fix it by running this command once in PowerShell:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSignedType
Yand press Enter when prompted. This only affects your own user account and does not change system-wide security settings. After running it, try activating the environment again.
โณ Installation Time: The installation may take up to 10 minutes to complete. A large amount of text will scroll past โ this is normal. You will know it is finished when you see a line like
Successfully installed skema-kelp-X.X.Xand your command prompt reappears.
โ ๏ธ Opencv issue for macOS users: In some cases, the installation may fail while building the opencv-python-headless dependency (a computer vision library required by albumentations). If you see an error mentioning OpenCV or "Failed building wheel for opencv-python-headless", install OpenCV separately first and then install SKeMa again:
pip install opencv-python-headless==4.9.0.80
pip install skema-kelp
This installs a precompiled OpenCV wheel for macOS and avoids a lengthy build process.
Option 2: Install from source (for developers)
If you want to modify the code or contribute to development:
# Install Git first (see system-specific instructions below)
# Then clone the repository
git clone https://github.com/m5ghanba/skema.git
cd skema
# Create and activate virtual environment
python -m venv skema_env
# On Windows:
skema_env\Scripts\activate
# On macOS/Linux:
source skema_env/bin/activate
# Install in development mode
pip install -e .
Installing Git (only needed for Option 2):
- Windows:
winget install --id Git.Git -e --source wingetor download from git-scm.com - macOS:
brew install gitor download from git-scm.com - Linux:
sudo apt install git(Ubuntu/Debian) orsudo dnf install git(Fedora/RHEL)
Each line explained:
python -m venv skema_env: Creates a virtual environment namedskema_envto isolate project dependencies.skema_env\Scripts\activate(Windows) orsource skema_env/bin/activate(macOS/Linux): Activates the virtual environment, ensuring subsequent commands use its isolated Python and packages.pip install skema-kelp: Installs SKeMa and all its dependencies from PyPI.
If you encounter packaging errors, make sure your pip and build tools are up to date:
pip install --upgrade pip setuptools wheel
Usage
Activating the Virtual Environment
To use SKeMa after the initial installation, you must activate its virtual environment each time you start a new session (if you created one). Follow these steps each time you want to run the tool:
- Open a terminal (Command Prompt, PowerShell, or Terminal).
- Navigate to the directory where you created the virtual environment:
- On Windows:
cd path\to\your\directory - On macOS/Linux:
cd path/to/your/directory
- On Windows:
- Activate the virtual environment:
- On Windows:
skema_env\Scripts\activate - On macOS/Linux:
source skema_env/bin/activate
- On Windows:
- Run SKeMa using the commands described below.
If your command line prompt shows (skema_env), the virtual environment is activated and you're ready to proceed.
Downloading Sentinel-2 Images
SKeMa uses Sentinel-2 satellite images, which can be downloaded from the Copernicus Browser. You will need a free account to access and download these images, which are provided as .zip files.
Sentinel-2 Image Download Instructions
Follow these steps to download Sentinel-2 images:
-
Go to the Copernicus Browser: Navigate to https://browser.dataspace.copernicus.eu/
-
Register: If you haven't already, create a free account by clicking on the "Register" option.
-
Sign in: Log in to your account using your credentials.
-
Create an area of interest: Click on the top right option "Create an area of interest" (the pentagon shape icon).
-
Draw your polygon: Click on the option "Draw polygon of interest..." (the pencil shape icon).
-
Define your area: Draw a polygon around your area of interest by clicking on the map to create points. Close the polygon by clicking on the first point you placed.
-
Set parameters and search:
- Select the Time Range option and set the dates in the "From" and "Until" fields.
- Optionally, set the cloud coverage filter.
- Click on "Find products within selected time range".
- Verify that Sentinel-2 L2A is selected as the data level (default setting).
-
Choose your Sentinel-2 scene: From the map, select the desired Sentinel-2 scene by clicking on it.
-
Preview and download:
- Click on the "i" option to view a preview of the image and quick information.
- Click on the download icon (located at the bottom right) to download the scene.
Running SKeMa
SKeMa can be run on a single Sentinel-2 scene or on a directory of multiple scenes at once.
Single Scene
skema --input-dir "path/to/sentinel2/scene.SAFE" --output-filename output.tif
-
--input-dirmust be the full path to the.SAFEfolder.- Sentinel-2 images from the Copernicus Browser come as
.zipfiles. Extract them first. - Then, pass the full path to the
.SAFEfolder (e.g.,"C:\...\S2C_MSIL2A_20250715T194921_N0511_R085_T09UUU_20250716T001356.SAFE"). - Note: If your path or output filename contains spaces, enclose it in double quotation marks (as shown in the example).
- Sentinel-2 images from the Copernicus Browser come as
-
--output-filenameis the name of the output file (e.g.,output.tif). You only need to provide the filename, not the full directory path. The output will be saved in a folder created alongside the.SAFEfolder.
Batch Mode (Multiple Scenes + Mosaic)
If you have multiple Sentinel-2 scenes to process, use the --batch-dir flag instead of running the tool repeatedly. Place all your unzipped .SAFE folders inside a single directory and point --input-dir to that directory:
skema --input-dir "path/to/folder/with/safe/files/" --output-filename output.tif --batch-dir
SKeMa will:
- Detect all
.SAFEfolders inside the directory automatically. - Process each scene individually, exactly as in single-scene mode.
- Save each scene's prediction inside a subfolder named after that scene. The output filename will be the scene name with your
--output-filenamevalue appended as a suffix. For example, if the scene isS2B_MSIL2A_20220806T191919_N0510_R099_T10UCV_20240718T204439.SAFEand--output-filenameisoutput.tif, the prediction will be saved as:path/to/folder/with/safe/files/ โโโ S2B_MSIL2A_20220806T191919_N0510_R099_T10UCV_20240718T204439/ โโโ S2B_MSIL2A_20220806T191919_N0510_R099_T10UCV_20240718T204439_B2B3B4B8.tif โโโ S2B_MSIL2A_20220806T191919_N0510_R099_T10UCV_20240718T204439_B5B6B7B8A_B11B12.tif โโโ ... โโโ S2B_MSIL2A_20220806T191919_N0510_R099_T10UCV_20240718T204439_output.tif - After all scenes are processed, generate a single mosaic by merging all predictions into one GeoTIFF saved as
mosaic_kelp_map.tifin the input directory:path/to/folder/with/safe/files/ โโโ S2B_MSIL2A_.../ โโโ S2B_MSIL2A_.../ โโโ mosaic_kelp_map.tif โ combined prediction for all scenes
The mosaic is reprojected to BC Albers (EPSG:3005) at 10 m resolution (this is important if skema is applied to other regions in the world). Overlapping pixels between scenes are resolved by taking the maximum value, meaning a pixel is classified as kelp if any contributing scene predicted kelp there.
Model Types
SKeMa supports a few model types, selectable via the --model-type flag::
-
model_full(default): Uses all available data including Sentinel-2 bands, bathymetry, and substrate information. This model provides the most accurate predictions but requires bathymetry and substrate static files. -
model_s2bandsandindices_only: Uses only Sentinel-2 bands and derived spectral indices. This model does not require bathymetry or substrate files, making it suitable for areas outside British Columbia or when static files are unavailable. -
model_ensemble: An ensemble model that combines predictions from bothmodel_fullandmodel_s2bandsandindices_onlyby averaging their outputs. This model requires the same static files asmodel_full(bathymetry, slope, substrate) and can provide more robust predictions by leveraging both modeling approaches.
If --model-type is not specified, the tool defaults to model_s2bandsandindices_only.
Optional Flags
--use-bops-substrate (model_full and model_ensemble only): By default, model_full and model_ensemble use a substrate layer derived from a Random Forest (RF) model. When --use-bops-substrate is set, SKeMa instead uses substrate layers from the Bottom Patches (BoPs) dataset. Each substrate source has its own trained model weights, which are downloaded automatically. This flag cannot be used with model_s2bandsandindices_only.
--soft-substrate-masking (model_full and model_ensemble only): When set, kelp pixels that overlap with sandy or muddy substrate classes are reclassified to 0 (no kelp). Use this with care โ depending on substrate data quality in your area, it may remove a notable number of true kelp pixels.
--eelgrass-masking (all model types): When set, kelp pixels that fall within eelgrass polygons from the BC Marine Conservation Analysis (BCMCA) eelgrass dataset are reclassified to 0 (no kelp). Eelgrass (Zostera marina) is a marine vascular plant that provides important habitat โ kelp predictions overlapping with it are likely false positives. This flag is specific to British Columbia. It can be combined with --soft-substrate-masking.
When either or both masking flags are set, a single combined _masked.tif output is produced (rather than separate files per flag). In batch mode, a mosaic_kelp_map_masked.tif is also created.
Usage Examples
Note: Scroll right to see the complete command if it extends beyond your screen.
# Default: S2 bands and indices only (no static files required)
skema --input-dir "path/to/sentinel2/safe/folder" --output-filename output.tif
# Full model with RF substrate (default substrate source)
skema --input-dir "path/to/sentinel2/safe/folder" --output-filename output.tif --model-type model_full
# Full model with BoPs substrate
skema --input-dir "path/to/sentinel2/safe/folder" --output-filename output.tif --model-type model_full --use-bops-substrate
# Ensemble model with BoPs substrate
skema --input-dir "path/to/sentinel2/safe/folder" --output-filename output.tif --model-type model_ensemble --use-bops-substrate
# Full model with soft substrate masking (produces a combined _masked.tif output)
skema --input-dir "path/to/sentinel2/safe/folder" --output-filename output.tif --model-type model_full --soft-substrate-masking
# Apply eelgrass masking (works with any model type)
skema --input-dir "path/to/sentinel2/safe/folder" --output-filename output.tif --eelgrass-masking
# Combine both masking filters (single combined _masked.tif output)
skema --input-dir "path/to/sentinel2/safe/folder" --output-filename output.tif --model-type model_full --soft-substrate-masking --eelgrass-masking
# Batch mode with ensemble model and BoPs substrate
skema --input-dir "path/to/folder/with/safe/files/" --output-filename output.tif --batch-dir --model-type model_ensemble --use-bops-substrate
Output Files
Single Scene
After running, the tool generates a folder with the same name as the .SAFE file (without the .SAFE extension), located alongside it. Inside this folder, you'll find:
For model_s2bandsandindices_only:
<SAFE_name>_B2B3B4B8.tif: a 10 m resolution, 4-band GeoTIFF containing Sentinel-2 bands B02 (Blue), B03 (Green), B04 (Red), and B08 (Near-Infrared).<SAFE_name>_B5B6B7B8A_B11B12.tif: a 20 m resolution, 6-band GeoTIFF containing Sentinel-2 bands B05, B06, B07, B8A, B11, and B12.output.tif(or the filename you specify): a binary GeoTIFF, where kelp is labeled as1and non-kelp as0.
For model_fulland model_ensemble:
<SAFE_name>_B2B3B4B8.tif: a 10 m resolution, 4-band GeoTIFF containing Sentinel-2 bands B02 (Blue), B03 (Green), B04 (Red), and B08 (Near-Infrared).<SAFE_name>_B5B6B7B8A_B11B12.tif: a 20 m resolution, 6-band GeoTIFF containing Sentinel-2 bands B05, B06, B07, B8A, B11, and B12.<SAFE_name>_Bathymetry.tif: bathymetry data aligned and warped to the Sentinel-2 pixel grid.<SAFE_name>_Substrate.tif: substrate classification data aligned and warped to the Sentinel-2 pixel grid.<SAFE_name>_Slope.tif: slope data (derived from bathymetry) aligned and warped to the Sentinel-2 pixel grid.output.tif(or the filename you specify): a binary GeoTIFF, where kelp is labeled as1and non-kelp as0.output_masked.tif(only when--soft-substrate-maskingand/or--eelgrass-maskingare set): a single combined binary GeoTIFF with all selected masks applied. Kelp pixels on sandy/muddy substrate and/or within eelgrass polygons are set to 0.
Batch Mode
In addition to the per-scene output folders described above (with <SAFE_name>_output.tif inside each), batch mode produces one additional file in the input directory:
-
mosaic_kelp_map.tif: a single binary GeoTIFF mosaic merging all scene predictions, in BC Albers projection (EPSG:3005) at 10 m resolution. -
mosaic_kelp_map_masked.tif(only when--soft-substrate-maskingand/or--eelgrass-maskingare set): a combined masked mosaic built from the per-scene_masked.tiffiles, in BC Albers projection (EPSG:3005) at 10 m resolution.
๐๏ธ Static Files
These files are only required when using
model_fullormodel_ensemble. If you are using the defaultmodel_s2bandsandindices_only, you can skip this section entirely.
Static files are bathymetry and substrate rasters for the British Columbia coast that SKeMa uses as additional input channels when predicting kelp.
Bathymetry and Slope Files
Bathymetry.tifโ a single TIFF raster of seafloor depth.Slope.tifโ a single TIFF raster derived from the bathymetry data.
Substrate Files
SKeMa supports two substrate sources, selected via --use-bops-substrate:
1. Regional RF substrate files (20 m resolution) โ default:
- Five TIFF rasters:
NCC_substrate_20m.tif,SOG_substrate_20m.tif,WCVI_substrate_20m.tif,QCS_substrate_20m.tif,HG_substrate_20m.tif - Each covers a different region of the BC coast.
2. BoPs substrate files (10 m resolution) โ with --use-bops-substrate:
- Four TIFF rasters:
BoPs_HG_10m.tif,BoPs_NCC_10m.tif,BoPs_QCSSOG_10m.tif,BoPs_WCVI_10m.tif - Must be rasterized from shapefiles using the provided notebook
notebooks/rasterizeNearshoreBottomPatches_BoPs.ipynb.
Where to place static files
Place all files in the bathy_substrate folder inside the SKeMa package:
Windows (pip install):
skema_env\Lib\site-packages\skema\static\bathy_substrate
macOS/Linux (pip install):
skema_env/lib/python3.12/site-packages/skema/static/bathy_substrate/
Cloned from GitHub:
skema/static/bathy_substrate/
If you encounter any issues downloading or placing these files, please contact us for assistance.
Sources
-
Bathymetry โ Canadian Hydrographic Service (CHS), 20 m resolution:
-
RF Substrate โ Shallow substrate model (20 m) of the Pacific Canadian coast (Haggarty et al., 2020): https://osdp-psdo.canada.ca/dp/en/search/metadata/NRCAN-FGP-1-b100cf6c-7818-4748-9960-9eab2aa6a7a0
-
BoPs Substrate โ Nearshore Bottom Patches:
๐ฅ๏ธ GPU Support
Most users will not need this section. SKeMa runs on CPU by default and works well without a GPU. GPU support is optional and only relevant if you have an NVIDIA GPU and want faster inference.
Check your CUDA version:
nvcc --version
Then install the matching PyTorch build:
For CUDA 12.1:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
For CUDA 11.8:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
โ๏ธ Project Structure
skema/
โโโ skema/
โ โโโ cli.py
โ โโโ lib.py
โ โโโ __init__.py
โ โ
โ โโโ static/
โ โโโ __init__.py
โ โ
โ โโโ masks/
โ โ โโโ valid_depth_zone.gpkg
โ โ โโโ BCMCA_ECO_VascPlants_Eelgrass_Polygons_DATA.shp
โ โ โโโ (associated .dbf, .shx, .prj, .sbn, .sbx files)
โ โ
โ โโโ bathy_substrate/
โ โโโ __init__.py
โ โโโ Bathymetry.tif
โ โโโ Slope.tif
โ โโโ NCC_substrate_20m.tif
โ โโโ SOG_substrate_20m.tif
โ โโโ WCVI_substrate_20m.tif
โ โโโ QCS_substrate_20m.tif
โ โโโ HG_substrate_20m.tif
โ โโโ BoPs_HG_10m.tif
โ โโโ BoPs_NCC_10m.tif
โ โโโ BoPs_QCSSOG_10m.tif
โ โโโ BoPs_WCVI_10m.tif
โโโ notebooks/
โ โโโ rasterizeNearshoreBottomPatches_BoPs.ipynb
โโโ pyproject.toml
โโโ setup.py
โโโ requirements.txt
โโโ README.md
๐ License
- Code: MIT License (see LICENSE file)
- Model: The trained model is licensed under CC-BY-4.0 โ please cite the DOI when using it.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file skema_kelp-0.3.3.tar.gz.
File metadata
- Download URL: skema_kelp-0.3.3.tar.gz
- Upload date:
- Size: 5.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67ff088a18b8579dfe2a3810f79701c15015f37b3c303e474181fee9200226f3
|
|
| MD5 |
ada335b5448fd16456882d3a1cc774b6
|
|
| BLAKE2b-256 |
3823d158494dd1360b9a82d9523f331f4ecb9a779a289e16d0510af99832b30e
|
File details
Details for the file skema_kelp-0.3.3-py3-none-any.whl.
File metadata
- Download URL: skema_kelp-0.3.3-py3-none-any.whl
- Upload date:
- Size: 5.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57d6bbb38d392f146105666a0cccfb24e56a83e430bd9fabd515a35c354cbbd2
|
|
| MD5 |
4e9be13d007bc5433009f17cf18caeec
|
|
| BLAKE2b-256 |
2c07318aba5c03dd1b4ace8a93215d1efde8d9c139b2973d1e1f31c198ebbc05
|