{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Create bed shear stress example\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import pandas as pd\nimport toto\nimport matplotlib.pyplot as plt\nfrom toto.inputs.txt import TXTfile\nimport os\n# read the file\nhindcast='https://raw.githubusercontent.com/calypso-science/Toto/master/_tests/txt_file/wave_currents.txt.csv'\nos.system('wget %s ' % hindcast)\n\nhd=TXTfile(['wave_currents.txt.csv'],colNamesLine=1,skiprows=1,unitNamesLine=0,time_col_name={'year':'year','month':'month','day':'day','hour':'hour','min':'Minute'})\nhd.reads()\nhd.read_time()\nhd=hd._toDataFrame()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Switch from U and V to spd an drr\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "hd[0]['spd']=hd[0].DataTransformation.uv_to_spddir(u='Ve',v='Vn')['spd']"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Calculate bed shear stress\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "bed_shear=hd[0].DataTransformation.bed_shear_stress(spd='spd',hs='hs',tp='tp',\n                        args={'mode':'3D',\n                        'water_depth':10,\n                        'rho_water':1027,\n                              'z0': 0.001,\n                        })"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig=plt.figure()\nax1 = plt.subplot(211)\nax1.plot(hd[0].index,hd[0]['spd'],'b',label='Current speed')\nax1.set_ylabel('Current speed [m/s]',color='b')\nax1.tick_params(axis='y', color='b', labelcolor='b')\nax1bis = ax1.twinx()\nax1bis.plot(hd[0].index,hd[0]['hs'],'r',label='Wave height')\nax1bis.set_ylabel('Wave height [m]',color='r')\nax1bis.tick_params(axis='y', color='r', labelcolor='r')\nfig.autofmt_xdate()\n\nax2 = plt.subplot(212)\np1=ax2.plot(bed_shear.index,bed_shear['tau_cw'],'b',label='Mean bed shear stress during wave cycle')\nax2.set_ylabel('Mean bed shear stress [N/m2]',color='b')\nax2.tick_params(axis='y', color='b', labelcolor='b')\n\nax2bis = ax2.twinx()\np2=ax2bis.plot(bed_shear.index,bed_shear['tau_cw_max'],'r',label='Maximum bed shear stress during wave cycle')\nax2bis.tick_params(axis='y', color='r', labelcolor='r')\nax2bis.set_ylabel('Max bed shear stress [N/m2]',color='r')\n\nfig.autofmt_xdate()\nplt.tight_layout()\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "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.10"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}