Skip to content

Commit

Permalink
modified remove_drift function and how it fix the drift. This is now …
Browse files Browse the repository at this point in the history
…also shown in the showcase #303
  • Loading branch information
jorasinghr committed Jul 31, 2018
1 parent d2e864a commit 2fee8b9
Show file tree
Hide file tree
Showing 4 changed files with 2,145 additions and 3,512 deletions.
1,280 changes: 1,280 additions & 0 deletions .ipynb_checkpoints/Showcase_OnlineSensorBased-checkpoint.ipynb

Large diffs are not rendered by default.

4,343 changes: 835 additions & 3,508 deletions Showcase_OnlineSensorBased.ipynb

Large diffs are not rendered by default.

30 changes: 28 additions & 2 deletions wwdata/Class_HydroData.py
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ def drift_analysis(self, data_name, arange1, arange2=None, plot=False):
"""
pass

def remove_drift(self, data_name, arange, max_slope, period=None, plot=False):
def remove_drift(self, data_name, arange, max_slope, period=None, plot=False, drift_type=None):
"""
This function calculates the slope of the data in a certain given
period by fitting a line through it and removes the drift.
Expand Down Expand Up @@ -1829,8 +1829,34 @@ def remove_drift(self, data_name, arange, max_slope, period=None, plot=False):
series[value[0]:value[1]] = series[value[0]:value[1]]-line_segment1+ds

elif value[2] == 'm':
if drift_type == 'A' or drift_type is None:
series[value[0]:value[1]] = series[value[0]:value[1]] - (line_segment1 - line_segment1[-1])
#if value[1].day - value[0].day == 1:
elif drift_type == 'B':

#else:
detrend = signal.detrend(series[value[0]:value[1]], type='constant')
df2 = pd.DataFrame(detrend, index=series.index[len(series[:value[0]])-1:len(series[:value[1]])])

b = df2.iloc[1][0]
a = line_segment1[-1]
slope = (a-b) / len(df2)
f = [a]
s = df2
s[:] = b
for val in range(len(df2) - 1):
a += slope
f.append(a)

ds = pd.DataFrame(f, index=series.index[len(series[:value[0]])-1:len(series[:value[1]])])
ds = ds[:] + s[:]
ds = ds / 2
ds = ds.squeeze() # from dataframe to series
#ax.plot(series[value[0]:value[1]]-(line_segment-ds), 'm-', label='without drift')
series[value[0]:value[1]] = series[value[0]:value[1]] - line_segment1 + ds

# ax.plot(series[value[0]:value[1]]-(line_segment-line_segment[-1]), 'm-', label='without drift')
series[value[0]:value[1]] = series[value[0]:value[1]] - (line_segment1 - line_segment1[-1])
#series[value[0]:value[1]] = series[value[0]:value[1]] - (line_segment1 - line_segment1[-1])

"""
detrend = signal.detrend(series[value[0]:value[1]])
Expand Down
4 changes: 2 additions & 2 deletions wwdata/Class_OnlineSensorBased.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,8 +1375,8 @@ def check_filling_error(self,nr_iterations,data_name,filling_function,
# turn warnings on again
wn.filterwarnings("always")
raise ValueError("Checking of the filling function could not "+\
"be executed. Check docstring of the filling "+\
"function to provide appropriate arguments.")
"be executed. Check docstring of the filling "+\
"function to provide appropriate arguments.")

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

Expand Down

0 comments on commit 2fee8b9

Please sign in to comment.