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.
594 lines
27 KiB
Python
594 lines
27 KiB
Python
5 years ago
|
# -*- coding: utf-8 -*-
|
||
|
#==========================================================#
|
||
|
#Last Updated - June 2018
|
||
|
#@author: z5025317 Valentin Heimhuber
|
||
|
#code for creating climate prioritization plots for NARCLIM variables.
|
||
|
#Inputs: Uses CSV files that contain all 12 NARCLIM model runs time series for 1 grid cell created with: P1_NARCliM_NC_to_CSV_CCRC_SS.py
|
||
|
|
||
|
#Datum offset factors can be found at https://www.mhl.nsw.gov.au/docs/Data%20Conditions%20and%20Fit%20for%20Purpose.pdf
|
||
|
#==========================================================#
|
||
|
|
||
|
#==========================================================#
|
||
|
#Load packages
|
||
|
#==========================================================#
|
||
|
import numpy as np
|
||
|
import os
|
||
|
import pandas as pd
|
||
|
import geopandas as gpd
|
||
|
import glob
|
||
|
import matplotlib
|
||
|
import matplotlib.pyplot as plt
|
||
|
from datetime import datetime
|
||
|
from datetime import timedelta
|
||
|
#from matplotlib.backends.backend_pdf import PdfPages
|
||
|
import seaborn
|
||
|
matplotlib.style.use('ggplot')
|
||
|
#set plot parameters
|
||
|
ALPHA_figs = 1
|
||
|
font = {'family' : 'sans-serif',
|
||
|
'weight' : 'normal',
|
||
|
'size' : 14}
|
||
|
matplotlib.rc('font', **font)
|
||
|
#==========================================================#
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#==========================================================#
|
||
|
#Set Input parameters
|
||
|
#==========================================================#
|
||
|
River = 'Macleay'
|
||
|
Order_ID = 'Ocean_bdr' #choose order column name
|
||
|
startdate = '2007 04 13'
|
||
|
enddate = '2007 04 21'
|
||
|
tideanalysis_day = '2018 06 01'
|
||
|
#usually the min and max observed water levels in the estuary in AHD used for plot ylims
|
||
|
#========================================================#
|
||
|
|
||
|
|
||
|
#========================================================#
|
||
|
#mostly automated part of the code but might have to be double checked - debugged
|
||
|
#========================================================#
|
||
|
#set directory path for input and output files
|
||
|
main_input_directory = 'J:/Project/wrl2018064 Fisheries RAP/04_Working/05_Modelling/RMA/HEMIP/Global_Data/MHL_Gauge_Data/Analysis/'
|
||
|
output_directory = 'J:/Project/wrl2018064 Fisheries RAP/04_Working/05_Modelling/RMA/HEMIP/Global_Data/MHL_Gauge_Data/Analysis/Postprocessed'
|
||
|
if not os.path.exists(output_directory + '/' ):
|
||
|
os.makedirs(output_directory+ '/' )
|
||
|
|
||
|
|
||
|
#load MHL gauge shapefile to store the results of the statistics
|
||
|
MHL_gauges_df = gpd.read_file('J:/Project/wrl2018064 Fisheries RAP/04_Working/05_Modelling/RMA/HEMIP/Global_Data/GIS/MHL_gauges_received_MGA56.shp')
|
||
|
#MHL_gauges_df = MHL_gauges_df.loc[MHL_gauges_df['River'] == River]
|
||
|
MHL_gauges_df = MHL_gauges_df.loc[MHL_gauges_df[Order_ID].notnull()]
|
||
|
MHL_gauges_df = pd.DataFrame(MHL_gauges_df)
|
||
|
MHL_gauges_df = MHL_gauges_df.reset_index()
|
||
|
gauges = MHL_gauges_df['Station Na'].values
|
||
|
gauge_type = MHL_gauges_df[Order_ID].values
|
||
|
#rivers = MHL_gauges_df['River'].values
|
||
|
order_dict = dict(zip(gauges, gauge_type))
|
||
|
|
||
|
#Load in situ gauge data
|
||
|
WL_df = pd.DataFrame()
|
||
|
for gauge in gauges:
|
||
|
#gauge = gauges[1]
|
||
|
#gauge = 'Harrington'
|
||
|
print('loading MHL gauge data for ' + str(gauge))
|
||
|
CSVpath = glob.glob('J:/Project/wrl2018064 Fisheries RAP/04_Working/05_Modelling/RMA/HEMIP/Global_Data/MHL_Gauge_Data/20200409_Recieved/*/' + '*' + gauge.replace(" ", "") + '*' )
|
||
|
Full_df = pd.read_csv(CSVpath[0] ,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.loc[datetime.strptime(startdate , '%Y %m %d').date() : datetime.strptime(enddate , '%Y %m %d').date()]
|
||
|
Full_df = Full_df.iloc[:,[-2]]
|
||
|
Full_df.columns = [gauge]
|
||
|
Full_df = Full_df.loc[~Full_df.index.duplicated(keep='first')] #get rid of possible duplicate dates
|
||
|
Full_df = Full_df.replace(to_replace ='---', value =np.NaN) #--- is used as the no data value in the MHL data provided
|
||
|
Full_df = pd.DataFrame(pd.to_numeric(Full_df[gauge]))
|
||
|
Full_df = Full_df - np.float(MHL_gauges_df['AHDadjust'][MHL_gauges_df['Station Na']==gauge]) #subtract the datum adjustment factor provided by MHL as written in the shapefile
|
||
|
WL_df = pd.concat([WL_df, Full_df], axis=1)
|
||
|
#postprocess the in situ gauge dataframe
|
||
|
#WL_df = WL_df.replace(to_replace ='---', value =np.NaN) #--- is used as the no data value in the MHL data provided
|
||
|
#WL_df = WL_df.convert_objects(convert_numeric=True)
|
||
|
#WL_df = WL_df - datum_offset
|
||
|
order_colnames=[]
|
||
|
for colname in WL_df.columns:
|
||
|
order_colnames.append(str(order_dict[colname]) + '_' + colname)
|
||
|
#WL_df.columns = order_colnames
|
||
|
WL_df.columns = [str(s) + '_MHL' for s in order_colnames]
|
||
|
order_colnames.sort() #this will later be used to loop through the MHL gauges in a downstream to upstream order
|
||
|
order_colnames = pd.Series(order_colnames).str.replace("(",'')
|
||
|
order_colnames = pd.Series(order_colnames).str.replace(")",'')
|
||
|
order_colnames = order_colnames[~order_colnames.duplicated(keep='first')]
|
||
|
print('Performing analysis in the following order of locations')
|
||
|
print(order_colnames)
|
||
|
#========================================================#
|
||
|
|
||
|
|
||
|
|
||
|
#plot annual MSL for all open ocean gauges
|
||
|
ylims = [-0.2,0.2]
|
||
|
Open_ocean_only_df = WL_df.filter(regex='1.0')
|
||
|
Open_ocean_only_df.columns
|
||
|
Open_ocean_only_df_annual = Open_ocean_only_df.resample('A').mean()
|
||
|
png_out_name = output_directory + '/Annual mean sea levels.pdf'
|
||
|
fig = plt.figure(figsize=(40,18))
|
||
|
ax=plt.subplot(1,1,1)
|
||
|
plt.title('Annual mean sea levels at MHL open ocean gauges')
|
||
|
ax.set_prop_cycle(color=['steelblue', 'coral', 'red', 'deeppink'],linestyle=[ '-', '-','--','-'], lw=[2,2,2,2])
|
||
|
Open_ocean_only_df_annual.iloc[:,[0,1,2,3]].plot( legend=False,style=['+-','o-','.--','s:'], ax=ax)
|
||
|
plt.axhline(y=0, color='slateblue', linestyle='--', lw=1, alpha=0.5)
|
||
|
#plt.axhline(y=0.9, color='tomato', linestyle='--', lw=1, alpha=0.5)
|
||
|
plt.ylim(ylims)
|
||
|
plt.ylabel("Water level [m AHD]")
|
||
|
plt.xlabel("Time")
|
||
|
# Put a legend to the right of the current axis
|
||
|
#lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
|
||
|
ax.legend()
|
||
|
#plot tides
|
||
|
#ax=plt.subplot(2,1,2)
|
||
|
#plt.title('Max and min water surface elevation along the estuary at time of high & low tide')
|
||
|
#ax.set_prop_cycle(color=['slateblue', 'tomato', ], linestyle=[ '-', '-'], lw=[2,2])
|
||
|
#WL_df.iloc[:,[2,3]].plot(legend=False, ax=ax)
|
||
|
#plt.ylabel("Water level [m AHD]")
|
||
|
#plt.ylim(ylims)
|
||
|
#plt.xlabel("Time")
|
||
|
##lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
|
||
|
#ax.legend()
|
||
|
#plot tides
|
||
|
fig.tight_layout()
|
||
|
fig.savefig(png_out_name)
|
||
|
plt.close()
|
||
|
|
||
|
|
||
|
|
||
|
#plot annual MSL for all open ocean gauges
|
||
|
ylims = [-0.5,0.5]
|
||
|
Open_ocean_only_df = WL_df.filter(regex='1.0')
|
||
|
Open_ocean_only_df_annual = Open_ocean_only_df.resample('M').mean()
|
||
|
Plot_Title = 'Monthly mean sea levels at MHL open ocean gauges'
|
||
|
fig = plt.figure(figsize=(40,18))
|
||
|
ax=plt.subplot(1,1,1)
|
||
|
plt.title(Plot_Title)
|
||
|
png_out_name = output_directory + '/' + Plot_Title + '.pdf'
|
||
|
ax.set_prop_cycle(color=['steelblue', 'coral', 'red', 'deeppink'],linestyle=[ '-', '-','--','-'], lw=[2,2,2,2])
|
||
|
Open_ocean_only_df_annual.iloc[:,[0,1,2,3]].plot( legend=False,style=['+-','o-','.--','s:'], ax=ax)
|
||
|
plt.axhline(y=0, color='slateblue', linestyle='--', lw=1, alpha=0.5)
|
||
|
#plt.axhline(y=0.9, color='tomato', linestyle='--', lw=1, alpha=0.5)
|
||
|
plt.ylim(ylims)
|
||
|
plt.ylabel("Water level [m relative]")
|
||
|
plt.xlabel("Time")
|
||
|
# Put a legend to the right of the current axis
|
||
|
#lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
|
||
|
ax.legend()
|
||
|
#plot tides
|
||
|
#ax=plt.subplot(2,1,2)
|
||
|
#plt.title('Max and min water surface elevation along the estuary at time of high & low tide')
|
||
|
#ax.set_prop_cycle(color=['slateblue', 'tomato', ], linestyle=[ '-', '-'], lw=[2,2])
|
||
|
#WL_df.iloc[:,[2,3]].plot(legend=False, ax=ax)
|
||
|
#plt.ylabel("Water level [m AHD]")
|
||
|
#plt.ylim(ylims)
|
||
|
#plt.xlabel("Time")
|
||
|
##lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
|
||
|
#ax.legend()
|
||
|
#plot tides
|
||
|
fig.tight_layout()
|
||
|
fig.savefig(png_out_name)
|
||
|
plt.close()
|
||
|
|
||
|
|
||
|
|
||
|
#plot time series for a few windows
|
||
|
ylims = [-1,1.5]
|
||
|
Open_ocean_only_df = WL_df.filter(regex='1.0')
|
||
|
halfwindow = 15
|
||
|
Open_ocean_only_df = Open_ocean_only_df[datetime.strptime(tideanalysis_day , '%Y %m %d').date()- timedelta(days=halfwindow) : datetime.strptime(tideanalysis_day , '%Y %m %d').date() + timedelta(days=halfwindow) ]
|
||
|
#Open_ocean_only_df = Open_ocean_only_df.iloc[:,[0,1,2,3]][Open_ocean_only_df.iloc[:,0].notnull()]
|
||
|
Plot_Title = 'water level time series '+ tideanalysis_day + ' _window_of_' + str(halfwindow*2) +'_days'
|
||
|
fig = plt.figure(figsize=(40,18))
|
||
|
ax=plt.subplot(1,1,1)
|
||
|
plt.title(Plot_Title)
|
||
|
png_out_name = output_directory + '/' + Plot_Title + '.pdf'
|
||
|
ax.set_prop_cycle(color=['steelblue', 'coral', 'green', 'deeppink'],linestyle=[ '-', '-','--','-'], lw=[2,2,2,2])
|
||
|
Open_ocean_only_df.iloc[:,[0,1,2,3]].interpolate(method='linear').plot( legend=False, ax=ax)
|
||
|
plt.axhline(y=0, color='slateblue', linestyle='--', lw=1, alpha=0.5)
|
||
|
#plt.axhline(y=0.9, color='tomato', linestyle='--', lw=1, alpha=0.5)
|
||
|
plt.ylim(ylims)
|
||
|
plt.ylabel("Water level [m relative]")
|
||
|
plt.xlabel("Time")
|
||
|
# Put a legend to the right of the current axis
|
||
|
#lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
|
||
|
ax.legend()
|
||
|
#plot tides
|
||
|
#ax=plt.subplot(2,1,2)
|
||
|
#plt.title('Max and min water surface elevation along the estuary at time of high & low tide')
|
||
|
#ax.set_prop_cycle(color=['slateblue', 'tomato', ], linestyle=[ '-', '-'], lw=[2,2])
|
||
|
#WL_df.iloc[:,[2,3]].plot(legend=False, ax=ax)
|
||
|
#plt.ylabel("Water level [m AHD]")
|
||
|
#plt.ylim(ylims)
|
||
|
#plt.xlabel("Time")
|
||
|
##lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
|
||
|
#ax.legend()
|
||
|
#plot tides
|
||
|
fig.tight_layout()
|
||
|
fig.savefig(png_out_name)
|
||
|
plt.close()
|
||
|
|
||
|
|
||
|
#plot time series for a few windows
|
||
|
ylims = [-1,1.5]
|
||
|
xlocation = datetime.strptime(tideanalysis_day , '%Y %m %d').date()
|
||
|
Regex = 'Port Macquarie'
|
||
|
Regex = 'Tweed'
|
||
|
#Regex = 'haven'
|
||
|
#'Crowdy', 'Harrington'
|
||
|
Open_ocean_only_df = WL_df.filter(regex=Regex )
|
||
|
halfwindow = 200
|
||
|
Open_ocean_only_df = Open_ocean_only_df[datetime.strptime(tideanalysis_day , '%Y %m %d').date()- timedelta(days=halfwindow) : datetime.strptime(tideanalysis_day , '%Y %m %d').date() + timedelta(days=halfwindow) ]
|
||
|
#Open_ocean_only_df = Open_ocean_only_df.iloc[:,[0,1,2,3]][Open_ocean_only_df.iloc[:,0].notnull()]
|
||
|
Plot_Title = 'water level time series ocean vs entrance '+ tideanalysis_day + ' _window_of_' + str(halfwindow*2) +'_days_' + Regex + 'V2'
|
||
|
fig = plt.figure(figsize=(40,18))
|
||
|
ax=plt.subplot(1,1,1)
|
||
|
plt.title(Plot_Title)
|
||
|
png_out_name = output_directory + '/' + Plot_Title + '.pdf'
|
||
|
ax.set_prop_cycle(color=['steelblue', 'coral', 'green', 'deeppink'],linestyle=[ '-', '-','--','-'], lw=[2,2,2,2])
|
||
|
Open_ocean_only_df.iloc[:,[0,1]].interpolate(method='linear').plot( legend=False, ax=ax)
|
||
|
plt.axhline(y=0, color='slateblue', linestyle='--', lw=1, alpha=0.5)
|
||
|
|
||
|
plt.axhline(y=np.nanpercentile(Open_ocean_only_df.iloc[:,[0]],50), color='steelblue', linestyle='solid', lw=2, alpha=1)
|
||
|
plt.text(xlocation, (np.nanpercentile(Open_ocean_only_df.iloc[:,[0]],50)), 'MSL= ' + str(np.round(np.nanpercentile(Open_ocean_only_df.iloc[:,[0]],50),2)) , ha='left', va='bottom')
|
||
|
|
||
|
plt.axhline(y=np.nanpercentile(Open_ocean_only_df.iloc[:,[1]],50), color='red', linestyle='solid', lw=2, alpha=1)
|
||
|
plt.text(xlocation , (np.nanpercentile(Open_ocean_only_df.iloc[:,[1]],50)), 'MSL= ' + str(np.round(np.nanpercentile(Open_ocean_only_df.iloc[:,[1]],50),2)), ha='left', va='bottom')
|
||
|
|
||
|
#plt.axhline(y=0.9, color='tomato', linestyle='--', lw=1, alpha=0.5)
|
||
|
plt.ylim(ylims)
|
||
|
plt.ylabel("Water level [m relative]")
|
||
|
plt.xlabel("Time")
|
||
|
# Put a legend to the right of the current axis
|
||
|
#lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
|
||
|
ax.legend()
|
||
|
#plot tides
|
||
|
#ax=plt.subplot(2,1,2)
|
||
|
#plt.title('Max and min water surface elevation along the estuary at time of high & low tide')
|
||
|
#ax.set_prop_cycle(color=['slateblue', 'tomato', ], linestyle=[ '-', '-'], lw=[2,2])
|
||
|
#WL_df.iloc[:,[2,3]].plot(legend=False, ax=ax)
|
||
|
#plt.ylabel("Water level [m AHD]")
|
||
|
#plt.ylim(ylims)
|
||
|
#plt.xlabel("Time")
|
||
|
##lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
|
||
|
#ax.legend()
|
||
|
#plot tides
|
||
|
fig.tight_layout()
|
||
|
fig.savefig(png_out_name)
|
||
|
plt.close()
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#========================================================#
|
||
|
#fully automated part of the code doing the data extraction
|
||
|
#========================================================#
|
||
|
#load RMA2 data
|
||
|
Summary_df = pd.DataFrame()
|
||
|
df = pd.DataFrame()
|
||
|
for f in fs:
|
||
|
#set input and output directories
|
||
|
input_directory = main_input_directory + f + '_' + Order_ID
|
||
|
# Set working direcotry (where postprocessed NARClIM data is located)
|
||
|
os.chdir(input_directory)
|
||
|
#Load data file
|
||
|
if variable == 'depth' or variable == 'elev':
|
||
|
Clim_Var_CSVs = glob.glob('*' + variable + '*')
|
||
|
clim_var_csv_path = Clim_Var_CSVs[0]
|
||
|
df = pd.read_csv(clim_var_csv_path, index_col=False, sep=' ', nrows= maxrowsincsv)
|
||
|
df.index = pd.to_datetime(df.Year, format = '%Y') + pd.to_timedelta(df.Hour, unit='h')
|
||
|
df= df.drop(columns=['Year', 'Hour'])
|
||
|
a=len(df.columns)-1
|
||
|
df=df.iloc[:,:a]
|
||
|
if variable == 'vel':
|
||
|
#x velocity
|
||
|
Clim_Var_CSVs = glob.glob('*' +'x'+ variable + '*')
|
||
|
clim_var_csv_path = Clim_Var_CSVs[0]
|
||
|
df = pd.read_csv(clim_var_csv_path, index_col=False, sep=' ', nrows= maxrowsincsv)
|
||
|
df.index = pd.to_datetime(df.Year, format = '%Y') + pd.to_timedelta(df.Hour, unit='h')
|
||
|
dfx= df.drop(columns=['Year', 'Hour','1'])
|
||
|
#y velocity
|
||
|
Clim_Var_CSVs = glob.glob('*' +'y'+ variable + '*')
|
||
|
clim_var_csv_path = Clim_Var_CSVs[0]
|
||
|
df = pd.read_csv(clim_var_csv_path, index_col=False, sep=' ',nrows= maxrowsincsv)
|
||
|
df.index = pd.to_datetime(df.Year, format = '%Y') + pd.to_timedelta(df.Hour, unit='h')
|
||
|
dfy= df.drop(columns=['Year', 'Hour','1'])
|
||
|
df = np.sqrt(dfx*dfx + dfy*dfy)
|
||
|
df.columns = df.columns + '_'+ f + '_'+ variable
|
||
|
#cut down the df to start and end date
|
||
|
df = df[datetime.strptime(startdate , '%Y %m %d').date():datetime.strptime(enddate, '%Y %m %d').date()]
|
||
|
Summary_df = pd.concat([Summary_df, df], axis=1, join='outer')
|
||
|
HD_Summary_df = Summary_df
|
||
|
#========================================================#
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#========================================================#
|
||
|
#interactive data analysis part of the code - alternatively, the dataframe could be written to csv at this stage and analysed with a separate code.
|
||
|
#========================================================#
|
||
|
#Summary_df.columns = chainages
|
||
|
#subset the input data frame
|
||
|
Summary_df_nodes = pd.DataFrame()
|
||
|
#for node, gauges in nodes:
|
||
|
for key,value in node_dict.items():
|
||
|
df1 = HD_Summary_df.filter(regex='^'+ str(key)+'_').filter(regex=variable)
|
||
|
df1.columns = [value + '_' + str(s) for s in df1.columns]
|
||
|
Summary_df_nodes = pd.concat([Summary_df_nodes, df1], axis=1, join='outer')
|
||
|
|
||
|
for key,value in scenario_dict.items():
|
||
|
Summary_df_nodes.columns = pd.Series(Summary_df_nodes.columns).str.replace(key, value)
|
||
|
|
||
|
combined_df = pd.DataFrame()
|
||
|
combined_df = pd.concat([Summary_df_nodes , WL_df], axis=1, join='outer')
|
||
|
combined_df.columns = pd.Series(combined_df.columns).str.replace("(",'') #brackets mess up the regex commands below
|
||
|
combined_df.columns = pd.Series(combined_df.columns).str.replace(")",'')
|
||
|
combined_df_hourly = combined_df.resample('1H').max()
|
||
|
|
||
|
#this needs to be fixed to be more generic!
|
||
|
Histogram_df = combined_df.loc[datetime.strptime(startdate , '%Y %m %d').date() : datetime.strptime(enddate , '%Y %m %d').date()] #dataframe for histogram comparison between RMA and MHL
|
||
|
|
||
|
#========================================================#
|
||
|
#drop first gauge which doesn't have any data in 2006
|
||
|
#gauges = gauges[1:]
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#========================================================#
|
||
|
# Plot water level histograms at control points
|
||
|
#========================================================#
|
||
|
ylims = [-0.9,2.5]
|
||
|
#set plot parameters
|
||
|
ALPHA_figs = 1
|
||
|
font = {'family' : 'sans-serif',
|
||
|
'weight' : 'normal',
|
||
|
'size' : 5}
|
||
|
matplotlib.rc('font', **font)
|
||
|
lwd_hist = 2 #line width of histograms
|
||
|
|
||
|
i=1
|
||
|
png_out_name = output_directory + '/' + Plot_scenario + '/RMA_vs_MHL_gauges_water level histogram and exceedance planes '+ startdate + '_' + enddate + '2.pdf'
|
||
|
fig = plt.figure(figsize=(len(gauges)*7,12))
|
||
|
|
||
|
for Gauge in order_colnames:
|
||
|
#Gauge = order_colnames[0]
|
||
|
ax=plt.subplot(1,len(gauges),i)
|
||
|
plt.title( Gauge + ' WL '+ startdate + '-' + enddate)
|
||
|
xlocation = 0.6
|
||
|
#Gauge_only_df = Histogram_df.filter(regex=Gauge[3:])
|
||
|
Gauge_only_df = combined_df.filter(regex=Gauge[3:])
|
||
|
#scenario 1
|
||
|
TS_1 = Gauge_only_df[Gauge+'_MHL']
|
||
|
TS_1.name = 'MHL full period' + str(TS_1.index[0].date()) + '_' + str(TS_1.index[-1].date())
|
||
|
if len(TS_1[TS_1.notnull()])>0:
|
||
|
color_1 = 'blue'
|
||
|
width = 1
|
||
|
#full period density comparison for individual gauges overlaid by tidal planes
|
||
|
seaborn.kdeplot(TS_1, vertical=True, color=color_1, lw=1, linestyle='dotted', ax=ax)
|
||
|
|
||
|
Gauge_only_df = Gauge_only_df[Gauge_only_df.iloc[:,0].notnull()]
|
||
|
TS_1 = Gauge_only_df[Gauge+'_MHL']
|
||
|
TS_1 = TS_1.loc[datetime.strptime(startdate , '%Y %m %d').date() : datetime.strptime(enddate , '%Y %m %d').date()]
|
||
|
TS_1.name = 'MHL period from ' + startdate + '_' + enddate
|
||
|
if len(TS_1[TS_1.notnull()])>0:
|
||
|
color_1 = 'royalblue'
|
||
|
width = 1
|
||
|
#full period density comparison for individual gauges overlaid by tidal planes
|
||
|
seaborn.kdeplot(TS_1, vertical=True, color=color_1, lw=lwd_hist, ax=ax)
|
||
|
#seaborn.kdeplot(Gauge_only_df.iloc[:,2], vertical=True, color=color_1, lw=3)
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,87), color=color_1, linestyle='solid', lw=width, alpha=1)
|
||
|
plt.text( xlocation , (np.nanpercentile(TS_1,87)), '13% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,93.6), color=color_1, linestyle='dotted', lw=width, alpha=1)
|
||
|
plt.text(xlocation , (np.nanpercentile(TS_1,93.6)), '6.4% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,98.7), color=color_1, linestyle='dashed', lw=width, alpha=1)
|
||
|
plt.text( xlocation ,np.nanpercentile(TS_1,98.7) , '1.3% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,99.99), color=color_1, linestyle='dashdot', lw=width, alpha=1)
|
||
|
plt.text( xlocation ,np.nanpercentile(TS_1,99.99) , '0.01% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,50), color=color_1, linestyle='solid', lw=width, alpha=1)
|
||
|
plt.text( xlocation , np.nanpercentile(TS_1,50), '50% exceedance', ha='left', va='bottom')
|
||
|
|
||
|
#scenario 2
|
||
|
#TS_1 = Gauge_only_df.filter(regex='elev')
|
||
|
TS_1 = Gauge_only_df.iloc[:,0][Gauge_only_df.iloc[:,0].notnull()]
|
||
|
color_1 = 'red'
|
||
|
width = 1
|
||
|
seaborn.kdeplot(TS_1, vertical=True, color=color_1, lw=lwd_hist, ax=ax)
|
||
|
#plt.axhline(y=np.nanpercentile(TS_1,87), color=color_1, linestyle='solid', lw=width, alpha=1)
|
||
|
#plt.text( xlocation , (np.nanpercentile(TS_1,87)), '13% exceedance', ha='left', va='bottom')
|
||
|
#plt.axhline(y=np.nanpercentile(TS_1,93.6), color=color_1, linestyle='dotted', lw=width, alpha=1)
|
||
|
#plt.text(xlocation , (np.nanpercentile(TS_1,93.6)), '6.4% exceedance', ha='left', va='bottom')
|
||
|
#plt.axhline(y=np.nanpercentile(TS_1,98.7), color=color_1, linestyle='dashed', lw=width, alpha=1)
|
||
|
#plt.text( xlocation ,np.nanpercentile(TS_1,98.7) , '1.3% exceedance', ha='left', va='bottom')
|
||
|
#plt.axhline(y=np.nanpercentile(TS_1,99.99), color=color_1, linestyle='dashdot', lw=width, alpha=1)
|
||
|
#plt.text( xlocation ,np.nanpercentile(TS_1,99.99) , '0.01% exceedance', ha='left', va='bottom')
|
||
|
#plt.axhline(y=np.nanpercentile(TS_1,50), color=color_1, linestyle='solid', lw=width, alpha=1)
|
||
|
#plt.text( xlocation , np.nanpercentile(TS_1,50), '50% exceedance', ha='left', va='bottom')
|
||
|
|
||
|
#scenario 3
|
||
|
TS_1 = Gauge_only_df.iloc[:,1][Gauge_only_df.iloc[:,1].notnull()]
|
||
|
color_1 = 'limegreen'
|
||
|
width = 1
|
||
|
seaborn.kdeplot(TS_1, vertical=True, color=color_1, lw=lwd_hist, ax=ax)
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,87), color=color_1, linestyle='solid', lw=width, alpha=1)
|
||
|
#plt.text( xlocation , (np.nanpercentile(TS_1,87)), '13% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,93.6), color=color_1, linestyle='dotted', lw=width, alpha=1)
|
||
|
#plt.text(xlocation , (np.nanpercentile(TS_1,93.6)), '6.4% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,98.7), color=color_1, linestyle='dashed', lw=width, alpha=1)
|
||
|
#plt.text( xlocation ,np.nanpercentile(TS_1,98.7) , '1.3% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,99.99), color=color_1, linestyle='dashdot', lw=width, alpha=1)
|
||
|
#plt.text( xlocation ,np.nanpercentile(TS_1,99.99) , '0.01% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,50), color=color_1, linestyle='solid', lw=width, alpha=1)
|
||
|
#plt.text( xlocation , np.nanpercentile(TS_1,50), '50% exceedance', ha='left', va='bottom')
|
||
|
|
||
|
#finish the plot
|
||
|
plt.ylim(ylims)
|
||
|
if i == 1:
|
||
|
plt.ylabel("Water level [m AHD]")
|
||
|
|
||
|
plt.xlabel("Probability/density")
|
||
|
fig.tight_layout()
|
||
|
i=i+1
|
||
|
fig.savefig(png_out_name)
|
||
|
plt.close()
|
||
|
#========================================================#
|
||
|
|
||
|
|
||
|
#========================================================#
|
||
|
# Plot MHL water levels only
|
||
|
#========================================================#
|
||
|
ylims = [-1,1.5]
|
||
|
#set plot parameters
|
||
|
ALPHA_figs = 1
|
||
|
font = {'family' : 'sans-serif',
|
||
|
'weight' : 'normal',
|
||
|
'size' : 6}
|
||
|
matplotlib.rc('font', **font)
|
||
|
|
||
|
i=1
|
||
|
png_out_name = output_directory + '/' + Plot_scenario + '/MHL_gauges_water level histograms and exceedance planes '+ startdate + '_' + enddate + '.pdf'
|
||
|
fig = plt.figure(figsize=(len(gauges)*5,11))
|
||
|
|
||
|
for Gauge in order_colnames:
|
||
|
#Gauge = order_colnames[0]
|
||
|
ax=plt.subplot(1,len(gauges),i)
|
||
|
plt.title( Gauge + ' wL '+ startdate + '-' + enddate)
|
||
|
xlocation = 0.6
|
||
|
TS_1 = combined_df[Gauge+'_MHL']
|
||
|
TS_1 = TS_1[TS_1.notnull()]
|
||
|
#scenario 1
|
||
|
TS_1.name = 'Full Period ' + str(TS_1.index[0].date()) + '_' + str(TS_1.index[-1].date())
|
||
|
color_1 = 'royalblue'
|
||
|
width = 1
|
||
|
#full period density comparison for individual gauges overlaid by tidal planes
|
||
|
seaborn.kdeplot(TS_1, vertical=True, color=color_1, lw=2, ax=ax)
|
||
|
#seaborn.kdeplot(Gauge_only_df.iloc[:,2], vertical=True, color=color_1, lw=3)
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,87), color=color_1, linestyle='solid', lw=width, alpha=1)
|
||
|
plt.text( xlocation , (np.nanpercentile(TS_1,87)), '13% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,93.6), color=color_1, linestyle='dotted', lw=width, alpha=1)
|
||
|
plt.text(xlocation , (np.nanpercentile(TS_1,93.6)), '6.4% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,98.7), color=color_1, linestyle='dashed', lw=width, alpha=1)
|
||
|
plt.text( xlocation ,np.nanpercentile(TS_1,98.7) , '1.3% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,99.99), color=color_1, linestyle='dashdot', lw=width, alpha=1)
|
||
|
plt.text( xlocation ,np.nanpercentile(TS_1,99.99) , '0.01% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,50), color=color_1, linestyle='solid', lw=width, alpha=1)
|
||
|
plt.text( xlocation , np.nanpercentile(TS_1,50), '50% exceedance', ha='left', va='bottom')
|
||
|
|
||
|
#scenario 2
|
||
|
#TS_1 = Gauge_only_df.filter(regex='elev')
|
||
|
|
||
|
TS_1 = TS_1.loc[datetime.strptime(startdate , '%Y %m %d').date() : datetime.strptime(enddate , '%Y %m %d').date()]
|
||
|
if len(TS_1[TS_1.notnull()])>0:
|
||
|
TS_1.name = 'Period from ' + startdate + '_' + enddate
|
||
|
color_1 = 'red'
|
||
|
width = 1
|
||
|
seaborn.kdeplot(TS_1, vertical=True, color=color_1, lw=2, ax=ax)
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,87), color=color_1, linestyle='solid', lw=width, alpha=1)
|
||
|
plt.text( xlocation , (np.nanpercentile(TS_1,87)), '13% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,93.6), color=color_1, linestyle='dotted', lw=width, alpha=1)
|
||
|
plt.text(xlocation , (np.nanpercentile(TS_1,93.6)), '6.4% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,98.7), color=color_1, linestyle='dashed', lw=width, alpha=1)
|
||
|
plt.text( xlocation ,np.nanpercentile(TS_1,98.7) , '1.3% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,99.99), color=color_1, linestyle='dashdot', lw=width, alpha=1)
|
||
|
plt.text( xlocation ,np.nanpercentile(TS_1,99.99) , '0.01% exceedance', ha='left', va='bottom')
|
||
|
plt.axhline(y=np.nanpercentile(TS_1,50), color=color_1, linestyle='solid', lw=width, alpha=1)
|
||
|
plt.text( xlocation , np.nanpercentile(TS_1,50), '50% exceedance', ha='left', va='bottom')
|
||
|
|
||
|
#finish the plot
|
||
|
plt.ylim(ylims)
|
||
|
if i == 1:
|
||
|
plt.ylabel("Water level [m AHD]")
|
||
|
|
||
|
plt.xlabel("Probability/density")
|
||
|
fig.tight_layout()
|
||
|
i=i+1
|
||
|
fig.savefig(png_out_name)
|
||
|
plt.close()
|
||
|
#========================================================#
|
||
|
|
||
|
|
||
|
#========================================================#
|
||
|
# Plot time series over various intervals at control points
|
||
|
#========================================================#
|
||
|
#set plot parameters
|
||
|
ALPHA_figs = 1
|
||
|
font = {'family' : 'sans-serif',
|
||
|
'weight' : 'normal',
|
||
|
'size' : 5}
|
||
|
matplotlib.rc('font', **font)
|
||
|
|
||
|
halfwindows = [1,2,5,10,15]
|
||
|
for halfwindow in halfwindows:
|
||
|
#halfwindow = 10
|
||
|
png_out_name = output_directory + '/' + Plot_scenario + '/water level time series '+ startdate + '_' + enddate + ' _window_of_' + str(halfwindow*2) +'_days.pdf'
|
||
|
fig = plt.figure(figsize=(10,len(gauges)*3))
|
||
|
i=1
|
||
|
for Gauge in order_colnames:
|
||
|
Gauge_only_df = combined_df.filter(regex=Gauge[3:])
|
||
|
combined_df.columns
|
||
|
#Gauge_only_df = df1.filter(regex=Gauge)
|
||
|
#Gauge_only_df_1 = Gauge_only_df.loc[(Gauge_only_df.index >= '2008-05-09 12:00:00') & (Gauge_only_df.index <= '2008-05-20 12:00:00')]
|
||
|
Gauge_only_df_1 = Gauge_only_df[datetime.strptime(tideanalysis_day , '%Y %m %d').date()- timedelta(days=halfwindow) : datetime.strptime(tideanalysis_day , '%Y %m %d').date() + timedelta(days=halfwindow) ]
|
||
|
Gauge_only_df_1 = Gauge_only_df_1[Gauge_only_df_1.iloc[:,0].notnull()]
|
||
|
ax=plt.subplot(len(gauges),1,i)
|
||
|
plt.title('Tidal water levels at ' + Gauge + ' | ' + River +' Estuary')
|
||
|
ax.set_prop_cycle(color=['steelblue', 'coral', 'steelblue', 'deeppink'],linestyle=[ '-', '-','--','-'], lw=[0.8,0.8,0.8,0.8])
|
||
|
Gauge_only_df_1.iloc[:,[0,1,2]].plot( legend=False, ax=ax)
|
||
|
|
||
|
plt.axhline(y=0, color='black', linestyle='-', lw=0.8, alpha=0.5)
|
||
|
#plt.axhline(y=0.9, color='tomato', linestyle='--', lw=1, alpha=0.5)
|
||
|
plt.ylim(ylims)
|
||
|
plt.ylabel("Water level [m AHD]")
|
||
|
plt.xlabel("Time")
|
||
|
ax.legend()
|
||
|
fig.tight_layout()
|
||
|
i=i+1
|
||
|
fig.savefig(png_out_name)
|
||
|
plt.close()
|
||
|
#========================================================#
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
##========================================================#
|
||
|
##write out exceedance data to csv
|
||
|
##========================================================#
|
||
|
#Summary={}
|
||
|
#Summary['13% exceedance'] = Wollow_13ExPr
|
||
|
#Summary['6.4% exceedance'] = Wollow_6p4ExPr
|
||
|
#Summary['1.3% exceedance'] = Wollow_1_3ExPr
|
||
|
#Summary['0.01% exceedance'] = Wollow_0p01ExPr
|
||
|
#Summary['50% exceedance'] = Wollow_50ExPr
|
||
|
#pdf1 = pd.DataFrame(Summary, index=[0])
|
||
|
#pdf1.to_csv(os.path.join( Out_Folder + Gauge + '_entrance_stats.csv'))
|
||
|
##========================================================#
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|