#added a couple of plotting abilities to the existing code and all is working.

the only problem remaining is that currently, the present day plot for extreme indices isn't working properly
it's showing the annual sums or averages
Development1
Valentin Heimhuber 6 years ago
parent 78fd10e93b
commit 00e63c6c29

@ -48,21 +48,25 @@ for Est in Estuaries:
Base_period_start = '1970-01-01' #Start of interval for base period of climate variability 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_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 Base_period_end = '2009-01-01' #use last day that's not included in period as < is used for subsetting
Clim_var_type = 'tasmean' #Name of climate variable in NARCLIM models '*' will create pdf for all variables in folder Clim_var_type = 'pracc' #Name of climate variable in NARCLIM models '*' will create pdf for all variables in folder
Stats = 'maxdaily' #'maxdaily' #maximum takes the annual max Precipitation instead of the sum
PD_Datasource = 'SILO' #Source for present day climate data (historic time series) can be either: 'Station' or 'SILO' 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 SILO_Clim_var = ['daily_rain'] #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 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? presentdaybar = False #include a bar for present day variability in the plots?
present_day_plot = 'no' #save a time series of present day present_day_plot = 'yes' #save a time series of present day
Version = "V1" Allin1_delta_plot = 'no'
Stats = 'mean' #'maxdaily' #maximum takes the annual max Precipitation instead of the sum Version = "V4"
ALPHA_figs = 0 #Set alpha of figure background (0 makes everything around the plot panel transparent) ALPHA_figs = 0 #Set alpha of figure background (0 makes everything around the plot panel transparent)
font = {'family' : 'sans-serif',
'weight' : 'normal',
'size' : 14}
matplotlib.rc('font', **font) #size of axis labels
#==========================================================# #==========================================================#
#==========================================================# #==========================================================#
#set directory path for output files #set directory path for output files
output_directory = 'Output/' + Case_Study_Name + '/' + Estuary + '/' + '/Clim_Deviation_Plots/' output_directory = 'Output/' + Case_Study_Name + '/' + Estuary + '/' + '/Clim_Deviation_Plots/'
@ -190,6 +194,8 @@ for Est in Estuaries:
times = ['annual', 'DJF', 'MAM', 'JJA','SON'] times = ['annual', 'DJF', 'MAM', 'JJA','SON']
fig = plt.figure(figsize=(14,8)) fig = plt.figure(figsize=(14,8))
delta_all_df = pd.DataFrame() delta_all_df = pd.DataFrame()
Combined_Delta_df = pd.DataFrame()
Combined_Med_df = pd.DataFrame()
i=1 i=1
for temp in times: for temp in times:
#temp = 'annual' #temp = 'annual'
@ -197,20 +203,22 @@ for Est in Estuaries:
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
Column_names = ['near', 'far']
else: else:
Ensemble_Delta_df = Ensemble_Delta_full_df.filter(regex= temp) Ensemble_Delta_df = Ensemble_Delta_full_df.filter(regex= temp)
Ensemble_Delta_df.columns = ['near', 'far'] Ensemble_Delta_df.columns = ['near', 'far']
if temp == 'DJF': if temp == 'DJF':
Mean_df = Fdf_Seas_means[Fdf_Seas_means.index.quarter==1] Mean_df = Fdf_Seas_means[Fdf_Seas_means.index.quarter==1]
Column_names = ['DJF_near', 'DJF_far'] Column_names = ['DJF_near', 'DJF_far']
if temp == 'MAM': if temp == 'MAM':
Mean_df = Fdf_Seas_means[Fdf_Seas_means.index.quarter==2] Mean_df = Fdf_Seas_means[Fdf_Seas_means.index.quarter==2]
Column_names = ['MAM_near', 'MAM_far'] Column_names = ['MAM_near', 'MAM_far']
if temp == 'JJA': if temp == 'JJA':
Mean_df = Fdf_Seas_means[Fdf_Seas_means.index.quarter==3] Mean_df = Fdf_Seas_means[Fdf_Seas_means.index.quarter==3]
Column_names = ['JJA_near', 'JJA_far'] Column_names = ['JJA_near', 'JJA_far']
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]
Column_names = ['SON_near', 'SON_far']
Present_Day_ref_df = Mean_df Present_Day_ref_df = Mean_df
#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)])
@ -290,7 +298,7 @@ for Est in Estuaries:
tick.set_rotation(0) tick.set_rotation(0)
fig.tight_layout() fig.tight_layout()
fig.patch.set_alpha(ALPHA_figs) fig.patch.set_alpha(ALPHA_figs)
plt.set_facecolor('g') #plt.set_facecolor('g')
if temp == 'annual': if temp == 'annual':
ax=plt.subplot(2,2,1) ax=plt.subplot(2,2,1)
@ -315,15 +323,47 @@ for Est in Estuaries:
i=i+4 i=i+4
else: else:
i=i+1 i=i+1
#create a data frame that contains all of the delta bars
Plot_in_df_tp.index = Column_names
Plot_in_df_tp['-2std'] = Plot_in_df_tp['-2std'] - Present_Day_Mean
Combined_Delta_df = pd.concat([Combined_Delta_df, Plot_in_df_tp], axis=0)
#plt.show() #plt.show()
if presentdaybar == False: if presentdaybar == False:
out_file_name = Estuary + '_' + Clim_var_type + '_' + Stats + '_' + PD_Datasource + '_' + SILO_Clim_var[0] + Version + '_' + '_NPDB.png' out_file_name = Estuary + '_' + Clim_var_type + '_' + Stats + '_' + PD_Datasource + '_' + SILO_Clim_var[0] + '_' + Version + '_' + '_NPDB.png'
else: else:
out_file_name = Estuary + '_' + Clim_var_type + '_' + Stats + '_' + PD_Datasource + '_' + SILO_Clim_var[0] + Version + '_' + '2.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 out_path = output_directory + '/' + out_file_name
fig.savefig(out_path) fig.savefig(out_path)
if Allin1_delta_plot == 'yes':
fig = plt.figure(figsize=(14,8))
ax = fig.add_subplot(2, 2, 1)
Plot_in_df_tp = pd.DataFrame(Combined_Delta_df)
Bottom = int(Plot_in_df_tp.stack().min(axis=None,skipna=True)) - 1
Plot_in_df_tp = Plot_in_df_tp - Bottom
Plot_in_df = Plot_in_df_tp.transpose()
uni_colors = ['none', 'cornflowerblue', 'cornflowerblue','cornflowerblue','cornflowerblue']
Plot_in_df_tp.plot.bar(stacked=True, color=uni_colors, edgecolor='none', legend=False, width=0.5,ax=ax, bottom=Bottom)
plt.plot(Plot_in_df_tp['Med'], linestyle="", markersize=23,
marker="_", color='darkblue', label="Median")
z = plt.axhline(float(0), linestyle='--', color='red', alpha=.5)
z.set_zorder(-1)
#plt.ylim(xmin, xmax)
plt.title(Clim_var_type + ' All Delstas ' + Stats)
ax.grid(False)
for tick in ax.get_xticklabels():
tick.set_rotation(90)
fig.tight_layout()
fig.patch.set_alpha(ALPHA_figs)
#plt.show()
#export plot to png
out_file_name = Estuary + '_' + Clim_var_type + '_' + Stats + '_' + Base_period_start + '_' + Base_period_end + '_' + Version + '_All_Deltas_In1.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))
@ -350,7 +390,7 @@ for Est in Estuaries:
fig.patch.set_alpha(0) fig.patch.set_alpha(0)
plt.ylim(13, xmax) plt.ylim(13, xmax)
#export plot to png #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 = Estuary + '_' + Clim_var_type + '_' + Stats + '_' + Base_period_start + '_' + Base_period_end + '_' + Version + 'Present_Day_Period.png'
out_path = output_directory + '/' + out_file_name out_path = output_directory + '/' + out_file_name
fig.savefig(out_path) 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

@ -26,6 +26,10 @@ os.chdir('C:/Users/z5025317/OneDrive - UNSW/WRL_Postdoc_Manual_Backup/WRL_Postdo
import climdata_fcts as fct import climdata_fcts as fct
import silo as sil import silo as sil
ALPHA_figs = 0 ALPHA_figs = 0
font = {'family' : 'sans-serif',
'weight' : 'normal',
'size' : 14}
matplotlib.rc('font', **font)
#==========================================================# #==========================================================#
# 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/')
@ -44,14 +48,14 @@ for Est in Estuaries:
Estuary = Est # 'Belongil' Estuary = Est # 'Belongil'
print Estuary print Estuary
#Clim_var_type = 'potevpmean' # '*' will create pdf for all variables in folder "pracc*|tasmax*" #Clim_var_type = 'potevpmean' # '*' will create pdf for all variables in folder "pracc*|tasmax*"
Clim_var_types = ['tasmean'] Clim_var_types = ['pracc']
for climvar in Clim_var_types: for climvar in Clim_var_types:
Clim_var_type = climvar Clim_var_type = climvar
plot_pdf = 'yes' plot_pdf = 'no'
plot_pngs = 'yes' plot_pngs = 'yes'
delta_csv = 'yes' delta_csv = 'no'
Stats = 'mean' # 'maxdaily', 'mean' Stats = 'mean' # 'maxdaily', 'mean'
Version = 'V1' Version = 'V2'
#==========================================================# #==========================================================#
@ -299,7 +303,7 @@ for Est in Estuaries:
#output some summary plot into pdf #output some summary plot into pdf
#==========================================================# #==========================================================#
if plot_pdf == 'yes': if plot_pdf == 'yes':
#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 #write the key plots to a single pdf document
pdf_out_file_name = Clim_var_type + '_' + Stats + '_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 pdf_out_path = output_directory +'/' + pdf_out_file_name

Loading…
Cancel
Save