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.
HEMIP_GIT/Code/MHL_gauge_shapefile_generat...

99 lines
3.9 KiB
Python

# -*- coding: utf-8 -*-
"""
Created on Tue Mar 24 19:02:20 2020
@author: z5025317
"""
#this code simply opens up all the MHL tide gauge csv files and writes the key information provided in there into a cvs file for GIS import
#==========================================================#
#Load packages
#==========================================================#
import os
import pandas as pd
import glob
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import seaborn
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/'
filenames = glob.glob(Ocean_gauges_folder +'*/' + '*.csv')
WL_df = pd.DataFrame()
for tgr_csv_name in filenames:
print (os.path.basename(tgr_csv_name)[:-11])
#tgr_csv_name = filenames[3]
Full_df = pd.read_csv(tgr_csv_name ,nrows=7, skiprows= 17, parse_dates = True)
Full_df = Full_df.transpose()
Full_df['River'] = os.path.basename(os.path.dirname(tgr_csv_name))
Full_df2 = pd.read_csv(tgr_csv_name ,header= 0, skiprows= 30, parse_dates = True)
Full_df['Start_Date'] =Full_df2.Date[0]
Full_df['End_Date'] =Full_df2.Date[len(Full_df2.Date)-1]
Full_df2.index = pd.to_datetime(Full_df2.Date, format = '%d/%m/%Y') + pd.to_timedelta(Full_df2.Time, unit='h')
Full_df2 = Full_df2.iloc[:,[-2]]
Full_df2.columns = ['WL[AHD]']
WL_df = pd.concat([WL_df, Full_df], axis=0)
#WL_df.to_csv(Ocean_gauges_folder + 'summary_dataframe_of_all_gauges4.csv')
#create a histogram for each gauge if desired
#this isn't working yet due to gaps and weird stuff in the data
ylims = [-1.5,2.2]
#set plot parameters
ALPHA_figs = 1
font = {'family' : 'sans-serif',
'weight' : 'normal',
'size' : 6}
matplotlib.rc('font', **font)
pdf_out_name = os.path.dirname(tgr_csv_name) + os.path.basename(tgr_csv_name)[:-11]+ '_histogram.pdf'
fig = plt.figure(figsize=(4,8))
np.array(np.float16(Full_df2['WL[AHD]'])
#full period density comparison for individual gauges overlaid by tidal planes
Wollow_13ExPr = np.nanpercentile(np.array(Full_df2['WL[AHD]']),87)
np.percentile(Full_df2['WL[AHD]'].astype(float), 50)
Wollow_6p4ExPr = np.nanpercentile(Full_df2['WL[AHD]'].astype(float),93.6)
Wollow_1_3ExPr = np.nanpercentile(Full_df2,98.7)
Wollow_0p01ExPr = np.nanpercentile(Full_df2,99.99)
Wollow_50ExPr = np.nanpercentile(Full_df2,50)
ax=plt.subplot(4,1,i)
plt.title( Gauge + ' water level density comparison - Jan 2016- Feb 2020')
#WL_df[Gauge].plot.kde(xlim=(-0.5,1),vertical=True, lw=3, ax=ax)
seaborn.kdeplot(Full_df2['WL[AHD]'], vertical=True, color='royalblue', lw=3)
plt.axhline(y=Wollow_13ExPr, color='firebrick', linestyle='--', lw=3, alpha=1)
plt.text( xlocation , (Wollow_13ExPr), '13% exceedance', ha='left', va='bottom')
plt.axhline(y=Wollow_6p4ExPr, color='orange', linestyle='--', lw=3, alpha=1)
plt.text(xlocation , (Wollow_6p4ExPr), '6.4% exceedance', ha='left', va='bottom')
plt.axhline(y=Wollow_1_3ExPr, color='yellow', linestyle='--', lw=3, alpha=1)
plt.text( xlocation ,Wollow_1_3ExPr , '1.3% exceedance', ha='left', va='bottom')
plt.axhline(y=Wollow_0p01ExPr, color='limegreen', linestyle='--', lw=3, alpha=1)
plt.text( xlocation , Wollow_0p01ExPr , '0.01% exceedance', ha='left', va='bottom')
plt.axhline(y=Wollow_50ExPr, color='cyan', linestyle='--', lw=3, alpha=1)
plt.text( xlocation , Wollow_50ExPr , '50% exceedance', ha='left', va='bottom')
plt.ylim(-1,1.7)
plt.xlabel("Probability/density")
plt.ylabel("Water level [m AHD]")
fig.tight_layout()
fig.savefig(png_out_name)
plt.close()
fig.tight_layout()
fig.savefig(png_out_name)