Skip to content

Commit

Permalink
Small changes to calc_ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
jorasinghr committed Jul 5, 2018
1 parent 9e675cb commit f6efc69
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions wwdata/Class_HydroData.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,26 +1320,46 @@ def calc_ratio(self,data_1,data_2,arange,only_checked=False):
raise IndexError('Index out of bounds. Check whether the values of ' + \
'"arange" are within the index range of the data.')

if only_checked == True:
#create new pd.Dataframes for original values in range,
#merge only rows in which both values are original
# original:
"""
if only_checked is True:
# create new pd.Dataframes for original values in range,
# merge only rows in which both values are original
data_1_checked = pd.DataFrame(self.data[arange[0]:arange[1]][data_1][self.meta_valid[data_1]=='original'].values, \
index=self.data[arange[0]:arange[1]][data_1][self.meta_valid[data_1]=='original'].index)
data_2_checked = pd.DataFrame(self.data[arange[0]:arange[1]][data_2][self.meta_valid[data_2]=='original'].values, \
index=self.data[data_2][arange[0]:arange[1]][self.meta_valid[data_2]=='original'].index)
ratio_data = pd.merge(data_1_checked,data_2_checked,left_index=True, right_index=True, how = 'inner')
ratio_data.columns = data_1, data_2
mean = (ratio_data[data_1] / ratio_data[data_2]).replace(np.inf, np.nan).mean()
std = (ratio_data[data_1] / ratio_data[data_2]).replace(np.inf, np.nan).std()
"""

if only_checked is True:
try:
data_1_checked = pd.DataFrame(self.data[arange[0]:arange[1]][data_1][self.meta_valid[data_1]=='original'].values,
index=self.data[arange[0]:arange[1]][data_1][self.meta_valid[data_1]=='original'].index)
data_2_checked = pd.DataFrame(self.data[arange[0]:arange[1]][data_2][self.meta_valid[data_2]=='original'].values, \
index=self.data[data_2][arange[0]:arange[1]][self.meta_valid[data_2]=='original'].index)
ratio_data = pd.merge(data_1_checked,data_2_checked,left_index=True, right_index=True, how = 'inner')
ratio_data.columns = data_1,data_2
except KeyError:
# if self.meta_valid[data_1] and self.meta_valid[data_2] in globals():
# type(self.meta_valid[data_1]) is str:

wn.warn('only_checked cannot be fulfilled')
# create new pd.Dataframes for original values in range,
# merge only rows in which both values are original
data_1_checked = pd.DataFrame(self.data[arange[0]:arange[1]][data_1]\
[self.meta_valid[data_1] == 'original'].values,
index=self.data[arange[0]:arange[1]][data_1][self.meta_valid[data_1]== 'original'].index)
data_2_checked = pd.DataFrame(self.data[arange[0]:arange[1]][data_2]\
[self.meta_valid[data_2] == 'original'].values,
index=self.data[data_2][arange[0]:arange[1]][self.meta_valid[data_2] == 'original'].index)

ratio_data = pd.merge(data_1_checked, data_2_checked,left_index=True, right_index=True, how='inner')
ratio_data.columns = data_1, data_2

mean = (ratio_data[data_1] / ratio_data[data_2]).replace(np.inf, np.nan).mean()
std = (ratio_data[data_1] / ratio_data[data_2]).replace(np.inf, np.nan).std()

mean = (ratio_data[data_1]/ratio_data[data_2])\
.replace(np.inf,np.nan).mean()
std = (ratio_data[data_1]/ratio_data[data_2])\
.replace(np.inf,np.nan).std()
except KeyError:
# else:
raise KeyError('only_checked cannot be fulfilled for the self.meta_valid DataFrame')

else:
mean = (self.data[arange[0]:arange[1]][data_1]/self.data[arange[0]:arange[1]][data_2])\
Expand Down

0 comments on commit f6efc69

Please sign in to comment.