Access to historical records is important to
Here we will see how we can query historical data from a buoy located offshore Sydney.
Our dataset is available from:
IMOS Data Portal and has been recorded by the Manly Hydraulics Laboratory:
We will use the netCDF libary (Network Common Data Form) is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data. The project homepage is hosted by the Unidata program at the University Corporation for Atmospheric Research (UCAR).
Loading a module is straight forward:
%matplotlib inline
from pylab import *
import netCDF4
import datetime as dt
import numpy as np
import pandas as pd
from pylab import rcParams
import warnings
warnings.filterwarnings('ignore')
We will use a dataset containing ocean wave data from wave monitoring buoy moored off Sydney at latitude 33$^o$46'26" S, longitude 151$^o$24'42" E and water depth 90 metres.
Sydney Waverider Buoy location history
The data is gathered using the Directional Waverider system developed by the Dutch company, Datawell. The Directional Waverider buoy utilises a heave-pitch-roll sensor, two fixed X and Y accelerometers and a three axis fluxgate compass to measure both vertical and horizontal motion. An on-board processor converts the buoy motion to three orthogonal (vertical, north-south, east-west) translation signals that are transmitted to the shore station. The directional spectrum is also routinely transmitted to the receiving station for further processing. The wave data is stored on the receiving station PC before routine transfer to Manly Hydraulics Laboratory.
# Offshore Sydney buoy data
filename = '../../dataset/IMOS_ANMN-NSW_W_20150210T230000Z_WAVESYD_WAVERIDER_FV01_END-20171231T130000Z.nc'
# Offshore Batemans Bay buoy data
#filename = '../../dataset/IMOS_ANMN-NSW_W_20080124T210000Z_WAVEBAB_WAVERIDER_FV01_END-20151231T130000Z.nc'
nc_data=netCDF4.Dataset(filename)
Let have a look at the loaded netCDF variables
nc_data.variables.keys()
print(nc_data.variables['TIME'])
Get the time extension of the gathered data...
units = nc_data.variables['TIME'].units
calendar = nc_data.variables['TIME'].calendar
times = netCDF4.num2date(nc_data.variables['TIME'][:], units=units, calendar=calendar)
start = dt.datetime(1985,1,1)
# Get desired time step
time_var = nc_data.variables['TIME']
itime = netCDF4.date2index(start,time_var,select='nearest')
dtime = netCDF4.num2date(time_var[itime],time_var.units)
daystr = dtime.strftime('%Y-%b-%d %H:%M')
print('buoy record start time:',daystr)
end = dt.datetime(2018,1,1)
# Get desired time step
time_var = nc_data.variables['TIME']
itime2 = netCDF4.date2index(end,time_var,select='nearest')
dtime2 = netCDF4.num2date(time_var[itime2],time_var.units)
dayend = dtime2.strftime('%Y-%b-%d %H:%M')
print('buoy record end time:',dayend)
print('Records per day:')
for k in range(1,25):
print(netCDF4.num2date(time_var[k],time_var.units))
Check the location of the data
loni = nc_data.variables['LONGITUDE'][:]
lati = nc_data.variables['LATITUDE'][:]
print(loni,lati)
names=[]
names.append('Offshore Sydney Buoy')
Export for the historical time serie, the desired buoy variables, here we use HRMS:
times = nc_data.variables['TIME']
jd_data = netCDF4.num2date(times[:],times.units, only_use_cftime_datetimes=False,
only_use_python_datetimes=True).flatten()
hm_data = nc_data.variables['HRMS'][:].flatten()
#T_data = ???
jd_data
Now plot the exported dataset
MyDateFormatter = DateFormatter('%Y-%b-%d')
fig = plt.figure(figsize=(16,10), dpi=80)
ax1 = fig.add_subplot(111)
ax1.plot(jd_data[itime:itime2],hm_data[itime:itime2],linewidth=1)
ax1.xaxis.set_major_locator(WeekdayLocator(byweekday=MO,interval=12))
ax1.xaxis.set_major_formatter(MyDateFormatter)
ax1.grid(True)
setp(gca().get_xticklabels(), rotation=45, horizontalalignment='right')
plt.title('IMOS Offshore Sydney Buoy Data since 2015')
ax1.set_ylabel('meters')
ax1.legend(names,loc='upper right')
A man fools around in the wind at Bondi Beach, Sydney, on April 21 2015.
To find the temporal id
of the storm we use the python function argmax
:
idmax = hm_data[itime:itime2].argmax()
print('Temporal ID of the strom:',idmax)
print('Corresponding date:',jd_data[idmax])
Set the wave height RMS 48h before and after the recorded maximum wave height RMS time.
storm_time = ???
storm_hrms = ???
storm_period = ???
MyDateFormatter = DateFormatter('%b-%d %H:%M')
fig = plt.figure(figsize=(10,10), dpi=80)
ax1 = fig.add_subplot(111)
ax1.plot(storm_time,storm_hrms,linewidth=4)
ax1.xaxis.set_major_locator(HourLocator(byhour=range(24),interval=6))
ax1.xaxis.set_major_formatter(MyDateFormatter)
ax1.grid(True)
setp(gca().get_xticklabels(), rotation=45, horizontalalignment='right')
plt.title('Offshore Sydney Buoy Data for April 2015 storm')
ax1.set_ylabel('meters')
names = ['HRMS']
ax1.legend(names,loc='upper right')
def wave_power(rho,g,h,t):
power = ???
return power
def wave_energy(rho,g,h):
energy = ???
return energy
storm_power = wave_power(???)
storm_energy = wave_energy(???)
dates = pd.to_datetime(data_df['TIME'], format = '%Y-%m-%dT%H:%M:%SZ')
data_df['WHTH']
import matplotlib.dates as mdates
MyDateFormatter = DateFormatter('%Y-%b-%d')
fig = plt.figure(figsize=(16,10), dpi=160)
ax1 = fig.add_subplot(111)
ax1.plot(dates,data_df['WHTH'],linewidth=3)
locator = mdates.AutoDateLocator()
ax1.xaxis.set_major_locator(locator)
ax1.xaxis.set_major_formatter(MyDateFormatter)
ax1.grid(True)
setp(gca().get_xticklabels(), rotation=45, horizontalalignment='right')
plt.title('IMOS Offshore Sydney Buoy Data since 2015')
ax1.set_ylabel('meters')
fig.show()