From 78fd10e93be71e1cd667aa45162f6b141c79d952 Mon Sep 17 00:00:00 2001 From: Valentin Heimhuber Date: Mon, 9 Jul 2018 19:25:57 +1000 Subject: [PATCH] #added better png plotting for the tech guide plots --- ...RCliM_First_Pass_variab_deviation_plots.py | 9 +- Analysis/Code/P1_NARCliM_plots_Windows.py | 143 +++++++++++++++--- Analysis/Code/climdata_fcts.pyc | Bin 4926 -> 7783 bytes 3 files changed, 130 insertions(+), 22 deletions(-) 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 d6785bb0032c5461c8921092c616e9c93fb9b561..78d8b7d376c8c094149c0d1cf76d0ba3d7b32406 100644 GIT binary patch literal 7783 zcmcgxOK%*<5$@ULYgc?fL{gHak!(e4O5w|vV+ry@AWhhcMH{=c4KbD{!<}AosM*=o z^sGc0WPm`5?F0q_1j#LTA9Knjha8fhkUx=oE=F=lzOQ;8Bu$Av1SWTSx~saXtE;Q4 zs(Z5k8px|}Uj12FHUBbrzm3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