{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# Analysing historical records of wave data from IMOS" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Access to historical records is important to \n", "* evaluate global and local impacts of climate change & anthropogenic influences and \n", "* test and validate models. In the modelling area, this kind of approach is done routinely to evaluate models performances (hindcast models).\n", "\n", "Here we will see how we can query historical data from a buoy located offshore Sydney. \n", "\n", "Our dataset is available from: \n", "\n", "IMOS Data Portal and has been recorded by the **Manly Hydraulics Laboratory**:\n", "+ dataset link\n", "\n", "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**).\n", "\n", "Loading a module is straight forward:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "from pylab import *\n", "import netCDF4\n", "import datetime as dt\n", "import numpy as np\n", "import pandas as pd\n", "\n", "from pylab import rcParams\n", "import warnings\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "# 2015 Waverider Buoy dataset\n", "\n", "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. \n", "\n", " Sydney Waverider Buoy location history\n", "\n", "\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Offshore Sydney buoy data\n", "filename = '../../dataset/IMOS_ANMN-NSW_W_20150210T230000Z_WAVESYD_WAVERIDER_FV01_END-20171231T130000Z.nc'\n", "# Offshore Batemans Bay buoy data\n", "#filename = '../../dataset/IMOS_ANMN-NSW_W_20080124T210000Z_WAVEBAB_WAVERIDER_FV01_END-20151231T130000Z.nc'\n", "\n", "nc_data=netCDF4.Dataset(filename)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Query dataset\n", "\n", "Let have a look at the loaded netCDF variables" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "nc_data.variables.keys()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(nc_data.variables['TIME'])" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## Find out time interval record\n", "\n", "Get the time extension of the gathered data..." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "units = nc_data.variables['TIME'].units\n", "calendar = nc_data.variables['TIME'].calendar\n", "\n", "times = netCDF4.num2date(nc_data.variables['TIME'][:], units=units, calendar=calendar)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "start = dt.datetime(1985,1,1)\n", "# Get desired time step \n", "time_var = nc_data.variables['TIME']\n", "itime = netCDF4.date2index(start,time_var,select='nearest')\n", "dtime = netCDF4.num2date(time_var[itime],time_var.units)\n", "daystr = dtime.strftime('%Y-%b-%d %H:%M')\n", "\n", "print('buoy record start time:',daystr)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "end = dt.datetime(2018,1,1)\n", "# Get desired time step \n", "time_var = nc_data.variables['TIME']\n", "itime2 = netCDF4.date2index(end,time_var,select='nearest')\n", "dtime2 = netCDF4.num2date(time_var[itime2],time_var.units)\n", "dayend = dtime2.strftime('%Y-%b-%d %H:%M')\n", "\n", "print('buoy record end time:',dayend)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('Records per day:')\n", "for k in range(1,25):\n", " print(netCDF4.num2date(time_var[k],time_var.units))" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "## Buoy location\n", "\n", "Check the location of the data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "loni = nc_data.variables['LONGITUDE'][:]\n", "lati = nc_data.variables['LATITUDE'][:]\n", "print(loni,lati)\n", "names=[]\n", "names.append('Offshore Sydney Buoy')" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Visualise buoy records\n", "\n", "Export for the historical time serie, the desired buoy variables, here we use HRMS:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "times = nc_data.variables['TIME']\n", "jd_data = netCDF4.num2date(times[:],times.units, only_use_cftime_datetimes=False, \n", " only_use_python_datetimes=True).flatten()\n", "hm_data = nc_data.variables['HRMS'][:].flatten()\n", "#T_data = ???" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jd_data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now plot the exported dataset" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "MyDateFormatter = DateFormatter('%Y-%b-%d')\n", "fig = plt.figure(figsize=(16,10), dpi=80) \n", "ax1 = fig.add_subplot(111)\n", "\n", "ax1.plot(jd_data[itime:itime2],hm_data[itime:itime2],linewidth=1) \n", "ax1.xaxis.set_major_locator(WeekdayLocator(byweekday=MO,interval=12))\n", "ax1.xaxis.set_major_formatter(MyDateFormatter)\n", "ax1.grid(True)\n", "setp(gca().get_xticklabels(), rotation=45, horizontalalignment='right')\n", "plt.title('IMOS Offshore Sydney Buoy Data since 2015')\n", "ax1.set_ylabel('meters')\n", "ax1.legend(names,loc='upper right')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# April 2015 storm\n", "\n", "![alt text](https://i.guim.co.uk/img/media/643dfa81d4bbca129906d8a26c683e3e6901c053/0_110_3000_1801/3000.jpg?w=1010&q=55&auto=format&usm=12&fit=max&s=6dac931858af8c21404a5604900ae71d)\n", "\n", "_A man fools around in the wind at Bondi Beach, Sydney, on April 21 2015._\n", "\n", "To find the temporal `id` of the storm we use the python function `argmax`:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "idmax = hm_data[itime:itime2].argmax()\n", "print('Temporal ID of the strom:',idmax)\n", "print('Corresponding date:',jd_data[idmax])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plotting variables \n", "\n", "Set the wave height RMS 48h before and after the recorded maximum wave height RMS time." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "storm_time = ???\n", "storm_hrms = ???\n", "storm_period = ???" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "MyDateFormatter = DateFormatter('%b-%d %H:%M')\n", "fig = plt.figure(figsize=(10,10), dpi=80) \n", "ax1 = fig.add_subplot(111)\n", "\n", "ax1.plot(storm_time,storm_hrms,linewidth=4) \n", "ax1.xaxis.set_major_locator(HourLocator(byhour=range(24),interval=6))\n", "ax1.xaxis.set_major_formatter(MyDateFormatter)\n", "ax1.grid(True)\n", "setp(gca().get_xticklabels(), rotation=45, horizontalalignment='right')\n", "plt.title('Offshore Sydney Buoy Data for April 2015 storm')\n", "ax1.set_ylabel('meters')\n", "names = ['HRMS']\n", "ax1.legend(names,loc='upper right')" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Wave power and energy\n", "\n", "- Wave power:\n", "$$P = \\frac{\\rho g^2}{64 \\pi} H_{mo}^2 T \\simeq 0.5 H_{mo}^2 T$$\n", "\n", "- Wave energy:\n", "$$E = \\frac{1}{16}\\rho g H_{mo}^2$$\n", "\n", "_Note:_\n", "You can define $\\pi$ using np.pi.\n", "\n", "### Define the functions" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def wave_power(rho,g,h,t):\n", " power = ???\n", " return power\n", "\n", "def wave_energy(rho,g,h):\n", " energy = ???\n", " return energy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "storm_power = wave_power(???)\n", "storm_energy = wave_energy(???)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Plot the data over the storm duration" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dates = pd.to_datetime(data_df['TIME'], format = '%Y-%m-%dT%H:%M:%SZ')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data_df['WHTH']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.dates as mdates\n", "MyDateFormatter = DateFormatter('%Y-%b-%d')\n", "fig = plt.figure(figsize=(16,10), dpi=160) \n", "ax1 = fig.add_subplot(111)\n", "ax1.plot(dates,data_df['WHTH'],linewidth=3) \n", "locator = mdates.AutoDateLocator()\n", "ax1.xaxis.set_major_locator(locator)\n", "ax1.xaxis.set_major_formatter(MyDateFormatter)\n", "ax1.grid(True)\n", "setp(gca().get_xticklabels(), rotation=45, horizontalalignment='right')\n", "plt.title('IMOS Offshore Sydney Buoy Data since 2015')\n", "ax1.set_ylabel('meters')\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.15" } }, "nbformat": 4, "nbformat_minor": 1 }