spotpy - A Statistical Parameter Optimization Tool

raw JSON →
1.6.7 verified Sat May 09 auth: no python

spotpy is a Python library for statistical parameter optimization, calibration, and sensitivity analysis of environmental models. It provides a range of algorithms including Monte Carlo, Markov chain Monte Carlo (MCMC), Shuffled Complex Evolution (SCE-UA), DREAM, and various sensitivity analysis methods like FAST and Morris. Current version: 1.6.7. Release cadence is irregular, with several minor releases in recent years.

pip install spotpy
error ModuleNotFoundError: No module named 'spotpy_setup'
cause user tries to import spotpy_setup directly as a top-level module, but it is inside spotpy.examples.
fix
Use: from spotpy.examples.spotpy_setup_hymod import spotpy_setup as setup
error AttributeError: module 'spotpy' has no attribute 'algorithms'
cause Old code that directly imports spotpy.algorithms without importing spotpy first, or incorrect import path.
fix
Import spotpy first, then use spotpy.algorithms.mc(...) or from spotpy.algorithms import mc
error ValueError: Unknown database format 'csv'
cause Database format is case-sensitive. 'csv' is correct, but some users may accidentally use 'CSV' or 'Csv'.
fix
Use lowercase: dbformat='csv'
breaking Migration to pyproject.toml in v1.6.1 removed setup.py. Installations via 'pip install -e .' may require setuptools update or use of 'pip install -e . --no-use-pep517'.
fix Update pip and setuptools: pip install --upgrade pip setuptools. Or use 'pip install -e . --no-use-pep517' if needed.
deprecated Python 2 support was removed in v1.6.1. Python 3.6+ is required, but the current version specifies Python >=3.10.
fix Upgrade to Python 3.10 or higher.
gotcha When using the DREAM algorithm, the 'random_state' parameter must be an integer for reproducible results. Passing None leads to non-reproducible chains.
fix Set random_state to an integer, e.g., sampler = spotpy.algorithms.dream(..., random_state=42).

Basic Monte Carlo sampling using spotpy with a built-in example setup (HYMOD model).

import spotpy
from spotpy.examples.spotpy_setup_hymod import spotpy_setup as setup

# Create a test setup
spotpy_setup = setup()

# Select algorithm (here: Monte Carlo)
sampler = spotpy.algorithms.mc(spotpy_setup, dbname='MC_test', dbformat='csv')
sampler.sample(100)

# Get results
results = sampler.getdata()
print(results.keys())