| import numpy as np
|
| import pandas as pd
|
| from typing import TYPE_CHECKING
|
|
|
| if TYPE_CHECKING:
|
|
|
| from aquacrop.entities.clockStruct import ClockStruct
|
| from aquacrop.entities.paramStruct import ParamStruct
|
| from aquacrop.entities.groundWater import GroundWater
|
|
|
|
|
|
|
| def read_groundwater_table(
|
| ParamStruct: "ParamStruct",
|
| GwStruct: "GroundWater",
|
| ClockStruct: "ClockStruct") -> "ParamStruct":
|
| """
|
| Function to initialise groundwater parameters
|
|
|
| Arguments:
|
|
|
| ParamStruct (ParamStruct): Contains model paramaters
|
|
|
| GwStruct (GroundWater): groundwater params
|
|
|
| ClockStruct (ClockStruct): time params
|
|
|
| Returns:
|
|
|
| ParamStruct (ParamStruct): updated with GW info
|
|
|
| """
|
|
|
|
|
| WT = GwStruct.water_table
|
| WTMethod = GwStruct.method
|
|
|
|
|
| if WT == "N":
|
| ParamStruct.water_table = 0
|
| ParamStruct.z_gw = 999 * np.ones(len(ClockStruct.time_span))
|
| ParamStruct.zGW_dates = ClockStruct.time_span
|
| ParamStruct.WTMethod = "None"
|
| elif WT == "Y":
|
| ParamStruct.water_table = 1
|
|
|
| df = pd.DataFrame([GwStruct.dates, GwStruct.values]).T
|
| df.columns = ["Date", "Depth(mm)"]
|
|
|
|
|
| df.Date = pd.DatetimeIndex(df.Date)
|
|
|
|
|
|
|
| if len(df) == 1:
|
|
|
|
|
|
|
| z_gw = pd.DataFrame(
|
| data=df["Depth(mm)"].iloc[0]*np.ones(len(ClockStruct.time_span)),
|
| index=pd.to_datetime(ClockStruct.time_span),
|
| columns=['Depth(mm)']
|
| )['Depth(mm)']
|
|
|
| elif len(df) > 1:
|
|
|
| if WTMethod == "Constant":
|
|
|
|
|
|
|
|
|
| z_gw = pd.Series(
|
| np.nan * np.ones(len(ClockStruct.time_span)), index=ClockStruct.time_span
|
| )
|
|
|
|
|
| for row in range(len(df)):
|
| date = df.Date.iloc[row]
|
| depth = df["Depth(mm)"].iloc[row]
|
| z_gw.loc[z_gw.index >= date] = depth
|
| if row == 0:
|
| z_gw.loc[z_gw.index <= date] = depth
|
|
|
| elif WTMethod == "Variable":
|
|
|
|
|
|
|
|
|
|
|
| z_gw = pd.Series(
|
| np.nan * np.ones(len(ClockStruct.time_span)), index=ClockStruct.time_span
|
| )
|
|
|
| for row in range(len(df)):
|
| date = df.Date.iloc[row]
|
| depth = df["Depth(mm)"].iloc[row]
|
| z_gw.loc[date] = depth
|
|
|
|
|
| z_gw = z_gw.interpolate()
|
|
|
|
|
| ParamStruct.z_gw = z_gw.values
|
| ParamStruct.zGW_dates = z_gw.index.values
|
| ParamStruct.WTMethod = WTMethod
|
|
|
| return ParamStruct
|
|
|
|
|