{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Example on Quantitative Precipitation Estimate (QPE)\n\nThis example demonstrates how to perform QPE,\nusing raingauge data from Manila.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import os\nimport pandas\nimport numpy as np\nfrom swirlspy.qpe.rfmap import raingauge\nfrom swirlspy.qpe.rfmap import to_map_coordinates\nfrom swirlspy.qpe.rfmap import epsilon\nfrom swirlspy.qpe.rfmap import rbf_interpolation\nfrom swirlspy.qpe.rfmap import save_fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read files and declare raingauge object\n\nRead files in consecutive timesteps to obtain accumulated rainfall,\nreturn as a raingauge object.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "THIS_DIR = '../tests/test_qpe'\nos.chdir(THIS_DIR)\n \nfilelist = [\"rf60m_201808102340_qced\", \"rf60m_201808102350_qced\", \n \"rf60m_201808110000_qced\", \"rf60m_201808110010_qced\", \n \"rf60m_201808110020_qced\", \"rf60m_201808110030_qced\",\n \"rf60m_201808110040_qced\"]\ntable = pandas.read_csv(filepath_or_buffer=filelist[0], header=None, \n\t\t\t\t\t\tdelim_whitespace=True, skiprows=[0], \n\t\t\t\t\t\tusecols=[1,2,3], dtype=float, na_values=3276.7, \n\t\t\t\t\t\tlow_memory=False) #override nan values\nnrow, ncol = table.shape\naccu_rf = np.zeros(nrow)\n#accumulate rainfall\nfor i in range (0,len(filelist)):\n file = open(filelist[i])\n if i == 0:\n START_time = file.readline()\n elif i == len(filelist)-1:\n END_time = file.readline()\n table = pandas.read_csv(filepath_or_buffer=filelist[i], header=None, \n\t\t\t\t\t\t\tdelim_whitespace=True, skiprows=[0],\n\t\t\t\t\t\t\tusecols=[1,2,3], dtype=float, na_values=3276.7, \n\t\t\t\t\t\t\tlow_memory=False) #override nan values\n table = table.dropna()\n gauge_lat = table[1].values\n gauge_lon = table[2].values\n accu_rf = accu_rf + table[3].values\n \n#Declare raingauge object\nrg_object = raingauge(START_time, END_time, gauge_lat, \n\t\t\t\t\t gauge_lon, accu_rf)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Interpolation\n\nPerform RBF interpolation.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "lllon = 119.8\nurlon = 122.0\nlllat = 13.6\nurlat = 16.5\nRESOLUTION = 1000\nMODE= \"RBF\"\nm_rg_lon, m_rg_lat, m_lllon, m_lllat, m_urlon, m_urlat, \\\nRBF_gx, RBF_gy = to_map_coordinates(lllon, urlon, lllat, urlat, \n rg_object.gauge_lon, \n rg_object.gauge_lat,\n RESOLUTION) \nepsilon_value = epsilon(urlon, lllon, RESOLUTION, rg_object.rg_number)\ninterpolated_rf = rbf_interpolation(m_rg_lon, m_rg_lat, RBF_gx, \n RBF_gy, rg_object.rainfall, \n epsilon_value)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate rainfall map\n\nHere, we create a rainfall map with Cartopy basemap and\nshowing raingauge values. Please refer to \n`swirlspy.qpe.rfmap.save_fig` for customization.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#Options here: showing raingauge values, Cartopy basemap\nsave_fig(MODE, rg_object.START_time, rg_object.END_time, lllon, urlon, lllat, \n urlat, m_rg_lon, m_rg_lat, rg_object.rainfall, \n RBF_gx, RBF_gy, interpolated_rf, True, True)" ] } ], "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.6.15" } }, "nbformat": 4, "nbformat_minor": 0 }