Last active
January 25, 2019 16:54
-
-
Save chrisb13/bb0b8ba97187f28d058065653ca8de94 to your computer and use it in GitHub Desktop.
NOW code for Tasman Sea boxplot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if paper_case=='20170113_EACnowClimateChange01': | |
section_description_dict=collections.OrderedDict() | |
section_description_dict['AB']=[ 60, 61,217,226,0,54,'zonal' ] | |
section_description_dict['BC']=[ 60, 61,226,303,0,54,'zonal' ] | |
section_description_dict['GD']=[ 85,128,311,312,0,54,'meridional' ] | |
section_description_dict['FE']=[127,128,239,247,0,54,'zonal' ] | |
section_description_dict['ED']=[127,128,247,311,0,54,'zonal' ] | |
section_description_dict['IH']=[ 46,58 ,212,213,0,54,'meridional' ] | |
section_description_dict['JK']=[ 85,86 ,224,231,0,54,'zonal' ] | |
section_description_dict['PQ']=[ 68,80 ,212,213,0,54,'meridional' ] | |
section_description_dict['RS']=[ 58,66 ,306,307,0,54,'meridional' ] | |
section_description_dict['DU']=[128,148,311,312,0,54,'meridional' ] | |
section_description_dict['VW']=[147,148,230,295,0,54,'zonal' ] | |
section_description_dict['XU']=[147,148,297,312,0,54,'zonal' ] | |
def main_pretty_new_sections_now_climatechange(hdf_in,evaluation=False,ctl_anom_only=''): | |
"""main function to actually create the plot, re-factored to do bar charts with seaborn... | |
:hdf_in: HDFSTORE from ./mk_nemo_UV_transport.py | |
:evaluation(optional): plots the evaulation numbers | |
:ctl_anom_only(optional): remove the CTRL simulation | |
:returns: @todo | |
""" | |
import seaborn as sns #bit dodgy but don't want to mess up my other plots | |
sns.set_style("whitegrid", {'axes.grid' : False}) | |
df=pd.HDFStore(hdf_in).DF | |
df['RG94']=np.nan | |
df['CARS']=np.nan | |
df['OFAM']=np.nan | |
df['MOM']=np.nan | |
df.loc['ED','RG94']=17.7 | |
df.loc['GD','RG94']=3.6 | |
df.loc['FE','RG94']=27.4 | |
df.loc['BC','RG94']=2.0 | |
df.loc['IH','RG94']=8.1 | |
df.loc['AB','RG94']=8.1 | |
df.loc['ED','CARS']=14.8 | |
df.loc['GD','CARS']=3.7 | |
df.loc['FE','CARS']=25.8 | |
df.loc['BC','CARS']=3.2 | |
df.loc['IH','CARS']=10.8 | |
df.loc['AB','CARS']=9.7 | |
df.loc['ED','OFAM']=8.5 | |
df.loc['GD','OFAM']=12.6 | |
df.loc['FE','OFAM']=27.5 | |
df.loc['BC','OFAM']=2.7 | |
df.loc['IH','OFAM']=10.8 | |
df.loc['AB','OFAM']=9.7 | |
df.loc['ED','MOM']=7.9 | |
df.loc['GD','MOM']=9.0 | |
df.loc['FE','MOM']=20.4 | |
df.loc['BC','MOM']=5.6 | |
df.loc['IH','MOM']=np.nan | |
df.loc['AB','MOM']=9.7 | |
# df=pd.DataFrame(\ | |
# {'RG94':[17.7,3.6,27.4,2.0,8.1,8.1],\ | |
# 'CARS':[14.8,3.7 ,25.8,3.2 ,10.8,9.7 ],\ | |
# 'OFAM':[8.5 ,12.6,27.5,2.7 ,10.8,9.7 ],\ | |
# 'MOM':[7.9 ,9.0 ,20.4,5.6 ,np.nan,9.7 ],\ | |
# },index=['ED','DG','FE','BC','IH','AB']) | |
plt.close('all') | |
#width then height | |
#fig=plt.figure() | |
fig=plt.figure(figsize=(10.0,10.0)) | |
ax=fig.add_subplot(1, 1,1) | |
#plotmask(ax,filled=True) | |
plotmask(ax,filled=True) | |
if evaluation: | |
plotpointslines(ax,jk=False,pts=points) | |
else: | |
plotpointslines(ax,jk=True,pts=points) | |
# sm.pl_inset_title_box(ax,'b',bwidth="5%",location=2) | |
#plotmask(ax,strechgrid=False,filled=True) | |
#ax.set_title('msg') | |
ax.set_xlabel('Longitude') | |
ax.set_ylabel('Latitude') | |
colour_dict=collections.OrderedDict() | |
if evaluation: | |
colour_dict['RG94']='#e6ab02' | |
colour_dict['CARS']='#a6761d' | |
colour_dict[sm.exp_names_now()['now_cordex24_BMJv2_BILAP']] ='#e41a1c' | |
#force the order we like... | |
order=\ | |
[\ | |
'RG94',\ | |
'CARS',\ | |
'now_cordex24_BMJv2_BILAP'\ | |
] | |
else: | |
if ctl_anom_only=='': | |
colour_dict[sm.exp_names_now()['now_cordex24_BMJv2_BILAP']] =sm.exp_colours_now()[0]['now_cordex24_BMJv2_BILAP'] | |
colour_dict[sm.exp_names_now()['now_cordex24_BMJv2_BILAP_CO2']] =sm.exp_colours_now()[0]['now_cordex24_BMJv2_BILAP_CO2'] | |
colour_dict[sm.exp_names_now()['now_cordex24_BMJv2_BILAP_OCEBDY']] =sm.exp_colours_now()[0]['now_cordex24_BMJv2_BILAP_OCEBDY'] | |
colour_dict[sm.exp_names_now()['now_cordex24_BMJv2_BILAP_ATMBDY']] =sm.exp_colours_now()[0]['now_cordex24_BMJv2_BILAP_ATMBDY'] | |
colour_dict[sm.exp_names_now()['now_cordex24_BMJv2_BILAP_ALL']] =sm.exp_colours_now()[0]['now_cordex24_BMJv2_BILAP_ALL'] | |
#force the order we like... | |
order=\ | |
[\ | |
'now_cordex24_BMJv2_BILAP',\ | |
'now_cordex24_BMJv2_BILAP_CO2',\ | |
'now_cordex24_BMJv2_BILAP_OCEBDY',\ | |
'now_cordex24_BMJv2_BILAP_ATMBDY',\ | |
'now_cordex24_BMJv2_BILAP_ALL'\ | |
] | |
sm.pl_inset_title_box(ax,'d',bwidth="5%",location=2) | |
# colour_dict['OFAM']='#fb9a99' | |
# colour_dict['MOM']= '#fccde5' | |
#when we remove the mean we no longer want to plot it.. | |
if ctl_anom_only!='' and not evaluation: | |
order.remove(ctl_anom_only) | |
ins_custom_legend(ax,colour_dict,location=4,ncols=1) | |
if evaluation: | |
secs=['ED','DG','FE','AB','BC','IH'] | |
else: | |
secs=['ED','DG','FE','AB','BC','JK','IH'] | |
for section_name in secs: | |
# for section_name in ['ED','DG','FE','AB','BC']: | |
x=np.average([points[section_name[0:1]][0],points[section_name[1:]][0]]) | |
x=points[section_name[0:1]][0] | |
y=points[section_name[0:1]][1] | |
# print section_name | |
if section_name=='ED': | |
x=x+10 | |
y=y-1.3 | |
elif section_name=='DG': | |
x=x-.3 | |
y=y-8.6 | |
elif section_name=='FE': | |
x=x+3.2 | |
y=y-6 | |
elif section_name=='IH': | |
x=x-0.1 | |
y=y-2.5 | |
# print section_name,x,y | |
elif section_name=='AB': | |
x=x+5 | |
y=y-3.3 | |
# print section_name,x,y | |
elif section_name=='BC': | |
x=x+12 | |
y=y+1.2 | |
elif section_name=='JK': | |
x=x+4.4 | |
y=y-3.8 | |
# if section_name=='HI': | |
# section_name='IH' | |
if section_name=='DG': | |
section_name='GD' | |
x,y=axis_data_coords_sys_transform(ax,x,y,True) | |
#last two numbers indicate size... (width then height) | |
inset_axes = fig.add_axes([x,y,0.17,0.1]) | |
data=df.ix[section_name] | |
#check for negatives | |
if data.iloc[0]<0: | |
data=np.abs(data) | |
# data.sort(ascending=False,inplace=True) | |
# else: | |
# data.sort(ascending=True,inplace=True) | |
#remove the CTRL simulation from the transports | |
if ctl_anom_only!='' and not evaluation: | |
data=data-data[ctl_anom_only] | |
# print order | |
b=sns.barplot(order,data.ix[order],palette=colour_dict.values(),ax=inset_axes) | |
#turn axis stuff off | |
inset_axes.axes.get_yaxis().set_visible(False) | |
inset_axes.axes.get_xaxis().set_visible(False) | |
b.set_yticks([]) | |
sns.despine(ax=b, left=True, bottom=True) | |
#put title up high | |
plt.text(0.5, 1.28, section_name, | |
horizontalalignment='center', | |
fontsize=13, | |
transform = inset_axes.transAxes) | |
# inset_axes.set_title(section_name) | |
# inset_axes.set_xlabel(section_name) | |
#insert size of transport.. | |
for p in b.patches: | |
b.annotate( | |
s='{:.1f}'.format(p.get_height()), | |
xy=(p.get_x()+p.get_width()/2.,p.get_height()), | |
ha='center',va='center', | |
xytext=(0,10), | |
textcoords='offset points' | |
) | |
make_arrow(ax,'meri','ED','up',points) | |
make_arrow(ax,'meri','FE','down',points) | |
make_arrow(ax,'meri','BC','up',points) | |
make_arrow(ax,'meri','AB','down',points) | |
make_arrow(ax,'zonal','DG','right',points) | |
make_arrow(ax,'zonal','HI','left',points) | |
if not evaluation: | |
make_arrow(ax,'meri','JK','down',points) | |
#since it's a schematic AK and I have decided to kill axis labels... | |
ax.set_xticklabels([]) | |
ax.set_yticklabels([]) | |
# sm.ins_legend(ax,exp_subset=None,lw=3,location=1,invisible=False,ncols=1) | |
# sm.change_tick_labels_add_dirs(ax) | |
# plt.show() | |
if evaluation: | |
path_to_png=output_folder+'nemo_UV_transports_'+'pretty_bar_charts_fxdtrans_evaluation.png' | |
else: | |
path_to_png=output_folder+'nemo_UV_transports_'+'pretty_bar_charts_fxdtrans.png' | |
if ctl_anom_only!='' and not evaluation: | |
path_to_png=output_folder+'nemo_UV_transports_'+'pretty_bar_charts_fxdtrans_anomalies.png' | |
plt.savefig(path_to_png,dpi=300) | |
#plt.savefig(output_folder+'nemo_UV_transports_'+exptwoname+'.pdf') | |
it.AddTrkr(path_to_png,{'Created with':os.path.realpath(__file__),'time':datetime.datetime.now().strftime("%Y-%m-%d %H:%M"),'machine':socket.gethostname()}) | |
# print path_to_png | |
lg.info("Plot path is: " + path_to_png) | |
#plt.show() | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment