@@ -14,7 +14,7 @@ class DataManager:
1414
1515 def simulated_timeseries_df (
1616 self ,
17- target_file : str | pathlib .Path ,
17+ sim_file : str | pathlib .Path ,
1818 has_units : bool ,
1919 begin_date : typing .Optional [str ] = None ,
2020 end_date : typing .Optional [str ] = None ,
@@ -29,7 +29,7 @@ def simulated_timeseries_df(
2929 A new `date` column is constructed using `datetime.date` objects from the `yr`, `mon`, and `day` columns.
3030
3131 Args:
32- target_file (str | pathlib.Path): Path to the input file containing time series data generated by
32+ sim_file (str | pathlib.Path): Path to the input file containing time series data generated by
3333 the method [`run_swat`](https://swat-model.github.io/pySWATPlus/api/txtinout_reader/#pySWATPlus.TxtinoutReader.run_swat).
3434 The file must contain `yr`, `mon`, and `day` columns.
3535
@@ -72,13 +72,13 @@ def simulated_timeseries_df(
7272 )
7373
7474 # Absolute file path
75- target_file = pathlib .Path (target_file ).resolve ()
75+ sim_file = pathlib .Path (sim_file ).resolve ()
7676
7777 # DataFrame from input file
78- skip_rows = [0 , 2 ] if has_units else [0 ]
79- df = utils ._load_file (
80- path = target_file ,
81- skip_rows = skip_rows
78+ skiprows = [0 , 2 ] if has_units else [0 ]
79+ df = utils ._df_extract (
80+ input_file = sim_file ,
81+ skiprows = skiprows
8282 )
8383
8484 # DataFrame columns
@@ -92,7 +92,7 @@ def simulated_timeseries_df(
9292 ]
9393 if len (missing_cols ) > 0 :
9494 raise ValueError (
95- f'Missing required time series columns "{ missing_cols } " in file "{ target_file .name } "'
95+ f'Missing required time series columns "{ missing_cols } " in file "{ sim_file .name } "'
9696 )
9797 df [date_col ] = pandas .to_datetime (
9898 df [time_cols ].rename (columns = {'yr' : 'year' , 'mon' : 'month' })
@@ -105,9 +105,9 @@ def simulated_timeseries_df(
105105
106106 # Fix reference day
107107 if ref_day is not None :
108- if target_file .stem .endswith (('_day' , '_subday' )):
108+ if sim_file .stem .endswith (('_day' , '_subday' )):
109109 raise ValueError (
110- f'Parameter "ref_day" is not applicable for daily or sub-daily time series in file "{ target_file .name } " '
110+ f'Parameter "ref_day" is not applicable for daily or sub-daily time series in file "{ sim_file .name } " '
111111 f'because it would assign the same day to all records within a month.'
112112 )
113113 df [date_col ] = df [date_col ].apply (
@@ -116,9 +116,9 @@ def simulated_timeseries_df(
116116
117117 # Fix reference month
118118 if ref_month is not None :
119- if target_file .stem .endswith ('_mon' ):
119+ if sim_file .stem .endswith ('_mon' ):
120120 raise ValueError (
121- f'Parameter "ref_month" is not applicable for monthly time series in file "{ target_file .name } " '
121+ f'Parameter "ref_month" is not applicable for monthly time series in file "{ sim_file .name } " '
122122 f'because it would assign the same month to all records within a year.'
123123 )
124124 df [date_col ] = df [date_col ].apply (
@@ -128,26 +128,26 @@ def simulated_timeseries_df(
128128 # Check if filtering by date removed all rows
129129 if df .empty :
130130 raise ValueError (
131- f'No data found between "{ begin_date } " and "{ end_date } " in file "{ target_file .name } "'
131+ f'No data found between "{ begin_date } " and "{ end_date } " in file "{ sim_file .name } "'
132132 )
133133
134134 # Filter rows by dictionary criteria
135135 if apply_filter is not None :
136136 for col , val in apply_filter .items ():
137137 if col not in df_cols :
138138 raise ValueError (
139- f'Column "{ col } " in apply_filter was not found in file "{ target_file .name } "'
139+ f'Column "{ col } " in apply_filter was not found in file "{ sim_file .name } "'
140140 )
141141 if not isinstance (val , list ):
142142 raise TypeError (
143- f'Column "{ col } " in apply_filter for file "{ target_file .name } " must be a list, '
143+ f'Column "{ col } " in apply_filter for file "{ sim_file .name } " must be a list, '
144144 f'but got type "{ type (val ).__name__ } "'
145145 )
146146 df = df .loc [df [col ].isin (val )]
147147 # Check if filtering removed all rows
148148 if df .empty :
149149 raise ValueError (
150- f'Filtering by column "{ col } " with values "{ val } " returned no rows in "{ target_file .name } "'
150+ f'Filtering by column "{ col } " with values "{ val } " returned no rows in "{ sim_file .name } "'
151151 )
152152
153153 # Reset DataFrame index
@@ -162,7 +162,7 @@ def simulated_timeseries_df(
162162 for col in usecols :
163163 if col not in df_cols :
164164 raise ValueError (
165- f'Column "{ col } " specified in "usecols" was not found in file "{ target_file .name } "'
165+ f'Column "{ col } " specified in "usecols" was not found in file "{ sim_file .name } "'
166166 )
167167 retain_cols = [date_col ] + usecols
168168
@@ -191,22 +191,23 @@ def simulated_timeseries_df(
191191
192192 def read_sensitive_dfs (
193193 self ,
194- sim_file : pathlib .Path ,
194+ sensim_file : str | pathlib .Path ,
195195 df_name : str ,
196196 add_problem : bool = False ,
197197 add_sample : bool = False
198198 ) -> dict [str , typing .Any ]:
199199 '''
200- Read sensitivity simulation data generated by the [`simulation_by_sobol_sample`](https://swat-model.github.io/pySWATPlus/api/sensitivity_analyzer/#pySWATPlus.SensitivityAnalyzer.simulation_by_sobol_sample)
201- method, and return a dictionary mapping each scenario integer to its corresponding `DataFrame`.
200+ Read sensitivity simulation data generated by the method
201+ [`simulation_by_sample_parameters`](https://swat-model.github.io/pySWATPlus/api/sensitivity_analyzer/#pySWATPlus.SensitivityAnalyzer.simulation_by_sample_parameters),
202+ and return a dictionary mapping each scenario integer to its corresponding `DataFrame`.
202203
203204 The returned dictionary may include the following keys:
204205 - `scenario` (default): A mapping between each scenario integer and its corresponding DataFrame.
205206 - `problem` (optional): The problem definition.
206207 - `sample` (optional): The sample list used in the sensitivity simulation.
207208
208209 Args:
209- sim_file (str | pathlib.Path): Path to the `sensitivity_simulation.json` file generated by `simulation_by_sobol_sample `.
210+ sensim_file (str | pathlib.Path): Path to the `sensitivity_simulation.json` file generated by `simulation_by_sample_parameters `.
210211
211212 df_name (str): Name of the `DataFrame` within `sensitivity_simulation.json`.
212213
@@ -218,12 +219,24 @@ def read_sensitive_dfs(
218219 A dictionary with the following keys:
219220
220221 - `scenario` (default): A mapping between each scenario integer and its corresponding DataFrame.
221- - `problem` (optional): The problem definition.
222+ - `problem` (optional): The definition dictionary passed to sampling .
222223 - `sample` (optional): The sample list used in the sensitivity simulation.
223224 '''
224225
226+ # Check input variables type
227+ validators ._variable_origin_static_type (
228+ vars_types = typing .get_type_hints (
229+ obj = self .read_sensitive_dfs
230+ ),
231+ vars_values = locals ()
232+ )
233+
234+ # Absolute file path
235+ sensim_file = pathlib .Path (sensim_file ).resolve ()
236+
237+ # Sensitiivty output data
225238 output = utils ._retrieve_sensitivity_output (
226- sim_file = sim_file ,
239+ sensim_file = sensim_file ,
227240 df_name = df_name ,
228241 add_problem = add_problem ,
229242 add_sample = add_sample
0 commit comments