Requires C++23 (e.g., -std=c++23 for GCC/Clang, /std:c++latest for MSVC).


API Reference · Usage Guide · Data and Method · Releases
Daily weather for any place on land and any date: the low and the high, rain or snow and how much, thunder, cloud, humidity, wind, sunrise, sunset and hours of sunshine, drawn around the place's 1991-2020 climate normals so that thirty generated years look like thirty real ones.
2024-01-15: rain, 6.8 to 9.4 °C, 2.8 mm
2024-01-16: light rain, 5.4 to 10.2 °C, 0.3 mm
2024-01-17: light rain, 6.7 to 8.7 °C, 1.2 mm
2024-01-18: mostly cloudy, 4.1 to 9.4 °C
Features
- Any Place, Any Date. Give a latitude and longitude (or leave them out for a place drawn by land area) and any date. The climate comes from the CRU TS 1991-2020 normals of the nearest cell: a 2-degree grid in
lite, half a degree in full. A point off the coast takes the nearest land's weather up to 100 km out, and reports how far it is. An elevation moves temperatures by the standard lapse rate, and warming shifts them for a warmer climate than the normals'.
- Weather That Behaves Like Weather. Wet days cluster, warm spells last, and some months run wet or cold: a Richardson-type weather generator (a rain Markov chain, gamma-distributed amounts, autocorrelated daily mean and range, month-to-month anomalies), fitted on 162 GHCN-Daily stations and checked against 120 others it never saw. Monthly means, wet days, wet-day amounts, day-to-day spread and year-to-year spread land within a few percent of those stations (see Data and Method).
- Series That Agree. A day's weather depends only on the seed, the place and the date, so the weather of 10 March is the same whether it is asked for alone or inside a series that starts in January, and overlapping series agree.
- Rain, Snow, Sleet and Thunder. The form of precipitation follows the day's temperature, and thunder its heat and rain, both fitted on station records. Twelve conditions from
clear to heavy_snow and thunderstorm, and frost on days below 0 °C.
- The Sun. Sunrise, sunset and day length from NOAA's solar equations, polar day and night included, and the hours of sunshine the day's cloud lets through.
- Hours, Imperial Units and Real Years. Ask for a day's 24 hours (a temperature curve from sunrise to the next night, rain in spells that add up to the day, cloud, wind, humidity and sunshine); for °F, inches and mph; or for any month of 1991-2020 as it really was (a cold winter cold, a drought summer dry), from CRU TS monthly records. All three are opt-in: a plain request gives the same days as before.
- Climate Normals Too.
climate_at(lat, lon) returns the monthly normals a place's weather is drawn around: temperature, diurnal range, precipitation, wet days, humidity, cloud and wind.
- Deterministic Seeding. Per-call
get_weather(request, seed) for reproducible results, and weather::seed() for replaying a previous generation with the same request and data.
- Batch Generation. Generate thousands of results from one seed, on several threads with the same output for any thread count, and stream them as JSON Lines or CSV (see the usage guide).
- Identical Everywhere. A seed gives the same result on every compiler, standard library and CPU (GCC, Clang, MSVC, Emscripten; x86-64 and ARM64), checked by known-answer tests.
- Extensible Data. The climate table is a TSV file you can extend with layers (
extend()): add a station's own normals and the points nearest it use them.
- JSON and Replay.
to_json() on every result, and a signature() recording the seed and the data it came from.
- Compiled-in Data. Define
DASMIG_WEATHER_EMBED to build the lite tier into the program, for WebAssembly and other builds without files.
- Multi-Instance Support. Construct independent
wtg instances with their own data and random engine.
Integration
weathergen.hpp is the library released here. Keep core.hpp and the core/ directory (dasmig-core) in the same directory. Add
Weather Generator library — daily weather for any place and date from climate normals for C++23.
to the files you want to use it in, and supply the resources folder (or define DASMIG_WEATHER_EMBED).
Usage
#include <iostream>
using namespace std::chrono_literals;
paris.
date = 2024y / 1 / 15;
auto day = gen.get_weather(paris, 7);
std::cout << day << '\n';
std::cout << day.to_json() << '\n';
for (const auto& d : gen.get_weather_series(paris, 7, 42))
std::cout << d << '\n';
auto again = gen.get_weather(paris, day.seed());
static wtg & instance()
Access the global singleton instance.
What a weather call asks for.
std::optional< double > longitude
Degrees east, -180 to 180. Set with latitude.
double warming
Degrees Celsius added to every temperature, -10 to 10. The normals are 1991-2020 means (centred on 20...
std::optional< double > elevation
Metres above sea level, -500 to 9000. Temperatures move by the standard lapse rate (6....
std::optional< double > latitude
Degrees north, -90 to 90. Set with longitude, or leave both unset to draw a place on land by area.
std::chrono::year_month_day date
The day (any valid date). A series starts here.
See the usage guide for everything else.
Building
make # example
make test # tests
make bench # benchmarks, results in build/bench.tsv
make test-embed # tests with the lite tier compiled in
make coverage # code coverage
make lint # clang-tidy
make docs # API docs
make embed # regenerate dasmig/weathergen_data.hpp from resources/lite
Compiler Support
Tested with:
- Clang 18+ (
-std=c++23)
- GCC 14+ (
-std=c++23)
- MSVC 19.38+ (
/std:c++latest)
- Emscripten 3.1.74
Dependencies
| Dependency | Version | Bundled | Purpose |
| dasmig-core | 1.3 | Yes (core.hpp, core/) | Platform-independent random engine and distributions, data layers, JSON |
| Catch2 | 3.x | Yes (amalgamated) | Unit testing |
Related Libraries
| Library | Description |
| address-generator | Postal addresses with real streets by place |
| biodata-generator | Procedural human physical characteristics |
| birth-generator | Demographically plausible birthdays |
| city-generator | Weighted city selection by population |
| country-generator | Weighted country selection by population |
| device-generator | Devices, browsers, user agents and IP addresses that fit together |
| email-generator | Email addresses in each country's style |
| entity-generator | ECS-based entity generation |
| interest-generator | Religion, hobbies and favourite media by country, age and sex |
| name-generator | Culturally appropriate full names |
| nickname-generator | Gamer-style nicknames |
| occupation-generator | Employment status, education and occupation by country, age and sex |
| persona-generator | Complete characters composed from the other generators |
| phone-generator | Phone numbers valid in each country's numbering plan |
| relationship-generator | Families around a person: parents, siblings, partners and children |
| trait-generator | Personality traits with conflicts, synergies and Big Five axes |
| user-generator | Complete user records: account, username, email, phone and address |
License
This library is released under the MIT License. The climate data comes from CRU TS and CRU CL 2.0, which have their own terms (the Open Database License); the sources are listed in LICENSE_DATA.txt and doc/data.md.
MIT License
Copyright (c) 2026 Diego Dasso Migotto