%matplotlib inline
from matplotlib import pylab
import matplotlib.pyplot as plt
import netCDF4 as NC
import numpy as np
import datetime
import requests
from salishsea_tools import nc_tools
from salishsea_tools import tidetools
import os
import csv
Grab observations at Point Atkinson from 2013
yr=2013
statID = '7795'# station ID number
start = '31-Dec-' + str(yr-1) #start date
end = '02-Jan-' + str(yr+1) #end date
tidetools.get_dfo_wlev(statID,start,end)
# now there is a csv file in this directory with the sear surface height information. Let's take a look at the plots.
filename = 'wlev_' +str(statID) + '_' + start +'_' +end +'.csv'
yr=2014
start = '31-Dec-' + str(yr-1) #start date
end = '02-Jan-' + str(yr+1) #end date
filename = 'Point Atkinson_t_tide_compare8_' + start+'_'+end+'.csv'
import datetime
import pandas as pd
import pytz
def dateParserMeasured2(s):
#convert the string to a datetime object
unaware = datetime.datetime.strptime(s, "%d-%b-%Y %H:%M:%S ")
#add in the local time zone (Canada/Pacific)
aware = unaware.replace(tzinfo=pytz.timezone('Canada/Pacific'))
#convert to UTC
return aware.astimezone(pytz.timezone('UTC'))
ttide = pd.read_csv(filename,skiprows=3,parse_dates=[0],date_parser=dateParserMeasured2,delimiter='\t')
ttide = ttide.rename(columns={'Time_Local ': 'time', ' pred_8 ': 'pred_8', ' pred_all ': 'pred_all'})
Plot and adjust axis.
fig,ax=plt.subplots(1,1,figsize=(10,5))
ax.plot(ttide.time,ttide.pred_all,'-k')
ax.set_xlim(datetime.datetime(2014,9,9),datetime.datetime(2014,9,16))
ax.set_ylim([-3,3])
ax.grid()
ax.set_ylabel('Tidal elevation (m)')
<matplotlib.text.Text at 0x475fc10>