tran-SAS v 1 . 0 : a numerical model to compute catchment-scale hydrologic transport using StorAge Selection functions

This paper presents the “tran-SAS” package, which includes a set of codes to model solute transport and water residence times through a hydrological system. The model is based on a catchment-scale approach that aims at reproducing the integrated response of the system at one of its outlets. The codes are implemented in MATLAB and are meant to be easy to edit, so that users with minimal programming knowledge can adapt them to the desired application. The problem of large-scale solute transport has both theoretical and practical implications. On the one side, the ability to represent the ensemble of water flow trajectories through a heterogeneous system helps unraveling streamflow generation processes and allows us to make inferences on plant–water interactions. On the other side, transport models are a practical tool that can be used to estimate the persistence of solutes in the environment. The core of the package is based on the implementation of an age master equation (ME), which is solved using general StorAge Selection (SAS) functions. The age ME is first converted into a set of ordinary differential equations, each addressing the transport of an individual precipitation input through the catchment, and then it is discretized using an explicit numerical scheme. Results show that the implementation is efficient and allows the model to run in short times. The numerical accuracy is critically evaluated and it is shown to be satisfactory in most cases of hydrologic interest. Additionally, a higher-order implementation is provided within the package to evaluate and, if necessary, to improve the numerical accuracy of the results. The codes can be used to model streamflow age and solute concentration, but a number of additional outputs can be obtained by editing the codes to further advance the ability to understand and model catchment transport processes.


Introduction
The field of hydrologic transport focuses on how water flows through a watershed and mobilizes solutes towards the catchment outlets.The proper representation of transport processes is important for a number of purposes such as understanding streamflow generation processes (Weiler et al., 2003;McGuire and McDonnell, 2010;McMillan et al., 2012), modeling the fate of nutrients and pollutants (Jackson et al., 2007;Hrachowitz et al., 2015), characterizing how watersheds respond to change (Kauffman et al., 2003;Oda et al., 2009;Danesh-Yazdi et al., 2016;Wilusz et al., 2017), and estimating solute mass export to stream (Destouni et al., 2010;Maher, 2011).The spatiotemporal evolution of a solute is typically expressed (Rinaldo and Marani, 1987;Hrachowitz et al., 2016) as a combination of displacements, due to the carrier motion, and biogeochemical reactions, due to the interactions with the surrounding environment.
Water trajectories within a catchment are usually considered from the time water enters as precipitation to the time it leaves as discharge or evapotranspiration.As watersheds are heterogeneous and subject to time-variant atmospheric forcing, water flow paths have marked spatiotemporal variability.For this reason, a formulation of transport by travel time distributions (see Cvetkovic and Dagan, 1994;Botter et al., 2005) can be particularly convenient as it allows the transformation of complex 3-D trajectories into a single variable: the travel time, i.e., the time elapsed from the entrance of a water particle to its exit.
While early catchment-scale approaches (see McGuire and McDonnell, 2006) focused on the identification of an appropriate shape for the travel time distributions (TTDs), emphasis has recently been put on a new generation of Published by Copernicus Publications on behalf of the European Geosciences Union.P. Benettin and E. Bertuzzo: Numerical solution to the age master equation catchment-scale transport models, in which TTDs result from a mass balance equation rather than being assigned a priori (Botter et al., 2011).As a consequence, TTDs change through time, as observed experimentally (e.g., Queloz et al., 2015a;Kim et al., 2016) and as required for consistency with mass conservation.This approach has the advantage of being consistent with the observed hydrologic fluxes and follows from the formulation of an age master equation (ME) (Botter et al., 2011), describing the age-time evolution of each individual precipitation input after entering the catchment.The key ingredient of this new approach is the "Stor-Age Selection" (SAS) function, which describes how storage volumes of different ages contribute to discharge (and evapotranspiration) fluxes.The direct use of SAS functions has already provided insights on water age in headwater catchments (van der Velde et al., 2012Velde et al., , 2015;;Harman, 2015;Benettin et al., 2017b;Wilusz et al., 2017), intensively managed landscapes (Danesh-Yazdi et al., 2016), lysimeter experiments (Queloz et al., 2015b;Kim et al., 2016), and reachscale hyporheic transport (Harman et al., 2016), and it has also been applied to non-hydrologic systems like bird migrations (Drever and Hrachowitz, 2017).In principle, applications can be extended to any system in which the chronology of the inputs plays a role in the output composition.
The new theoretical formulation has improved capabilities, including being less biased to spatial aggregation (Danesh-Yazdi et al., 2017) as opposed to traditional methods like the lumped convolution approach (e.g., Maloszewski and Zuber, 1993), but the numerical implementation of the governing equations is more demanding.This can represent a barrier to the diffusion of the new models, preventing their widespread use in transport processes investigation.To make the use of the new theory more accessible, the tran-SAS package includes a basic numerical model that solves the age ME using arbitrary SAS functions.The model is developed to simulate the transport of tracers in watershed systems, but it can be extended to other hydrologic systems (e.g., water circulation in lakes and oceans).The numerical code is written in MATLAB and it is intended to be intuitive and easy to edit; hence minimal programming knowledge should be sufficient to adapt it to the desired application.
The specific objectives of this paper are to (i) provide a numerical model that solves the age master equation with any form of the SAS functions in a computationally efficient way, (ii) show the potential of the model for simulating catchmentscale solute transport, and (iii) assess the numerical accuracy of the model for different aggregation time steps.

Model description
The model implemented in tran-SAS solves the age ME by means of general SAS functions and uses the solution to compute the concentration of an ideal tracer (conservative and passive to vegetation uptake) in streamflow.The model is described here using hydrologic terminology and applications.

Definitions
The general theoretical framework relies on the works by Botter et al. (2011), van der Velde et al. (2012), Harman (2015) and Benettin et al. (2015b).Here, we consider a typical hydrologic system with precipitation J (t) as input and evapotranspiration ET(t) and streamflow Q(t) as outputs.The total system storage is obtained as S(t) = S 0 + V (t), where S 0 is the initial storage in the system and V (t) is the storage variations obtained from the hydrologic balance equation dV /dt = J − ET − Q.
The system state variable is the age distribution of the water storage.Indeed, at any time t, the water storage is comprised of precipitation inputs that occurred in the past and that have not left the system yet.Each of these past inputs can be associated with an age T , representing the time elapsed since its entrance into the watershed.Hence, at any time t the storage is characterized by a distribution of ages p S (T , t).Similarly, discharge and evapotranspiration fluxes are characterized by age distributions p Q (T , t) and p ET (T , t), respectively.Each water parcel in storage can also be characterized by its solute concentration C S (T , t), which in case of an ideal tracer is equal to the concentration of precipitation upon entering the catchment C J (t −T ).Tracer concentration in streamflow is indicated as C Q .A useful, transformed version of the storage age distribution is the rank storage S T , which is defined as S T (T , t) = S(t) T 0 p S (τ, t)dτ and represents the volume in storage younger than T at time t.
The key element of the formulation is the SAS function, which formalizes the functional relationship between the age distribution of the system storage and that of the outflows.Different forms have been proposed to express the SAS function directly as a function of age or as a derived distribution of the storage age distribution, (e.g., absolute, fractional or ranked SAS functions; see Harman, 2015).For numerical convenience, here SAS functions are expressed in terms of cumulative distribution functions (CDFs) of the rank storage, for both discharge ( Q (S T , t)) and evapotranspiration ( ET (S T , t)).Namely, Q (S T , t) is, at any time t, the fraction of total discharge which is produced by S T (T , t).Hence, it is equal to the fraction of discharge younger than T .The corresponding probability density functions are indicated as ω Q (S T , t) and ω ET (S T , t).The main model variables are illustrated in Fig. 1.

The age master equation
The age ME (Botter et al., 2011) can be seen as a hydrologic balance applied to every parcel of water stored in the catchment.Two different equations can be formulated that describe the forward-in-time or the backward-in-time process (Benettin et al., 2015b;Calabrese and Porporato, 2015;  et al., 2016).Here, we focus on the backward form, as it is the most convenient to model solute concentration in streamflow.The backward form of the ME can be written in a number of equivalent forms that have been proposed in the literature (e.g., Botter et al., 2011;van der Velde et al., 2012;Harman, 2015).Here, we employ the cumulative version, which has a less intuitive physical interpretation but a better suitability to numerical implementation.The complete set of equations reads as follows.

Rigon
∂S T (T , t) ∂t + ∂S T (T , t) ∂T = (1) Boundary condition: S T (T = 0, t) = 0 (3) The initial condition S T 0 indicates some initial distribution of the rank storage at time 0. Note that to ensure that p S , p Q and p ET are distributions over the age domain (0, +∞), the SAS functions must verify the condition Q (S T → S(t), t) = ET (S T → S(t), t) = 1.This condition, however, is automatically verified as the SAS functions were defined as CDFs.
The solution of Eq. (1) gives the rank storage S T (T , t), from which the discharge age distributions p Q (T , t) can be obtained as The same reasoning applies to the age distributions and concentration of the evapotranspiration flux.

The SAS functions
As explained in Sect.2.1, SAS functions are CDFs over the finite interval [0, S(t)].A simple class of probability distributions that is suitable to serve as an SAS function is the power-law distribution (Queloz et al., 2015b;Benettin et al., 2017b), which takes the form The parameter k ∈ (0, +∞) controls the affinity of the outflow for relatively younger or older water in storage.Specifically, k < 1 [k > 1] implies affinity for young (old) water, whereas the case k = 1 represents random sampling, i.e., outfluxes select water irrespective of its age.k can be conveniently made time variant (e.g., dependent on the system wetness) to account for possible changes in the properties of the system (see van der Velde et al., 2015;Harman, 2015).Equation ( 6) also requires knowledge of the initial storage in the system S 0 , which can be difficult to estimate experimentally and it is often treated as a calibration parameter.When using power-law SAS functions for both Q and ET, the system only requires three calibration parameters: k Q , k ET and S 0 .Different classes of probability distributions can be used to have more flexibility in the SAS function shape, e.g., the beta (van der Velde et al., 2012;Drever and Hrachowitz, 2017) or the gamma (Harman, 2015;Wilusz et al., 2017) distributions.Such functions can be more difficult to implement numerically, but they are usually available in software libraries.

The special case of well-mixed or random sampling
In case all the outflows remove the stored ages proportionally to their abundance, the outflow age distributions become a perfect sample (or random sample, RS) of the storage age distribution.The SAS functions in this case assume the linear form Q (S T , t) = ET (S T , t) = S T (T , t)/S(t) and Eq. ( 1) has the analytical solution (Botter, 2012) Equation ( 7) can be seen as a generalization of the linear reservoir equation to fluctuating storage.Indeed, in the special case of a stationary system, where J = Q + ET and the ratio J /S is a constant c, Eq. ( 7) takes the simple form p S (T ) = c exp(−c T ).
3 Model implementation

Problem discretization
Equation ( 1) does not have an exact solution, except for the particular case of randomly sampled storage (Sect.2.4).Thus in general a numerical implementation is required.Following the approach by Queloz et al. (2015b) and Harman (2015), the partial differential equation (Eq. 1) is first converted into a set of ordinary differential equations using the method of characteristics.Indeed, along a characteristic line of the type t = T + t 0 , Eq. ( 1) simplifies into an ordinary differential equation in the single variable T : with initial conditions S T (0, t 0 ) = 0.In this context, reformulating the problem along characteristic lines means following the variable S T (T , T + t 0 ), i.e., the fraction of storage younger than the water input entered in t 0 .This can be equally interpreted as the amount of water storage entered after time t 0 .The solution S T (T , T +t 0 ) starts from the value 0, corresponding to the initial time t 0 .Then, as time (and age) grows, S T (T , T + t 0 ) increases when precipitation J introduces younger water into the system and decreases when outfluxes Q and ET withdraw water younger than T .Water entered after t 0 gradually replaces the water entered before t 0 and for very large T the solution reaches (asymptotically) the total storage in the system, as no water that had entered before t 0 is still present in the system.We discretize time and age using the same time steps T = t = h, resulting in T i = i •h and t j = j •h, with i, j ∈ N and we use the convention that the discrete variables T i and t j refer to the beginning of the time step.To simplify the notation, square brackets are used to indicate the numerical evaluation of a function and the indexes i and j are used for T i and t j , respectively.For example, f [i, j ] indicates the numerical evaluation of function f (T i , t j ).The conventions used for the discretization are illustrated in Fig. 2. For numerical convenience and because real-world data often represent an average over a certain time interval, all fluxes (J , Q, ET) are considered as averages over the time step h (e.g., J [j ] = 1/ h (j +1)h j h J (τ )dτ ).As a consequence, storage variations obtained from a hydrologic balance are linear during a time step and each value refers to the beginning of the time step.
To solve Eq. ( 8), we implement a forward Euler scheme.This explicit numerical scheme is intuitive and fast to solve, and its numerical accuracy is shown to be satisfactory for many hydrologic applications (see model verification, Sect.5.1).By terming [i, j ] = (S T [i, j ], t j ), the discretized problem becomes with N indicating the number of time steps in the simulation, and boundary condition S T [0, j ] = 0.In a pure forward Euler scheme, this boundary condition implies that [0, j ] = (0, t j ) = 0, meaning that no input can be part of an output during the same time step.This can be a limitation for catchment applications, where "event" water is often not negligible and it can bear important information on catchment form and function.For this reason, in Eq. ( 9) we use a modified * defined as where e[j ] is an estimate of the youngest water stored in the system at the end of time step j .Such an estimate is obtained here as e[j ] = max(0, J , it is a water balance for current precipitation input using the SAS functions evaluated at a previous time step.The classic Euler scheme is returned if e[j ] = 0.This modification of the classic numerical scheme only affects the behavior of the youngest age in the system and it is a simple and efficient way to account for transport of event water.The accuracy of this numerical scheme is evaluated in Sect.5.1.

Numerical routine
The model solves Eq. ( 9) by implementing an external forloop on j (i.e., on the chronological time) and an internal forloop on i (i.e., on the ages).This means that during one time step j all the characteristic curves (Eq.9) are updated by one time step.The internal loop is implemented using vector operations.The vector length is indicated as n j and it depends on the number of age classes (which is also the number of characteristic curves) that are included in the computations at time j (see Sect. 3.3).At any time step, the two fundamental operations to solve the discretized ME are compute * Q [i, j ] and * ET [i, j ] using Eq. ( 10) compute S T [i, j ] using Eq. ( 9) for i ∈ [1, n j ].
To compute the model output, further operations are required.In particular, which is valid for conservative solutes entering through precipitation; Starting from these basic routines, many additional operations can be implemented to, for example, characterize the nonconservative behavior of solutes or to compute some age distribution statistics.

Additional numerical details
A first issue that the model needs to take into account is that age distributions are defined over an age domain [0, +∞), meaning that the rank storage is made of an infinite number of elements where the oldest elements typically represent infinitesimal stored volumes.To have a finite number of elements in the computations, an arbitrary old fraction of rank storage can be considered as a single undifferentiated volume of "older" water.This allows us to merge a high number of very little residual volumes into a single old pool.Note that the term old should be used carefully as its definition depends on the particular system under consideration and it may differ depending on the characteristic timescales of the solute used to infer water age (Benettin et al., 2017a).The old pool is defined here as the volume S T (T , t) > S th , where S th is a numerical parameter that can be fixed for each different application.S th also defines the age T th , corresponding to S(T = T th , t) = S th , which indicates the oldest age that is computed individually.Numerically, the parameter S th controls the number n j of age classes (or equivalently rank storage volumes) that are taken into account in the computations.S th should be chosen so that the number of elements used in the computations remains small but the numerical accuracy is not compromised.It can be convenient to define a nondimensional threshold f th ∈ [0, 1] such that S th = f th S(t).In this case, a value f th = 0.9 means that the old pool comprises the oldest 10 % of the water storage.When f th = 1 no old pool is taken into account.Once a storage element is merged to the old pool, its individual age and concentration properties cannot be retrieved, but the mean properties of the old pool like the mean solute concentration are preserved.
A second, connected problem regards the initial conditions of the system, i.e., the unknown storage age distribution and solute concentration to be used at the beginning of the calculations.In the absence of information, the initial storage can be considered as one single old pool; hence the initial number of age classes n 0 is equal to 1. Once computations start, new elements are introduced and accounted for in the balance, reducing the impact and the influence of the initial conditions.The old pool gets progressively smaller (and vector length n j larger) until it reaches the stationary value defined by S th .An initial spinup period can be used to initialize the ME balance and reduce the size of the initial old water pool.This is particularly indicated when modeling solutes with long turnover times like tritium.The influence of the initial conditions decreases with time, but given the long timescales that may characterize transport processes, it is likely never completely exhausted.This has little impact on the output concentration but it limits the maximum computable age to the time elapsed since the start of the simulation.
The computational time of a simulation can be reduced by not accounting for zero-precipitation inputs as they have no influence in the balance but increase the number of operations required at each time step.In such a case, however, the position of an element in the vector does not correspond with its age anymore and age has to be counted separately.To keep the model intuitive, we decided to not remove zeroprecipitation inputs.

Application example
Application of the approach requires knowledge of the input or output water fluxes to or from the catchment, the input solute concentration, and the initial conditions for the water storage magnitude and concentration.Then, an SAS function must be specified for each outflow.The code comes with example virtual data that can be used to evaluate the model capabilities.Hydrologic data for 4 years were obtained from recorded precipitation and streamflow at the Mebre-Aval catchment near Lausanne (CH).Evapotranspiration was obtained from regional daily estimates around the Lausanne area and modified to match the long-term mass balance.On average, yearly precipitation is 1100 mm, discharge is 580 mm (53 % of precipitation) and evapotranspiration is 520 mm.The storage variations, computed by solving the hydrologic balance, were normalized to the interval [0,1] to serve as a nondimensional metric of catchment wetness (variable wi).Overall, the data are not meant to be representative of a particular location, but they constitute a realistic set of hydrologic variables to test the model.
The code was run on the example data using the four illustrative shapes for the discharge SAS function listed in Table 1.All simulations share the following settings: 12 h time step, 4-year spinup period obtained by repeating the example data, storage threshold f th = 1 (i.e., no old-pool schematization), initial storage parameter S 0 = 1000, and evapotranspiration SAS function selected as a power law with parame- and ω 2 ) to the random sampling case (ω 3 ) and the preferential release of older waters (ω 4 ).The time-variant power-law SAS (ω 1 ) was obtained by using Eq. ( 6) with a time-variant exponent ), with parameters k Q1 and k Q2 corresponding to the exponent k during the wettest (wi = 1) and driest (wi = 0) conditions.This parameter choice is used for illustration purposes and should not be taken as representative of a general catchment behavior.
Two different examples of solute transport were simulated in the test.In the first case, solute input concentration was generated by adding noise to a sinusoidal wave with an annual cycle.This example can be representative of atmospheric tracers with a yearly period (like stable water isotopes).In the second case, the initial storage was set to a concentration of 100 mg L −1 and any subsequent input was assigned a concentration of 0 mg L −1 , causing the system to dilute.This example can be representative of a diluting system, e.g., a catchment with conservative agricultural inputs like chloride (Martin et al., 2004;van der Velde et al., 2010) that undergoes a step reduction.Results of both examples are shown in Fig. 3.
Each discharge SAS function simulates different transport mechanisms and provides rather different outputs, both in terms of water age and streamflow concentration.In the first solute transport example (Fig. 3a), discharge concentration gets progressively damped and shifted as the SAS function moves from younger-water preference to older-water preference.The travel time distributions extracted for 15 February 2016 (Fig. 3d) show that the median age of streamflow may vary by a factor of 3-8 simply based on the selection of the SAS function (i.e., leaving the storage parameter unchanged).The affinity for younger water is rather typical in catchments, at least during wet conditions, while the release of older water is more representative of soil columns or aquifers.The second solute example (Fig. 3b) evaluates the "memory" of a system, i.e., the time needed to adapt to a new condition.Again, the preferential release of older storage volumes and the implied lack of young water in streamflow makes the system response more damped.However, this also means that the old water gets depleted faster; hence in the long term the trend may be reversed and the residual legacy of the initial conditions may be stronger in systems with a high affinity for younger water.This is visible in Fig. 3b right after year 2, although the effect is very mild in this case.The time-variant SAS function (ω 1 ) is particularly illustrative in this example because it shows that streamflow concentration can increase in time (e.g., around year 1 in Fig. 3b), even in the absence of new solute input, just as a consequence of the changing transport mechanisms.
Overall, these quick examples were used to illustrate the model capabilities and to show that results may change significantly depending on the choice of the parameters.A sensitivity analysis is generally advised to identify the parameters that have the highest impact on model results.For example, previous catchment studies (e.g., Benettin et al., 2017b) highlighted the challenge in constraining the SAS function of ET flux when based on streamflow concentration measurements only.As a consequence, the hypothesis of random sampling for the ET flux is often as valid as the preference for the younger or older stored water, but it is more parsimonious.Different model outputs are affected by parameters in different ways, and water ages (for example the median age, Fig. 3d) are typically more sensitive than solute concentration to parameter variations.The low computational times of the model aid the development of sensitivity analyses.

Model verification
Here we evaluate the numerical accuracy of the model in computing the solution of the age ME (i.e., the rank storage S T ) and streamflow concentration C Q .The numerical model is first evaluated by comparing our modified Euler solution (Eq.9) to a numerical implementation of the analytic solution (Eq. 1).This comparison is only possible for the case  of random sampling (see Sect. 2.4), as no analytic solution is usually available for other transport schemes.Then, the comparison is made for other shapes of the SAS function, approximating the true solution with a higher-order implementation of Eq. ( 8).As in Sect.4, comparisons are made on the example dataset, using daily average fluxes and the sinusoidal tracer input concentration.
For the RS comparison, the analytic solution was obtained by implementing Eq. ( 7) at a daily scale, considering that fluxes are piecewise constant while the storage is piecewise linear during the time step.The numerical solution for the RS was obtained by setting both Q and ET as power laws with parameters k Q = k ET = 1.The numerical model was run for eight different aggregation time steps h: 1, 2, 3, 4, 6, 8, 12 and 24 h.For each run, the resulting streamflow concentration and one rank storage (corresponding to the end of day 2745) were used for comparison with the analytic solution.Models were run for 8 years using 4 years of spinup.To allow direct comparisons across different aggregation time steps, streamflow concentrations were extracted at the end of each day, resulting in eight different time series (one per h) of 2920 elements.The time series were then normalized by the mean and standard deviation of the analytic solution.A time series of model errors on streamflow concentration (err C Q ) was finally obtained from the difference between the analytic and the numerical (normalized) solutions.The rank storage was evaluated on the entire age domain every 24 h (again, to allow comparisons across different time steps).To avoid comparisons between cumulative functions, the rank storage was used to compute the storage age probability density function p S (see Sect. 2.1).The errors on p S were obtained from the difference between the analytic and the numerical solutions.In this case, the error time series (err p S ) consists, for each of the eight aggregation time steps, of 2745 elements.For ad-ditional comparisons, the performance of our numerical implementation (EF * ) was compared to the classic implementation of the forward Euler scheme (EF, i.e., Eq. ( 10) with e[j ] = 0).Results are obtained for four different values of the initial storage S 0 : 300, 500, 1000 and 2000 mm.The standard deviations of err p S and err C Q are shown in Fig. 4 as a function of the aggregation time step.The EF and EF * implementations almost have the same error on p S , indicating that accounting for the event water does not have a major impact on the overall solution of the age ME.However, as different ages do not contribute equally to streamflow, the event water can have a larger impact on streamflow concentration.This is evident in the performance on err C Q , where the modified EF * implementation is about 1 order of magnitude more accurate than the classic Euler scheme.The error is on average smaller than 10 −2 the variance of the C Q signal, which is lower than most measurement errors.The performance on err C Q also shows that the errors tend to grow with decreasing values of the mean storage, i.e., when the storage gets depleted (or filled) faster.The error of the EF * scheme shows a good stability.This is not surprising as the RS case resembles a linear reservoir (see Sect. 2.4) with a coefficient c approximately equal to the mean ratio between the fluxes and the storage J /S during a time step.The stability condition for the Euler forward scheme in the case of a linear reservoir requires that c < 2/ h (no fast decay).In typical hydrologic applications, fluxes are usually much smaller than the storage; hence J /S 1/ h and the EF solution is stable.Results show that the numerical implementation of the ME is satisfactory for the RS solution in terms of both accuracy and stability.However, solutions other than the RS case may be more challenging owing to the nonuniform age selection played by the outflows.For this reason, we tested power-law SAS functions (Eq.6) with different values of the exponent Figure 5. Solute concentration (C Q ) time series obtained from power-law SAS functions with parameter S 0 = 1000 and parameter k ∈ [0.2, 3.0], using a 24 h time step (a).The time series are rather different, as they are progressively more lagged and damped for increasing values of k.The difference with the higher-order solution forms the residual time series (b, same scale as a).Residuals are overall limited and they do not cumulate during the 8-year simulation.k: 0.2, 0.3, 0.5, 0.7, 1, 1.2, 1.5, 2 and 3.The same exponent was used each time for both Q and ET .The model was run with a fixed initial storage S 0 = 1000, for the same timespan and aggregation time steps as in the RS case, and the performance was again evaluated in terms of err p S and err C Q .Given the lack of analytical solutions, we approximated the true solution by using a higher-order implementation (built-in MATLAB solver "ode113"; Shampine and Reichelt, 1997) for Eq. ( 8).An example of the C Q time series obtained from the different values of k for h = 24 h is reported in Fig. 5.The C Q time series are rather different, being progressively more lagged and damped for increasing values of k.Although the residual with respect to the higherorder solution can occasionally be up to 1.3 mg L −1 , it is on average very low compared to the signal.Thus in this case the accuracy of the model is satisfactory even for h = 24 h.Note that for this dataset, the parameters of the SAS function (k = 0.2 and S 0 = 1000) imply that 30 % of the input, on average, becomes output during the same day.The residuals are overall low and do not accumulate during the 8-year simulation, suggesting that even the 24 h simulation is stable.The performance on C Q was further evaluated in the same way as for the RS case: we normalized the concentration signals and obtained the error time series err C Q from the difference with the higher-order solution.Similarly, we computed the errors err p S with respect to the higher-order solution for simulation day 2745.
The standard deviations of the errors are shown in Fig. 6 for different values of k aggregation time steps.The errors on p S grow for increasing of the SAS functions for the younger stored volumes (lower values of k).This indicates that the young water preference is a more chal-lenging numerical condition for the solution of the age ME.This behavior is to be mostly attributed to the errors on the youngest waters in storage.Although we use a modified version of the EF scheme to account for the presence of event water in the outflows (Eq.10), this approximation has some limitations.In particular, the youngest age in storage (e[j ]) is quantified through the SAS function from previous time step; thus it may give rise to errors at the onset of intense storm events.The interpretation of the behavior of the error on C Q (Fig. 6b) is less straightforward as the errors on the solution p S can be amplified in various ways by the different SAS functions.Errors appear not too dissimilar for k in the range 0.5-1.2 and they are all reduced by 1 order of magnitude moving from daily to hourly time steps.The more extreme age selections (i.e., k ≤ 0.3 and k ≥ 2) tend to result in higher errors, although the error magnitude remains low (less than 10 −2 the signal variance) and the solution is stable.
These examples suggest that the behavior of the system can be interpreted using a (nonlinear) reservoir analogy.Each individual water parcel can be seen as a depleting reservoir that decreases in time owing to the particular outflow removal (Eq.8).removal is mediated by the SAS functions; thus it can become large corresponding to high values of ω(S T , t), potentially leading to an unstable fast decay.The depletion pattern of the reservoir is rather complex as it is nonlinear and it changes at every time step, but it suggests that very pronounced age selections should be considered carefully and checked for potential numerical instabilities.Note that for illustration purposes the effects of the two power-law SAS function parameters k and S 0 were presented separately (Figs. 4 and 6), but they should be considered together as lower storage values may enhance the selection of younger  The error time series are summarized through their standard deviation.Each plot shows the model performance for several shapes of the SAS function, parameterized as a power-law distribution with parameter k (Eq.6).The color code is the same as in Fig. 5.The random-sampling case (i.e., k = 1) is indicated in black and it is equivalent to the curves featuring S 0 = 1000 in Fig. 4.
or older waters and increase the numerical errors.The model was tested here for several shapes of the SAS functions on a realistic hydrochemical dataset.Although every dataset is different and it would be impossible to perform a model verification valid for all applications, these results provide some first guidelines as to where the explicit numerical implementation may become critical.

Model applicability, limitations and perspectives
The model is based on a catchment-scale approach, so it only requires catchment-scale fluxes like precipitation, discharge and evapotranspiration.These fluxes can often be measured (or modeled in the case of ET) without the need for a full hydrologic model.Moreover, the pure SAS function approach implies that, differently from previous approaches (e.g., Bertuzzo et al., 2013;Benettin et al., 2015a), the transport equations which are solved in the model are completely decoupled from the way fluxes were obtained.This notably reduces the number of involved parameters and it simplifies the applicability of the model to different datasets and contexts.Although more research is needed to classify the expected shapes of the SAS functions based on measurable catchment properties, one can quickly obtain first-order evaluations of solute transport by using SAS functions already tested in the literature (e.g., van der Velde et al., 2015;Harman, 2015;Queloz et al., 2015b;Benettin et al., 2017b;Wilusz et al., 2017) and a reasonable choice of the initial storage S 0 .The use of an explicit numerical scheme has the potential of greatly reducing the computational times.Short aggregation time steps are generally recommended, especially when testing the affinity for younger storage volumes (e.g., Eq. ( 6) with parameter k < 0.3), but in case larger time steps (e.g., h = 24 h) prove satisfactory, the model can typically run in less than a second on a normal computer.The short computational times make the use of calibration techniques easier and the model structure is directly compatible with the DREAM (Vrugt et al., 2009;ter Braak and Vrugt, 2008) calibration packages.The model can be made faster by not considering the zero-precipitation times but, as explained in Sect.3.3, this improvement is currently not implemented to keep the model more intuitive.
The model is based on a catchment-scale formulation of transport processes; thus it cannot provide spatial information unless the system is partitioned into a series of spatial compartments (e.g., Soulsby et al., 2015).Even in this case, one would need to know the fluxes to and from each compartment, hence losing one of the main advantages of the general SAS approach.The catchment-scale nature of the formulation also implies that SAS functions have a conceptual character and they cannot be determined directly from physical properties of the system.Their general shape, however, can be traced back to elementary advection-dispersion processes (Benettin et al., 2013) and the mechanistic basis for timevariable SAS functions has recently been highlighted (Pangle et al., 2017).
Although the numerical accuracy of the computations has to be evaluated for each different application, Sect.5.1 provides some first guidelines to cases in which the numerical accuracy may not be satisfactory.Systems whose storage is quickly depleted by the fluxes are prone to inaccuracies and instabilities.This can happen, for instance, if the system storage is small compared to the fluxes and the SAS functions have a very strong preference for some storage portions.In such cases, higher-order schemes may become desirable.The model package already provides a higher-order solution to Eq. ( 8) (obtained through the MATLAB built-in function "ode113") that can help evaluate the numerical accuracy of the results.
The codes implemented in the tran-SAS package can be used to simulate the transport of conservative solutes through a catchment.This represents a first step towards the modeling of large-scale solute transport.Simple reactive transport equations can be easily implemented in the main model routine (Sect.3.2) using effective formulations that integrate biogeochemical processes across the catchment heterogeneity (Rinaldo and Marani, 1987).Being based on a travel time formulation of transport, the model is obviously not suited to simulating the circulation of solutes for which the chronology of the inputs and the age of water are irrelevant.For a number of cases of interest, however, both the time of entry into the catchment and the residence time of water within the catchment storage may play an important role in the transport process.Many such examples have been addressed in the literature using a catchment-scale approach, including the case of nitrate export from agricultural catchments (Botter et al., 2006;van der Velde et al., 2012), solutes influenced by evapoconcentration effects (Queloz et al., 2015b), pesticide transport (Bertuzzo et al., 2013;Lutz et al., 2017) and solutes produced by mineral weathering (Benettin et al., 2015a).The provided codes are designed to be easy to understand, so that they can be easily customized by the user and adapted to different contexts and applications.The next step is then to adapt the model to real-world problems, for which solutes' nonconservative behavior has to be taken into account.

Conclusions
The tran-SAS package includes a basic implementation of the age master equation (Eq. 1) using general SAS functions.The codes can be used to simulate the transport of solutes through a catchment and to evaluate water residence times.The package is ready to go and it includes some example data that can be used to test the main model features.The codes are extensively commented on so that they can be edited according to the user's needs.The model is based on a catchment-scale formulation of solute transport and it only relies on measurable data.Main model equations are implemented using an explicit Euler scheme that allows us to reduce computational times.The numerical accuracy of the model was verified on the example data and was shown to be generally satisfactory even at larger (e.g., daily) computation time steps.The most critical cases are those in which the stored water parcels are rapidly removed by the outflows.This situation can occur when the SAS function assumes very high values for some stored water volumes.In such cases, higher-order model implementations (provided within the package) should be used to check the numerical accuracy of the solution.The model allows us to test different SAS functions and evaluate solute transport in the catchment storage and outflows.Applications can be oriented to different catchments and solutes, advancing our ability to understand and model catchment transport processes.

Figure 2 .
Figure 2. Illustration of the conventions used to discretize the time domain.Time steps have a fixed length h (e.g., 12 h) and each time step j starts in t j = j • h.The numerical evaluation of a function f at time t j is indicated as f [j ].

Figure 3 .
Figure 3. Example of results that can be obtained from the model.(a) Streamflow solute response in the case of sinusoidal tracer input; (b) streamflow solute response in the case of step reduction of the tracer input; (c) illustration of the different ω Q used in the simulations and listed in Table 1 (as ω 1 is time variant; its possible shapes are represented by a colored band); (d) cumulative streamflow travel time distributions (TTDs) extracted on a specific day (15 February 2016, indicated with a cross in a and b).All simulations share the same settings and only differ in the choice of the ω Q function.

Figure 4 .
Figure 4. Numerical errors on the storage age distribution (a) and on streamflow concentration (b) as a function of the aggregation time step.The error time series are summarized through their standard deviation (SD).Each plot shows the performance of two different numerical schemes: classic Euler forward (EF) and modified Euler forward (EF * , which is the default model version).The EF * implementation shows significant improvements with respect to EF in the accuracy of streamflow concentration.

Figure 6 .
Figure 6.Numerical errors on the storage age distribution (a) and on streamflow concentration (b) as a function of the aggregation time step.The error time series are summarized through their standard deviation.Each plot shows the model performance for several shapes of the SAS function, parameterized as a power-law distribution with parameter k (Eq.6).The color code is the same as in Fig.5.The random-sampling case (i.e., k = 1) is indicated in black and it is equivalent to the curves featuring S 0 = 1000 in Fig.4.

Table 1 .
Description of the discharge SAS functions used in the application.All the functions were tested with the same initial total storage S 0 = 1000 mm.