Notebook to compare DFO tides with my tides
import matplotlib.pyplot as plt
import pandas as pd
from salishsea_tools import stormtools
import datetime
from dateutil import tz
import numpy as np
%matplotlib inline
def date_parser(s):
unaware =datetime.datetime.strptime(s, '%Y-%m-%d %H:%M')
aware = unaware.replace(tzinfo=tz.tzutc())
return aware
DFO_file='/data/nsoontie/MEOPAR/analysis/Nancy/tides/Observed-DFO.csv'
DFO=pd.read_csv(DFO_file,parse_dates=[1],header=0,names=['station','time','tides','e1','e2'],date_parser=date_parser)
my_file='/data/nsoontie/MEOPAR/analysis/Nancy/tides/Point Atkinson_t_tide_compare8_31-Dec-2013_02-Jan-2015.csv'
ttide,msl=stormtools.load_tidal_predictions(my_file)
fig,ax=plt.subplots(1,1,figsize=(10,5))
ax.plot(DFO.time,DFO.tides,'-o',label='DFO')
ax.plot(ttide.time,ttide.pred_all +msl,'-o',label='pred_all')
ax.plot(ttide.time,ttide.pred_8+msl,label='pred_8')
ax.set_xlim(datetime.datetime(2014,12,7),datetime.datetime(2014,12,12))
ax.legend(loc=0)
<matplotlib.legend.Legend at 0x7f651408ec90>
Zoom on Dec 8 lows
fig,ax=plt.subplots(1,1,figsize=(10,5))
ax.plot(DFO.time,DFO.tides,'-o',label='DFO')
ax.plot(ttide.time,ttide.pred_all +msl,label='pred_all')
ax.plot(ttide.time,ttide.pred_8+msl,label='pred_8')
ax.set_xlim(datetime.datetime(2014,12,8),datetime.datetime(2014,12,9))
ax.set_ylim([0,1])
ax.legend(loc=0)
ax.grid()
Zoom on Dec 8 highs
fig,ax=plt.subplots(1,1,figsize=(10,5))
ax.plot(DFO.time,DFO.tides,'-o',label='DFO')
ax.plot(ttide.time,ttide.pred_all +msl,label='pred_all')
ax.plot(ttide.time,ttide.pred_8+msl,label='pred_8')
ax.set_xlim(datetime.datetime(2014,12,8),datetime.datetime(2014,12,9))
ax.set_ylim([4,5])
ax.legend(loc=0)
ax.grid()
Zoom on Dec 8 middles
fig,ax=plt.subplots(1,1,figsize=(10,5))
ax.plot(DFO.time,DFO.tides,'-o',label='DFO')
ax.plot(ttide.time,ttide.pred_all +msl,label='pred_all')
ax.plot(ttide.time,ttide.pred_8+msl,label='pred_8')
ax.set_xlim(datetime.datetime(2014,12,8),datetime.datetime(2014,12,9))
ax.set_ylim([3,4])
ax.legend(loc=0)
ax.grid()
Looks like we are shifted in our tidal predictions. Eyeballing, we are 10-15cm low (pred_all)
How do means, maxes and mins compare for Dec 8-12?
t1=datetime.datetime(2014,12,8); t2=datetime.datetime(2014,12,12)
t1 = t1.replace(tzinfo=tz.tzutc())
t2 = t2.replace(tzinfo=tz.tzutc())
subDFO=np.array(DFO.tides)
timDFO=np.array(DFO.time)
indices = np.where(np.logical_and(timDFO >= t1, timDFO <= t2))
subDFO=subDFO[indices];
timDFO=timDFO[indices];
meanDFO=np.nanmean(subDFO); maxDFO=np.nanmax(subDFO); minDFO=np.nanmin(subDFO)
submine=np.array(ttide.pred_all);
timmine=np.array(ttide.time);
indices = np.where(np.logical_and(timmine >= t1, timmine <= t2))
submine=submine[indices] +msl;
timmine=timmine[indices];
meanmine=np.nanmean(submine); maxmine=np.nanmax(submine); minmine=np.nanmin(submine)
print 'DFO: Mean {}, Max {}, Min {}'.format(meanDFO,maxDFO,minDFO)
print 'Mine: Mean {}, Max {}, Min {}'.format(meanmine,maxmine,minmine)
DFO: Mean 3.13881439722, Max 4.77, Min 0.681 Mine: Mean 2.9987344433, Max 4.631196, Min 0.536173
print 'Differences: Mean {}, Max {}, Min {}'.format(meanDFO-meanmine,maxDFO-maxmine,minDFO-minmine)
Differences: Mean 0.140079953926, Max 0.138804, Min 0.144827
So our tidal predictions are 14 cm too low (at least for this time period). This is a pretty consistent shift in the mean, max and min.
Why? My tidal predictions are calculated based on harmonics from a 2013 time series. So the mean sea level for the tidal predictions is based on the 2013 value. Could the 2014 mean sea level be higher? How would this be reflected in the tidal predictions? Are annual variations in the mean sea level controlled by tides or non-tidal phenomena (like ENSO...)?
In the paper, the same method was used to calculate tidal predictions: take the harmonics from the year before and generate a tidal prediction. Since the residual was calculated based on the difference between observations and these tidal predictions, any year-to-year changes in mean sea level should be reflected in the residual. To determine the modelled water level, I added a long term mean sea level (from xtide) to each station. But for these nowcasts I'm adding the 2013 annual mean so that the model and tides are measured about the same level. (If I'm caclulating modelled residuals with the tidal predictions I thought it makes most sense for them to have the same mean but maybe not?).
What does this mean for our nowcasts?
Notes: Pt Atkinson 2013 msl: 3.05 m, Pt Atkinson xtide msl: 3.10 m, Pt Atkinson Dec 2013-Nov 2014 msl: 3.12m
Another thought: Should we calculate the tidal predictions more often than hourly? I'm not sure if I can use some of the stormtools in that case...
Remove means over that time period
fig,ax=plt.subplots(1,1,figsize=(10,5))
ax.plot(timDFO,subDFO-meanDFO,'-o',label='DFO')
ax.plot(timmine,submine-meanmine,'-o',label='pred_all')
ax.set_xlim(datetime.datetime(2014,12,7),datetime.datetime(2014,12,12))
ax.legend(loc=0)
<matplotlib.legend.Legend at 0x7f6513d383d0>
fig,ax=plt.subplots(1,1,figsize=(10,5))
ax.plot(timDFO,subDFO-meanDFO,'-o',label='DFO')
ax.plot(timmine,submine-meanmine,'-o',label='pred_all')
ax.set_xlim(datetime.datetime(2014,12,7),datetime.datetime(2014,12,12))
ax.legend(loc=0)
ax.set_xlim(datetime.datetime(2014,12,8),datetime.datetime(2014,12,9))
ax.set_ylim([0,.5])
ax.legend(loc=0)
ax.grid()
fig,ax=plt.subplots(1,1,figsize=(10,5))
ax.plot(timDFO,subDFO-meanDFO,'-o',label='DFO')
ax.plot(timmine,submine-meanmine,'-o',label='pred_all')
ax.set_xlim(datetime.datetime(2014,12,7),datetime.datetime(2014,12,12))
ax.legend(loc=0)
ax.set_xlim(datetime.datetime(2014,12,8),datetime.datetime(2014,12,9))
ax.set_ylim([1.2,1.7])
ax.legend(loc=0)
ax.grid()