{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Generate IDV_teleport script." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd #only requirement" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "raw=pd.read_csv('Igel_WEIO_case_list.txt',sep='\\s+',names=['syyyy','smm','sdd','eyyyy','emm','edd'])" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
syyyysmmsddeyyyyemmedd
01997227199734
11997228199735
219979301997103
319992211999227
419994221999427
\n", "
" ], "text/plain": [ " syyyy smm sdd eyyyy emm edd\n", "0 1997 2 27 1997 3 4\n", "1 1997 2 28 1997 3 5\n", "2 1997 9 30 1997 10 3\n", "3 1999 2 21 1999 2 27\n", "4 1999 4 22 1999 4 27" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.head() #s prefix for start and e prefix for end" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Teleport script needs a centered date and time delta to teleport, so calculate center of the state and timedelta " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "startdate=raw.apply(lambda x:pd.datetime(x['syyyy'],x['smm'],x['sdd']),axis=1)\n", "enddate=raw.apply(lambda x:pd.datetime(x['eyyyy'],x['emm'],x['edd']),axis=1)+pd.to_timedelta(1,unit='days')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "raw['startdate']=startdate\n", "raw['timedelta']=((enddate-startdate)/2.0).apply(lambda x:pd.to_timedelta(x.days,unit='days'))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "raw['teleportdate']=raw['startdate']+raw['timedelta']" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
syyyysmmsddeyyyyemmeddstartdatetimedeltateleportdate
019972271997341997-02-273 days1997-03-02
119972281997351997-02-283 days1997-03-03
2199793019971031997-09-302 days1997-10-02
3199922119992271999-02-213 days1999-02-24
4199942219994271999-04-223 days1999-04-25
\n", "
" ], "text/plain": [ " syyyy smm sdd eyyyy emm edd startdate timedelta teleportdate\n", "0 1997 2 27 1997 3 4 1997-02-27 3 days 1997-03-02\n", "1 1997 2 28 1997 3 5 1997-02-28 3 days 1997-03-03\n", "2 1997 9 30 1997 10 3 1997-09-30 2 days 1997-10-02\n", "3 1999 2 21 1999 2 27 1999-02-21 3 days 1999-02-24\n", "4 1999 4 22 1999 4 27 1999-04-22 3 days 1999-04-25" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Generate teleport script by applying a function to every row of the dataframe and save it" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "executable=\"idv_teleport\"\n", "bundle=\"-b ERAI_MERRA2_TPW_2soundings_IRsat.xidv\"\n", "bbox='-bbox 17 36 -15 90' #NW SW\n", "extra=\"-nohead True\"\n", "#needed -t -td -case\n", "def teleport_str(x):\n", " tdate=str(x['teleportdate']).split(' ')[0]\n", " td=str(x['timedelta'].days)+'days'\n", " case='Igel_WEIO_case_'+str(x['startdate']).split(' ')[0]\n", " return ' '.join([executable,bundle,'-t',tdate,'-td',td,bbox,'-case',case,extra])" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "teleport_str=raw.apply(teleport_str,axis=1)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'idv_teleport -b ERAI_MERRA2_TPW_2soundings_IRsat.xidv -t 1997-03-02 -td 3days -bbox 17 36 -15 90 -case Igel_WEIO_case_1997-02-27 -nohead True'" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "teleport_str[0]" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "teleport_str.to_csv('teleport_Igel_WEIO_cases.sh',sep='\\n',index=False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.5" } }, "nbformat": 4, "nbformat_minor": 2 }