#!/usr/bin/env python # coding: utf-8 # In[ ]: # Bar Plot from SRO: from plot_fate_byOilAndLocation.ipynb # In[14]: import matplotlib.pyplot as plt import numpy as np import pandas as pd import yaml # In[62]: plt.style.use(r'extraction_from_rachaels.template') # In[19]: MIDOSScolors={ 'ANS': 'darkslategrey', 'Bunker-C':'teal', 'Dilbit':'slategrey', 'Diesel':'darkgoldenrod', } # In[20]: with open('SRO_files_try3_t2.yaml') as file: sro = yaml.safe_load(file) # In[21]: df={} df['ANS'] = pd.DataFrame(sro['akns']) df['Bunker-C'] = pd.DataFrame(sro['bunker']) df['Diesel'] = pd.DataFrame(sro['diesel']) df['Dilbit'] = pd.DataFrame(sro['dilbit']) oil_types = ['ANS', 'Bunker-C', 'Diesel', 'Dilbit'] locations = ['water','sfc','beach','air'] # In[22]: final = {} initial={} for location in locations: final[location]={} for oil in oil_types: final[location][oil]=[] for oil in oil_types: final['water'][oil] = (df[oil]['MDispersed'] + df[oil]['MDissolved'] + df[oil]['MBio']) final['sfc'][oil] = df[oil]['MassOil'] final['beach'][oil] = df[oil]['MBeached'] final['air'][oil] = df[oil]['MEvaporated'] initial[oil]=df[oil]['MInitial'] # In[23]: persist = {} # Calculate Quantiles persist['Q1']={} persist['Q2']={} persist['Q3']={} for oil in ['ANS','Bunker-C','Diesel']: persist['Q1'][oil]={} persist['Q2'][oil]={} persist['Q3'][oil]={} for loc in locations: #Quantile 0.25 (in percent form) persist['Q1'][oil][loc]=100*np.quantile( final[loc][oil]/(initial[oil]), .25) #Quantile 0.5 (median, in percent form) persist['Q2'][oil][loc]=100*np.quantile( final[loc][oil]/(initial[oil]), .50) #Quantile 0.75 (in percent form) persist['Q3'][oil][loc]=100*np.quantile( final[loc][oil]/(initial[oil]), .75) persist_df = {} for opp in ['Q1','Q2','Q3']: persist_df[opp] = pd.DataFrame({ "ANS":[persist[opp]["ANS"]["water"], persist[opp]["ANS"]["sfc"], persist[opp]["ANS"]["beach"], persist[opp]["ANS"]["air"]], "Bunker-C":[persist[opp]["Bunker-C"]["water"], persist[opp]["Bunker-C"]["sfc"], persist[opp]["Bunker-C"]["beach"], persist[opp]["Bunker-C"]["air"]], "Diesel":[persist[opp]["Diesel"]["water"], persist[opp]["Diesel"]["sfc"], persist[opp]["Diesel"]["beach"], persist[opp]["Diesel"]["air"]] }, index=["water", "surface", "beach", "air"] ) persist_df[opp] = persist_df[opp].rename_axis(opp, axis=1) # In[50]: error_minxx = persist_df['Q2'] - persist_df['Q1'] error_maxxx = persist_df['Q3'] - persist_df['Q2'] print (error_minxx) print (error_minxx.to_numpy()) # In[57]: yerr_reorg = np.zeros((6, 4)) for ii in range(0, 6, 2): jj = int(ii/2) yerr_reorg[ii] = error_minxx.to_numpy()[:,jj] yerr_reorg[ii+1] = error_maxxx.to_numpy()[:,jj] print(yerr_reorg) # In[64]: fig, ax = plt.subplots(1, 1, figsize=(5, 5)) persist_df['Q2'].plot(ax=ax, kind="bar", color=[MIDOSScolors["ANS"],MIDOSScolors["Bunker-C"],MIDOSScolors["Diesel"]], legend=False, yerr=yerr_reorg, #np.append(error_max, error_min, axis=0), error_kw=dict(lw=3, capsize=4, capthick=3), ecolor='lightsteelblue' ) ax.set_ylabel("Fate (%)") ax.legend(bbox_to_anchor=(1.5, 1), loc='upper right') ax.set_ylim(0,100) ax.set_yticks([0, 20, 40, 60, 80, 100]) ax.set_xticklabels( ["water\ncolumn", "water\nsurface", "coast", "air"], rotation=45 ) plt.savefig('Fate_ByOilLocation_1panel_MedianErr.png') # In[ ]: # For Jose # In[ ]: from salishsea_tools import river_201702 # In[ ]: