You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
2.1 KiB
Python
51 lines
2.1 KiB
Python
5 years ago
|
# -*- coding: utf-8 -*-
|
||
|
"""
|
||
|
Created on Tue Mar 24 19:02:20 2020
|
||
|
|
||
|
@author: z5025317
|
||
|
"""
|
||
|
|
||
|
#creates a tide boundary time series in RMA format based on MHL tide data as provided for the RAP
|
||
|
|
||
|
#==========================================================#
|
||
|
#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')
|
||
|
year = '2015'
|
||
|
|
||
|
Ocean_gauges_folder = 'J:/Project/wrl2018064 Fisheries RAP/04_Working/05_Modelling/RMA/HEMIP/Global_HEMIP_Data/MHL_Gauge_Data/20200409_Recieved/Open_ocean/'
|
||
|
filenames = glob.glob(Ocean_gauges_folder + '*.csv')
|
||
|
filenames = [filenames[0],filenames[1], filenames[3]]
|
||
|
|
||
|
timestep = 0
|
||
|
for tgr_csv_name in filenames:
|
||
|
print (tgr_csv_name)
|
||
|
tgr_csv_name = filenames[2]
|
||
|
tgr_outname = Ocean_gauges_folder + os.path.basename(tgr_csv_name)[:-4] + '_2' + year
|
||
|
|
||
|
Full_df = pd.read_csv(tgr_csv_name ,header= 0, skiprows= 30, parse_dates = True)
|
||
|
Full_df.index = pd.to_datetime(Full_df.Date, format = '%d/%m/%Y') + pd.to_timedelta(Full_df.Time, unit='h')
|
||
|
Full_df = Full_df.iloc[:,[-2]]
|
||
|
Full_df.columns = ['WL[AHD]']
|
||
|
Full_df = Full_df.loc[(Full_df.index >= year + '-01-01 00:00:00') & (Full_df.index <= str(np.int(year)+1) + '-01-01 00:00:00')]
|
||
|
# str(df['2'][1500].astype(int))
|
||
|
|
||
|
# RMA2: create input file
|
||
|
fq = open(
|
||
|
os.path.join(Ocean_gauges_folder, tgr_outname + '.tgr'),
|
||
|
'w')
|
||
|
|
||
|
fq.write('TT MHL tide for ' + os.path.basename(tgr_csv_name)+ ' ' + year + '\n')
|
||
|
fq.write('{:<5}{:>3}{:>8}{:>8}\n'.format('CL', '', '2', year))
|
||
|
#fq.write('{:<5}{:>3}{:>8}{:>8}\n'.format('CL', '', int(df['3'][0]), int(df['4'][0])))
|
||
|
for i in range(1,len(Full_df),1):
|
||
|
# For each new element
|
||
|
fq.write('{:<5}{:>3}{:>8}{:>8}\n'.format('HD', str(np.int(Full_df.index[i-1].strftime('%j'))), str(np.round((np.float(Full_df.index[i-1].strftime('%M'))+ np.float(Full_df.index[i-1].strftime('%H'))*60) /60,2)), str(np.round(np.float(Full_df['WL[AHD]'][i-1]),3))))
|
||
|
fq.write('ENDDATA')
|
||
|
fq.close()
|