A classic problem in hydrology! 😊
The Water Balance Equation
The water balance equation for a river catchment is:
ΔS = P - E - Q
where:
- ΔS (ΔStorage) is the change in water storage within the catchment [mm/day or mm/month]
- P (Precipitation) is the amount of water added to the catchment through precipitation [mm/day or mm/month]
- E (Evaporation) is the amount of water lost through evaporation [mm/day or mm/month]
- Q (Runoff) is the amount of water leaving the catchment through the river [mm/day or mm/month]
Since you have daily series of P, E, and Q, and monthly series of ΔS (inferred from water storage, S), your goal is to disaggregate the monthly ΔS into daily values, leveraging the daily patterns in P, E, and Q.
Mathematical Formulation for Disaggregation
-
Monthly Water Balance: You know the monthly changes in storage (ΔS_m), where m indexes the month (e.g., January = 1, February = 2, ...). These are derived from your accurate monthly water storage data (S_m) as:
ΔS_m = S_m - S_{m-1} (change from end of previous month to end of current month)
-
Daily Water Balance: Ideally, for each day d in month m:
ΔS_d = P_d - E_d - Q_d
But, you don't have daily ΔS_d directly. You only have monthly ΔS_m.
-
Disaggregation Approach: Assume the monthly ΔS_m (from your storage data) should be distributed across days in proportion to the daily net water balance (P_d - E_d - Q_d). The idea is:
- Compute the daily net flux:
net_flux_d = P_d - E_d - Q_d
- Normalize these daily net fluxes within each month so they sum to 1. This gives you daily weights (w_d) that represent the relative contribution of each day to the month's total water balance pattern.
- Apply these weights to the known monthly ΔS_m to get daily ΔS_d.
Mathematical Steps:
-
For each day d in month m, compute:
net_flux_d = P_d - E_d - Q_d
-
For each month m, sum these daily net fluxes:
total_net_flux_m = ∑_{d=1}^{N_m} net_flux_d
where N_m is the number of days in month m (28, 29, 30, or 31).
-
Compute daily weights for each day d in month m:
w_d = net_flux_d / total_net_flux_m
Note: If total_net_flux_m ≈ 0 (rare, but possible), set w_d = 1/N_m (equal weighting, no preferred day).
These w_d values tell you how much each day's net flux contributes to the month's pattern.
-
Disaggregate the monthly storage change (ΔS_m) into daily changes (ΔS_d):
ΔS_d = w_d * ΔS_m
This distributes the known monthly change in storage across days, guided by the daily patterns in P, E, Q.
-
Reconstruct Daily Storage Series (S_d):
- Start with the end-of-previous-month storage as your baseline (S_{m-1}).
- Cumulate the daily ΔS_d through the month:
S_d = S_{m-1} + ∑_{i=1}^{d} ΔS_i for d = 1, 2, ..., N_m
Now, let's implement this in Python.
Python Code
import pandas as pd
import numpy as np
def disaggregate_monthly_storage_change(daily_PEQR, monthly_storage):
"""
Disaggregate monthly ΔS into daily ΔS using daily P, E, Q patterns.
Parameters:
- daily_PEQR [pd.DataFrame]: Index = daily dates; columns = ['P', 'E', 'Q']
- monthly_storage [pd.Series]: Index = month-end dates; values = storage
Returns:
- daily_storage [pd.Series]: Index = daily dates; values = disaggregated storage
"""
# Ensure inputs are pandas objects with datetime index
daily_PEQR.index = pd.to_datetime(daily_PEQR.index)
monthly_storage.index = pd.to_datetime(monthly_storage.index)
# Compute monthly ΔS from storage data
monthly_delta_S = monthly_storage.diff().dropna()
# Compute daily net flux
daily_PEQR['net_flux'] = daily_PEQR['P'] - daily_PEQR['E'] - daily_PEQR['Q']
# Lists to store results
dates = []
daily_delta_S_values = []
daily_storage_values = []
# Loop over each month
for month_end, delta_S_m in monthly_delta_S.items():
month = month_end.strftime('%Y-%m')
days_in_month = daily_PEQR.loc[month].index
# Extract net fluxes for this month
net_fluxes_m = daily_PEQR.loc[month, 'net_flux'].values
# Compute total net flux for the month
total_net_flux_m = np.sum(net_fluxes_m)
if np.isclose(total_net_flux_m, 0, atol=1e-6): # Near zero
weights_d = np.full_like(net_fluxes_m, 1.0 / len(net_fluxes_m))
else:
weights_d = net_fluxes_m / total_net_flux_m
# Disaggregate monthly ΔS into daily ΔS_d
daily_delta_S_m = weights_d * delta_S_m
# Reconstruct daily storage for this month
# Start from the PREVIOUS month-end storage value
prev_month_end = month_end - pd.offsets.MonthEnd(1)
start_storage = monthly_storage.loc[prev_month_end]
daily_storage_m = start_storage + np.cumsum(np.insert(daily_delta_S_m, 0, 0))[:-1]
# Append results
dates.extend(days_in_month)
daily_delta_S_values.extend(daily_delta_S_m)
daily_storage_values.extend(daily_storage_m)
# Build resulting Series
daily_delta_S = pd.Series(daily_delta_S_values, index=dates, name='daily_delta_S')
daily_storage = pd.Series(daily_storage_values, index=dates, name='daily_storage')
return daily_delta_S, daily_storage
# Example usage
if __name__ == "__main__":
# Simulate your data (adapt to your actual data loading)
dates_daily = pd.date_range('2022-01-01', '2022-12-31', freq='D')
P = np.random.gamma(2, 5, size=len(dates_daily)) # Example precip
E = np.random.uniform(0, 3, size=len(dates_daily)) # Example evap
Q = np.random.uniform(0, 5, size=len(dates_daily)) # Example runoff
daily_PEQR = pd.DataFrame({'P':P, 'E':E, 'Q':Q}, index=dates_daily)
month_ends = pd.date_range('2022-01-31', '2022-12-31', freq='M')
S_monthly = pd.Series(np.random.uniform(100, 500, size=len(month_ends)), index=month_ends)
daily_delta_S, daily_storage = disaggregate_monthly_storage_change(daily_PEQR, S_monthly)
# Plot results (optional)
import matplotlib.pyplot as plt
plt.figure(figsize=(10,6))
plt.plot(daily_storage, label='Disaggregated Daily Storage')
plt.plot(S_monthly, marker='o', linestyle='None', label='Monthly Storage (observed)')
plt.legend()
plt.ylabel('Storage [mm]')
plt.title('Disaggregated Daily Storage')
plt.show()
How it works:
-
The function disaggregate_monthly_storage_change takes:
daily_PEQR: A DataFrame with daily dates as the index and columns for P, E, Q.
monthly_storage: A Series with month-end dates as the index and storage values.
-
It first computes the monthly changes in storage (monthly_delta_S) from the provided monthly_storage.
-
Then, for each month:
- Computes daily
net_flux = P - E - Q.
- Normalizes these to get daily weights (
w_d).
- Uses these weights to distribute the monthly
ΔS_m across days (daily_delta_S_m = w_d * ΔS_m).
- Cumulates these daily
ΔS_d to reconstruct the daily storage series, starting from the previous month-end's storage value.
-
The result is daily_storage: a Series with the same daily dates as daily_PEQR, now carrying the disaggregated storage values.
Notes:
- This approach assumes the relative pattern of
P-E-Q within a month is a good proxy for how storage changes daily. In reality, catchment storage dynamics can be nonlinear, but without more detailed info (e.g., soil moisture models), this is a reasonable first-order approximation.
- If your monthly storage series has gaps or non-end-of-month dates, you'll need to adjust the indexing logic.
- The example usage simulates random data; replace
daily_PEQR and S_monthly with your actual datasets.
Run the code, and you should see a plot (if you uncomment the plotting part) showing your original monthly storage points and the newly disaggregated daily storage series. Happy hydrology! 🌊📊