{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Decumulate rain fields\n", "======================\n", "and write it back to GRIB, ensuring proper validity" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Vortex 1.5.1 loaded ( Wednesday 19. December 2018, at 13:47:27 )\n" ] } ], "source": [ "import usevortex\n", "import epygram\n", "import os" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "pwd = os.getcwd()\n", "os.chdir('/home/mary/tmp')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "vortex_description = dict(# Resource...\n", " kind='gridpoint',\n", " geometry='ncaled0025',\n", " nativefmt='grib',\n", " origin='historic',\n", " model='arome',\n", " vapp='arome',\n", " vconf='caledonie',\n", " cutoff='prod',\n", " term=range(4),\n", " date='2018050800',\n", " # Provider...\n", " namespace='vortex.multi.fr',\n", " experiment='oper',\n", " block='forecast',\n", " # Container\n", " shouldfly=True)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "# [2018/12/19-13:47:28][common.util.usepygram][:0031][INFO]: Epygram 1.3.5 loaded.\n" ] } ], "source": [ "with usevortex.quiet_get():\n", " resources = usevortex.get_resources(getmode='epygram',\n", " **vortex_description)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "rain = [r.readfield('indicatorOfParameter:150') for r in resources[1:]] # term 0, no rain" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [], "source": [ "for i in range(len(rain)):\n", " if i == 0: continue # term 1, no decumulation to do\n", " rain[i].operation('-', rain[i-1])\n", " rain[i].validity[0].set(cumulativeduration=(rain[i].validity[0].get()-rain[i-1].validity[0].get()))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "FieldValidity containing:\n", " _basis: 2018-05-08 00:00:00\n", " _date_time: 2018-05-08 01:00:00\n", " _statistical_process_on_duration: None\n", " _cumulativeduration: 1:00:00\n", "FieldValidity containing:\n", " _basis: 2018-05-08 00:00:00\n", " _date_time: 2018-05-08 02:00:00\n", " _statistical_process_on_duration: None\n", " _cumulativeduration: 1:00:00\n", "FieldValidity containing:\n", " _basis: 2018-05-08 00:00:00\n", " _date_time: 2018-05-08 03:00:00\n", " _statistical_process_on_duration: None\n", " _cumulativeduration: 1:00:00\n" ] } ], "source": [ "rain_series = epygram.formats.resource(os.path.join(pwd,'../outputs/rain_series.grib'), 'w', fmt='GRIB')\n", "for r in rain:\n", " print(r.validity[0])\n", " rain_series.writefield(r)\n", "rain_series.close()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 0 }