from salishsea_tools import tidetools
tidetools.get_dfo_wlev(7795,'01-JAN-2003','01-JAN-2013')
Results saved here: wlev_7795_01-JAN-2003_01-JAN-2013.csv
reload(tidetools)
tidetools.get_all_perm_dfo_wlev('01-JAN-2003','01-JAN-2013')
Results saved here: wlev_8735_01-JAN-2003_01-JAN-2013.csv Results saved here: wlev_7277_01-JAN-2003_01-JAN-2013.csv Results saved here: wlev_7120_01-JAN-2003_01-JAN-2013.csv Results saved here: wlev_8408_01-JAN-2003_01-JAN-2013.csv Results saved here: wlev_7735_01-JAN-2003_01-JAN-2013.csv Results saved here: wlev_7795_01-JAN-2003_01-JAN-2013.csv Results saved here: wlev_8545_01-JAN-2003_01-JAN-2013.csv Results saved here: wlev_7654_01-JAN-2003_01-JAN-2013.csv Results saved here: wlev_8074_01-JAN-2003_01-JAN-2013.csv Results saved here: wlev_8615_01-JAN-2003_01-JAN-2013.csv
import datetime
import pandas as pd
import pytz
#define a function for dealing with parsed time from read_csv
def dateParserMeasured(s):
#convert the string to a datetime object
unaware = datetime.datetime.strptime(s, "%Y/%m/%d %H:%M")
#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'))
wlev_meas = pd.read_csv('wlev_ts_for_storms.csv',skiprows=7,parse_dates=[0],date_parser=dateParserMeasured)
wlev_meas = wlev_meas.rename(columns={'Obs_date': 'time', 'SLEV(metres)': 'slev'})
print(wlev_meas.time[0].tzinfo)
#convert to arrays
#wlev = numpy.array(wlev_all.slev)
UTC
#plot the measured data
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
plt.plot(wlev_meas.time[0:1000],wlev_meas.slev[0:1000])
plt.title('Station '+str(station_no))
plt.ylabel('Elevation [m CD]')
plt.xlabel('Time [UTC]')
<matplotlib.text.Text at 0x18920310>
I cheated and converted the output from Webtide (in html) into a slightly nicer CSV and deleted the space between the 'Julian' and 'Day' to read in properly. Then I read it in with pandas as follows.
#define a function for dealing with dates from pandas
import datetime
import pytz
import pandas as pd
def dateParserPredicted1(s):
unaware = datetime.datetime.strptime(s,'%Y %j %H %M %S')
return unaware.replace(tzinfo=pytz.UTC)
#import the predicted water level
wlev_pred = pd.read_csv('webtide_pred_7795_2002_2013.csv',skiprows=[0,1,2,3,4,5,7,8,9],delimiter=';',\
parse_dates={'time':['Year','JulianDay','Hour','Minute','Second']},\
date_parser=dateParserPredicted1)
#Vertical datum in Webtide is Mean Water Level
#Webtide_0m = MWL = +3.3mCD ==================> Taken from Approaches to Toba Inlet map... CHECK!!!!
wlev_pred.Elevation = wlev_pred.Elevation + 3.3
plt.plot(Test.time,Test.Elevation)
[<matplotlib.lines.Line2D at 0x722c290>]
#plot the predicted water level
plt.plot(wlev_pred.time[0:100],wlev_pred.Elevation[0:100])
plt.ylabel('Elevation [m CD]')
plt.xlabel('Time [UTC]')
<matplotlib.text.Text at 0x886ce10>
#find the sea surface anomaly (measured-predicted)
#check lengths
print(len(wlev_pred.time))
print(len(wlev_meas.time))
time = [0]*len(wlev_meas.time)
ssanomaly = [0]*len(wlev_meas.time)
for i in numpy.arange(0,len(wlev_meas.time)):
time[i] = wlev_meas.time[i]
#check that there is a corresponding time
#if any(wlev_pred.time == wlev_meas.time[i]):
ssanomaly[i] = wlev_pred.Elevation[wlev_pred.time==wlev_meas.time[i]] - wlev_meas.slev[i]
if not(ssanomaly[i]):
ssanomaly[i]=float('Nan')
96433 8761
for i in numpy.arange(1,2):
plt.figure()
plt.subplot(2,1,1)
plt.plot(wlev_meas.time,wlev_meas.slev,'b',label='measured')
plt.plot(wlev_pred.time,wlev_pred.Elevation,'m',label='predicted')
plt.xlim(datetime.datetime(req_year,1,1,0,0,0),datetime.datetime(req_year,12,31,23,59,59))
plt.legend(bbox_to_anchor=(1.05, 1), loc=2)
plt.xlabel('Time (UTC)')
plt.ylabel('Elevation (m CD)')
plt.subplot(2,1,2)
plt.plot(time,ssanomaly,'g',label='anomaly')
plt.xlim(datetime.datetime(req_year,1,1,0,0,0),datetime.datetime(req_year,12,31,23,59,59))
plt.legend(bbox_to_anchor=(1.05, 1), loc=2)
plt.xlabel('Time (UTC)')
plt.ylabel('Elevation (m CD)')
import numpy
#only look at December-March
test = numpy.zeros((len(wlev),1))
for i in numpy.arange(0,len(wlev)):
test[i,0] = wlev_meas.time[i].month
test1 = numpy.where(numpy.logical_or(test[:,0]>11,test[:,0]<4))
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-11-4f28a1688203> in <module>() 1 import numpy 2 #only look at December-March ----> 3 test = numpy.zeros((len(wlev),1)) 4 for i in numpy.arange(0,len(wlev)): 5 test[i,0] = wlev_meas.time[i].month NameError: name 'wlev' is not defined