## Wave transmission through a Breakwater
# Author: AJMR
# December 14, 2021

#%%  Setup Project
from mikeio import Dfs0
import pandas as pd
import pathlib as pl
import numpy as np
import geopandas as gp

#%% Read Model Log

pth = pl.Path("//srv-mad3.baird.com/", "Projects", "13632.101 South Shore Breakwater", "06_Models", "13632.101.W.zzAJMR.Rev0_ModelLog.xlsx")
runLog = pd.read_excel(pth.as_posix(), "ModelLog")
#%% Read in Point Sh
breakwaterPTS = gp.read_file("//srv-mad3.baird.com/Projects/"
                             "13632.101 South Shore Breakwater/08_CADD/Outgoing/"
                             "20211211_Toe Extents (to Alexander)/"
                             "20211211_Toe_Extents_NAD83_WISStatePlaneSZn_USFt_Lines_OffshoreClipSimple_10m_vertexUTM.shp")

#%% Read Model Results
modelPlot = [8]
# MIKEds    = [None] * (max(modelPlot)+1)

for i in modelPlot:
    dfsIN       = Dfs0(pl.Path(runLog['Run Location'][i],
                           runLog['Run Name'][i] + '.sw - Result Files','BreakPts.dfs0'))

    dfsIN_read  = dfsIN.read()

    A = dfsIN_read.to_dataframe()

    MIKEnp = np.empty((dfsIN_read.n_timesteps, dfsIN_read.shape[1], dfsIN_read.n_items-1))
    MIKEname = []

    for j in range(0, dfsIN_read.n_items-1):
        MIKEname.append(dfsIN_read.items[j].name)

        MIKEnp[:, :, j]   = dfsIN_read[j]

    MIKEds = pd.DataFrame(np.squeeze(MIKEnp[1:, :, :]), columns=MIKEname)

