Data Analysis
This section explains how to analysis data generated by different interfaces.
Time Series Data
A standard SWAT+
simulation generates TXT files with time series columns: day
, mon
, and yr
for day, month, and year, respectively.
The following method creates a time series DataFrame
that includes a new date
column with datetime.date
objects and save the resulting DataFrame to a JSON file.
import pySWATPlus
output = pySWATPlus.DataManager().simulated_timeseries_df(
data_file=r"C:\Users\Username\custom_folder\channel_sd_mon.txt",
has_units=True,
begin_date='01-Jun-2011',
end_date='01-Jun-2013',
ref_day=15,
apply_filter={'name': ['cha561']},
usecols=['name', 'flo_out'],
json_file=r"C:\Users\Username\output_folder\tmp.json"
)
print(output)
Read Sensitivity Simulation Data
The sensitivity analysis performed using the
simulation_by_sample_parameters
method generates a file named sensitivity_simulation.json
. This JSON file contains all the information required for sensitivity analysis, including:
problem
: Problem definition dictionarysample
: List of generated samplessimulation
: SimulatedDataFrame
corresponding to each sample
To retrieve the selected DataFrame
for all scenarios, use:
output = pySWATPlus.DataManager().read_sensitive_dfs(
sensim_file=r"C:\Users\Username\simulation_folder\sensitivity_simulation.json",
df_name='channel_sd_mon_df',
add_problem=True,
add_sample=True
)
Scenario Metrics
For a selected DataFrame
, scenario metrics across all simulations can be computed by comparing model outputs with observed data.
NSE: Nash–Sutcliffe Efficiency KGE: Kling–Gupta Efficiency MSE: Mean Squared Error RMSE: Root Mean Squared Error PBIAS: Percent Bias MARE: Mean Absolute Relative Error
-
To get the mapping between available indicators and their abbreviations:
indicators = pySWATPlus.PerformanceMetrics().indicator_names
-
To compute metrics for all scenarios using the desired indicators:
output = pySWATPlus.SensitivityAnalyzer().scenario_indicators( sensim_file=r"C:\Users\Username\simulation_folder\sensitivity_simulation.json", df_name='channel_sd_mon_df', sim_col='flo_out', obs_file=r"C:\Users\Username\observed_folder\discharge_monthly.csv", date_format='%Y-%m-%d', obs_col='discharge', indicators=['NSE', 'MSE'], json_file=r"C:\Users\Username\data_analysis\performance_metrics.json" )