#%% Plotting EWR Flume Tests

# Alexander Rey, 2022

#%% Import
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm

from scipy.interpolate import LinearNDInterpolator, interp1d

from dfm_tools.get_nc import get_netdata, get_ncmodeldata, plot_netmapdata
from dfm_tools.get_nc_helpers import get_timesfromnc, get_ncfilelist, get_hisstationlist, get_ncvardimlist, get_timesfromnc
import pathlib as pl

#%% Read Model Log

# runLog = pd.read_excel("Y:/12828.101 English Wabigoon River/06_Models/00_Delft3D/ModelRuns.xlsx", "Sensitivity")
pth = pl.Path("//srv-ott3.baird.com/", "Projects", "12828.101 English Wabigoon River", "06_Models", "00_Delft3D", "ModelRuns.xlsx")
runLog = pd.read_excel(pth.as_posix(), "Sensitivity")

dataPath = "FlowFM_map.nc"

#%% Import using DFM Functions

modelPlot  = 27

file_nc_map = pl.Path(runLog['Run Location'][modelPlot], 'Water_Quality', 'output', 'deltashell_map.nc')

tSteps = get_timesfromnc(file_nc=file_nc_map, varname='time')

# Print file variables
A = get_ncvardimlist(file_nc_map.as_posix())
# print(A)

# Define extraction variables
dataVars = ['FrHgIM1',   'FrHgIM2',   'FrHgIM3',   'FrHgDOC', 'FrHgPOC',   'FrHgPHYT',   'FrHgDis',
            'FrHgIM1S1', 'FrHgIM2S1', 'FrHgIM3S1', 'FrHgDOCS1', 'FrHgPOCS1', 'FrHgPHYTS1', 'FrHgDisS1',
            'FrHgIM1S2', 'FrHgIM2S2', 'FrHgIM3S2', 'FrHgDOCS2', 'FrHgPOCS2', 'FrHgPHYTS2', 'FrHgDisS2',
            'FrMmIM1',   'FrMmIM2',   'FrMmIM3',   'FrMmDOC',   'FrMmPOC',   'FrMmPHYT',   'FrMmDis',
            'FrMmIM1S1', 'FrMmIM2S1', 'FrMmIM3S1', 'FrMmDOCS1', 'FrMmPOCS1', 'FrMmPHYTS1', 'FrMmDisS1',
            'FrMmIM1S2', 'FrMmIM2S2', 'FrMmIM3S2', 'FrMmDOCS2', 'FrMmPOCS2', 'FrMmPHYTS2', 'FrMmDisS2',
            'IM1', 'IM2', 'IM3', 'Hg', 'Mm', 'H0', 'POC1', 'POC2',
            'IM1S1', 'IM2S1', 'IM3S1', 'HgS1', 'MmS1', 'DetCS1', 'OOCS1',
            'IM1S2', 'IM2S2', 'IM3S2', 'HgS2', 'MmS2', 'DetCS2', 'OOCS2',
            'fResS1IM1',  'fSedIM1',  'fResS1IM2', 'fSedIM2',
            'fResS1DetC', 'fSedPOC1', 'fResS1OOC', 'fSedPOC2',
            'fSedHg', 'fResS1Hg', 'fSedMm', 'fResS1Mm',
            'HgHgS1O', 'MmMmS1O',
            'HgMmO', 'HgS1MmS1O', 'MmHgO', 'MmS1HgS1O',
            'oPhoDeg', 'oPhoOxy', 'oPhoRed',
            'f_minPOC1', 'MnODCS1']

# Create Pandas Output Array
dataIN = get_ncmodeldata(file_nc=file_nc_map.as_posix(),
                         varname='mesh2d_face_x',
                         silent=True)
dataOUT = pd.DataFrame(index=np.array(dataIN[2:-2]))


# Extract variables
for vIDX, v in enumerate(dataVars):
    # Extract data from NetCDF file
    dataIN = get_ncmodeldata(file_nc=file_nc_map.as_posix(),
                             varname='mesh2d_' + v, timestep=len(tSteps)-1,
                             silent=True, layer=0)

    dataOUT[v] = np.array(dataIN[0][0][2:-2])

    print(v)

#%% Plot Partition Data

fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(9, 9))
fig.patch.set_facecolor('white')
fig.tight_layout(pad=3)
ax = axes.flat

#Hg Parition in Water
ax[0].set_title('Hg Fraction in Water')
ax[0].plot(dataOUT.index, dataOUT['FrHgIM1'], linewidth=3, label='IM1')
ax[0].plot(dataOUT.index, dataOUT['FrHgIM2'], linewidth=3, label='IM2')
ax[0].plot(dataOUT.index, dataOUT['FrHgIM3'], linewidth=3, label='IM3')
ax[0].plot(dataOUT.index, dataOUT['FrHgPOC'], linewidth=3, label='POC')
ax[0].plot(dataOUT.index, dataOUT['FrHgDOC'], linewidth=3, label='DOC')
ax[0].plot(dataOUT.index, dataOUT['FrHgPHYT'], linewidth=3, label='PHYT')
ax[0].plot(dataOUT.index, dataOUT['FrHgDis'], linewidth=3, label='Dissolved')

ax[0].legend()
ax[0].set_ylabel('Percentage Hg')
ax[0].set_xlabel('Distance Along Flume [m]')


#Mm Parition in Water
ax[1].set_title('MeHg Fraction in Water')
ax[1].plot(dataOUT.index, dataOUT['FrMmIM1'], linewidth=3, label='IM1')
ax[1].plot(dataOUT.index, dataOUT['FrMmIM2'], linewidth=3, label='IM2')
ax[1].plot(dataOUT.index, dataOUT['FrMmIM3'], linewidth=3, label='IM3')
ax[1].plot(dataOUT.index, dataOUT['FrMmPOC'], linewidth=3, label='POC')
ax[1].plot(dataOUT.index, dataOUT['FrMmDOC'], linewidth=3, label='DOC')
ax[1].plot(dataOUT.index, dataOUT['FrMmPHYT'], linewidth=3, label='PHYT')
ax[1].plot(dataOUT.index, dataOUT['FrMmDis'], linewidth=3, label='Dissolved')

ax[1].legend()
ax[1].set_ylabel('Percentage MeHg')
ax[1].set_xlabel('Distance Along Flume [m]')


#Hg Parition in S1
ax[2].set_title('Hg Fraction in Sediment')
ax[2].plot(dataOUT.index, dataOUT['FrHgIM1S1'], linewidth=3, label='IM1')
ax[2].plot(dataOUT.index, dataOUT['FrHgIM2S1'], linewidth=3, label='IM2')
ax[2].plot(dataOUT.index, dataOUT['FrHgIM3S1'], linewidth=3, label='IM3')
ax[2].plot(dataOUT.index, dataOUT['FrHgPOCS1'], linewidth=3, label='POC')
ax[2].plot(dataOUT.index, dataOUT['FrHgDOCS1'], linewidth=3, label='DOC')
ax[2].plot(dataOUT.index, dataOUT['FrHgPHYTS1'], linewidth=3, label='PHYT')
ax[2].plot(dataOUT.index, dataOUT['FrHgDisS1'], linewidth=3, label='Dissolved')

ax[2].legend()
ax[2].set_ylabel('Percentage Hg')
ax[2].set_xlabel('Distance Along Flume [m]')


#Mm Parition in S1
ax[3].set_title('MeHg Fraction in Sediment')
ax[3].plot(dataOUT.index, dataOUT['FrMmIM1S1'], linewidth=3, label='IM1')
ax[3].plot(dataOUT.index, dataOUT['FrMmIM2S1'], linewidth=3, label='IM2')
ax[3].plot(dataOUT.index, dataOUT['FrMmIM3S1'], linewidth=3, label='IM3')
ax[3].plot(dataOUT.index, dataOUT['FrMmPOCS1'], linewidth=3, label='POC')
ax[3].plot(dataOUT.index, dataOUT['FrMmDOCS1'], linewidth=3, label='DOC')
ax[3].plot(dataOUT.index, dataOUT['FrMmPHYTS1'], linewidth=3, label='PHYT')
ax[3].plot(dataOUT.index, dataOUT['FrMmDisS1'], linewidth=3, label='Dissolved')

ax[3].legend()
ax[3].set_ylabel('Percentage MeHg')
ax[3].set_xlabel('Distance Along Flume [m]')

plt.show()

fig.savefig('C:/Users/arey/files/Projects/Grassy Narrows/Modelling/ProcessFigures/Partitioning.png',
             bbox_inches='tight', dpi=200)


#%% Plot Total Data

fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(9, 9))
fig.patch.set_facecolor('white')
fig.tight_layout(pad=3)
ax = axes.flat

#Hg in Water
ax[0].set_title('Hg in Water')
ax[0].plot(dataOUT.index, dataOUT['Hg'] * 1000000, linewidth=3, label='Hg')

ax[0].legend()
ax[0].set_ylabel('Hg [ng/L]')
ax[0].set_xlabel('Distance Along Flume [m]')


# Mm in Water
ax[1].set_title('MeHg in Water')
ax[1].plot(dataOUT.index, dataOUT['Mm'] * 1000000, linewidth=3, label='MeHg')

ax[1].legend()
ax[1].set_ylabel('MeHg [ng/L]')
ax[1].set_xlabel('Distance Along Flume [m]')

#Hg in Sediment
ax[2].set_title('Hg in Sediment')
ax[2].plot(dataOUT.index, dataOUT['HgS1'] * 1*10 ** 9 / (dataOUT['IM1S1'] + dataOUT['IM2S1'] + dataOUT['IM3S1'] + dataOUT['DetCS1'] + dataOUT['OOCS1']),
           linewidth=3, label='HgS1')

ax[2].legend()
ax[2].set_ylabel('HgS1 [ng/g]')
ax[2].set_xlabel('Distance Along Flume [m]')


# Mm in Sediment
ax[3].set_title('MeHg in Sediment')
ax[3].plot(dataOUT.index, dataOUT['MmS1'] * 1*10 ** 9 / (dataOUT['IM1S1'] + dataOUT['IM2S1'] + dataOUT['IM3S1'] + dataOUT['DetCS1'] + dataOUT['OOCS1']),
           linewidth=3, label='MeHgS1')
ax[3].legend()
ax[3].set_ylabel('MeHg [ng/g]')
ax[3].set_xlabel('Distance Along Flume [m]')

plt.show()

fig.savefig('C:/Users/arey/files/Projects/Grassy Narrows/Modelling/ProcessFigures/HgTotals.png',
             bbox_inches='tight', dpi=200)

#%% Plot POC total Data

fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(9, 9))
fig.patch.set_facecolor('white')
fig.tight_layout(pad=3)
ax = axes.flat

# POC1 in Water
ax[0].set_title('POC1 (Fast) in Water')
ax[0].plot(dataOUT.index, dataOUT['POC1'], linewidth=3, label='POC1')

ax[0].legend()
ax[0].set_ylabel('POC1 [g/m3]')
ax[0].set_xlabel('Distance Along Flume [m]')

# POC2 in Water
ax[1].set_title('POC2 (Slow) in Water')
ax[1].plot(dataOUT.index, dataOUT['POC2'], linewidth=3, label='POC2')

ax[1].legend()
ax[1].set_ylabel('POC2 [g/m3]')
ax[1].set_xlabel('Distance Along Flume [m]')


#DetC in sediment
ax[2].set_title('DetC (Fast) in Sediment')
ax[2].plot(dataOUT.index, dataOUT['DetCS1']
           / (dataOUT['IM1S1'] + dataOUT['IM2S1'] + dataOUT['IM3S1'] + dataOUT['DetCS1'] + dataOUT['OOCS1'])
           , linewidth=3, label='DetCS1')

ax[2].legend()
ax[2].set_ylabel('DetCS1 [g/g]')
ax[2].set_xlabel('Distance Along Flume [m]')


# OOC in Sediment
ax[3].set_title('OOC (Slow) in Sediment')
ax[3].plot(dataOUT.index, dataOUT['OOCS1']
           / (dataOUT['IM1S1'] + dataOUT['IM2S1'] + dataOUT['IM3S1'] + dataOUT['DetCS1'] + dataOUT['OOCS1']),
           linewidth=3, label='OOCS1')

ax[3].legend()
ax[3].set_ylabel('OOCS1 [g/g]')
ax[3].set_xlabel('Distance Along Flume [m]')


plt.show()
fig.savefig('C:/Users/arey/files/Projects/Grassy Narrows/Modelling/ProcessFigures/POCTotals.png',
             bbox_inches='tight', dpi=200)


#%% More Total Data

fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(9, 9))
fig.patch.set_facecolor('white')
fig.tight_layout(pad=3)
ax = axes.flat

#H0 in Water
ax[0].set_title('Hg(0) in Water')
ax[0].plot(dataOUT.index, dataOUT['H0']* 1000000, linewidth=3, label='Hg(0)')

ax[0].legend()
ax[0].set_ylabel('Hg(0) [ng/L]')
ax[0].set_xlabel('Distance Along Flume [m]')


# IM1 in Water
ax[1].set_title('IM1 (Sand) in Water')
ax[1].plot(dataOUT.index, dataOUT['IM1'], linewidth=3, label='IM1')

ax[1].legend()
ax[1].set_ylabel('IM1 [g/m3]')
ax[1].set_xlabel('Distance Along Flume [m]')

# IM2 in Water
ax[2].set_title('IM2 (Silt) in Water')
ax[2].plot(dataOUT.index, dataOUT['IM2'], linewidth=3, label='IM2')

ax[2].legend()
ax[2].set_ylabel('IM2 [g/m3]')
ax[2].set_xlabel('Distance Along Flume [m]')

# IM3 in Water
ax[3].set_title('IM3 (Woodchips) in Water')
ax[3].plot(dataOUT.index, dataOUT['IM3'], linewidth=3, label='IM3 (Woodchips)')

ax[3].legend()
ax[3].set_ylabel('IM3 [g/m3]')
ax[3].set_xlabel('Distance Along Flume [m]')

plt.show()

fig.savefig('C:/Users/arey/files/Projects/Grassy Narrows/Modelling/ProcessFigures/InorganicTotals.png',
             bbox_inches='tight', dpi=200)

#%% Plot Fluxes

fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(9, 9))
fig.patch.set_facecolor('white')
fig.tight_layout(pad=3)
ax = axes.flat

# IM1 Sediment Flux
ax[0].set_title('IM1 (Sand) Resuspension Flux')
ax[0].plot(dataOUT.index, dataOUT['fResS1IM1'], linewidth=3, label='IM1 Resuspension')
ax[0].plot(dataOUT.index, dataOUT['fSedIM1'], linewidth=3, label='IM1 Sedimentation')

ax[0].legend()
ax[0].set_ylabel('IM1 (Sand) Sedimentation and Resuspension [g/m2/d]')
ax[0].set_xlabel('Distance Along Flume [m]')

# POC Sediment Flux
ax[1].set_title('POC Resuspension Flux')
ax[1].plot(dataOUT.index, dataOUT['fResS1DetC'], linewidth=3, label='DetC Resuspension')
ax[1].plot(dataOUT.index, dataOUT['fResS1OOC'], linewidth=3, label='OOC Resuspension')
ax[1].plot(dataOUT.index, dataOUT['fSedPOC1'], linewidth=3, label='POC1 (Fast) Sedimentation')
ax[1].plot(dataOUT.index, dataOUT['fSedPOC2'], linewidth=3, label='POC2 (Slow) Sedimentation')

ax[1].legend()
ax[1].set_ylabel('POC Sedimentation and Resuspension [g/m2/d]')
ax[1].set_xlabel('Distance Along Flume [m]')

# Hg Sediment Flux
ax[2].set_title('Hg Resuspension Flux')
ax[2].plot(dataOUT.index, dataOUT['fResS1Hg'], linewidth=3, label='Hg Resuspension')
ax[2].plot(dataOUT.index, dataOUT['fSedHg'], linewidth=3, label='Hg Sedimentation')

ax[2].legend()
ax[2].set_ylabel('Hg Sedimentation and Resuspension [g/m2/d]')
ax[2].set_xlabel('Distance Along Flume [m]')

# Mm Sediment Flux
ax[3].set_title('MeHg Resuspension Flux')
ax[3].plot(dataOUT.index, dataOUT['fResS1Mm'], linewidth=3, label='MeHg Resuspension')
ax[3].plot(dataOUT.index, dataOUT['fSedMm'], linewidth=3, label='MeHg Sedimentation')

ax[3].legend()
ax[3].set_ylabel('MeHg Sedimentation and Resuspension [g/m2/d]')
ax[3].set_xlabel('Distance Along Flume [m]')

plt.show()

fig.savefig('C:/Users/arey/files/Projects/Grassy Narrows/Modelling/ProcessFigures/HgFluxes.png',
             bbox_inches='tight', dpi=200)

#%% Plot More Fluxes

fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(9, 9))
fig.patch.set_facecolor('white')
fig.tight_layout(pad=4)
ax = axes.flat

# Methylation Flux
ax[0].set_title('Methylation Flux in Water')
ax[0].plot(dataOUT.index, dataOUT['HgMmO'], linewidth=3, label='Mehtylation')
ax[0].plot(dataOUT.index, dataOUT['MmHgO'], linewidth=3, label='Demehtylation')

ax[0].legend()
ax[0].set_ylabel('Methylation Flux in Water [g/m3/d]')
ax[0].set_xlabel('Distance Along Flume [m]')

# Methylation Flux in Sediment
ax[1].set_title('Methylation Flux in Sediment')
ax[1].plot(dataOUT.index, dataOUT['HgS1MmS1O']
           / (dataOUT['HgS1']),
           linewidth=3, label='Mehtylation')
ax[1].plot(dataOUT.index, dataOUT['MmS1HgS1O']
           / (dataOUT['MmS1']),
           linewidth=3, label='Demehtylation')

ax[1].legend()
ax[1].set_ylabel('Methylation Flux in Sediment [g/gHg/d]')
ax[1].set_xlabel('Distance Along Flume [m]')

# Hg Diffusion Flux
# ax[2].set_title('Diffusion Flux')
# ax[2].plot(dataOUT.index, dataOUT['HgHgS1O'], linewidth=3, label='Hg Diffusion')
# ax[2].plot(dataOUT.index, dataOUT['MmMmS1O'], linewidth=3, label='MeHg Diffusion')
#
# ax[2].legend()
# ax[2].set_ylabel('Diffusion [g/m2/d]')
# ax[2].set_xlabel('Distance Along Flume [m]')

# POC Degradation Flux
ax[2].set_title('POC Degradation Flux in Water')
ax[2].plot(dataOUT.index, dataOUT['f_minPOC1'], linewidth=3, label='POC Degradation Water')
ax[2].legend()
ax[2].set_ylabel('POC Degradation [g/m3/d]')
ax[2].set_xlabel('Distance Along Flume [m]')


# POC Degradation Flux
ax[3].set_title('POC Degradation Flux in Sediment')
ax[3].plot(dataOUT.index, dataOUT['MnODCS1']
            / (dataOUT['DetCS1'] + dataOUT['OOCS1']),
           linewidth=3, label='POC Degradation Sediment')

ax[3].legend()
ax[3].set_ylabel('POC Degradation [g/gPOC/d')
ax[3].set_xlabel('Distance Along Flume [m]')

plt.show()

fig.savefig('C:/Users/arey/files/Projects/Grassy Narrows/Modelling/ProcessFigures/POCFluxes.png',
             bbox_inches='tight', dpi=200)

#%% Photo Fluxes

fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(9, 9))
fig.patch.set_facecolor('white')
fig.tight_layout(pad=4)
ax = axes.flat

# Diffusion Flux
ax[0].set_title('Diffusion Flux')
ax[0].plot(dataOUT.index, dataOUT['HgHgS1O'], linewidth=3, label='Hg Diffusion')
ax[0].plot(dataOUT.index, dataOUT['MmMmS1O'], linewidth=3, label='MeHg Diffusion')

ax[0].legend()
ax[0].set_ylabel('Diffusion [g/m2/d]')
ax[0].set_xlabel('Distance Along Flume [m]')

# Photo Oxidation Flux
ax[1].set_title('Photo Oxidation Flux')
ax[1].plot(dataOUT.index, dataOUT['oPhoOxy'], linewidth=3, label='Photo Oxidation Flux')

ax[1].legend()
ax[1].set_ylabel('Photo Oxidation Flux [g/m3/d]')
ax[1].set_xlabel('Distance Along Flume [m]')


# Photo Degradation Flux
ax[2].set_title('Photo Degradation Flux')
ax[2].plot(dataOUT.index, dataOUT['oPhoDeg'], linewidth=3, label='Photo Degradation Flux')

ax[2].legend()
ax[2].set_ylabel('Photo Degradation Flux [g/m3/d]')
ax[2].set_xlabel('Distance Along Flume [m]')


# Photo Reduction Flux
ax[3].set_title('Photo Reduction Flux')
ax[3].plot(dataOUT.index, dataOUT['oPhoRed'], linewidth=3, label='Photo Reduction Flux')

ax[3].legend()
ax[3].set_ylabel('Photo Reduction Flux [g/m3/d]')
ax[3].set_xlabel('Distance Along Flume [m]')

plt.show()

fig.savefig('C:/Users/arey/files/Projects/Grassy Narrows/Modelling/ProcessFigures/H0Fluxes.png',
             bbox_inches='tight', dpi=200)

#%% Make summary table
dataTableOut = dict()

#Hg Parition in Water
dataTableOut['Hg:IM1 Fraction'] = dataOUT['FrHgIM1'].mean()
dataTableOut['Hg:IM2 Fraction'] = dataOUT['FrHgIM2'].mean()
dataTableOut['Hg:IM3 Fraction'] = dataOUT['FrHgIM3'].mean()
dataTableOut['Hg:POC Fraction'] = dataOUT['FrHgPOC'].mean()
dataTableOut['Hg:DOC Fraction'] = dataOUT['FrHgDOC'].mean()
dataTableOut['Hg:Phyt Fraction'] = dataOUT['FrHgPHYT'].mean()
dataTableOut['Hg:Dissolved Fraction'] = dataOUT['FrHgDis'].mean()

#MeHg Parition in Water
dataTableOut['MeHg:IM1 Fraction'] = dataOUT['FrMmIM1'].mean()
dataTableOut['MeHg:IM2 Fraction'] = dataOUT['FrMmIM2'].mean()
dataTableOut['MeHg:IM3 Fraction'] = dataOUT['FrMmIM3'].mean()
dataTableOut['MeHg:POC Fraction'] = dataOUT['FrMmPOC'].mean()
dataTableOut['MeHg:DOC Fraction'] = dataOUT['FrMmDOC'].mean()
dataTableOut['MeHg:Phyt Fraction'] = dataOUT['FrMmPHYT'].mean()
dataTableOut['MeHg:Dissolved Fraction'] = dataOUT['FrMmDis'].mean()

#Hg Parition in S1
dataTableOut['Hg:IM1 Fraction S1'] = dataOUT['FrHgIM1S1'].mean()
dataTableOut['Hg:IM2 Fraction S1'] = dataOUT['FrHgIM2S1'].mean()
dataTableOut['Hg:IM3 Fraction S1'] = dataOUT['FrHgIM3S1'].mean()
dataTableOut['Hg:POC Fraction S1'] = dataOUT['FrHgPOCS1'].mean()
dataTableOut['Hg:DOC Fraction S1'] = dataOUT['FrHgDOCS1'].mean()
dataTableOut['Hg:Phyt Fraction S1'] = dataOUT['FrHgPHYTS1'].mean()
dataTableOut['Hg:Dissolved Fraction S1'] = dataOUT['FrHgDisS1'].mean()

#MeHg Parition in S1
dataTableOut['MeHg:IM1 Fraction S1'] = dataOUT['FrMmIM1S1'].mean()
dataTableOut['MeHg:IM2 Fraction S1'] = dataOUT['FrMmIM2S1'].mean()
dataTableOut['MeHg:IM3 Fraction S1'] = dataOUT['FrMmIM3S1'].mean()
dataTableOut['MeHg:POC Fraction S1'] = dataOUT['FrMmPOCS1'].mean()
dataTableOut['MeHg:DOC Fraction S1'] = dataOUT['FrMmDOCS1'].mean()
dataTableOut['MeHg:Phyt Fraction S1'] = dataOUT['FrMmPHYT'].mean()
dataTableOut['MeHg:Dissolved Fraction S1'] = dataOUT['FrMmDisS1'].mean()

#Hg in Water
dataTableOut['Hg in Water [ng/L]'] = dataOUT['Hg'].mean() * 1000000

# Mm in Water
dataTableOut['MeHg in Water [ng/L]'] = dataOUT['Mm'].mean() * 1000000

#Hg in Sediment
dataTableOut['Hg in Sediment [ng/g]'] = dataOUT['HgS1'].mean() * 1*10 ** 9 /\
                                     (dataOUT['IM1S1'].mean() + dataOUT['IM2S1'].mean() + dataOUT['IM3S1'].mean() +
                                      dataOUT['DetCS1'].mean() + dataOUT['OOCS1'].mean())

# Mm in Sediment
dataTableOut['MeHg in Sediment [ng/g]'] = dataOUT['MmS1'].mean() * 1*10 ** 9 /\
                                     (dataOUT['IM1S1'].mean() + dataOUT['IM2S1'].mean() + dataOUT['IM3S1'].mean() +
                                      dataOUT['DetCS1'].mean() + dataOUT['OOCS1'].mean())

# Hg(0) in Water
dataTableOut['Hg(0) in Water [ng/L]'] = dataOUT['H0'].mean() * 1000000

# IM1 in Water
ax[1].set_title('IM1 (Sand) in Water')
dataTableOut['IM1 (Sand) in Water [g/m3]'] = dataOUT['IM1'].mean()

# IM2 in Water
dataTableOut['IM2 (Silt) in Water [g/m3]'] = dataOUT['IM2'].mean()

# IM3 in Water
dataTableOut['IM3 (Woodchips) in Water [g/m3]'] = dataOUT['IM3'].mean()

# POC1 in Water
dataTableOut['POC1 (Fast) in Water [g/m3]'] = dataOUT['POC1'].mean()

# POC2 in Water
dataTableOut['POC1 (Slow) in Water [g/m3]'] = dataOUT['POC2'].mean()

#DetC in sediment
dataTableOut['DetC (Fast) in Sediment [g/g]'] = dataOUT['DetCS1'].mean() /\
                                     (dataOUT['IM1S1'].mean() + dataOUT['IM2S1'].mean() + dataOUT['IM3S1'].mean() +
                                      dataOUT['DetCS1'].mean() + dataOUT['OOCS1'].mean())

# OOC in Sediment
dataTableOut['OOC (Slow) in Sediment [g/g]'] = dataOUT['OOCS1'].mean() /\
                                     (dataOUT['IM1S1'].mean() + dataOUT['IM2S1'].mean() + dataOUT['IM3S1'].mean() +
                                      dataOUT['DetCS1'].mean() + dataOUT['OOCS1'].mean())


# IM1 Resuspension
dataTableOut['IM1 (Sand) Resuspension Flux [g/m2/d]'] = dataOUT['fResS1IM1'].mean()

# IM1 Sedimentation
dataTableOut['IM1 (Sand) Sedimentation Flux [g/m2/d]'] = dataOUT['fSedIM1'].mean()

# DetC Resuspension
dataTableOut['DetC Resuspension Flux [g/m2/d]'] = dataOUT['fResS1DetC'].mean()

# OOC Resuspension
dataTableOut['OOC Resuspension Flux [g/m2/d]'] = dataOUT['fResS1OOC'].mean()

# POC1 Sedimentation
dataTableOut['POC1 (Fast) Sedimentation [g/m2/d]'] = dataOUT['fSedPOC1'].mean()

# POC2 Sedimentation
dataTableOut['POC2 (Slow) Sedimentation [g/m2/d]'] = dataOUT['fSedPOC2'].mean()

# Hg Resuspension
dataTableOut['Hg Resuspension Flux [g/m2/d]'] = dataOUT['fResS1Hg'].mean()

# Hg Sedimentation
dataTableOut['Hg Sedimentation Flux [g/m2/d]'] = dataOUT['fSedHg'].mean()

# MeHg Resuspension
dataTableOut['MeHg Resuspension Flux [g/m2/d]'] = dataOUT['fResS1Mm'].mean()

# MeHg Sedimentation
dataTableOut['MeHg Sedimentation Flux [g/m2/d]'] = dataOUT['fSedMm'].mean()


# Methylation Flux in Water
dataTableOut['Methylation Flux in Water [g/m3/d]'] = dataOUT['HgMmO'].mean()

# Demehtylation Flux in Water
dataTableOut['Demehtylation Flux in Water [g/m3/d]'] = dataOUT['MmHgO'].mean()

# Methylation Flux in Sediment
dataTableOut['Methylation Flux in Sediment [g/gHg/d]'] = dataOUT['HgS1MmS1O'].mean() / dataOUT['HgS1'].mean()

# Demehtylation Flux in Sediment
dataTableOut['Demehtylation Flux in Sediment [g/gMm/d]'] = dataOUT['MmS1HgS1O'].mean() / dataOUT['MmS1'].mean()


# POC Degradation Flux in Water
dataTableOut['POC Degradation Flux in Water [g/m3/d]'] = dataOUT['f_minPOC1'].mean()

# POC Degradation Flux in Sediment
dataTableOut['Demehtylation Flux in Water [g/gPOC/d]'] = dataOUT['MnODCS1'].mean() /\
                                                       (dataOUT['DetCS1'].mean() + dataOUT['OOCS1'].mean())


# Hg Diffusion Flux
dataTableOut['Hg Diffusion [g/m2/d]'] = dataOUT['HgHgS1O'].mean()

# MeHg Diffusion Flux
dataTableOut['MeHg Diffusion [g/m2/d]'] = dataOUT['MmMmS1O'].mean()

# Photo Oxidation Flux
dataTableOut['Hg Diffusion [g/m3/d]'] = dataOUT['oPhoOxy'].mean()

# Photo Degradation Flux
dataTableOut['MeHg Diffusion [g/m3/d]'] = dataOUT['oPhoDeg'].mean()

# Photo Reduction Flux
dataTableOut['Hg Diffusion [g/m3/d]'] = dataOUT['oPhoRed'].mean()

#%% Save Data Table as Excel
dataTableOut_df = pd.DataFrame(data=dataTableOut, index=[0])
dataTableOut_df = (dataTableOut_df.T)

dataTableOut_df.to_excel('C:/Users/arey/files/Projects/Grassy Narrows/Modelling/ModelOutputs_Sept26.xlsx')