Skip to content

Commit 4deb8cd

Browse files
authored
Merge pull request #59 from debpal/main
Performance metrics and Sobol indices
2 parents a02ae35 + 5a63208 commit 4deb8cd

22 files changed

+1145
-384
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- Modify parameters via the `calibration.cal` file.
3939
- Run SWAT+ simulations.
4040
- Perform sensitivity analysis on model parameters using the [SALib](https://github.com/SALib/SALib) Python package, with support for parallel computation.
41+
- Compute performance metrics using widely adopted indicators and derive Sobol sensitivity indices.
4142

4243

4344
## 📥 Install pySWATPlus

docs/changelog.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
# Release Notes
22

3+
## Version 1.2.0 (Month DD, YYYY, not released yet)
4+
5+
- Introduced the `pySWATPlus.DataManager` class with the following methods to support data processing workflows:
6+
7+
- `read_sensitive_dfs`: Reads sensitivity simulation data generated by the `simulation_by_sobol_sample` method in the `pySWATPlus.SensitivityAnalyzer` class.
8+
- `simulated_timeseries_df`: Moved from the `pySWATPlus.SensitivityAnalyzer` class for improved modularity.
9+
10+
- Introduced the `pySWATPlus.PerformanceMetrics` class to compute performance metrics between simulated and observed values using the following indicators:
11+
12+
- Nash–Sutcliffe Efficiency
13+
- Kling–Gupta Efficiency
14+
- Mean Squared Error
15+
- Root Mean Squared Error
16+
- Percent Bias
17+
- Mean Absolute Relative Error
18+
19+
- Added the `sobol_indices` method to the `pySWATPlus.SensitivityAnalyzer`** class for computing Sobol indices using the available indicators in the `pySWATPlus.PerformanceMetrics` class.
20+
21+
- Added new methods to the `pySWATPlus.TxtinoutReader` class:
22+
23+
- `set_simulation_timestep`: Modifies the simulation timestep in the `time.sim` file.
24+
- `set_print_interval`: Modifies the print interval in the `print.prt` file.
25+
26+
- All SWAT+ simulations with modified parameters are now configured through the `calibration.cal` file, eliminating the need to read and modify individual input files.
27+
328

429
## Version 1.1.0 (August 26, 2025)
530

docs/userguide/data_analysis.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Data Analysis
2+
3+
This section explains how to analysis data generated by different interfaces.
4+
5+
```python
6+
import pySWATPlus
7+
```
8+
9+
10+
## Time Series Data
11+
12+
A standard `SWAT+` simulation generates TXT files with time series columns: `day`, `mon`, and `yr` for day, month, and year, respectively.
13+
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.
14+
15+
```python
16+
import pySWATPlus
17+
18+
output = pySWATPlus.DataManager().simulated_timeseries_df(
19+
data_file=r"C:\Users\Username\custom_folder\channel_sd_mon.txt",
20+
has_units=True,
21+
begin_date='01-Jun-2011',
22+
end_date='01-Jun-2013',
23+
ref_day=15,
24+
apply_filter={'name': ['cha561']},
25+
usecols=['name', 'flo_out'],
26+
json_file=r"C:\Users\Username\output_folder\tmp.json"
27+
)
28+
29+
print(output)
30+
```
31+
32+
33+
## Read Sensitivity Simulation Data
34+
35+
The sensitivity analysis performed using the [`simulation_by_sobol_sample`](https://swat-model.github.io/pySWATPlus/api/sensitivity_analyzer/#pySWATPlus.SensitivityAnalyzer.simulation_by_sobol_sample) method generates a file named `sensitivity_simulation.json` within the simulation directory.
36+
This JSON file contains all the information required for Sobol sensitivity analysis, including:
37+
38+
- `problem`: Sobol problem definition
39+
- `sample`: List of generated samples
40+
- `simulation`: Simulated `DataFrame` corresponding to each sample
41+
42+
To retrieve the selected `DataFrame` for all scenarios, use:
43+
44+
```python
45+
output = pySWATPlus.DataManager().read_sensitive_dfs(
46+
sim_file=r"C:\Users\Username\simulation_folder\sensitivity_simulation.json",
47+
df_name='channel_sd_mon_df',
48+
add_problem=True,
49+
add_sample=True
50+
)
51+
```
52+
53+
## Performance Metrics
54+
55+
For a selected `DataFrame`, performance metrics across all scenarios can be computed by comparing model outputs with observed data.
56+
57+
To view the mapping between performance indicators and their abbreviations:
58+
59+
```python
60+
indicators = pySWATPlus.PerformanceMetrics().indicator_names
61+
```
62+
63+
To compute performance metrics for the desired indicators:
64+
65+
66+
```python
67+
output = pySWATPlus.SensitivityAnalyzer().scenario_indicators(
68+
sim_file=r"C:\Users\Username\simulation_folder\sensitivity_simulation.json",
69+
df_name='channel_sd_mon_df',
70+
sim_col='flo_out',
71+
obs_file=r"C:\Users\Username\observed_folder\discharge_monthly.csv",
72+
date_format='%Y-%m-%d',
73+
obs_col='discharge',
74+
indicators=['NSE', 'MSE'],
75+
json_file=r"C:\Users\Username\data_analysis\performance_metrics.json"
76+
)
77+
```
78+
79+
## Sobol Indices
80+
81+
The available indicators can also be used to compute Sobol indices (first, second, and total orders) along with their confidence intervals.
82+
83+
```python
84+
output = pySWATPlus.SensitivityAnalyzer().sobol_indices(
85+
sim_file=r"C:\Users\Username\simulation_folder\sensitivity_simulation.json",
86+
df_name='channel_sd_mon_df',
87+
sim_col='flo_out',
88+
obs_file=r"C:\Users\Username\observed_folder\discharge_monthly.csv",
89+
date_format='%Y-%m-%d',
90+
obs_col='discharge',
91+
indicators=['KGE', 'RMSE'],
92+
json_file=r"C:\Users\Username\data_analysis\sobol_indices.json"
93+
)
94+
```
95+
96+
97+

docs/userguide/read_output.md

Lines changed: 0 additions & 76 deletions
This file was deleted.

docs/userguide/sensitivity_analysis.md

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)