|
|
| wtg ()=default |
| | Default constructor — creates an empty generator with no data.
|
| |
|
| wtg (const wtg &)=delete |
| | Not copyable.
|
| |
|
wtg & | operator= (const wtg &)=delete |
| | Not copyable.
|
| |
|
| wtg (wtg &&) noexcept=default |
| | Movable.
|
| |
|
wtg & | operator= (wtg &&) noexcept=default |
| | Movable.
|
| |
|
| ~wtg ()=default |
| | Destructor.
|
| |
| weather | get_weather (const weather_request &request) |
| | Generate one day's weather. Use weather_request{} for the defaults.
|
| |
| weather | get_weather (const weather_request &request, std::uint64_t call_seed) const |
| | Generate one day's weather, deterministically.
|
| |
| std::vector< weather > | get_weather_series (const weather_request &request, int days) |
| | Generate the weather of consecutive days.
|
| |
| std::vector< weather > | get_weather_series (const weather_request &request, int days, std::uint64_t call_seed) const |
| | Generate the weather of consecutive days, deterministically.
|
| |
| climate_normals | climate_at (double latitude, double longitude) const |
| | The monthly normals of the climate cell nearest a point.
|
| |
| std::vector< weather > | get_weather_batch (const weather_request &request, const core::batch_options &options) |
| | Generate a batch of weather results from a seed drawn like get_weather() draws its own.
|
| |
| std::vector< weather > | get_weather_batch (const weather_request &request, const core::batch_options &options, std::uint64_t batch_seed) const |
| | Generate a batch of weather results, deterministically.
|
| |
| template<typename Sink > |
| void | for_each_weather (const weather_request &request, const core::batch_options &options, std::uint64_t batch_seed, Sink &&sink) const |
| | Stream a batch of weather results to a sink without holding the whole batch.
|
| |
| template<typename Sink > |
| void | for_each_weather (const weather_request &request, const core::batch_options &options, Sink &&sink) |
| | Stream a batch of weather results with a batch seed drawn like get_weather() draws its own.
|
| |
| bool | has_data () const |
| | Check whether any data has been loaded.
|
| |
| std::size_t | count () const |
| | Return the number of loaded climate cells.
|
| |
| void | load (const std::filesystem::path &dir) |
| | Load data from a resource directory, replacing all data and layers loaded before.
|
| |
| bool | load (dataset tier) |
| | Load a dataset tier, replacing all data and layers loaded before.
|
| |
| const core::layer_info & | extend (const std::filesystem::path &file, core::layer_mode mode=core::layer_mode::override) |
| | Add a data layer from a TSV file with the climate.tsv columns.
|
| |
| const core::layer_info & | extend_from_string (std::string_view text, std::string source, core::layer_mode mode=core::layer_mode::override) |
| | Add a data layer from TSV text (for example from a WebAssembly host).
|
| |
| const core::layer_info & | extend (core::tsv_document doc, core::layer_mode mode=core::layer_mode::override) |
| | Add a data layer.
|
| |
| bool | load_history () |
| | Load the months of 1991-2020 for historical requests, from the compiled-in copy or resources/history/history.tsv.
|
| |
| void | load_history (const std::filesystem::path &file) |
| | Load the months of 1991-2020 from a file.
|
| |
| bool | has_history () const |
| | Check whether historical requests can be served.
|
| |
| const std::vector< core::layer_info > & | layers () const |
| | The data layers loaded, in order.
|
| |
| std::uint64_t | data_hash () const |
| | Hash of the loaded data, recorded in each result's signature().
|
| |
Weather Generator: daily weather drawn around monthly climate normals.
A Richardson (1981) type weather generator: rain falls by a two-state Markov chain, wet-day amounts are gamma distributed, the daily mean temperature and the daily range follow the season with residuals from a lag-1 autoregressive process, months carry their own anomalies, and cloud, humidity and wind follow the wet and dry days. Its parameters come from the place's monthly normals (CRU TS 4.10, 1991-2020) and from fits on GHCN-Daily stations (doc/data.md).
A day's weather depends only on the seed, the place and the date: the draws of each day come from that day's own stream, and the chains are read back to the day where their state no longer matters. So the weather of 10 March is the same whether it is asked for alone or inside a series that starts in January. Output is identical on every compiler and platform (dasmig-core).
Can be used as a singleton via instance() or constructed independently.
- Thread safety
- Each instance is independent. Concurrent calls to get_weather(request) on the same instance require external synchronisation.
Definition at line 504 of file weathergen.hpp.
| const core::layer_info & dasmig::wtg::extend |
( |
const std::filesystem::path & |
file, |
|
|
core::layer_mode |
mode = core::layer_mode::override |
|
) |
| |
|
inline |
Add a data layer from a TSV file with the climate.tsv columns.
Rows are keyed by key. In the default override mode a row replaces the loaded row with the same key and new keys are added (a station's own normals, say, which then serve the points nearest it); a row with disabled set to 1 removes its key. elevation, area, humidity, cloud and wind may be left out (0 m, never drawn as a random place, 70%, 50% and 3.5 m/s).
- Parameters
-
| file | The layer file. |
| mode | How the layer combines with the data loaded before. |
- Returns
- What the layer did (rows added, replaced, removed, warnings).
- Exceptions
-
| core::tsv_error | If the file cannot be read or a row is invalid; the data is then unchanged. |
Definition at line 753 of file weathergen.hpp.
| std::vector< weather > dasmig::wtg::get_weather_batch |
( |
const weather_request & |
request, |
|
|
const core::batch_options & |
options, |
|
|
std::uint64_t |
batch_seed |
|
) |
| const |
|
inline |
Generate a batch of weather results, deterministically.
Item i is exactly get_weather(request, core::item_seed(batch_seed, options.first + i)), so an item replays on its own, a range can be generated directly, two batches that follow each other equal one, and the output does not depend on options.threads. With no place set, each item draws its own place.
- Parameters
-
| request | What every item is generated from. |
| options | Count, first index, threads and uniqueness (see core::unique_rule; the rule must be made for weather). |
| batch_seed | Seed of the whole batch. |
- Returns
- The results, in index order.
- Exceptions
-
| std::invalid_argument | If the request or options are invalid. |
| std::runtime_error | If no data has been loaded, or a unique batch runs out of attempts. |
Definition at line 639 of file weathergen.hpp.
| void dasmig::wtg::load |
( |
const std::filesystem::path & |
dir | ) |
|
|
inline |
Load data from a resource directory, replacing all data and layers loaded before.
Expects the directory to contain climate.tsv, and reads the land mask from land.tsv when it is there (without one, a point must be within 100 km of a cell). A path that is not a directory, or a directory without climate.tsv, is ignored.
- Parameters
-
| dir | Directory such as resources/lite. |
- Exceptions
-
| core::tsv_error | If the file is malformed. |
Definition at line 701 of file weathergen.hpp.
| bool dasmig::wtg::load |
( |
dataset |
tier | ) |
|
|
inline |
Load a dataset tier, replacing all data and layers loaded before.
lite is a 2-degree grid (5,163 cells), full a half-degree grid (67,213 cells). Uses the compiled-in copy when the library is built with DASMIG_WEATHER_EMBED, otherwise searches resources/, ../resources, weather-generator/resources and ../weather-generator/resources.
- Parameters
-
- Returns
- False when the tier was not found.
- Exceptions
-
| core::tsv_error | If the file is malformed. |
Definition at line 726 of file weathergen.hpp.
| bool dasmig::wtg::load_history |
( |
| ) |
|
|
inline |
Load the months of 1991-2020 for historical requests, from the compiled-in copy or resources/history/history.tsv.
Not loaded by instance() or load(): the table is large (23 MB) and only historical requests read it. It holds, for each 2-degree block of land, each month's temperature, precipitation and wet days against the 1991-2020 normals (CRU TS 4.10); a cell takes the block its point lies in.
- Returns
- False when the file was not found.
- Exceptions
-
| core::tsv_error | If the file is malformed. |
Definition at line 796 of file weathergen.hpp.