# -*- coding: utf-8 -*- """ Created on Tue Mar 24 19:02:20 2020 @author: z5025317 """ #load existing tgr time series boundary, raise by 1m and output a new tgr file #==========================================================# #Load packages #==========================================================# import numpy as np import os import pandas as pd import glob os.chdir('C:/Users/z5025317/UNSW/Danial Khojasteh - HEMIP/RMA_result_explorer_code') River = 'Shoalhaven' tgr_csv_folder_path = 'C:/Users/z5025317/UNSW/Danial Khojasteh - HEMIP/Models/' + River + '/02_Input/Boundary_conditions/Tide/' filenames = glob.glob(tgr_csv_folder_path + '*05.csv') for tgr_csv_name in filenames: print (tgr_csv_name) #tgr_csv_name = 'R45_2008_existing_run_tgr.csv' Waterlevel_increases = [0.25, 0.5, 1, 2] # in m AHD for Waterlevel_increase in Waterlevel_increases: tgr_outname = tgr_csv_folder_path + os.path.basename(tgr_csv_name)[:-4] + '_plus_SLR_' + str(Waterlevel_increase) + 'm' Full_df = pd.read_csv(tgr_csv_name ,header= 0, parse_dates = False) Full_df.columns = ['1','2','3','4'] df = Full_df #.loc[1:2000] # str(df['2'][1500].astype(int)) # RMA2: create input file fq = open( os.path.join(tgr_csv_folder_path, tgr_outname + '.tgr'), 'w') fq.write('TT Manning base case tide + SLR of ' + str(Waterlevel_increase) + 'm \n') #fq.write('{:<5}{:>3}{:>8}{:>8}\n'.format('CLH', '', '2', '2008')) fq.write('{:<5}{:>3}{:>8}{:>8}\n'.format('CLH', '', int(df['3'][0]), int(df['4'][0]))) for i in range(1,len(df)-1,1): # For each new element fq.write('{:<5}{:>3}{:>8}{:>8}\n'.format(df['1'][i], df['2'][i], df['3'][i], str(np.round(df['4'][i].astype(float)+ Waterlevel_increase,3)))) fq.write('ENDDATA') fq.close()