In [1]:
import pandas as pd
import sys
import matplotlib
In [2]:
water23 = pd.read_csv("../data/waterlevel/Water23.csv", index_col='date')
In [3]:
%pylab inline
In [4]:
climate = pd.read_csv("../data/waterlevel/ClimateWater.csv", index_col='date')
In [5]:
climate
Out[5]:
In [6]:
newindex = []
for ind in water23.index:
newindex.append(ind.split()[0])
In [7]:
vals, inds = np.unique(newindex, return_inverse=True)
In [8]:
upperh_med = np.ones(vals.size)*np.nan
downh_med = np.ones(vals.size)*np.nan
upperh_std = np.ones(vals.size)*np.nan
downh_std = np.ones(vals.size)*np.nan
for i in range (vals.size):
active = inds==i
upperh_med[i] = np.median(water23["upperlevel"].values[active])
downh_med[i] = np.median(water23["downlevel"].values[active])
upperh_std[i] = np.std(water23["upperlevel"].values[active])
downh_std[i] = np.std(water23["downlevel"].values[active])
In [9]:
date = climate.index.values
In [10]:
climate.keys()
Out[10]:
In [ ]:
In [11]:
actind = np.in1d(date, vals)
In [12]:
upperh = np.ones(date.size)*np.nan
downh = np.ones(date.size)*np.nan
upperh[actind] = upperh_med
downh[actind] = downh_med
In [13]:
waterdataset = list (zip(date, climate['WaterH1'].values, upperh, downh,\
climate['Rainfall(mm)'].values, climate['SurfaceTemp(\xa1\xc6C)'].values, climate['Moisture(%)'].values))
df = pd.DataFrame(data = waterdataset, columns=['date', 'reservoirH', 'upperH_med', 'downH_med',\
'Rainfall (mm)', 'Temp (degree)', 'Moisture (percent)'])
df.set_index('date')
Out[13]:
In [14]:
df['upperH_med'].plot(figsize=(20,3),color='k')
Out[14]:
In [15]:
fig = plt.figure(figsize=(12,4))
ax1 = plt.subplot(111)
ax1_1 = ax1.twinx()
df['upperH_med'].plot(figsize=(20,3), ax=ax1, color='k')
df['reservoirH'].plot(figsize=(20,3), ax=ax1, color='b')
df['downH_med'].plot(figsize=(20,3), ax=ax1_1, color='r')
grid(True)
In [16]:
df.keys()
Out[16]:
In [17]:
ax1 = plt.subplot(111)
ax1_1 = ax1.twinx()
df.plot(figsize=(12,3), x='date', y='reservoirH', ax=ax1, color='k', linestyle='-', lw=2, marker='.', ms=2)
df.plot(figsize=(12,3), x='date', y='upperH_med', ax=ax1, color='k', linestyle='--', lw=2)
df.plot(figsize=(12,3), x='date', y='downH_med', ax=ax1_1, color='r', linestyle='-')
ax1_1.legend(loc=4)
ax1.grid(True)
indst, indend = 80, 100
ax1.plot(np.r_[indst, indst], np.r_[28, 42], 'k-')
ax1.plot(np.r_[indend, indend], np.r_[28, 42], 'k--')
print df['date'].values[indst], df['date'].values[indst]
# ax1.set_ylim(39.5, 40.5)
# ax1.set_xlim(indst, indend)
In [18]:
ax1 = plt.subplot(111)
ax1_1 = ax1.twinx()
df.plot(figsize=(12,3), x='date', y='reservoirH', ax=ax1, color='k', linestyle='-', lw=2, marker='.', ms=2)
df.plot(figsize=(12,3), x='date', y='upperH_med', ax=ax1, color='k', linestyle='--', lw=2)
df.plot(figsize=(12,3), x='date', y='downH_med', ax=ax1_1, color='r', linestyle='-')
ax1_1.legend(loc=4)
ax1.grid(True)
indst, indend = 80, 100
ax1.plot(np.r_[indst, indst], np.r_[28, 42], 'k-')
ax1.plot(np.r_[indend, indend], np.r_[28, 42], 'k--')
print df['date'].values[indst], df['date'].values[indst]
ax1.set_ylim(39.5, 40.5)
ax1.set_xlim(indst, indend)
Out[18]:
In [19]:
ax1 = plt.subplot(111)
df.plot(figsize=(12,3), x='date', y='Rainfall (mm)', ax=ax1, color='b', marker='o', linestyle="-", ms=3)
df.plot(figsize=(12,3), x='date', y='Temp (degree)', ax=ax1, color='k', marker='None', linestyle="-", ms=3)
plt.tight_layout()
In [20]:
import sys
sys.path.append("../codes/")
from Readfiles import getFnames
from DCdata import readReservoirDC_data, readReservoirDC_all
directory = "../data/ChungCheonDC/"
fnames = getFnames(directory, dtype="apr", minimumsize=7000.)
In [21]:
import datetime
import numpy as np
In [22]:
def getdate(fstring):
temp = fstring.split('.')[0]
return datetime.date(int(temp[:4]), int(temp[4:6]), int(temp[6:8]))
In [23]:
date_temp = getdate(fnames[20])
In [24]:
date_temp.strftime("%Y-%m-%d")
Out[24]:
In [25]:
# for i in range (vals.size):
# active = inds==i
# upperh_med[i] = np.median(water23["upperlevel"].values[active])
# downh_med[i] = np.median(water23["downlevel"].values[active])
# upperh_std[i] = np.std(water23["upperlevel"].values[active])
# downh_std[i] = np.std(water23["downlevel"].values[active])
In [26]:
dat_temp, htemp, ID = readReservoirDC_all(directory+fnames[0])
ID.append('date')
ID.append('fnames')
ntimes = len(fnames)
DATA = np.zeros((dat_temp.shape[0], ntimes))*np.nan
index = np.ones(ntimes, dtype='bool')
for i, fname in enumerate(fnames):
dat_temp = readReservoirDC_data(directory+fname)
if dat_temp.shape[0] == 380:
DATA[:,i] = dat_temp[:,-1]
else:
print fname,dat_temp.shape[0]
index[i] = False
In [27]:
fnameDC = np.array(fnames)[index]
datesDC = []
for i in range(fnameDC.size):
tempdate = getdate(fnameDC[i])
datesDC.append(tempdate.strftime("%Y-%m-%d"))
datesDC = np.array(datesDC)
In [28]:
datesDC.size
Out[28]:
In [29]:
vals, inds = np.unique(datesDC, return_inverse=True)
In [30]:
DATA_active = DATA[:,index]
DATA_DC = np.zeros((vals.size,DATA.shape[0]))*np.nan
DATA_DC_std = np.zeros((vals.size,DATA.shape[0]))*np.nan
for i in range (vals.size):
active = inds==i
DATA_DC[i,:] = np.median(DATA_active[:,active], axis=1)
DATA_DC_std[i,:] = np.std(DATA_active[:,active], axis=1)
In [31]:
actind = np.in1d(date, vals)
DATA_DC_final = np.zeros((365,DATA.shape[0]))*np.nan
DATA_DC_std_final = np.zeros((365,DATA.shape[0]))*np.nan
DATA_DC_final[actind,:] = DATA_DC
DATA_DC_std_final[actind,:] = DATA_DC_std
In [32]:
DATA_DC.shape
Out[32]:
In [33]:
df_DCstd = pd.DataFrame(data = np.hstack((DATA_DC_std_final, date.reshape([-1,1]))), columns=ID)
df_DCstd.set_index('date')
df_DC = pd.DataFrame(data = np.hstack((DATA_DC_final, date.reshape([-1,1]))), columns=ID)
df_DC.set_index('date')
In [34]:
# df.to_csv("../data/ChungCheonDC/CompositeETCdata.csv")
# df_DC.to_csv("../data/ChungCheonDC/CompositeDCdata.csv")
# df_DCstd.to_csv("../data/ChungCheonDC/CompositeDCstddata.csv")
In [ ]: