#!/usr/bin/env python # coding: utf-8 # # Copy Forcing Files with Specific Date This notebook is used to copy all of the forcing files needed to run SMELT that are for a specific date. 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. # In[2]: import re import os import pandas as pd import subprocess # In[19]: start_date = pd.DatetimeIndex(["2016-03-29"])[0] end_date = pd.DatetimeIndex(["2016-04-18"])[0] # In[20]: atmospheric_source_dir = "/results/forcing/atmospheric/GEM2.5/operational/" open_bounds_source_dir = "orcinus:/home/sallen/MEOPAR/NEMO-forcing/open_boundaries/west/ssh/" rivers_source_dir = "/results/forcing/rivers/" # In[21]: atmospheric_dest_dir = "jasper:/home/jpetrie/MEOPAR/NEMO-forcing/atmospheric/" open_bounds_dest_dir = "jasper:/home/jpetrie/MEOPAR/NEMO-forcing/open_boundaries/west/ssh/" rivers_dest_dir = "jasper:/home/jpetrie/MEOPAR/NEMO-forcing/rivers/" # In[22]: def numStrLength2(num): if(num < 10): return("0" + str(num)) else: return(str(num)) def toFileDateFormat(dt_date): return("y" + str(dt_date.year) + "m" + numStrLength2(dt_date.month) + "d" + numStrLength2(dt_date.day)) # In[23]: def copyRiver(src_dir, dest_dir, date_str): rfce_file = "RFraserCElse_" + date_str + ".nc" rlfce_file = "RLonFraCElse_" + date_str + ".nc" files = [rfce_file, rlfce_file] for f in files: src = src_dir + f subprocess.check_call(["scp", src, dest_dir]) def copyAtmospheric(src_dir, dest_dir, date_str): ops_file = "ops_" + date_str + ".nc" src = src_dir + ops_file subprocess.check_call(["scp", src, dest_dir]) def copyOpenBounds(src_dir, dest_dir, date_str): ssh_file = "ssh_" + date_str + ".nc" src = src_dir + ssh_file subprocess.check_call(["scp", src, dest_dir]) # In[24]: current_date = start_date while(current_date <= end_date): date_str = toFileDateFormat(current_date) try: copyRiver(rivers_source_dir, rivers_dest_dir, date_str) copyAtmospheric(atmospheric_source_dir, atmospheric_dest_dir, date_str) copyOpenBounds(open_bounds_source_dir, open_bounds_dest_dir, date_str) print("Copied files for: " + date_str) except Exception as e: print("Couldn't copy files for: " + date_str) print(e) current_date = current_date + pd.Timedelta(days = 1) print("Done")