|
| 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 | + |
0 commit comments