Skip to content

Commit

Permalink
trying to suppress warnings in reliability functions; didn't work, cr…
Browse files Browse the repository at this point in the history
…eating issue #584
  • Loading branch information
cdemulde committed Apr 9, 2019
1 parent 558feed commit 1bee5cd
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 459 deletions.
517 changes: 73 additions & 444 deletions Showcase_OnlineSensorBased.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion wwdata/Class_HydroData.py
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ def calc_daily_profile(self,column_name,arange,quantile=0.9,plot=False,
if rain :
wn.warn("Data points obtained during a rain event will be used for" \
" the calculation of an average day. This might lead to a not-" \
"representative average day and/or high standard deviations.",stacklevel=1)
"representative average day and/or high standard deviations.")

daily_profile = pd.DataFrame()

Expand Down
42 changes: 28 additions & 14 deletions wwdata/Class_OnlineSensorBased.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(self,data,timedata_column='index',data_type='WWTP',
self.filling_error = pd.DataFrame(index = self.data.columns,
columns=['imputation error [%]'])
self._filling_warning_issued = False
self._rain_warning_issued = False

#def time_to_index(self,drop=True,inplace=True,verify_integrity=False):
# """CONFIRMED
Expand Down Expand Up @@ -341,11 +342,14 @@ def _rain_warning(self,lineno):
'''
Wrapper function for the rain warning.
'''
#wn.showwarning = self._warning
wn.showwarning("\nData points obtained during a rain event will be replaced. \n"\
"Make sure you are confident in this replacement method for the "\
"filling of gaps in the data during rain events.",
UserWarning, __file__, lineno)
if not self._rain_warning_issued:
#wn.showwarning = self._warning
wn.showwarning("\nData points obtained during a rain event will be replaced. \n"\
"Make sure you are confident in this replacement method for the "\
"filling of gaps in the data during rain events.",
UserWarning, __file__, lineno)
# don't change value of self._rain_warning_issued; this needs to be printed
# every time! The reason this variable exists is for the reliability checking

def _check_rain(self,arange,lineno):
'''
Expand Down Expand Up @@ -1212,15 +1216,22 @@ def check_filling_error(self,nr_iterations,data_name,filling_function,
"""
# shut off warnings, to avoid e.g. warning about replacing datapoints
# in wet weather
wn.filterwarnings("ignore")
# wn.filterwarnings("ignore")

if nr_small_gaps == 0 and nr_large_gaps == 0 :
raise ValueError("No information was provided to make the gaps \
with. Please specify the number of small or \
large gaps you want to create for testing")
raise ValueError("No information was provided to make the gaps \
with. Please specify the number of small or \
large gaps you want to create for testing")

filling_errors = pd.Series([])
for iteration in range(0,nr_iterations):

prev_filling_warning_issued = self._filling_warning_issued
self._filling_warning_issued = True
self._rain_warning_issued = True

#with warnings.catch_warnings():
#warnings.simplefilter("ignore") # turn off warnings in for-loop
for iteration in range(0,nr_iterations):
iter_error = self._calculate_filling_error(data_name,filling_function,test_data_range,
nr_small_gaps=nr_small_gaps,
max_size_small_gaps=max_size_small_gaps,
Expand All @@ -1230,21 +1241,24 @@ def check_filling_error(self,nr_iterations,data_name,filling_function,
#print(options_filling_function)
if iter_error == None:
# turn warnings on again
wn.filterwarnings("always")
#wn.filterwarnings("always")
raise ValueError("Checking of the filling function could not \
be executed. Check docstring of the filling \
function to provide appropriate arguments.")

filling_errors = filling_errors.append(pd.Series([iter_error]))


self._filling_warning_issued = prev_filling_warning_issued
self._rain_warning_issued = False

avg = filling_errors.dropna().mean()

self.filling_error.ix[data_name] = avg
print('Average deviation of imputed points from the original ones is '+\
str(avg)+"%. This value is also saved in self.filling_error.")
str(round(avg,2))+"%. This value is also saved in self.filling_error.")

# turn warnings on again
wn.filterwarnings("always")
#wn.filterwarnings("always")

###############################################################################
## LOOKUP FUNCTIONS ##
Expand Down

0 comments on commit 1bee5cd

Please sign in to comment.