diff --git a/Analysis/Code/P1_NARCliM_First_Pass_variab_deviation_plots.py b/Analysis/Code/P1_NARCliM_First_Pass_variab_deviation_plots.py index 6788090..4eb9dac 100644 --- a/Analysis/Code/P1_NARCliM_First_Pass_variab_deviation_plots.py +++ b/Analysis/Code/P1_NARCliM_First_Pass_variab_deviation_plots.py @@ -48,7 +48,7 @@ for Est in Estuaries: Base_period_start = '1970-01-01' #Start of interval for base period of climate variability Base_period_DELTA_start = '1990-01-01' #Start of interval used for calculating mean and SD for base period (Delta base period) 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 + Clim_var_type = 'tasmean' #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 @@ -57,8 +57,8 @@ for Est in Estuaries: 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) + Stats = 'mean' #'maxdaily' #maximum takes the annual max Precipitation instead of the sum + ALPHA_figs = 0 #Set alpha of figure background (0 makes everything around the plot panel transparent) #==========================================================# @@ -290,6 +290,7 @@ for Est in Estuaries: tick.set_rotation(0) fig.tight_layout() fig.patch.set_alpha(ALPHA_figs) + plt.set_facecolor('g') if temp == 'annual': ax=plt.subplot(2,2,1) @@ -319,7 +320,7 @@ for Est in Estuaries: if presentdaybar == False: out_file_name = Estuary + '_' + Clim_var_type + '_' + Stats + '_' + PD_Datasource + '_' + SILO_Clim_var[0] + Version + '_' + '_NPDB.png' else: - out_file_name = Estuary + '_' + Clim_var_type + '_' + Stats + '_' + PD_Datasource + '_' + SILO_Clim_var[0] + Version + '_' + '.png' + out_file_name = Estuary + '_' + Clim_var_type + '_' + Stats + '_' + PD_Datasource + '_' + SILO_Clim_var[0] + Version + '_' + '2.png' out_path = output_directory + '/' + out_file_name fig.savefig(out_path) diff --git a/Analysis/Code/P1_NARCliM_plots_Windows.py b/Analysis/Code/P1_NARCliM_plots_Windows.py index 175a12b..bb814a6 100644 --- a/Analysis/Code/P1_NARCliM_plots_Windows.py +++ b/Analysis/Code/P1_NARCliM_plots_Windows.py @@ -25,7 +25,7 @@ matplotlib.style.use('ggplot') 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 - +ALPHA_figs = 0 #==========================================================# # 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/') @@ -44,12 +44,13 @@ for Est in Estuaries: Estuary = Est # 'Belongil' print Estuary #Clim_var_type = 'potevpmean' # '*' will create pdf for all variables in folder "pracc*|tasmax*" - Clim_var_types = ['tasmax'] + Clim_var_types = ['tasmean'] for climvar in Clim_var_types: Clim_var_type = climvar - plot_pdf = 'no' + plot_pdf = 'yes' + plot_pngs = 'yes' delta_csv = 'yes' - Stats = 'days_h_35' # 'maxdaily', 'mean' + Stats = 'mean' # 'maxdaily', 'mean' Version = 'V1' #==========================================================# @@ -63,6 +64,15 @@ for Est in Estuaries: print('-------------------------------------------') print("output directory folder didn't exist and was generated") print('-------------------------------------------') + + #set directory path for individual png files + png_output_directory = 'Output/' + Case_Study_Name + '/' + Estuary + '/NARCLIM_Key_Figs' + #output_directory = 'J:/Project wrl2016032/NARCLIM_Raw_Data/Extracted' + if not os.path.exists(png_output_directory): + os.makedirs(png_output_directory) + print('-------------------------------------------') + print("output directory folder didn't exist and was generated") + print('-------------------------------------------') #==========================================================# @@ -182,23 +192,116 @@ for Est in Estuaries: Summarized_df.columns = ['present', 'near', 'far'] #==========================================================# - + + #==========================================================# + #generate colour schemes for plotting + #==========================================================# + plotcolours36 = ['darkolivegreen','turquoise', 'lightgreen', 'darkgreen', 'lightpink','slateblue', 'slategray', 'orange', 'tomato', 'peru', 'navy', 'teal', + 'darkolivegreen','turquoise', 'lightgreen', 'darkgreen', 'lightpink','slateblue', 'slategray', 'orange', 'tomato', 'peru', 'navy', 'teal', + 'darkolivegreen','turquoise', 'lightgreen', 'darkgreen', 'lightpink','slateblue', 'slategray', 'orange', 'tomato', 'peru', 'navy', 'teal'] + plotcolours36b = ['tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , + 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , + 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' ] + plotcolours12 = ['darkolivegreen','turquoise', 'lightgreen', 'darkgreen', 'lightpink','slateblue', 'slategray', 'orange', 'tomato', 'peru', 'navy', 'teal'] + plotcolours15 = ['darkolivegreen','turquoise', 'lightgreen', 'darkgreen', 'lightpink','slateblue', 'slategray', 'orange', 'tomato', 'peru', 'navy', 'teal', 'lightgreen','lightpink','slateblue'] + #==========================================================# + + + #==========================================================# + #output crucial summary plots into individual png files + #==========================================================# + if plot_pngs == 'yes': + #=========# + #Barplot of near and far future deltas + #=========# + #out name + png_out_file_name = Clim_var_type + '_' + Stats + '_Deltas_Barplot_' + Version + '.png' + png_out_path = png_output_directory + '/' + png_out_file_name + #prepare data frame for plot + neardeltadf=delta_all_df['near'] + ymin = min(neardeltadf) + 0.1 *min(neardeltadf) + ymax = max(neardeltadf) + 0.1 * max(neardeltadf) + neardeltadf=delta_all_df['far'] + ymin2 = min(neardeltadf) + 0.1 *min(neardeltadf) + ymax2 = max(neardeltadf) + 0.1 * max(neardeltadf) + ymin = min(ymin, ymin2) + if (Clim_var_type == 'tasmax' or Clim_var_type == 'tasmean'): + ymin = 0 + ymax = max(ymax, ymax2) + # + fig = plt.figure(figsize=(5,6)) + ax=plt.subplot(2,1,1) + plt.title(Clim_var_type + ' - ' + Stats + ' - deltas - near') + neardeltadf=delta_all_df['near'] + neardeltadf.plot(kind='bar', color=plotcolours15, ylim=(ymin,ymax), ax=ax) + plt.xticks([]) + ax=plt.subplot(2,1,2) + plt.title(Clim_var_type + ' - ' + Stats + ' - deltas - far') + neardeltadf=delta_all_df['far'] + neardeltadf.plot(kind='bar', color=plotcolours15, ylim=(ymin,ymax), ax=ax) + ax.xaxis.grid(False) + #ax.patch.set_alpha(ALPHA_figs) + fig.patch.set_alpha(ALPHA_figs) + fig.tight_layout() + fig.savefig(png_out_path) + #=========# + + #=========# + #full period density comparison + #=========# + #out name + png_out_file_name = Clim_var_type + '_' + Stats + '_MaxDeltaMod_Histogram_' + Version + '.png' + png_out_path = png_output_directory + '/' + png_out_file_name + plt.title(Clim_var_type + ' - ' + Stats + ' - hist - full period - max delta model') + #prepare data + xmin = float(max(np.nanpercentile(Fdf_1900_2080.filter(regex= Max_dif_mod_name[:-5]),50) - 4 * np.std(Fdf_1900_2080.filter(regex= Max_dif_mod_name[:-5])))) + xmax = float(max(np.nanpercentile(Fdf_1900_2080.filter(regex= Max_dif_mod_name[:-5]),50) + 4 * np.std(Fdf_1900_2080.filter(regex= Max_dif_mod_name[:-5])))) + fig = plt.figure(figsize=(5,5)) + ax=plt.subplot(2,1,1) + Fdf_1900_2080.filter(regex= Max_dif_mod_name[:-5]).plot.kde(xlim=(xmin,xmax), ax=ax) + plt.legend(loc=9, bbox_to_anchor=(0.5, -0.3)) + #ax.xaxis.grid(False) + ax.yaxis.grid(False) + fig.patch.set_alpha(ALPHA_figs) + fig.tight_layout() + fig.savefig(png_out_path) + #=========# + + #=========# + # time series plot annual ALL models + #=========# + png_out_file_name = Clim_var_type + '_' + Stats + '_TimeSeries_AllMods_' + Version + '.png' + png_out_path = png_output_directory + '/' + png_out_file_name + plt.title(Clim_var_type + ' - ' + Stats + ' - Time series - representative models') + #prepare data + Mod_order = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,19,20,21,16,17,18,22,23,24,31,32,33,25,26,27,28,29,30,34,35,36] + test = Fdf_1900_2080_annual + Mod_Names = test.columns + New_Mod_Name = [] + for i in range(0,len(Mod_Names)): + New_Mod_Name.append(str(Mod_order[i]+10) + '_' + Mod_Names[i]) + test.columns = New_Mod_Name + test_sorted = test.reindex_axis(sorted(test.columns), axis=1) + colnamest = test.columns + test_sorted.columns = [w[3:-5] for w in colnamest] + #plot + fig = plt.figure(figsize=(8,7)) + ax=plt.subplot(2,1,1) + test_sorted.plot(ax=ax,color = plotcolours36) + plt.legend(loc=9, bbox_to_anchor=(0.5, -0.2)) + ax.xaxis.grid(False) + fig.patch.set_alpha(ALPHA_figs) + fig.tight_layout() + fig.savefig(png_out_path) + #=========# #==========================================================# #output some summary plot into pdf #==========================================================# if plot_pdf == 'yes': - plotcolours36 = ['darkolivegreen','turquoise', 'lightgreen', 'darkgreen', 'lightpink','slateblue', 'slategray', 'orange', 'tomato', 'peru', 'navy', 'teal', - 'darkolivegreen','turquoise', 'lightgreen', 'darkgreen', 'lightpink','slateblue', 'slategray', 'orange', 'tomato', 'peru', 'navy', 'teal', - 'darkolivegreen','turquoise', 'lightgreen', 'darkgreen', 'lightpink','slateblue', 'slategray', 'orange', 'tomato', 'peru', 'navy', 'teal'] - plotcolours36b = ['tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , - 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , - 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' , 'tomato', 'royalblue', 'mediumpurple' ] - plotcolours12 = ['darkolivegreen','turquoise', 'lightgreen', 'darkgreen', 'lightpink','slateblue', 'slategray', 'orange', 'tomato', 'peru', 'navy', 'teal'] - plotcolours15 = ['darkolivegreen','turquoise', 'lightgreen', 'darkgreen', 'lightpink','slateblue', 'slategray', 'orange', 'tomato', 'peru', 'navy', 'teal', 'lightgreen','lightpink','slateblue'] - #plt.cm.Paired(np.arange(len(Fdf_1900_2080_means))) + #plt.cm.Paired(np.arange(len(Fdf_1900_2080_means))) #write the key plots to a single pdf document - pdf_out_file_name = Clim_var_type + '_' + Stats + '_start_' + Base_period_start + '_NARCliM_summary_' + Version + '.pdf' + pdf_out_file_name = Clim_var_type + '_' + Stats + '_NARCliM_summary_' + Version + '.pdf' pdf_out_path = output_directory +'/' + pdf_out_file_name #open pdf and add the plots with PdfPages(pdf_out_path) as pdf: @@ -226,6 +329,7 @@ for Est in Estuaries: plt.title(Clim_var_type + ' - model deltas - near-present') neardeltadf=delta_all_df['near'] neardeltadf.plot(kind='bar', color=plotcolours15, ylim=(ymin,ymax), ax=ax) + ax.patch.set_alpha(ALPHA_figs) plt.xticks([]) #ax.xaxis.set_ticklabels([]) #pdf.savefig(bbox_inches='tight', ylim=(ymin,ymax), pad_inches=0.4) @@ -234,9 +338,10 @@ for Est in Estuaries: ax=plt.subplot(2,1,2) plt.title(Clim_var_type + ' - model deltas - far-present') neardeltadf=delta_all_df['far'] - neardeltadf.plot(kind='bar', color=plotcolours15, ylim=(ymin,ymax), ax=ax) + fig = neardeltadf.plot(kind='bar', color=plotcolours15, ylim=(ymin,ymax), ax=ax) ax.xaxis.grid(False) - #fig.patch.set_alpha(0) + ax.patch.set_alpha(ALPHA_figs) + #fig.patch.set_alpha(ALPHA_figs) #plt.show() pdf.savefig(bbox_inches='tight', ylim=(ymin,ymax), pad_inches=0.4) plt.close() @@ -253,6 +358,7 @@ for Est in Estuaries: xmax = float(max(np.nanpercentile(Fdf_1900_2080.filter(regex= Max_dif_mod_name[:-5]),50) + 4 * np.std(Fdf_1900_2080.filter(regex= Max_dif_mod_name[:-5])))) Fdf_1900_2080.filter(regex= Max_dif_mod_name[:-5]).plot.kde(xlim=(xmin,xmax)) pdf.savefig(bbox_inches='tight', pad_inches=0.4) + fig.patch.set_alpha(ALPHA_figs) plt.close() #annual box plt.title(Clim_var_type + ' - Annual means/sums for max diff model') @@ -277,8 +383,9 @@ for Est in Estuaries: test_sorted = test.reindex_axis(sorted(test.columns), axis=1) colnamest = test.columns test_sorted.columns = [w[3:-5] for w in colnamest] - test_sorted.plot(legend=False, color = plotcolours36) + fig = test_sorted.plot(legend=False, color = plotcolours36) pdf.savefig(bbox_inches='tight', pad_inches=0.4) + fig.patch.set_alpha(ALPHA_figs) plt.close() # time series plot annual ALL models plt.title(Clim_var_type + ' - Time series - representative models') diff --git a/Analysis/Code/climdata_fcts.pyc b/Analysis/Code/climdata_fcts.pyc index d6785bb..78d8b7d 100644 Binary files a/Analysis/Code/climdata_fcts.pyc and b/Analysis/Code/climdata_fcts.pyc differ