Introducing SynHydro: a Python package providing access to many synthetic streamflow generation methods

· 14 minute read

Motivation

Those familiar with this blog, and our research more broadly, will be familiar with the concept of synthetic streamflow generation (AKA stochastic generation, stochastic streamflow synthesis).

Several WaterProgramming posts have been made on the topic of synthetic generation and these post will be helpful for anyone who is unfamiliar with the motivation for, and usage of, stochastic streamflow ensembles in water resources planning. To point to just a few:

Over the last several years I’ve had a side-project, slowly building python package which is designed to provide access to multiple different synthetic streamflow generation models with a consistent API (think sklearn but designed specifically for synthetic streamflow generation). This project was motivated partly out of necessity (I need reliable stochastic generation implementations that I could use across research projects) and partly out of interest in exploring different generation methods.

Eventually, this side project grew into a full package that I call SynHydro. The SynHydro package currently implements 11 different synthetic streamflow generation and 2 different disaggregation approaches from the water resources literature.

The main idea is that the SynHydro package provides access to user-friendly generation tools in order to make synthetic generation and simulation accessible to broader range of water resource researchers or practitioners. Also, the package makes it easy to generate and compare results from multiple different synthetic generators and select appropriate generators for their specific basin and context.

This post is meant as a soft-launch of the SynHydro package, in an attempt to get some feedback, potential users and collaborators.

This post does not include:

  • Any comprehensive synthetic streamflow generation literature review (see the above-linked blog posts for those).
  • Mathematical details of any individual streamflow generator implementation. I provide the algorithmic details for each generator, along with their source publications, on the SynHydro documentation site.

Content:

  • A note on the creation of this code
  • Package overview
    • Streamflow Generators
    • Ensembles
    • Temporal Disaggregators
    • Validation plotting
  • Documentation
  • A look at some outputs
  • Limitations and future work
  • References

A note on the creation of this code

My initial commit on, what is now the SynHydro repository was almost 3 years ago. At the time, I had been calling it “SGLib” (Synthetic Generation Library) as a nod to SALib which serves a similar purpose for sensitivity analysis methods, and was inspiration for the project.

By the end of 2023, I’d had added implementations of the Kirsch et al. (2013) streamflow generator which has shown up frequently in Reed group research and on this blog, the Thomas-Fiering model which I discussed in a 2024 blog post, and the Gaussian Hidden-Markov Model (HMM).

Eventually, I was searching the literature for other generation techniques, and finding new generators faster than I was implementing them.

When developing the implementation for any synthetic generation model, I tried to implement the method as accurately as feasible as described by it’s source publication reference (see Table 1).

Additionally, whenever I was able to find publicly available source code associated with a publication, I based the SynHydro implementation strongly on the author’s source code. For example, I was able to build the synhydro.MultisiteHMMGenerator based on the code provided by Gold et al., (2024). Sometimes, I needed to translate source code from another language into Python, for example Touskalas et al. (2018a, 2018b) provide two open-source parametric generators (synhydro.SPARTA and synhydro.SMARTA) on GitHub which required translation from R to Python.

With that said, it is important to note that this package was developed with support from LLMs (specifically Claude Code). Claude code has been very helpful in allowing this code to transform from a side-project/hobby into a fully fledged package along with all of the documentation, testing, etc.

All that is to say, there may be bugs! I’ve run diagnostics using all of the generators and confirmed that the resulting stochastic series behave as expected, but diagnostics have not been comprehensive for all 11 generators & 2 disaggregators.

Package overview

From the project README:

SynHydro is a Python library for generating synthetic hydrologic timeseries using a unified, scikit-learn-style API. All generators share a common fit() and generate() workflow, and the library includes validation, drought analysis, plotting, and ensemble data management tools.

SynHydro links:

I’ve not yet taken the steps to get the code up on PyPI, but it can be installed directly from GitHub using:

pip install git+https://github.com/TrevorJA/SynHydro.git

Below, I’ll discuss the Generators, Disaggregators, ensemble data structure and other key package features.

Streamflow Generators

The current release includes 11 synthetic streamflow generator implementations (Fig 1 and Table 1 below).

These generators are grouped/classified into three categories by the nature of their generation scheme, following the classification in Studnicka and Panu (2025) and elsewhere.

The three categories are:

  • Parametric generators fit a probability model to the historical record, then generate new flows from the fitted model.
  • Non-parametric generators resample directly from the empirical distribution without an intermediate fitted model.
  • Hybrid (AKA semi-parametric) generators combine elements of both parametric and non-parametric approaches. Often hybrid generators use a parametric approach for standardizing streamflow marginals or moments along with non-parametric layer for the generation procedure (e.g., bootstrapping).

The Figure below shows an illustration of all generators currently implemented in SynHydro, organizing them based on their output timescale (x-axis), generation method family (y-axis) and whether they are single-site or multi-site in nature.

Each Algorithms page in the documentation provides mathematical details and summaries of the key statistical characteristics of each generator.

Matrix of SynHydro generators organized by output timescale, method family, and single-site or multi-site support

The table below presents the same information, along with the original reference for each model formulation.

Generator NameClassFreq.SitesReference
ThomasFieringGeneratorParametricMSingleThomas & Fiering (1962)
MatalasGeneratorParametricMMultiMatalas (1967)
ARFIMAGeneratorParametricM/ASingleHosking (1984)
SPARTAGeneratorParametricMMultiTsoukalas et al. (2018a)
SMARTAGeneratorParametricAMultiTsoukalas et al. (2018b)
MultiSiteHMMGeneratorParametricAMultiGold et al. (2024)
KirschGeneratorHybridW/MMultiKirsch et al. (2013)
WARMGeneratorHybridASingleNowak et al. (2011)
PhaseRandomizationGeneratorHybridDSingleBrunner et al. (2019)
MultisitePhaseRandomizationGeneratorHybridDMultiBrunner & Gilleland (2020)
KNNBootstrapGeneratorNon-parametricM/AMultiLall & Sharma (1996)

Every generator class uses the same API steps.

  1. Initialize the generator
  2. Use the fit() method prepare and/or fit the generator based provided streamflow data.
  3. Use the generate() method to synthesize/generate new streamflow realizations.

Swapping one generator for another is meant to be a one-line change. Since all generators are currently “direct” generators (generate streamflow directly rather than generating hydrologic model inputs) they all require only streamflow data as the input source. Thus, all generator classes require only the pd.DataFrame of streamflow data as the only necessary input.

Here is a basic monthly example using the Kirsch generator (Kirsch et al., 2013) for monthly generation:

import synhydro

# daily and monthly dataframe of streamflow
Q_obs = synhydro.load_example_data()
Q_monthly = Q_obs.resample("MS").sum()

generator = synhydro.KirschGenerator()
generator.fit(Q_monthly)
ensemble = generator.generate(n_realizations=50, n_years=30, seed=42)

Ensembles

Every generator returns an Ensemble data object that stores the synthetic timeseries data along with some basic metadata. The Ensemble object maintains a standard data formatting structure, designed to be passed to later disaggregator and plotting functions.

The class stores the data in two equivalent representations that you can switch between as needed:

  • A by_site view (ensemble.data_by_site) returns a dict mapping each gauge name to a DataFrame whose columns are realizations. This is convenient for plotting and gauge-level statistics.
  • A by_realization view (ensemble.data_by_realization) returns a dict mapping each realization ID to a DataFrame whose columns are gauges. This is closer to what most downstream simulation models want.

Ensembles can be saved and reloaded as HDF5 files with ensemble.to_hdf5(path) and Ensemble.from_hdf5(path), which preserves the ensemble metadata (number of realizations, time period, source generator) along with the data. This is useful when generation is the slow step and you want to separate it from any downstream analysis.

All of the plotting functions in synhydro.plotting take an Ensemble as their first argument, so the typical workflow is to fit a generator once, save the resulting ensemble, then reload it and pass it directly into the diagnostic plotting helpers.

Temporal Disaggregators

The SynHydro package currently includes two temporal disaggregators (Table 2 below). To date, the disaggregator methods have not been a focus, so I will be interested in exploring more methods in the future.

DisaggregatorDirectionReference
NowakDisaggregatorMonthly to DailyNowak et al. (2010)
ValenciaSchaakeDisaggregatorAnnual to MonthlyValencia & Schaake (1973)

Each disaggregator class is designed to accept an Ensemble data object as input, and returns a new Ensemble object with data at the new output frequency.

Validation plotting

The synhydro.plotting module collects a set of utilities for comparing an Ensemble against an observed reference.

Each function takes an Ensemble data object as its first argument, an observed series as an optional overlay, and returns (fig, ax). Most ensemble-vs-time plots default to a median line with a 10th-90th percentile band.

A short summary of what is currently available:

  • plot_timeseries, plot_flow_ranges, plot_seasonal_cycle for ensemble traces and aggregated ranges over time.
  • plot_flow_duration_curve, plot_cdf, plot_histogram, plot_monthly_distributions for marginal and seasonal distributions.
  • plot_autocorrelation, plot_spatial_correlation for temporal and across-gauge dependence.
  • plot_drought_characteristics, plot_ssi_timeseries for SSI-based drought diagnostics.
  • plot_validation_panel is a single five-panel figure that bundles the most common marginal and seasonal checks.

The plotting API page in the docs has the full set of plotting tools along with their descriptions for those who are interested.

Documentation

The documentation site is at trevorja.github.io/SynHydro.

If you are interested in exploring the package deeper, I’d recommend starting with:

  • The Algorithms Overview page describes each generator’s underlying model and which statistical properties it is designed to preserve.
  • The Tutorials includes example workflows to get you started with generating your own ensembles.

A look at some outputs

A flow duration curve is one of many summary views of a generator’s output, and reproducing one is necessary but not sufficient. It is still a reasonable place to start. The figure below shows an FDC at gauge USGS-01434000 for every generator in the library, fit on the same eighty years of daily flow at four upper Delaware sites available through load_example_data().

Rows correspond to the timescale each generator produces output at, panel titles are colored by family, and each panel compares the historical record (black line) against the shaded range across synthetic realizations.

Flow duration curves for all SynHydro generators

Again, this figure is not meant to be a comprehensive diagnostic, since many of the key statistical properties (flow seasonality, spatial correlation across gauges, temporal autocorrelation, drought duration statistics) are not visible here. However, at a glance we can see the generators all reproducing the streamflow distributions from the historical FDCs relatively well.

Limitations and future work

The SynHydro package is a continual work in progress.

A few directions I would like to develop further include:

  • Inclusion of machine learning based generators.
  • More disaggregators options.
  • Improved ability to modify and manage generator hyperparameters, parameters, and other settings.
  • Improved plotting functionality.
  • Climate-conditioned generators that can ingest GCM or downscaled-projection inputs.

I have tested the library against the examples and references I had on hand, but there are likely edge cases and outright mistakes I have not caught yet. If you find something that looks wrong, please open a GitHub issue with a small reproducible example. Collaborators are welcome. The contributing guide in the repo walks through the testing and documentation expectations.

Thanks for reading. If you end up trying SynHydro for your own purposes, or have recommendations for improved functionality, I would be glad to hear about it.

References

Brunner, M. I., Bardossy, A., and Furrer, R. (2019). Technical note: Stochastic simulation of streamflow time series using phase randomization. Hydrology and Earth System Sciences, 23, 3175-3187. https://doi.org/10.5194/hess-23-3175-2019

Brunner, M. I., and Gilleland, E. (2020). Stochastic simulation of streamflow and spatial extremes: a continuous, wavelet-based approach. Hydrology and Earth System Sciences, 24, 3967-3982. https://doi.org/10.5194/hess-24-3967-2020

Gold, D. F., Reed, P. M., and Gupta, R. S. (2024). Exploring the spatially compounding multi-sectoral drought vulnerabilities in Colorado’s West Slope river basins. Earth’s Future, 12. https://doi.org/10.1029/2024EF004841

Hosking, J. R. M. (1984). Modeling persistence in hydrological time series using fractional differencing. Water Resources Research, 20(12), 1898-1908. https://doi.org/10.1029/WR020i012p01898

Kirsch, B. R., Characklis, G. W., and Zeff, H. B. (2013). Evaluating the impact of alternative hydro-climate scenarios on transfer agreements: A practical improvement for generating synthetic streamflows. Journal of Water Resources Planning and Management, 139(4), 396-406. https://doi.org/10.1061/(ASCE)WR.1943-5452.0000287

Lall, U., and Sharma, A. (1996). A nearest neighbor bootstrap for resampling hydrologic time series. Water Resources Research, 32(3), 679-693. https://doi.org/10.1029/95WR02966

Matalas, N. C. (1967). Mathematical assessment of synthetic hydrology. Water Resources Research, 3(4), 937-945. https://doi.org/10.1029/WR003i004p00937

Nowak, K., Prairie, J., Rajagopalan, B., and Lall, U. (2010). A nonparametric stochastic approach for multisite disaggregation of annual to daily streamflow. Water Resources Research, 46(8). https://doi.org/10.1029/2009WR008530

Nowak, K., Rajagopalan, B., and Zagona, E. (2011). Wavelet Auto-Regressive Method (WARM) for multi-site streamflow simulation of data with non-stationary spectra. Journal of Hydrology

Studnicka, S., and Panu, U. S. (2025). Techniques and developments in stochastic streamflow synthesis-A comprehensive review. Encyclopedia, 5, 198. https://doi.org/10.3390/encyclopedia5040198

Thomas, H. A., and Fiering, M. B. (1962). Mathematical synthesis of streamflow sequences for the analysis of river basins by simulation. In A. Maass, M. M. Hufschmidt, R. Dorfman, H. A. Thomas Jr., S. A. Marglin, and G. M. Fair (Eds.), Design of Water Resource Systems (pp. 459-493). Harvard University Press.

Tsoukalas, I., Efstratiadis, A., and Makropoulos, C. (2018a). Stochastic periodic autoregressive to anything (SPARTA): Modeling and simulation of cyclostationary processes with arbitrary marginal distributions. Water Resources Research, 54(1), 161-185. https://doi.org/10.1002/2017WR021394

Tsoukalas, I., Makropoulos, C., and Koutsoyiannis, D. (2018b). Simulation of stochastic processes exhibiting any-range dependence and arbitrary marginal distributions. Water Resources Research, 54(11), 9484-9513. https://doi.org/10.1029/2017WR022462

Valencia, R. D., and Schaake, J. C. (1973). Disaggregation processes in stochastic hydrology. Water Resources Research, 9(3), 580-585. https://doi.org/10.1029/WR009i003p00580