swxg
swxg is a Python package for modern stochastic weather generation. It is suitable for any use case where traces of precipitation, temperature, and its internal variability across a single or multiple sites impact the model outcomes to be investigated. It expands on existing generators which are often designed for more niche applications like replicating weather regimes, downscaling global circulation models, or using weather as an intermediate step in determining flood or drought indices.
All that is needed to use swxg is a set of data with precipitation and temperature observations, one or more locations where the observations were collected, and a timestamp for each of the collected observations. swxg quickly generates arbitrarily-long sequences of monthly or daily weather variables that match the spatial and temporal correlations from input observations by:
- fitting observed precipitation individually to a (Gaussian mixture) hidden Markov model with 1 or more hidden states;
- fitting both observed precipitation and temperature with hydroclimatic copulas;
- sampling precipitation from its fit, disaggregating to finer resolution where necessary, and;
- conditionally sampling temperature from the sampled precipitation and its fit, disaggregating to finer resolution where necessary
Dependencies
The required dependencies to use swxg are:
Python >= 3.10copulae >= 0.8copulas >= 0.10, < 0.12hmmlearn >= 0.3matplotlib >= 3.8numpy == 2.0pandas >= 2.1scikit-learn >= 1.4scipy >= 1.15statsmodels >= 0.14, < 0.15
Note that these required packages will be automatically downloaded when you install this package.
Installation
To install swxg from PyPI with pip:
pip install swxg
Alternatively, you can install from this repository:
git clone https://github.com/xthames/swxg.git
cd swxg
pip install .
Contributing, Reporting Issues, and Seeking Support
To contribute, please fork this repository and create your own branch. If you are unfamiliar with that process the corresponding documentation on how to do so from FirstContributions is a good place to start. To report issues and seek support, please use the GitHub Issues tab for this repository.
Important Links
If your work uses swxg, please cite:
- [JORS PAPER IN REVIEW], specifically for the software
- Thames et al. (2026, preprint), if relevant to applied (first) use case
Known Model Limitations
Because swxg is a semi-parametric model, the quality of the input dataset will be reflected in: (1) the confidence of the fits for precipitation and the copulas, and; (2) the resolution of the generated weather.
- To fit precipitation and the copulas
swxgaggregates precipitation and temperature both annually and monthly, meaning that more complete years of input data will produce better fitting. AUserWarningwill appear if you use fewer than 30 years of input data; anotherUserWarningwill appear if more than 20 sites are considered. Fitting will still procede regardless, but it is strongly recommended to validate the precipitation and copula fitness through additional metrics if either condition is met. - When generating weather
swxggives the option to determine its output resolution, either at themonthlyordailyscale. How resolved the generated weather can be is determined by the input dataset:monthlyinputs can be resolved tomonthlyoutputs;dailyinputs can be resolved to bothdailyandmonthlyoutputs. AUserWarningwill appear when trying to resolvedailyoutputs frommonthlyinputs. If attempted, themonthlyresolution will output instead. Subdaily inputs are accepted but generating at the subdaily scale is not yet implemented, and so subdaily data is aggregated to daily.
Metadata
Release files for swxg 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swxg-0.4.1.tar.gz | 492.8 kB | Without provenance | Details for swxg-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swxg-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for swxg-0.4.1-py3-none-any.whl |
Total release size: 990.5 kB
Release files / swxg-0.4.1.tar.gz
| Download URL | swxg-0.4.1.tar.gz |
|---|---|
| Size | 492.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b27ca41a112945b484094cf3ff0f917b08615c408dc84f7c8d5fe2c4b7d9df0c
|
|
BLAKE2b-256 checksum How to use checksums |
76d87bd611481d6d86ee751d6f07279872645b6011374c0584046012891fe0ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|
Release files / swxg-0.4.1-py3-none-any.whl
| Download URL | swxg-0.4.1-py3-none-any.whl |
|---|---|
| Size | 497.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9c90c3c7379cdf6b930276e04ab8edfe866ca60831a1f6db182471b461eb4f2d
|
|
BLAKE2b-256 checksum How to use checksums |
20a9e69172242bc77acf8dd1f368f938f533678404c8430110591e6fe038f140
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|
Security for swxg 0.4.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.