{'fraction_non_alphanumeric': 0.030405405405405407, 'fraction_numerical': 0.002329916123019571, 'mean_word_length': 4.948948948948949, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A Data Scientist's Guide to Streamflow Prediction

In recent years, the paradigms of data-driven science have become essential components of physical sciences, particularly in geophysical disciplines such as climatology. The field of hydrology is one of these disciplines where machine learning and data-driven models have attracted significant attention. This offers significant potential for data scientists' contributions to hydrologic research. As in every interdisciplinary research effort, an initial mutual understanding of the domain is key to successful work later on. In this work, we focus on the element of hydrologic rainfall--runoff models and their application to forecast floods and predict streamflow, the volume of water flowing in a river. This guide aims to help interested data scientists gain an understanding of the problem, the hydrologic concepts involved, and the details that come up along the way. We have captured lessons that we have learned while"coming up to speed"on streamflow prediction and hope that our experiences will be useful to the community.


The Problem in a Nutshell
At its core, streamflow prediction is a spatio-temporal prediction effort that tries to predict the amount of water flowing past a given point of a river, given the past measurements of river streamflow, past meteorological variables known as forcings (e.g., air temperature, humidity, amount of precipitation), and geophysical variables (e.g., land cover, soil, elevation).
Thus, models used for this purpose take as input meteorological forcings and geophysical information and output a sequence of streamflow predictions at some temporal granularity at some location. This temporal granularity can range anywhere from hours to years: During flood events, we might need models at an hourly scale to predict exact peak times, whereas climate change analyses focus on changes over several years.
Under the influence of climate change, both floods and droughts are likely to become increasingly common and pose huge dangers on humans, flora, and fauna [8,18]. During these extreme events, accurate streamflow predictions are an important prerequisite for mitigative action, as they allow authorities to proactively warn citizens, manage water regulation facilities, and direct help to where it will be needed the most. term watershed may also refer to a drainage divide: the border between two neighboring catchments, where precipitation divides into water flowing in one or the other catchment.) We call a catchment a gauged basin if its outlet is equipped with a gauging station to measure the time series of actual streamflow (known as hydrograph). Catchments without gauging station are called ungauged basins. Mostly, the delineation of catchments is based on topological information, a natural implication of water following downward gradients. Clearly, the size of a basin depends on the selected outlet. The further upstream along a river the outlet, the smaller the basin. In addition, rivers and lakes drain into each other. Consequently, basins contain nested sub-basins (or sub-catchments or sub-watersheds). The example in Figure 1 illustrates these concepts: The solid black line outlines an ungauged basin, whereas the gauge station at the city represents the outlet of a gauged sub-basin (dashed gray line). More formally, we can think of the river network as a directed graph where each node is a sub-basin or grid cell and each edge represents a downstream-relationship. For instance, an edge from node A to B indicates that all water flowing out of cell A drains into cell B. The gray arrows in Figure 1 show a few example downstream relations between grid cells-note how the arrows point to the adjacent cell with the lowest elevation (i.e., with the greenest hue).
Hydrologists distinguish two concepts: runoff and streamflow. Runoff refers to an amount of water that flows inside or between basins and their building blocks such as hillslope. This can happen on the surface (surface runoff), near the surface (interflow), or through the groundwater (groundwater seepage). Commonly, the runoff is expressed in millimetres during a fixed time period such as one day. An intuitive explanation for this notion is the hypothetical depth of water if all outflowing water was equally distributed over the geographical area of interested (e.g., a grid cell, hill slope, or basin).
Streamflow on the other hand is the amount of water that flows through the cross-section at a point along a stream and usually expressed as cubic meters per second. We can think of streamflow as the aggregation of runoff from across the whole basin that drains into a river. At any point in a river, hydrologists can set up a gauging station that measures streamflow. An often neglected yet important detail of these measurements is that they come with an uncertainty. Depending on the gauging technique, the measurements can have errors of 5 % or more. This error can increase during a flood event and in the worst case, the flood can sweep away the whole gauging device [5].
Note that runoff is defined for arbitrary areas, even if there is no stream in the area. Hence, we can talk about the runoff in or from an area; this is the amount of water that the area contributes to the streamflow. Streamflow, meanwhile, is only defined at points on a stream or river, so we cannot talk about the streamflow at arbitrary points in space.
While it is relatively easy to measure streamflow at any point along a stream, runoff is much harder to measure-especially for large basins. Hence, models are often evaluated against streamflow rather than runoff. This is also why streamflow modeling is commonly called rainfall-runoff modeling: internally, many models predict runoff, but the evaluation is based on streamflow. To obtain streamflow from runoff values, hydrologists use routing models. A routing model is based on the directed graph of downstream-relations in the river network. During routing, we multiply the runoff in mm d −1 by the area (including unit conversion to m d −1 and m 2 ), which yields the total water volume in m 3 per day. Next, we accumulate the runoff along the edges of the routing graph to obtain daily streamflow. To comply with SI base units, we finally normalize the streamflow to per-second values in m 3 s −1 .
Hence, in a nutshell, streamflow is routed runoff at a point along a stream.

Understanding the Types of Input Data
There are two broad types of input data: forcings and geophysical data. Forcings are time series of meteorological data such as precipitation or temperature. Their name stems from the fact that these data are needed to run, or force, the model. Geophysical data are static (non-time-series) data that provide information such as land cover, soil, or elevation. Clearly, these variables are not actually static; land usage, for example, changes over time-but generally at a much slower pace than meteorological information. In most cases other than long-term simulations (for example, multi-decade climate change analyses), such data can be safely treated as static.
If we forecast into the future, we have no choice but to rely on forcings that are predictions themselves, for instance, from a numerical weather prediction model. For simulations of historical streamflow, the forcings can, if available, be observed data. Since observations are generally sparse, however, we commonly use forcings that are generated by other models, for instance, climate reanalyses. Climate reanalyses are a type of data product that use one consistent parameterization to simulate long periods of historical meteorologic variables. They use data assimilation techniques to ensure that the output is as close to the available observations as possible. What makes these reanalysis products valuable compared to short-term weather predictions is their consistency: environmental agencies update their weather prediction models frequently, which leads to inconsistent variable contents over time.
The data a model takes as input can come in two forms, depending on whether the model is lumped, semi-distributed, or fully-distributed. Lumped models take forcings and geophysical data that are aggregated to a basin-level as input. A lumped model that predicts streamflow for a certain basin will need "pointwise" forcing time series and geophysical data. For example, a lumped model of the gauged sub-basin in Figure 1 might take as input the sub-basin's minimum and maximum temperature, the cumulative precipitation, and the mean elevation calculated across all cells within the dashed sub-basin outline.
Most publicly available streamflow datasets are well-suited for lumped models, as there is a long history of streamflow recordings through gauging stations along rivers, where scientists have been measuring streamflow and meteorological variables for decades. One common collection of such datasets are the Catchment Attributes and Meteorology for Large-sample Studies (CAMELS) that contain data for basins across the continental United States [1,17]. Recently, similar datasets for basins in Chile, CAMELS-CL [2], and Great Britain, CAMELS-GB [6], have been published, and datasets for other regions are in development. It is important to note, however, that each of these datasets is based on its own meteorological forcing product. Consequently, the resulting lumped datasets have different biases and we cannot simply apply a model that was, for example, trained on the U.S.-CAMELS to basins from the Chilean version.
Distributed and semi-distributed models take a spatial grid of input variables, although semidistributed models internally aggregate the grid cells into response units, as we will see in subsection 2.3. For example, a distributed model of the gauged sub-basin in Figure 1 would take as input forcings and geophysical data individually for each cell within the dashed sub-basin outline.
Such gridded forcings for large spatial extents are much harder to get hold of. As it is impossible to actually measure the meteorological variables in all grid cells, these datasets require either computationally expensive simulations that spatially interpolate between the available measurements, or data acquired through remote sensing, which is costly and not accurately possible for all variables of interest. To make things worse, the different available measurements will likely need preprocessing to be used within one dataset, as they might be in different units, use different measurement techniques, or have other inconsistent characteristics.

Understanding How
We're Actually Predicting

Spectrum of Models
There are various mutually orthogonal ways to classify hydrologic rainfall-runoff models. First, we distinguish between process-based models that explicitly model hydrologic processes and data-driven models that encompass machine learning models.
Process-Based Models -Process-based rainfall-runoff models are simplified representations of the underlying dominant natural processes that generate runoff or streamflow from rainfall. The hydrologic processes involved are, for example, evaporation from the surface or transpiration from plants (both of which depend on solar radiation), or soil infiltration (which depends on the soil's capacity of holding water; different soil types have different water capacities). Process-based models are also sometimes called physically-based models [3], which is somewhat misleading, since these models model simplified abstractions rather than the actual physical processes (in fact, the actual processes are still partly unknown). Process-based models usually consist of model states and model parameters that govern the behavior of model states. Model parameters are the "knobs" that are adjusted during the training phase (which hydrologists call the calibration phase). Data scientists may compare these parameters to the weights in a neural network (note, this is not to say that hydrologic models are neural networks, but only to illustrate the kind of parameter). Model states (or storages) meanwhile are "memory cells" that have an initial value, and are updated by the model equations, depending on the input. Such states can, for example, simulate current snow depth or soil moisture. Sub-zero temperature, combined with precipitation, will increase the value of the snow depth state. This snow will eventually melt, so the model needs the state as a memory of snow events. In our illustrative comparison, these states are similar to memory states in a recurrent neural network, with the difference that hydrologists have a physical interpretation of a state's value. To provide good predictions after calibration, it is key that the initial model states are adjusted to the beginning of the test period. For instance, an initial snow depth state of zero might not be suitable for a test period in winter. To ensure good initial states, as it usually hard to estimate the initial states, hydrologists prepend warm-up periods before the training and test periods. During warm-up, the model takes input data and updates its states based on the input, but the period is not considered in evaluation metrics. As the test period commonly immediately succeeds the training period, there is often no need for explicit warm-up before testing. The model simply runs through the training warm-up and training periods before it starts to generate test predictions. Refer to Appendix A for an example of a simple process-based model. Data-Driven Models -Data-driven models on the other hand are what is familiar to data scientists: machine-learned models that do not try to model any physical dependencies, but just generate a prediction based on historical training data. Since we try to predict a continuous time series, we generally use regression models. A common architecture for time-series modeling are Long Short-Term Memory networks (LSTMs), but we can also apply models that are not directly tailored to time-series prediction such as regression tree-based models [10,15]. In this case, we simply feed the model a fixed-history window of forcings to predict one time step of streamflow. Of course, one can image hybrid models that blur the lines between process-based and data-driven approaches-a research direction known as theory-guided data science or physics-guided machine learning [13,14]. For instance, we might train a data-driven regression model to perform error correction on a processbased model, and obtain a hybrid ensemble model.
Another way to classify streamflow models is grounded in their degree of spatial distribution. Models can be either lumped, semi-distributed, or distributed.
Lumped Models -Lumped models do not operate on gridded data at all. Instead, they require aggregated, or lumped, forcings for one point in space as input, and provide a prediction for this point in space. Hence, if our forcings are spatially distributed, we need to aggregate the variables across the whole basin before passing them to the model. An example for a process-based lumped model is the Large Basin Runoff Model (LBRM), used in production for the U.S. Army Corps of Engineers' (USACE) water level predictions in the Great Lakes region [7]. Up to now, most purely data-driven models are also lumped setups [10,15]. The reason for this is that a lumped model's design is much more straight-forward, since it does not have to deal with differently-sized and -shaped basins and the resulting varying input dimensions.
Distributed and Semi-Distributed Models -Distributed models are computationally the most expensive, as they operate on gridded forcings and output runoff for each grid cell. They require meteorological forcings and potentially geophysical input data for an entire area.
Semi-distributed models fall conceptually between lumped and fully-distributed models. These models operate on arbitrarily-shaped polygonal spatial extents, sometimes called hydrologic response units, or HRUs. The model assumes the area within each unit to have identical hydrologic properties. HRUs are usually derived from the overlay of various geophysical maps, such as soil, vegetation, and slope characteristics. Each continuous parcel of identical properties forms a response unit. Although semi-distributed models might take fully-distributed forcing grids as input, they will internally process them per HRU and, for instance, only have one set of parameters per HRU rather than one per grid cell. Hence, semi-distributed models are in some sense lumped models at the scale of HRUs rather than the scale of entire catchments. As the HRUs will usually be larger than grid cells in distributed models, semi-distributed offer a compromise between computational efficiency and prediction accuracy. One example for a semi-distributed model is the Variable Infiltration Capacity model (VIC) [12,16].

Model Transferability
Although a data scientist might speak generically about models making predictions, hydrologist are careful to distinguish between distinct types of predictions, depending on the temporal and spatial domains to which we apply a model: Transferability in Time: Simulation, Forecasting, and Hindcasting Models -Simulation models predict past streamflow-they try to reproduce past system states. Forecasting models predict streamflow for future dates. Of course, it is entirely possible to act as if the input were only available up to a certain time step in the past, and then "forecast" the past streamflow after this time step; this process is known as hindcasting. The word prediction can, meanwhile, refer to any of these classes. We refer to Beven and Young [4] for even more fine-grained distinctions between different prediction models in the hydrologic literature.
Transferability in Space: Modeling Across Locations -Many models, especially lumped setups, are designed to be trained and evaluated on one single basin or a fixed set of basins. This means that we cannot expect reasonable predictions when we evaluate the model on basins that were not part of the training procedure, a process known as spatial validation. Instead, these models are only evaluated in temporal validation, where we use the same basins as in training, but a different time period. Clearly, achieving good temporal validation results is much easier than achieving good spatial validation results, as the relationships between forcings and streamflow remain relatively static over time, while the geophysical properties of other basins can make for completely different relationships (although climate change threatens to alter these "static" relations, which may make temporal validation harder in the future). More sophisticated models try to adapt their streamflow generation to the geophysical properties of a basin to achieve some degree of spatial generalization. Further, there exist lots of so-called regionalization techniques to transfer a model to a new set of basins, for instance, by scaling the predictions according to the basin area. Forcing variables for lumped and semi-distributed or distributed models Σ R σ or R σ×(h×w) Static, non-time-series model input for lumped and semidistributed or distributed models

Performance Metrics
Given time series of streamflow ground truth y and predictionsŷ, there are a variety of metrics to quantify the error. A very common metric is the Nash-Sutcliffe model efficiency coefficient (NSE): y denotes the mean observed streamflow, hence, the denominator is the variance of the streamflow observations y. Equation 1 shows that NSE is strongly correlated with the mean squared error (MSE), which will be more familiar to data scientists [11]. NSE values range from −∞ to 1, where 1 corresponds to perfect predictions and 0 corresponds to a model that constantly predicts the station's mean ground truth.
Another common metric is the Percent Bias (PBIAS), which measures the tendency of predictions to be larger or smaller than the ground truth: PBIAS values range between −∞ and ∞, where the best value is zero. If a model's PBIAS is larger than zero, this means that it over-estimates streamflow on average. Conversely, a negative PBIAS corresponds to models that generally under-estimate streamflow.
Related to PBIAS is the concept of water balance. Process-based models are inherently designed in such a way that they conserve mass: they do not generate water out of nowhere. In other words, for any interval of time, the precipitation over a basin equals the sum of evapotranspiration (water that evaporates from the surface or transpiration from plants), streamflow, and changes in water storage (note that for the sake of simplicity, we assume a closed system where adjacent basins do not exchange any water, e.g., through groundwater in-and outflow).

Formal Notation for the Problem
We denote the hydrograph for one gauging station, measured in m 3 s −1 , as Note that hydrologists commonly refer to streamflow as q or Q. We use y to align with the usual notation for dependent variables in the machine learning literature, and denote predictions asŷ. Note that the time steps can arbitrarily granular, but typical step sizes are hourly, daily, monthly, or yearly.
The most important input variables for streamflow prediction are meteorological time-series forcings such as air temperature, precipitation, wind speed, etc., which we denote with X. In addition to the time-series forcings X, we denote the geophysical information that is assumed not to change over time with Σ. Examples for static input data include digital elevation, land cover, and soil maps. The exact format of X and Σ depends on whether the model is lumped or (semi-)distributed. For lumped models, the input data are aggregated to one single basin-wide time series for each of the σ geophysical and the d forcing variables: For (semi-)distributed models, the input data are a spatially-distributed grid of cells for each geophysical or meteorological variable. The shape of these grids is a discretization of the basin shape, but for simplicity we denote it as h × w grid cells: . . .
In the standard setup with gauged basins, along with Σ we're given D = {(X t , y t )} T t=1 as training data, which directly aligns with the standard supervised machine learning setup. I.e., our task is to learn the parameters θ of a model f that minimize some loss or maximize some metric (see subsection 2.4): f (Σ, X t−k+1 , . . . , X t ; θ) =ŷ t It is important to note that the model f does not take past streamflow as input. This may seem unreasonable from a mere prediction-quality viewpoint, since streamflow usually has a high autocorrelation. In hydrology, however, hydrologists are not only interested in obtaining good predictions, but also in explaining the physical drivers of streamflow. Clearly, a model that requires past streamflow to provide good predictions does not fully capture the physical processes behind streamflow: Water that has already passed a gauging station can no longer affect that station's streamflow. Further, we might want to apply the model to ungauged basins, where simply no measurements exist that could be used as input.
In many operational forecasting scenarios, however, we care much more about accurate predictions than hydrologic understanding. In these cases it does make sense to explicitly use previous time steps of streamflow to generate predictions. This procedure is called data assimilation: models explicitly use streamflow values y t−k+1 , . . . , y t−1 to predict streamflowŷ t (or, when forecasting the future, they useŷ t−k+1 , . . . ,ŷ t−1 ). Process-based models that perform data assimilation usually do so by changing internal model states, while model parameters remain fixed after the initial calibration. Forecasting without assimilation is called open-loop forecasting.
The above problem setup is for a single gauge, but ideally, we would strive for a model that applies universally to any basin-even if it does not contain a gauging station. This motivates the case of ungauged basins, where we don't have the ground truth y for (some of) the basins that we're predicting. That is, we are attempting to learn models from one location and apply it to another-the location can be nearby (e.g., in the same watershed) or halfway around the world.  To illustrate the concepts of parameters and storages that process-based models use, we introduce the ABC-Model [9]. It is a simplistic educational model that is not used in practice, but nevertheless helpful to illustrate a lumped process-based model (some would argue that its high level of abstraction makes it not truly process-based but rather purely conceptual, but this discussion is out of scope for this introduction). The model only takes a one-dimensional precipitation time-series as input. Figure 2 visualizes the schematic setup with three parameters, a, b, and c, and one storage (or model state) G. Parameter b represents evapotranspiration, the fraction of rain that evaporates or transpires from the soil, lakes, and plants and consequently never affects streamflow. a models the fraction of precipitation that trickles through the soil into the groundwater storage G. Finally, c is the fraction of groundwater that flows from the storage into the stream at each time step.
This schematic setup translates into the following equations: During model calibration, we search suitable values for the parameters a, b, c. In the warm-up period, we start with some initial value for G 1 , and generate predictions. We discard the predictions right away, but keep the updates to G. Finally, we can test the model on the time span that immediately follows the warm-up phase.