{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Copy Forcing Files with Specific Date" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "This notebook is used to copy all of the forcing files needed to run SMELT that are for a specific date.\n", "All of the other files have already been copied over, but these ones need to be copied depending on what dates the model will be running." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import re\n", "import os\n", "import pandas as pd\n", "import subprocess" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": true }, "outputs": [], "source": [ "start_date = pd.DatetimeIndex([\"2016-03-29\"])[0]\n", "end_date = pd.DatetimeIndex([\"2016-04-18\"])[0]" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": true }, "outputs": [], "source": [ "atmospheric_source_dir = \"/results/forcing/atmospheric/GEM2.5/operational/\"\n", "open_bounds_source_dir = \"orcinus:/home/sallen/MEOPAR/NEMO-forcing/open_boundaries/west/ssh/\"\n", "rivers_source_dir = \"/results/forcing/rivers/\"" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": true }, "outputs": [], "source": [ "atmospheric_dest_dir = \"jasper:/home/jpetrie/MEOPAR/NEMO-forcing/atmospheric/\"\n", "open_bounds_dest_dir = \"jasper:/home/jpetrie/MEOPAR/NEMO-forcing/open_boundaries/west/ssh/\"\n", "rivers_dest_dir = \"jasper:/home/jpetrie/MEOPAR/NEMO-forcing/rivers/\"" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def numStrLength2(num):\n", " if(num < 10):\n", " return(\"0\" + str(num))\n", " else:\n", " return(str(num))\n", "def toFileDateFormat(dt_date):\n", " return(\"y\" + str(dt_date.year) + \"m\" + numStrLength2(dt_date.month) + \"d\" + numStrLength2(dt_date.day))\n", " " ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def copyRiver(src_dir, dest_dir, date_str):\n", " rfce_file = \"RFraserCElse_\" + date_str + \".nc\"\n", " rlfce_file = \"RLonFraCElse_\" + date_str + \".nc\"\n", " files = [rfce_file, rlfce_file]\n", " for f in files:\n", " src = src_dir + f\n", " subprocess.check_call([\"scp\", src, dest_dir])\n", "\n", "def copyAtmospheric(src_dir, dest_dir, date_str):\n", " ops_file = \"ops_\" + date_str + \".nc\"\n", " src = src_dir + ops_file\n", " subprocess.check_call([\"scp\", src, dest_dir])\n", " \n", " \n", "def copyOpenBounds(src_dir, dest_dir, date_str):\n", " ssh_file = \"ssh_\" + date_str + \".nc\"\n", " src = src_dir + ssh_file\n", " subprocess.check_call([\"scp\", src, dest_dir])\n" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Copied files for: y2016m03d29\n", "Copied files for: y2016m03d30\n", "Copied files for: y2016m03d31\n", "Copied files for: y2016m04d01\n", "Copied files for: y2016m04d02\n", "Copied files for: y2016m04d03\n", "Copied files for: y2016m04d04\n", "Copied files for: y2016m04d05\n", "Copied files for: y2016m04d06\n", "Copied files for: y2016m04d07\n", "Copied files for: y2016m04d08\n", "Copied files for: y2016m04d09\n", "Copied files for: y2016m04d10\n", "Copied files for: y2016m04d11\n", "Copied files for: y2016m04d12\n", "Copied files for: y2016m04d13\n", "Copied files for: y2016m04d14\n", "Copied files for: y2016m04d15\n", "Copied files for: y2016m04d16\n", "Copied files for: y2016m04d17\n", "Copied files for: y2016m04d18\n" ] } ], "source": [ "current_date = start_date\n", "\n", "while(current_date <= end_date):\n", " date_str = toFileDateFormat(current_date)\n", " try:\n", " copyRiver(rivers_source_dir, rivers_dest_dir, date_str)\n", " copyAtmospheric(atmospheric_source_dir, atmospheric_dest_dir, date_str)\n", " copyOpenBounds(open_bounds_source_dir, open_bounds_dest_dir, date_str)\n", " print(\"Copied files for: \" + date_str)\n", " except Exception as e:\n", " print(\"Couldn't copy files for: \" + date_str)\n", " print(e)\n", " current_date = current_date + pd.Timedelta(days = 1)\n", " \n", "print(\"Done\")" ] } ], "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.5.2" } }, "nbformat": 4, "nbformat_minor": 0 }