@@ -90,6 +90,7 @@ def partial_series(rolling_sum_values, measurement_period):
9090
9191
9292def _lin_regress2 (x , y ):
93+ # based on math - custom function
9394 sample_size = len (x )
9495 x_mean = np .mean (x )
9596 y_mean = np .mean (y )
@@ -102,6 +103,7 @@ def _lin_regress2(x, y):
102103
103104
104105def _lin_regress (x , y ):
106+ # using scipy
105107 res = linregress (x , y )
106108 return {PARAM .U : res .intercept , PARAM .W : res .slope }
107109
@@ -128,42 +130,27 @@ def _improve_factor(interval):
128130 list (improve_factor .values ()))
129131
130132
131- def calculate_u_w (file_input , duration_steps , series_kind ):
133+ def iter_event_series (file_input , duration_steps ):
132134 """
133135 Statistical analysis for each duration step.
134136
135137 acc. to DWA-A 531 chap. 5.1
136138
137139 Save the parameters of the distribution function as interim results.
138140
139- acc. to DWA-A 531 chap. 4.4: use the annual series only for measurement periods over 20 years
140-
141-
142141 Args:
143142 file_input (pandas.Series): precipitation data
144143 duration_steps (list[int] | numpy.ndarray): in minutes
145- series_kind (str): 'annual' or 'partial'
146144
147- Returns :
148- dict[int, dict]: with key=durations and values=dict(u, w)
145+ Yields :
146+ series: max rainfall intensity per event for each duration step
149147 """
150148 ts = file_input .copy ()
151- # -------------------------------
152- # measuring time in years
153- measurement_start , measurement_end = ts .index [[0 , - 1 ]]
154- measurement_period = (measurement_end - measurement_start ) / year_delta (years = 1 )
155- if round (measurement_period , 1 ) < 10 :
156- warnings .warn ("The measurement period is too short. The results may be inaccurate! "
157- "It is recommended to use at least ten years. "
158- "(-> Currently {}a used)" .format (measurement_period ))
159149
160150 # -------------------------------
161151 base_frequency = guess_freq (ts .index ) # DateOffset/Timedelta
162152
163153 # ------------------------------------------------------------------------------------------------------------------
164- interim_results = {}
165-
166- # -------------------------------
167154 # acc. to DWA-A 531 chap. 4.2:
168155 # The values must be independent of each other for the statistical evaluations.
169156 # estimated four hours acc. (Schilling, 1984)
@@ -202,11 +189,47 @@ def calculate_u_w(file_input, duration_steps, series_kind):
202189
203190 roll_sum = ts .rolling (duration ).sum ()
204191
192+ year_index = events [COL .START ].dt .year .values
193+
205194 # events[COL.rolling_sum_valuesAX_OVERLAPPING_SUM] = agg_events(events, roll_sum, 'max') * improve
206- rolling_sum_values = agg_events (events , roll_sum , 'max' ) * improve
195+ yield agg_events (events , roll_sum , 'max' ) * improve , duration_integer , year_index
196+
197+
198+ def calculate_u_w (file_input , duration_steps , series_kind ):
199+ """
200+ Statistical analysis for each duration step.
201+
202+ acc. to DWA-A 531 chap. 5.1
203+
204+ Save the parameters of the distribution function as interim results.
205+
206+ acc. to DWA-A 531 chap. 4.4: use the annual series only for measurement periods over 20 years
207+
208+
209+ Args:
210+ file_input (pandas.Series): precipitation data
211+ duration_steps (list[int] | numpy.ndarray): in minutes
212+ series_kind (str): 'annual' or 'partial'
213+
214+ Returns:
215+ dict[int, dict]: with key=durations and values=dict(u, w)
216+ """
217+ # -------------------------------
218+ # measuring time in years
219+ measurement_start , measurement_end = file_input .index [[0 , - 1 ]]
220+ measurement_period = (measurement_end - measurement_start ) / year_delta (years = 1 )
221+ if round (measurement_period , 1 ) < 10 :
222+ warnings .warn ("The measurement period is too short. The results may be inaccurate! "
223+ "It is recommended to use at least ten years. "
224+ "(-> Currently {}a used)" .format (measurement_period ))
225+
226+ # -------------------------------
227+ interim_results = {}
228+
229+ for rolling_sum_values , duration_integer , year_index in iter_event_series (file_input , duration_steps ):
207230
208231 if series_kind == SERIES .ANNUAL :
209- interim_results [duration_integer ] = annual_series (rolling_sum_values , events [ COL . START ]. dt . year . values )
232+ interim_results [duration_integer ] = annual_series (rolling_sum_values , year_index )
210233 elif series_kind == SERIES .PARTIAL :
211234 interim_results [duration_integer ] = partial_series (rolling_sum_values , measurement_period )
212235 else :
0 commit comments