Skip to main content

stemflow 🐦

stemflow logo

A Python Package for Adaptive Spatio-Temporal Exploratory Model (AdaSTEM)

GitHub PyPI version PyPI downloads Anaconda version Anaconda downloads GitHub last commit codecov status


Documentation 📖

stemflow Documentation

JOSS paper


Installation 🔧

pip install stemflow

For optional memory monitoring (psutil) and tuning (XGBoost and Optuna):

pip install "stemflow[monitoring,tuning]"

Use stemflow[monitoring] or stemflow[tuning] to install either separately.

To install the latest version from GitHub:

pip install "stemflow @ git+https://github.com/chenyangkang/stemflow.git"

Or using conda:

conda install -c conda-forge stemflow

Brief introduction ℹ️

stemflow is a toolkit for Adaptive Spatio-Temporal Exploratory Model (AdaSTEM [1, 2]) in Python. Typical usage is daily abundance estimation using eBird citizen science data (survey data).

stemflow adopts "split-apply-combine" philosophy. It

  1. Splits input data using Quadtree or Sphere Quadtree.
  2. Trains each spatiotemporal split (called stixel) separately.
  3. Aggregates the ensemble to make the prediction.

The framework leverages the "adjacency" information of surroundings in space and time to model/predict the values of target spatiotemporal points. This framework ameliorates the long-distance/long-range prediction problem [3], and has a good spatiotemporal smoothing effect.

For more information, please see an introduction to stemflow and learning curve analysis


Model and data 🎰

Main functionality of stemflow Supported indexing Supported tasks
✅ Spatiotemporal modeling & prediction
✅ User-defined 2D spatial indexing (CRS)
✅ Binary classification task
✅ Calculate overall feature importances
✅ 3D spherical indexing
✅ Regression task
✅ Plot spatiotemporal dynamics
✅ User-defined temporal indexing
✅ Hurdle task (two step regression – classify then regress the non-zero part)
✅ Spatial-only modeling
For details see AdaSTEM Demo For details and tips see Tips for spatiotemporal indexing For details and tips see Tips for different tasks
Supported data types Supported base models
✅ Both continuous and categorical features (prefer one-hot encoding)
✅ sklearn style BaseEstimator classes (you can make your own base model), for example here
✅ Both static (e.g., yearly mean temperature) and dynamic features (e.g., daily temperature)
✅ sklearn style Maxent model. Example here.
For details and tips see Tips for data types For details see Base model choices

Usage ⭐

Use Hurdle model as the base model of AdaSTEMRegressor. This example uses XGBoost, so install the tuning extra shown above:

import numpy as np
from stemflow.model.AdaSTEM import AdaSTEM, AdaSTEMClassifier, AdaSTEMRegressor
from stemflow.model.Hurdle import Hurdle
from xgboost import XGBClassifier, XGBRegressor

## "hurdle in Ada"
model = AdaSTEMRegressor(
    base_model=Hurdle(
        classifier=XGBClassifier(tree_method='hist',random_state=42, verbosity = 0, n_jobs=1),
        regressor=XGBRegressor(tree_method='hist',random_state=42, verbosity = 0, n_jobs=1)
    ),                                      # hurdel model for zero-inflated problem (e.g., count)
    save_gridding_plot = True,
    ensemble_fold=50,                       # data are modeled 50 times, each time with jitter and rotation in Quadtree algo
    min_ensemble_required=30,               # Only points covered by > 30 ensembles will be predicted
    grid_len_upper_threshold=25,            # force splitting if the grid length exceeds 25
    grid_len_lower_threshold=5,             # stop splitting if the grid length fall short 5         
    temporal_start=1,                       # The next 4 params define the temporal sliding window
    temporal_end=366,                            
    temporal_step=20,                       # The window takes steps of 20 DOY (see AdaSTEM demo for details)
    temporal_bin_interval=50,               # Each window will contain data of 50 DOY
    points_lower_threshold=50,              # Only stixels with more than 50 samples are trained and used for prediction
    Spatio1='longitude',                    # The next three params define the name of 
    Spatio2='latitude',                     # spatial coordinates shown in the dataframe
    Temporal1='DOY',
    use_temporal_to_train=True,             # In each stixel, whether 'DOY' should be a predictor
    n_jobs=1,
    random_state=42
)

Fitting and prediction methods follow the style of sklearn BaseEstimator class:

## fit
model = model.fit(X_train.reset_index(drop=True), y_train)

## predict
pred = model.predict(X_test)
pred = np.where(pred<0, 0, pred)
eval_metrics = AdaSTEM.eval_STEM_res('hurdle', y_test, pred)
print(eval_metrics)

Where the pred is the mean of the predicted values across ensembles.

See AdaSTEM demo for further functionality.
Besides, stemflow also support lazy loading and database query to reduce memory load during parallel computing.

The execution rewrite adds a Pandas-friendly database helper and optional shared training arrays:

from stemflow.lazyloading import make_training_databases

X_path, y_path = make_training_databases(X_train, y_train, "data/training")
model.fit(X_path, y_path, temporal_window_prequery=True,
          training_data_backend="memmap", inner_max_num_threads=1,
          max_concurrent_ensembles=4)

Native Pandas, DuckDB or Parquet execution remains the default; memory-mapped execution is optional. See the parallel execution guide and executed example for compatibility, scratch-space requirements and complete-job memory trade-offs. The repository also contains reproducible benchmarks in scripts/00_benchmarks/ and measured comparisons in resources/REWRITE.md.

For optional live wall timings and parent/worker memory, install stemflow[monitoring] and wrap fitting and prediction in with model.monitor_execution(output_path="data/execution_monitor.json") as monitor:. The monitor reports sampled process-tree peaks, named stages and optional flushed log updates. Its plain report remains available as model.execution_monitor_ and survives model saving/loading; it retains summaries by default. RSS uses a portable psutil reader, with optional platform-specific USS/PSS/footprint measurements. See the monitoring guide for interpretation and target-machine checks.

Mean predictions now support streaming ensemble aggregation. Optional calibration and tuning wrappers can be used independently or together, inside or outside AdaSTEM. The pipeline report compares timings, peak memory, calibration diagnostics and compatibility limits.


Plot QuadTree ensembles 🌲

model.gridding_plot
# Here, the model is a AdaSTEM class, not a hurdle class

QuadTree example

Here, each color shows an ensemble generated during model fitting. In each of the 10 ensembles, regions (in terms of space and time) with more training samples were gridded into finer resolution, while the sparse one remained coarse. Prediction results were aggregated across the ensembles (that is, in this example, data were modeled 10 times).

If you use SphereAdaSTEM module, the gridding plot is a plotly generated interactive object by default:

See SphereAdaSTEM demo and Interactive spherical gridding plot.


Example of visualization 🗺️

Daily Abundance Map of Barn Swallow

GIF visualization

See section AdaSTEM demo for how to generate this GIF.


Citation

Chen et al., (2024). stemflow: A Python Package for Adaptive Spatio-Temporal Exploratory Model. Journal of Open Source Software, 9(94), 6158, https://doi.org/10.21105/joss.06158

@article{Chen2024, 
  doi = {10.21105/joss.06158}, 
  url = {https://doi.org/10.21105/joss.06158}, 
  year = {2024}, 
  publisher = {The Open Journal}, 
  volume = {9}, 
  number = {94}, 
  pages = {6158}, 
  author = {Yangkang Chen and Zhongru Gu and Xiangjiang Zhan}, 
  title = {stemflow: A Python Package for Adaptive Spatio-Temporal Exploratory Model}, 
  journal = {Journal of Open Source Software} 
}

Contribute to stemflow 💜

We welcome pull requests. Contributors should follow contributor guidelines.

Application-level cooperation is also welcomed. We recognized that stemflow may consume large computational resources especially as data volume boosts in the future. We always welcome research collaboration of all kinds.


References:

  1. Fink, D., Damoulas, T., & Dave, J. (2013, June). Adaptive Spatio-Temporal Exploratory Models: Hemisphere-wide species distributions from massively crowdsourced eBird data. In Proceedings of the AAAI Conference on Artificial Intelligence (Vol. 27, No. 1, pp. 1284-1290).

  2. Fink, D., Auer, T., Johnston, A., Ruiz‐Gutierrez, V., Hochachka, W. M., & Kelling, S. (2020). Modeling avian full annual cycle distribution and population trends with citizen science data. Ecological Applications, 30(3), e02056.

  3. Fink, D., Hochachka, W. M., Zuckerberg, B., Winkler, D. W., Shaby, B., Munson, M. A., ... & Kelling, S. (2010). Spatiotemporal exploratory models for broad‐scale survey data. Ecological Applications, 20(8), 2131-2147.

  4. Johnston, A., Fink, D., Reynolds, M. D., Hochachka, W. M., Sullivan, B. L., Bruns, N. E., ... & Kelling, S. (2015). Abundance models improve spatial and temporal prioritization of conservation resources. Ecological Applications, 25(7), 1749-1756.

Metadata

Release files for stemflow 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stemflow 2.0.0
File Size Uploaded Provenance Actions
stemflow-2.0.0.tar.gz 114.6 kB With provenance Details for stemflow-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for stemflow 2.0.0
File Interpreter ABI Platform Actions
stemflow-2.0.0-py3-none-any.whl Python 3 none any Details for stemflow-2.0.0-py3-none-any.whl

Total release size: 239.8 kB

Release files / stemflow-2.0.0.tar.gz

Download URL stemflow-2.0.0.tar.gz
Size 114.6 kB
Tags Source
SHA-256 checksum
How to use checksums
95e149cc8c73291feafce7eb4cd8f6296a3331b061ecb7632ec332b29922a2a9
BLAKE2b-256 checksum
How to use checksums
402f7a3d914e58033e3760593847ca6b622e1b33b89153c7778d62fee00d742a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Release files / stemflow-2.0.0-py3-none-any.whl

Download URL stemflow-2.0.0-py3-none-any.whl
Size 125.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
be994d5f9952d4a0cf28a629501387a899e0152e251998c8ad2108cbb809465e
BLAKE2b-256 checksum
How to use checksums
7791f61279244a9278205d9c91d1a9caf5fd59eeea266780fb21dc496d0b9aed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

Security for stemflow 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for stemflow-2.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page