@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# ####################################----------------------------------
# ==========================================================#
#Last Updated - March 2018
#Last Updated - March 2018
#@author: z5025317 Valentin Heimhuber
#@author: z5025317 Valentin Heimhuber
#code for creating future climate variability deviation plots for NARCLIM variables.
#code for creating future climate variability deviation plots for NARCLIM variables.
#Inputs: Uses CSV files that containthe deltas of all 12 NARCLIM models for 1 grid cell at the site of interest, generated with P1_NARCLIM_plots_Windows.py
#Inputs: Uses CSV files that containthe deltas of all 12 NARCLIM models for 1 grid cell at the site of interest, generated with P1_NARCLIM_plots_Windows.py
#This code is used only for the NARCLIM variables - a separate code is used for ocean variables etc that are not part of the NARCLIM ensemble
#This code is used only for the NARCLIM variables - a separate code is used for ocean variables etc that are not part of the NARCLIM ensemble
#####################################----------------------------------
#==========================================================#
#Load packages
#Load packages
# ####################################----------------------------------
# ==========================================================#
import numpy as np
import numpy as np
import os
import os
import pandas as pd
import pandas as pd
@ -18,113 +19,183 @@ from datetime import datetime
from datetime import timedelta
from datetime import timedelta
from matplotlib . backends . backend_pdf import PdfPages
from matplotlib . backends . backend_pdf import PdfPages
from ggplot import *
from ggplot import *
import csv
matplotlib . style . use ( ' ggplot ' )
matplotlib . style . use ( ' ggplot ' )
#plt.rcParams.update(plt.rcParamsDefault)
# Load my own functions
#
os . chdir ( ' C:/Users/z5025317/OneDrive - UNSW/WRL_Postdoc_Manual_Backup/WRL_Postdoc/Projects/Paper#1/Analysis/Code ' )
import climdata_fcts as fct
import silo as sil
#==========================================================#
#==========================================================#
# Set working direcotry (where postprocessed NARClIM data is located)
# Set working direcotry (where postprocessed NARClIM data is located)
os . chdir ( ' C:/Users/z5025317/OneDrive - UNSW/WRL_Postdoc_Manual_Backup/WRL_Postdoc/Projects/Paper#1/ ' )
os . chdir ( ' C:/Users/z5025317/OneDrive - UNSW/WRL_Postdoc_Manual_Backup/WRL_Postdoc/Projects/Paper#1/ ' )
#
#==========================================================#
#####################################----------------------------------
#set input parameters
#loop through case study estuaries
Base_period_start = ' 1986-01-01 '
Estuaries = [ ' HUNTER ' , ' RICHMOND ' , ' NADGEE ' , ' SHOALHAVEN ' , ' GEORGES ' , ' CATHIE ' ]
Base_period_end = ' 2005-01-01 ' #use last day that's not included in period as < is used for subsetting
Estuaries = [ ' HUNTER ' ]
Estuary = ' Nadgee ' # 'Belongil'
for Est in Estuaries :
Clim_var_type = " * " # '*' will create pdf for all variables in folder
Clim_var_type = " pracc* " # '*' will create pdf for all variables in folder
#==========================================================#
Present_Day_Clim_Var = ' Rainfall ' #MaxT, MinT, Rainfall, ET Wind
#set input parameters
present_day_plot = ' yes '
#==========================================================#
Version = " V2 "
Case_Study_Name = ' CASESTUDY2 '
Stats = ' dailymax ' #maximum takes the annual max Precipitation instead of the sum
Casestudy2_csv_path = " Data/NARCLIM_Site_CSVs/CASESTUDY2/CASESTDUY2_NARCLIM_Point_Sites.csv "
#####################################----------------------------------
#Estuary = 'HUNTER' # 'Belongil'
Estuary = Est # 'Belongil'
#set directory path for output files
print Estuary
output_directory = ' Output/Clim_Deviation_Plots/ ' + Estuary
Base_period_start = ' 1970-01-01 ' #Start of interval for base period of climate variability
#output_directory = 'J:/Project wrl2016032/NARCLIM_Raw_Data/Extracted'
Base_period_DELTA_start = ' 1990-01-01 ' #Start of interval used for calculating mean and SD for base period (Delta base period)
if not os . path . exists ( output_directory ) :
Base_period_end = ' 2009-01-01 ' #use last day that's not included in period as < is used for subsetting
Clim_var_type = ' tasmax ' #Name of climate variable in NARCLIM models '*' will create pdf for all variables in folder
PD_Datasource = ' SILO ' #Source for present day climate data (historic time series) can be either: 'Station' or 'SILO'
SILO_Clim_var = [ ' max_temp ' ] #select the SILO clim variable to be used for base period. - see silo.py for detailed descriptions
Location = ' Estuary ' # pick locaiton for extracting the SILO data can be: Estuary, Catchment, or Ocean
presentdaybar = False #include a bar for present day variability in the plots?
present_day_plot = ' no ' #save a time series of present day
Version = " V1 "
Stats = ' days_h_35 ' #'maxdaily' #maximum takes the annual max Precipitation instead of the sum
ALPHA_figs = 1 #Set alpha of figure background (0 makes everything around the plot panel transparent)
#==========================================================#
#==========================================================#
#set directory path for output files
output_directory = ' Output/ ' + Case_Study_Name + ' / ' + Estuary + ' / ' + ' /Clim_Deviation_Plots/ '
#output_directory = 'J:/Project wrl2016032/NARCLIM_Raw_Data/Extracted'
if not os . path . exists ( output_directory ) :
os . makedirs ( output_directory )
os . makedirs ( output_directory )
print ( ' ------------------------------------------- ' )
print ( ' ------------------------------------------- ' )
print ( " output directory folder didn ' t exist and was generated " )
print ( " output directory folder didn ' t exist and was generated " )
print ( ' ------------------------------------------- ' )
print ( ' ------------------------------------------- ' )
print ( ' ------------------- ' )
print ( ' ------------------- ' )
Clim_Var_CSVs = glob . glob ( ' ./Output/ ' + Estuary + ' / ' + Estuary + ' _ ' + Clim_var_type [ : - 1 ] + ' _ ' + Stats + ' * ' )
#==========================================================#
#read CSV file
clim_var_csv_path = Clim_Var_CSVs [ 0 ]
Filename = os . path . basename ( os . path . normpath ( clim_var_csv_path ) )
#==========================================================#
Clim_var_type = Filename . split ( ' _ ' , 2 ) [ 1 ]
#read CSV file
print ( Clim_var_type )
#==========================================================#
Ensemble_Delta_full_df = pd . read_csv ( clim_var_csv_path , index_col = 0 , parse_dates = True )
Clim_Var_CSVs = glob . glob ( ' ./Output/ ' + Case_Study_Name + ' / ' + Estuary + ' / ' + Estuary + ' _ ' + Clim_var_type + ' _ ' + Stats + ' * ' )
#Ensemble_Delta_full_df = pd.to_numeric(Ensemble_Delta_full_df)
clim_var_csv_path = Clim_Var_CSVs [ 0 ]
#
Filename = os . path . basename ( os . path . normpath ( clim_var_csv_path ) )
#load present day climate data for the same variable
Clim_var_type = Filename . split ( ' _ ' , 2 ) [ 1 ]
if Clim_var_type == ' evspsblmean ' : #ET time series that we have is not in the same format as the other variables, hence the different treatment
print ( Clim_var_type )
Present_day_Var_CSV = glob . glob ( ' ./Data/Wheather_Station_Data/**/ ' + Estuary + ' _ ' + Present_Day_Clim_Var + ' *csv ' )
Ensemble_Delta_full_df = pd . read_csv ( clim_var_csv_path , index_col = 0 , parse_dates = True )
Present_day_df = pd . read_csv ( Present_day_Var_CSV [ 0 ] )
Dates = pd . to_datetime ( Present_day_df . Date )
if Clim_var_type == ' rsdsmean ' :
Present_day_df . index = Dates
Clim_Var_CSVs = glob . glob ( ' ./Output/ ' + Case_Study_Name + ' / ' + Estuary + ' / ' + Estuary + ' _rsdsmean_ ' + Stats + ' * ' )
Present_day_df = Present_day_df . iloc [ : , 1 ]
clim_var_csv_path = Clim_Var_CSVs [ 0 ]
Present_day_df = Present_day_df . replace ( r ' \ s+ ' , np . nan , regex = True )
Filename = os . path . basename ( os . path . normpath ( clim_var_csv_path ) )
Present_day_df = pd . to_numeric ( Present_day_df )
Clim_var_type = Filename . split ( ' _ ' , 2 ) [ 1 ]
Present_day_df . index = Dates
print ( Clim_var_type )
Ensemble_Delta_full_df1 = pd . read_csv ( clim_var_csv_path , index_col = 0 , parse_dates = True )
Clim_Var_CSVs = glob . glob ( ' ./Output/ ' + Case_Study_Name + ' / ' + Estuary + ' / ' + Estuary + ' _rldsmean_ ' + Stats + ' * ' )
clim_var_csv_path = Clim_Var_CSVs [ 0 ]
Filename = os . path . basename ( os . path . normpath ( clim_var_csv_path ) )
Clim_var_type = Filename . split ( ' _ ' , 2 ) [ 1 ]
print ( Clim_var_type )
Ensemble_Delta_full_df2 = pd . read_csv ( clim_var_csv_path , index_col = 0 , parse_dates = True )
Ensemble_Delta_full_df = Ensemble_Delta_full_df2 + Ensemble_Delta_full_df1
#Ensemble_Delta_full_df = pd.to_numeric(Ensemble_Delta_full_df)
#==========================================================#
#==========================================================#
#load present day climate variable time series
#==========================================================#
if PD_Datasource == ' Station ' :
Present_day_df , minplotDelta , maxplotDelta = fct . import_present_day_climdata_csv ( Estuary , Clim_var_type )
if PD_Datasource == ' SILO ' :
#read the CSV to extract the lat long and case stuy sites
with open ( Casestudy2_csv_path , mode = ' r ' ) as infile :
reader = csv . reader ( infile )
next ( reader , None )
with open ( ' coors_new.csv ' , mode = ' w ' ) as outfile :
writer = csv . writer ( outfile )
if Location == ' Estuary ' :
mydict = dict ( ( rows [ 0 ] , [ rows [ 1 ] , rows [ 2 ] ] ) for rows in reader )
if Location == ' Ocean ' :
mydict = dict ( ( rows [ 0 ] , [ rows [ 3 ] , rows [ 4 ] ] ) for rows in reader )
if Location == ' Catchment ' :
mydict = dict ( ( rows [ 0 ] , [ rows [ 5 ] , rows [ 6 ] ] ) for rows in reader )
if Clim_var_type == ' tasmean ' :
silo_df = sil . pointdata ( [ " max_temp " , " min_temp " ] , ' Okl9EDxgS2uzjLWtVNIBM5YqwvVcCxOmpd3nCzJh ' , Base_period_start . replace ( " - " , " " ) , Base_period_end . replace ( " - " , " " ) ,
None , mydict [ Estuary ] [ 0 ] , mydict [ Estuary ] [ 1 ] , False , None )
#take mean of daily min and max temp
Present_day_df = silo_df . iloc [ : , [ 2 , 4 ] ] . mean ( axis = 1 )
else :
silo_df = sil . pointdata ( SILO_Clim_var , ' Okl9EDxgS2uzjLWtVNIBM5YqwvVcCxOmpd3nCzJh ' , Base_period_start . replace ( " - " , " " ) , Base_period_end . replace ( " - " , " " ) ,
None , mydict [ Estuary ] [ 0 ] , mydict [ Estuary ] [ 1 ] , False , None )
Present_day_df = silo_df . iloc [ : , [ 2 ] ]
#set the x and y limit deltas - for plotting only
if Clim_var_type in [ ' evspsblmean ' , ' potevpmean ' ] : #ET time series that we have is not in the same format as the other variables, hence the different treatment
[ minplotDelta , maxplotDelta ] = [ 50 , 50 ]
[ minplotDelta , maxplotDelta ] = [ 50 , 50 ]
#for tasmean, observed min and max T need to be converted into mean T
#for tasmean, observed min and max T need to be converted into mean T
elif Clim_var_type == ' tasmean ' :
elif Clim_var_type == ' tasmean ' :
Present_day_Var_CSV = glob . glob ( ' ./Data/Wheather_Station_Data/**/ ' + Estuary + ' _MaxT*csv ' )
[ minplotDelta , maxplotDelta ] = [ 0.2 , 1 ]
Present_day_df = pd . read_csv ( Present_day_Var_CSV [ 0 ] )
elif Clim_var_type == ' tasmax ' :
Dates = pd . to_datetime ( Present_day_df . Year * 10000 + Present_day_df . Month * 100 + Present_day_df . Day , format = ' % Y % m %d ' )
Present_day_df . index = Dates
Present_day_MaxT_df = Present_day_df . iloc [ : , 5 ]
Present_day_Var_CSV = glob . glob ( ' ./Data/Wheather_Station_Data/**/ ' + Estuary + ' _MinT*csv ' )
Present_day_df = pd . read_csv ( Present_day_Var_CSV [ 0 ] )
Dates = pd . to_datetime ( Present_day_df . Year * 10000 + Present_day_df . Month * 100 + Present_day_df . Day , format = ' % Y % m %d ' )
Present_day_df . index = Dates
Present_day_MinT_df = Present_day_df . iloc [ : , 5 ]
Present_day_df = ( Present_day_MaxT_df + Present_day_MinT_df ) / 2
[ minplotDelta , maxplotDelta ] = [ 1 , 2 ]
[ minplotDelta , maxplotDelta ] = [ 1 , 2 ]
elif Clim_var_type == ' tasmax ' :
elif Clim_var_type == ' wssmean ' or Clim_var_type == ' wss1Hmaxtstep ' :
[ minplotDelta , maxplotDelta ] = [ 1 , 2 ]
elif Clim_var_type == ' wssmean ' or Clim_var_type == ' wss1Hmaxtstep ' :
Present_day_Var_CSV = glob . glob ( ' ./Data/Wheather_Station_Data/**/ ' + Estuary + ' _ ' + Present_Day_Clim_Var + ' *csv ' )
Present_day_df = pd . read_csv ( Present_day_Var_CSV [ 0 ] )
Present_day_df . index = Present_day_df [ [ ' Year ' , ' Month ' , ' Day ' , ' Hour ' ] ] . apply ( lambda s : datetime ( * s ) , axis = 1 )
Present_day_df = Present_day_df . filter ( regex = ' m/s ' )
Present_day_df = Present_day_df . replace ( r ' \ s+ ' , np . nan , regex = True )
Present_day_df [ ' Wind speed measured in m/s ' ] = Present_day_df [ ' Wind speed measured in m/s ' ] . convert_objects ( convert_numeric = True )
[ minplotDelta , maxplotDelta ] = [ 1 , 1.5 ]
[ minplotDelta , maxplotDelta ] = [ 1 , 1.5 ]
else :
elif Clim_var_type == ' pracc ' :
Present_day_Var_CSV = glob . glob ( ' ./Data/Wheather_Station_Data/**/ ' + Estuary + ' _ ' + Present_Day_Clim_Var + ' *csv ' )
[ minplotDelta , maxplotDelta ] = [ 50 , 100 ]
Present_day_df = pd . read_csv ( Present_day_Var_CSV [ 0 ] )
elif Clim_var_type in [ ' rsdsmean ' , ' rldsmean ' ] :
Dates = pd . to_datetime ( Present_day_df . Year * 10000 + Present_day_df . Month * 100 + Present_day_df . Day , format = ' % Y % m %d ' )
[ minplotDelta , maxplotDelta ] = [ 100 , 100 ]
Present_day_df . index = Dates
#[minplotDelta, maxplotDelta]=[1,1]
Present_day_df = Present_day_df . iloc [ : , 5 ]
#==========================================================#
[ minplotDelta , maxplotDelta ] = [ 50 , 50 ]
#create seasonal sums etc.
#substract a constant from all values to convert from kelvin to celcius (temp)
if ( Clim_var_type == ' pracc ' or Clim_var_type == ' evspsblmean ' or Clim_var_type == ' potevpmean '
if Clim_var_type == ' sstmean ' :
or Clim_var_type == ' pr1Hmaxtstep ' or Clim_var_type == ' wss1Hmaxtstep ' ) :
Present_day_df = Present_day_df . iloc [ : , 0 : ( len ( Present_day_df ) - 1 ) ] - 273.15
if Stats == ' dailymax ' :
Present_day_df . index = Present_day_df . index . to_period ( ' D ' )
#==========================================================#
#create seasonal sums etc.
#==========================================================#
if Stats == ' maxdaily ' :
Present_day_df_annual = Present_day_df . resample ( ' A ' ) . max ( )
Present_day_df_annual = Present_day_df . resample ( ' A ' ) . max ( )
Present_day_df_annual = Present_day_df_annual . replace ( 0 , np . nan )
Present_day_df_annual = Present_day_df_annual . replace ( 0 , np . nan )
Fdf_Seas_means = Present_day_df . resample ( ' Q-NOV ' ) . max ( ) #seasonal means
Fdf_Seas_means = Fdf_Seas_means . replace ( 0 , np . nan )
if ( Stats [ : 4 ] == ' days ' ) :
Threshold = int ( Stats [ - 2 : ] )
agg = ( ' > ' + str ( Threshold ) + ' _count ' , lambda x : x . gt ( Threshold ) . sum ( ) ) ,
Present_day_df_annual = Present_day_df . resample ( ' A ' ) . agg ( agg )
Fdf_Seas_means = Present_day_df . resample ( ' Q-NOV ' ) . agg ( agg ) #seasonal means
else :
else :
if Clim_var_type in [ ' pracc ' , ' evspsblmean ' , ' potevpmean ' ,
' pr1Hmaxtstep ' , ' wss1Hmaxtstep ' ,
' rsdsmean ' , ' rldsmean ' ] :
Present_day_df_annual = Present_day_df . resample ( ' A ' ) . sum ( )
Present_day_df_annual = Present_day_df . resample ( ' A ' ) . sum ( )
Present_day_df_annual = Present_day_df_annual . replace ( 0 , np . nan )
Present_day_df_annual = Present_day_df_annual . replace ( 0 , np . nan )
Fdf_Seas_means = Present_day_df . resample ( ' Q-NOV ' ) . sum ( ) #seasonal means
Fdf_Seas_means = Present_day_df . resample ( ' Q-NOV ' ) . sum ( ) #seasonal means
Fdf_Seas_means = Fdf_Seas_means . replace ( 0 , np . nan )
Fdf_Seas_means = Fdf_Seas_means . replace ( 0 , np . nan )
else :
el if Clim_var_type in [ ' ta sm ean' , ' tasmax ' , ' sstmean ' ] :
Present_day_df_annual = Present_day_df . resample ( ' A ' ) . mean ( )
Present_day_df_annual = Present_day_df . resample ( ' A ' ) . mean ( )
Present_day_df_monthly = Present_day_df . resample ( ' M ' ) . mean ( )
Present_day_df_monthly = Present_day_df . resample ( ' M ' ) . mean ( )
Present_day_df_weekly = Present_day_df . resample ( ' W ' ) . mean ( )
Present_day_df_weekly = Present_day_df . resample ( ' W ' ) . mean ( )
Fdf_Seas_means = Present_day_df . resample ( ' Q-NOV ' ) . mean ( ) #seasonal means
Fdf_Seas_means = Present_day_df . resample ( ' Q-NOV ' ) . mean ( ) #seasonal means
#==========================================================#
#Loop through annual and seasons and create a deviation plot for each.
#==========================================================#
times = [ ' annual ' , ' DJF ' , ' MAM ' , ' JJA ' , ' SON ' ]
#Loop through annual and seasons and create a deviation plot for each.
fig = plt . figure ( figsize = ( 14 , 8 ) )
#==========================================================#
delta_all_df = pd . DataFrame ( )
times = [ ' annual ' , ' DJF ' , ' MAM ' , ' JJA ' , ' SON ' ]
i = 1
fig = plt . figure ( figsize = ( 14 , 8 ) )
for temp in times :
delta_all_df = pd . DataFrame ( )
temp = ' annual '
i = 1
for temp in times :
#temp = 'annual'
#subset the ensemble dataframe for the period used:
#subset the ensemble dataframe for the period used:
if temp == ' annual ' :
if temp == ' annual ' :
Ensemble_Delta_df = Ensemble_Delta_full_df . iloc [ : , range ( 0 , 2 ) ]
Ensemble_Delta_df = Ensemble_Delta_full_df . iloc [ : , range ( 0 , 2 ) ]
#
Present_Day_ref_df = Present_day_df_annual
Present_Day_ref_df = Present_day_df_annual
else :
else :
Ensemble_Delta_df = Ensemble_Delta_full_df . filter ( regex = temp )
Ensemble_Delta_df = Ensemble_Delta_full_df . filter ( regex = temp )
@ -141,11 +212,12 @@ for temp in times:
if temp == ' SON ' :
if temp == ' SON ' :
Mean_df = Fdf_Seas_means [ Fdf_Seas_means . index . quarter == 4 ]
Mean_df = Fdf_Seas_means [ Fdf_Seas_means . index . quarter == 4 ]
Present_Day_ref_df = Mean_df
Present_Day_ref_df = Mean_df
print ( Ensemble_Delta_df . columns . values )
#Subset to present day variability period
#Subset to present day variability period
Present_Day_ref_df = pd . DataFrame ( Present_Day_ref_df . loc [ ( Present_Day_ref_df . index > = Base_period_start ) & ( Present_Day_ref_df . index < = Base_period_end ) ] )
Present_Day_ref_df = pd . DataFrame ( Present_Day_ref_df . loc [ ( Present_Day_ref_df . index > = Base_period_start ) & ( Present_Day_ref_df . index < = Base_period_end ) ] )
Present_Day_Mean = np . percentile ( Present_Day_ref_df , 50 )
#Subset to present day variability delta base period (this is the statistical baseline used for present day conditions)
Present_Day_SD = np . std ( Present_Day_ref_df )
Present_Day_Delta_ref_df = pd . DataFrame ( Present_Day_ref_df . loc [ ( Present_Day_ref_df . index > = Base_period_DELTA_start ) & ( Present_Day_ref_df . index < = Base_period_end ) ] )
Present_Day_Mean = np . percentile ( Present_Day_Delta_ref_df , 50 )
Present_Day_SD = np . std ( Present_Day_Delta_ref_df )
#create data frame for floating stacked barplots
#create data frame for floating stacked barplots
index = [ ' -2std ' , ' -1std ' , ' Med ' , ' 1std ' , ' 2std ' ]
index = [ ' -2std ' , ' -1std ' , ' Med ' , ' 1std ' , ' 2std ' ]
columns = [ ' present ' , ' near future ' , ' far future ' ]
columns = [ ' present ' , ' near future ' , ' far future ' ]
@ -159,7 +231,14 @@ for temp in times:
np . NaN , float ( Present_Day_Mean + Ensemble_Delta_df . far [ - 3 : ] [ 2 ] ) ]
np . NaN , float ( Present_Day_Mean + Ensemble_Delta_df . far [ - 3 : ] [ 2 ] ) ]
#Create a second data frame that has the values in a way that they can be stacked up in bars with the correct absolute values
#Create a second data frame that has the values in a way that they can be stacked up in bars with the correct absolute values
Plot_in_df2 = pd . DataFrame ( index = index , columns = columns )
Plot_in_df2 = pd . DataFrame ( index = index , columns = columns )
#
if presentdaybar == False :
index = [ ' -2std ' , ' -1std ' , ' Med ' , ' 1std ' , ' 2std ' ]
columns = [ ' near future ' , ' far future ' ]
Plot_in_df2 = pd . DataFrame ( index = index , columns = columns )
#Plot_in_df2['present'] = [float(0),float(0), float(0),
# float(0), float(0)]
else :
Plot_in_df2 [ ' present ' ] = [ float ( Present_Day_Mean - 2 * Present_Day_SD ) , float ( Present_Day_SD ) , float ( Present_Day_SD ) ,
Plot_in_df2 [ ' present ' ] = [ float ( Present_Day_Mean - 2 * Present_Day_SD ) , float ( Present_Day_SD ) , float ( Present_Day_SD ) ,
float ( Present_Day_SD ) , float ( Present_Day_SD ) ]
float ( Present_Day_SD ) , float ( Present_Day_SD ) ]
Plot_in_df2 [ ' near future ' ] = [ float ( Present_Day_Mean + Ensemble_Delta_df . near [ - 3 : ] [ 0 ] ) , np . NaN , float ( Ensemble_Delta_df . near [ - 3 : ] [ 1 ] - Ensemble_Delta_df . near [ - 3 : ] [ 0 ] ) ,
Plot_in_df2 [ ' near future ' ] = [ float ( Present_Day_Mean + Ensemble_Delta_df . near [ - 3 : ] [ 0 ] ) , np . NaN , float ( Ensemble_Delta_df . near [ - 3 : ] [ 1 ] - Ensemble_Delta_df . near [ - 3 : ] [ 0 ] ) ,
@ -178,9 +257,22 @@ for temp in times:
#define colour scheme
#define colour scheme
#likert_colors = ['none', 'firebrick','firebrick','lightcoral','lightcoral']
#likert_colors = ['none', 'firebrick','firebrick','lightcoral','lightcoral']
likert_colors = [ ' none ' , ' darkblue ' , ' darkblue ' , ' cornflowerblue ' , ' cornflowerblue ' ]
likert_colors = [ ' none ' , ' darkblue ' , ' darkblue ' , ' cornflowerblue ' , ' cornflowerblue ' ]
uni_colors = [ ' none ' , ' cornflowerblue ' , ' cornflowerblue ' , ' cornflowerblue ' , ' cornflowerblue ' ]
#plot the stacked barplot
#plot the stacked barplot
ax = plt . subplot ( 2 , 3 , i )
if temp == ' annual ' :
Plot_in_df_tp . plot . bar ( stacked = True , color = likert_colors , edgecolor = ' none ' , legend = False , ax = ax )
ax = plt . subplot ( 2 , 4 , 3 )
else :
ax = plt . subplot ( 2 , 4 , i )
Plot_in_df_tp . plot . bar ( stacked = True , color = uni_colors , edgecolor = ' none ' , legend = False , ax = ax , width = 0.5 )
df = pd . DataFrame ( Plot_in_df . iloc [ 2 , [ 1 , 2 ] ] )
index2 = [ ' Med ' ]
columns2 = [ ' near future ' , ' far future ' ]
Plot_in_df3 = pd . DataFrame ( index = index2 , columns = columns2 )
Plot_in_df3 [ ' near future ' ] = df . iloc [ 1 , 0 ]
Plot_in_df3 [ ' far future ' ] = df . iloc [ 0 , 0 ]
Plot_in_df3 = Plot_in_df3 . transpose ( )
plt . plot ( Plot_in_df3 [ ' Med ' ] , linestyle = " " , markersize = 52 ,
marker = " _ " , color = ' darkblue ' , label = " Median " )
z = plt . axhline ( float ( Present_Day_Mean - 2 * Present_Day_SD ) , linestyle = ' - ' , color = ' black ' , alpha = .5 )
z = plt . axhline ( float ( Present_Day_Mean - 2 * Present_Day_SD ) , linestyle = ' - ' , color = ' black ' , alpha = .5 )
z . set_zorder ( - 1 )
z . set_zorder ( - 1 )
z = plt . axhline ( float ( Present_Day_Mean + 2 * Present_Day_SD ) , linestyle = ' - ' , color = ' black ' , alpha = .5 )
z = plt . axhline ( float ( Present_Day_Mean + 2 * Present_Day_SD ) , linestyle = ' - ' , color = ' black ' , alpha = .5 )
@ -197,20 +289,41 @@ for temp in times:
for tick in ax . get_xticklabels ( ) :
for tick in ax . get_xticklabels ( ) :
tick . set_rotation ( 0 )
tick . set_rotation ( 0 )
fig . tight_layout ( )
fig . tight_layout ( )
fig . patch . set_alpha ( 0 )
fig . patch . set_alpha ( ALPHA_figs )
#reset i to i+1 for next step
if temp == ' MAM ' :
if temp == ' annual ' :
i = i + 2
ax = plt . subplot ( 2 , 2 , 1 )
Present_Day_ref_df . plot ( legend = False , ax = ax )
z = plt . axhline ( float ( Present_Day_Mean - 2 * Present_Day_SD ) , linestyle = ' - ' , color = ' black ' , alpha = .5 )
z . set_zorder ( - 1 )
z = plt . axhline ( float ( Present_Day_Mean + 2 * Present_Day_SD ) , linestyle = ' - ' , color = ' black ' , alpha = .5 )
z . set_zorder ( - 1 )
z = plt . axhline ( float ( Present_Day_Mean - Present_Day_SD ) , linestyle = ' -- ' , color = ' black ' , alpha = .5 )
z . set_zorder ( - 1 )
z = plt . axhline ( float ( Present_Day_Mean + Present_Day_SD ) , linestyle = ' -- ' , color = ' black ' , alpha = .5 )
z . set_zorder ( - 1 )
z = plt . axhline ( float ( Present_Day_Mean ) , linestyle = ' -- ' , color = ' red ' , alpha = .5 )
z . set_zorder ( - 1 )
#fig.patch.set_facecolor('deepskyblue')
fig . tight_layout ( )
fig . patch . set_alpha ( ALPHA_figs )
plt . title ( Clim_var_type + ' ' + Stats + ' ' + temp + ' present day ' )
plt . ylim ( xmin , xmax )
ax . grid ( False )
#if temp == 'MAM':
i = i + 4
else :
else :
i = i + 1
i = i + 1
print ( i )
plt . show ( )
#plt.show()
out_file_name = Estuary + ' _ ' + Clim_var_type + ' _ ' + Stats + ' _ ' + ' _CC_prio_plot ' + Version + ' .png '
if presentdaybar == False :
out_path = output_directory + ' / ' + out_file_name
out_file_name = Estuary + ' _ ' + Clim_var_type + ' _ ' + Stats + ' _ ' + PD_Datasource + ' _ ' + SILO_Clim_var [ 0 ] + Version + ' _ ' + ' _NPDB.png '
fig . savefig ( out_path )
else :
out_file_name = Estuary + ' _ ' + Clim_var_type + ' _ ' + Stats + ' _ ' + PD_Datasource + ' _ ' + SILO_Clim_var [ 0 ] + Version + ' _ ' + ' .png '
out_path = output_directory + ' / ' + out_file_name
fig . savefig ( out_path )
if present_day_plot == ' yes ' :
if present_day_plot == ' yes ' :
#print present day climate data
#print present day climate data
fig = plt . figure ( figsize = ( 5 , 4 ) )
fig = plt . figure ( figsize = ( 5 , 4 ) )
ax = fig . add_subplot ( 1 , 1 , 1 )
ax = fig . add_subplot ( 1 , 1 , 1 )
@ -235,15 +348,11 @@ if present_day_plot == 'yes':
#fig.patch.set_facecolor('deepskyblue')
#fig.patch.set_facecolor('deepskyblue')
fig . patch . set_alpha ( 0 )
fig . patch . set_alpha ( 0 )
plt . ylim ( 13 , xmax )
plt . ylim ( 13 , xmax )
plt . show ( )
#export plot to png
out_file_name = Estuary + ' _ ' + Clim_var_type + ' _ ' + Stats + ' _ ' + Base_period_start + ' _ ' + Base_period_end + Version + ' Present_Day_Period.png '
out_file_name = ' C:/Users/z5025317/OneDrive - UNSW/WRL_Postdoc_Manual_Backup/WRL_Postdoc/Projects/OEH_Coastal_Node_Deliverables/Technical_Report_1/Figures/tasmean_present_day_manual_backgroundTP.png '
out_path = output_directory + ' / ' + out_file_name
out_path = output_directory + ' / ' + out_file_name
fig . savefig ( out_file_name )
fig . savefig ( out_path )
# use transparent=True if you want the whole figure with a transparent background
# use transparent=True if you want the whole figure with a transparent background