Installation
plMapcalc Python edition is a single script — plmapcalc.py — with no
build step. Installation means: get Python, install three packages, download the script.
Requirements
- Python 3.9 or newer
- numpy ≥ 1.24
- rasterio ≥ 1.3 — requires GDAL shared libraries (installed automatically via pip wheel)
- numba ≥ 0.61 (strongly recommended) — requires LLVM; pip wheel includes it on most platforms
- numba-cuda ≥ 0.29 (optional, GPU only) — CUDA target for numba; requires a dedicated venv, see GPU setup below
Step-by-step: Linux / macOS
Check Python version
python3 --version
Must print Python 3.9 or newer. If not, install Python from
python.org or via your system package manager.
Create a virtual environment (recommended)
python3 -m venv ~/.venv/mapcalc source ~/.venv/mapcalc/bin/activate
Install dependencies
pip install numpy rasterio numba
Or using the requirements file:
pip install -r requirements.txt
Download plmapcalc.py
wget https://plmapcalc.netzel.pl/plmapcalc.py
Verify
python3 plmapcalc.py --help
You should see the full usage message with all options listed.
Step-by-step: Windows
Install Python
Download the installer from python.org. During setup, check Add Python to PATH.
Install dependencies in Command Prompt
pip install numpy rasterio numba
Download plmapcalc.py and run
python plmapcalc.py --help
On Windows use double quotes instead of single quotes for
-e expressions and use backslash \ as the path separator
inside -i / -o / -r / -s.
Without numba
If numba cannot be installed, plMapcalc still works but uses a pure-Python fallback loop. Expect processing times 50–200× slower than the JIT path. The tool prints a warning at startup:
[WARN] numba not installed – processing will be slower.
On HPC clusters, load the numba conda package or use
pip install numba in a user-local environment. Numba ships its own
LLVM — no system LLVM needed.
GPU acceleration (optional)
Passing --gpu routes the pixel kernel to a CUDA-capable GPU
via numba-cuda. Each GPU thread processes one pixel; thousands of
pixels run simultaneously. This is most effective for large rasters with
compute-intensive expressions.
Hardware requirements
| Requirement | Minimum | Notes |
|---|---|---|
| GPU | NVIDIA, Compute Capability ≥ 3.5 | RTX 20/30/40/50 series, Tesla, Quadro — check with nvidia-smi |
| NVIDIA driver | ≥ 520 (CUDA 11.8+) | Blackwell (RTX 50xx) requires driver ≥ 570 (CUDA 12.8) |
| CUDA runtime | 12.x | Provided by nvidia-cuda-runtime-cu12 pip package — no system CUDA Toolkit required |
Python packages
GPU mode requires a dedicated virtual environment with the following pip packages.
These must not be mixed with torch (which pins cuda-bindings<13
— incompatible with numba-cuda≥0.25).
| Package | Version | Purpose |
|---|---|---|
numba | ≥ 0.61 | JIT compiler (CPU + GPU base) |
numba-cuda | ≥ 0.29 | CUDA target for numba; provides numba.cuda namespace and pathfinder for CUDA libs |
cuda-bindings | ≥ 13 (auto) | Installed automatically as a dependency of numba-cuda ≥ 0.25 |
nvidia-cuda-runtime-cu12 | ≥ 12.8 | Provides libcudart.so |
nvidia-cuda-nvcc-cu12 | ≥ 12.8 | Provides libnvvm.so (PTX compiler) |
nvidia-cuda-nvrtc-cu12 | ≥ 12.8 | Provides libnvrtc.so (runtime compilation) |
nvidia-nvjitlink-cu12 | ≥ 12.8 | Provides libnvJitLink.so (link-time optimisation; optional but eliminates a warning) |
Dedicated venv required. numba-cuda ≥ 0.25
installs cuda-bindings ≥ 13, which conflicts with
torch (requires cuda-bindings < 13).
Keep plmapcalc GPU mode in a separate virtual environment from any
PyTorch installation.
Install — step by step
-
Create a dedicated venv and activate it
shell
python3 -m venv ~/.venv/plmc_gpu source ~/.venv/plmc_gpu/bin/activate
-
Install plmapcalc core dependencies
shell
pip install numpy rasterio numba
-
Install numba-cuda and CUDA libraries
shell
pip install numba-cuda pip install nvidia-cuda-runtime-cu12 \ nvidia-cuda-nvcc-cu12 \ nvidia-cuda-nvrtc-cu12 \ nvidia-nvjitlink-cu12For Blackwell GPUs (RTX 50xx) ensure the CUDA 12.8 versions are installed:
shellpip install "nvidia-cuda-runtime-cu12>=12.8" \ "nvidia-cuda-nvcc-cu12>=12.8" \ "nvidia-cuda-nvrtc-cu12>=12.8" \ "nvidia-nvjitlink-cu12>=12.8" -
Create missing
.sosymlinkspip installs versioned libraries (e.g.
libnvvm.so.4.0.0) but not the unversioned symlink (libnvvm.so) that the pathfinder requires. Run once after installation:shellfind $VIRTUAL_ENV -path "*/nvidia/*" -name "lib*.so.*" | while read f; do link="${f%.so.*}.so" [ ! -e "$link" ] && ln -sf "$f" "$link" && echo "linked: $link" doneOr use the provided
patch_activate_cuda.shhelper which performs this step automatically alongside patchingLD_LIBRARY_PATH. -
Patch the venv activate script (
LD_LIBRARY_PATH)CUDA shared libraries installed via pip are not on the default library path. The helper script patches the venv
activateto add them automatically:shellbash patch_activate_cuda.sh # run with venv active source $VIRTUAL_ENV/bin/activate
-
Verify
shell
python -c "from numba import cuda; cuda.detect()"
Expected output lists your GPU(s) with compute capability and marks them as
[SUPPORTED].
Usage
python plmapcalc.py --gpu -i band4.tif -i band3.tif \
-o ndvi.tif:float32:-9999 \
-e 'x = IN[0]+IN[1]; OUT[0] = -9999 if x==0 else (IN[0]-IN[1])/x'Blackwell (RTX 50xx) note
Blackwell GPUs (Compute Capability 12.0, sm_120) are supported via PTX JIT compilation. The first run compiles PTX to native sm_120 code, which takes approximately 30 seconds. Subsequent runs use the cached binary and are fast. Native Blackwell kernels require CUDA 12.8 or newer and driver ≥ 570.
Automatic fallback: if CUDA is unavailable (no GPU,
missing driver, or numba-cuda not installed), --gpu
falls back to CPU automatically with a warning.
Expressions that write to MEM[]
(e.g. MEM[0] += IN[0]) always use the serial CPU kernel —
parallel GPU threads cannot safely write to shared memory cells without
race conditions. Expressions that only read from
MEM[] run on GPU normally.