%matplotlib inline
import matplotlib.pyplot as plt
import arrow
import datetime
import pandas as pd
from salishsea_tools import tidetools
from salishsea_tools import stormtools
import numpy as np
yr=2014
stations = {'PointAtkinson': 7795, 'Victoria': 7120, 'PatriciaBay': 7277, 'CampbellRiver': 8074}
s = '30-Nov-' + str(2013) #start date
e= '02-Dec-' + str(2014) #end date
tidetools.get_dfo_wlev(stations['CampbellRiver'],s,e)
tfile='Point Atkinson_t_tide_compare8_31-Dec-2013_02-Jan-2015.csv'
ttide1,msl= stormtools.load_tidal_predictions(tfile)
tfile='Point Atkinson_t_tide_compare8_31-Dec-2013_02-Dec-2015.csv'
ttide2,msl= stormtools.load_tidal_predictions(tfile)
%matplotlib inline
fig,ax=plt.subplots(1,1,figsize=(10,6))
ax.plot(ttide2.time,ttide2.pred_all)
ax.plot(ttide1.time,ttide1.pred_all)
ax.set_xlim([datetime.datetime(2014,8,14),datetime.datetime(2014,8,16)])
(735459.0, 735461.0)
subtide=np.array(ttide2.pred_all)
subtime=np.array(ttide2.time)
time1=np.array(ttide1.time)
tide1=np.array(ttide1.pred_all)
indices=np.where(np.logical_and(subtime<=time1[-1],subtime>=time1[0]))
subtide=subtide[indices]
subtime=subtime[indices]
diff= subtide-tide1;
print np.max(diff), subtime[np.argmax(diff)]
print np.mean(diff)
print np.min(diff), subtime[np.argmin(diff)]
0.051144 2014-08-15 09:00:00+00:00 4.97479850153e-06 -0.052169 2014-08-14 23:00:00+00:00
print subtime[0],time1[0]
print subtime[-1],time1[-1]
2013-12-31 08:00:00+00:00 2013-12-31 08:00:00+00:00 2015-01-02 08:00:00+00:00 2015-01-02 08:00:00+00:00
fig,ax=plt.subplots(1,1,figsize=(10,6))
ax.plot(subtime, diff)
ax.set_xlim([datetime.datetime(2014,8,14),datetime.datetime(2014,8,16)])
(735459.0, 735461.0)