<jupyter_start><jupyter_text>Tide Tuning Notebook<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
N36_Cin = {'North': {'S2': {'Pha': -9.2307801486176153, 'Amp': 1.038819257728969}, 'M2': {'Pha': 2.6888859885826322, 'Amp': 0.88935590323168601}, 'O1': {'Pha': -2.5, 'Amp': 0.96099403975860098}, 'Q1': {'Pha': -5, 'Amp': 0.955}, 'N2': {'Pha': -4.6638540853471788, 'Amp': 0.98340380585090903}, 'K1': {'Pha': 4, 'Amp': 1.0204698354704094}}, 'West': {'S2': {'Pha': 1.6977373796987445, 'Amp': 1.042595155967583}, 'M2': {'Pha': -7.2661477680807574, 'Amp': 0.87208325073801229}, 'O1': {'Pha': 2.0, 'Amp': 1.09}, 'Q1': {'Pha': 3.0, 'Amp': 0.99611855906827507}, 'N2': {'Pha': 0.8, 'Amp': 0.98014138690691721}, 'K1': {'Pha': -2.8032934372377518, 'Amp': 0.98438671203095895}}}
N36_Bin = {'North': {'Q1': {'Pha': -6, 'Amp': 0.95049054590546012}, 'K1': {'Pha': -4, 'Amp': 1.02}, 'M2': {'Pha': 2.3827828994834683, 'Amp': 0.88558971714596835}, 'N2': {'Pha': -4.6678925773866355, 'Amp': 0.98323714871353618}, 'S2': {'Pha': -8.8871723559264488, 'Amp': 1.0379680543704286}, 'O1': {'Pha': -3, 'Amp': 0.96353680059599056}}, 'West': {'Q1': {'Pha': 0, 'Amp': 0.9943368632471852}, 'K1': {'Pha': -4, 'Amp': 0.98682615564783738}, 'M2': {'Pha': -7.4948755798835851, 'Amp': 0.87901024019047747}, 'N2': {'Pha': -0.2, 'Amp': 0.9797124228733876}, 'S2': {'Pha': 1.6, 'Amp': 1.0447724256431379}, 'O1': {'Pha': 1.9, 'Amp': 1.06}}}
TS13in = {'North': {'M2': {'Amp': 0.8845477202697829, 'Pha': 2.3403076176485551}, 'O1': {'Amp': 0.96272350844507903, 'Pha': 12.0}, 'S2': {'Amp': 1.0379680543704286, 'Pha': -9.2}, 'K1': {'Amp': 1.0330857501316655, 'Pha': -19.0}, 'Q1': {'Amp': 0.97916112578543213, 'Pha': 4.0}, 'N2': {'Amp': 0.9832161382284451, 'Pha': -4.6840045875437299}}, 'West': {'M2': {'Amp': 0.88170684906405461, 'Pha': -7.5434415446258862}, 'O1': {'Amp': 1.0309632498092482, 'Pha': 12.2}, 'S2': {'Amp': 1.0446321721304719, 'Pha': 1.73}, 'K1': {'Amp': 1.0243962888030014, 'Pha': -14.26898720916071}, 'Q1': {'Amp': 0.9943368632471852, 'Pha': 9.85}, 'N2': {'Amp': 0.9797124228733876, 'Pha': 1.0}}}

TS12in = {'West': {'K1': {'Pha': -14.26898720916071, 'Amp': 1.0243962888030014}, 'S2': {'Pha': 1.73, 'Amp': 1.0446178034256923}, 'Q1': {'Pha': 9.8, 'Amp': 0.9943368632471852}, 'O1': {'Pha': 12.050236466923987, 'Amp': 1.0305322478848729}, 'N2': {'Pha': 1.1, 'Amp': 0.9797124228733876}, 'M2': {'Pha': -7.5808775409993272, 'Amp': 0.883}}, 'North': {'K1': {'Pha': -15.0, 'Amp': 1.0}, 'S2': {'Pha': -9.132874394421526, 'Amp': 1.0379680543704286}, 'Q1': {'Pha': 1.6326019921444512, 'Amp': 0.99137048561193775}, 'O1': {'Pha': 12.399628661111066, 'Amp': 0.96285725026965896}, 'N2': {'Pha': -4.6862481353032051, 'Amp': 0.98321613822844511}, 'M2': {'Pha': 2.3120312919802783, 'Amp': 0.88373899355715846}}}
TS11in = {'North': {'K1': {'Pha': -11.0, 'Amp': 1.0}, 'S2': {'Pha': -9.132874394421526, 'Amp': 1.0379680543704286}, 'Q1': {'Pha': 7.632601992144451, 'Amp': 1.023011793904681}, 'M2': {'Pha': 2.2779834668333558, 'Amp': 0.88270427351908831}, 'N2': {'Pha': -4.689607824516905, 'Amp': 0.98318244724240378}, 'O1': {'Pha': 18.399628661111066, 'Amp': 0.96361058463564087}}, 'West': {'K1': {'Pha': -14.26898720916071, 'Amp': 1.0243962888030014}, 'S2': {'Pha': 1.73, 'Amp': 1.0447177932216045}, 'Q1': {'Pha': 9.717984938287248, 'Amp': 0.99433686324718518}, 'M2': {'Pha': -7.62709254474166, 'Amp': 0.884}, 'N2': {'Pha': 1.4777129541142697, 'Amp': 0.9797124228733876}, 'O1': {'Pha': 12.050236466923987, 'Amp': 1.0299456999774774}}}
TS10in = {'North': {'Q1': {'Amp': 1.0825116171662457, 'Pha': 12.632601992144451}, 'S2': {'Amp': 1.0379680543704286, 'Pha': -9.332874394421525}, 'N2': {'Amp': 0.98355159834393069, 'Pha': -4.6814662131266642}, 'O1': {'Amp': 0.96565598198952585, 'Pha': 28.399628661111066}, 'K1': {'Amp': 0.8200000000000001, 'Pha': -9.0}, 'M2': {'Amp': 0.88138318239218327, 'Pha': 2.2386464647335269}}, 'West': {'Q1': {'Amp': 0.99470837890616992, 'Pha': 9.517984938287249}, 'S2': {'Amp': 1.0446956705700003, 'Pha': 1.7247857894725884}, 'N2': {'Amp': 0.9797124228733876, 'Pha': 0.7610588345320388}, 'O1': {'Amp': 1.0290395717320522, 'Pha': 11.550236466923987}, 'K1': {'Amp': 1.05, 'Pha': -16.26898720916071}, 'M2': {'Amp': 0.88774830007038597, 'Pha': -7.6851903099544563}}}
TS9in = {'North': {'O1': {'Amp': 0.9883470888743955, 'Pha': 23.399628661111066}, 'M2': {'Amp': 0.87832866964865763, 'Pha': 2.1477843647649064}, 'N2': {'Amp': 0.98342713711111474, 'Pha': -4.6896078245169051}, 'K1': {'Amp': 0.8200000000000001, 'Pha': -9.0}, 'Q1': {'Amp': 1.1482701669875641, 'Pha': 12.632601992144451}, 'S2': {'Amp': 1.0379680543704286, 'Pha': -8.4439557398943386}}, 'West': {'O1': {'Amp': 1.04, 'Pha': 12.550236466923987}, 'M2': {'Amp': 0.8906867359929187, 'Pha': -7.8166410932266306}, 'N2': {'Amp': 0.9797124228733876, 'Pha': 1.6187676872376835}, 'K1': {'Amp': 1.0243962888030014, 'Pha': -14.26898720916071}, 'Q1': {'Amp': 0.99162436129565101, 'Pha': 10.517984938287249}, 'S2': {'Amp': 1.0445332886627665, 'Pha': 1.7247857894725884}}}
TS8in = {'North': {'Q1': {'Pha': 17.63260199214445, 'Amp': 1.2}, 'N2': {'Pha': -4.6764732709324885, 'Amp': 0.98307570791396637}, 'O1': {'Pha': 33.399628661111066, 'Amp': 0.96834708887439547}, 'K1': {'Pha': -7.0, 'Amp': 0.77}, 'M2': {'Pha': 1.9437797162850838, 'Amp': 0.87105935851246963}, 'S2': {'Pha': -8.3328743944215251, 'Amp': 1.0379680543704286}}, 'West': {'Q1': {'Pha': 10.517984938287249, 'Amp': 0.99510234222303384}, 'N2': {'Pha': 1.7610588345320388, 'Amp': 0.9797124228733876}, 'O1': {'Pha': 12.550236466923987, 'Amp': 1.04}, 'K1': {'Pha': -16.26898720916071, 'Amp': 1.05}, 'M2': {'Pha': -8.0785860056219647, 'Amp': 0.89475860223501025}, 'S2': {'Pha': 1.7247857894725884, 'Amp': 1.050516310380342}}}
TS7in = {'West': {'S2': {'Amp': 1.0505163103803421, 'Pha': 3.7247857894725884}, 'N2': {'Amp': 0.96971242287338755, 'Pha': 1.7940575230642932}, 'O1': {'Amp': 1.02153509818521, 'Pha': 14.550236466923987}, 'M2': {'Amp': 0.89853811467771461, 'Pha': -8.7976656174843022}, 'K1': {'Amp': 1.0800017009372505, 'Pha': -18.268987209160709}, 'Q1': {'Amp': 0.97358470939406028, 'Pha': 13.517984938287249}}, 'North': {'S2': {'Amp': 1.0479680543704286, 'Pha': -8.5775631728451902}, 'N2': {'Amp': 0.9899441635274836, 'Pha': -4.9011012456689809}, 'O1': {'Amp': 0.98667683685586627, 'Pha': 43.399628661111066}, 'M2': {'Amp': 0.86150074612567795, 'Pha': 0.63888680551324561}, 'K1': {'Amp': 0.75, 'Pha': -5.0}, 'Q1': {'Amp': 1.2518950248746064, 'Pha': 27.632601992144451}}}
TS6in = {'North': {'N2': {'Pha': -5.0340458851303485, 'Amp': 0.99093746613836042}, 'Q1': {'Pha': 31.76446905720422, 'Amp': 1.29800213507216}, 'S2': {'Pha': -8.5545198974892447, 'Amp': 1.0490562377934676}, 'O1': {'Pha': 46.267709352580937, 'Amp': 0.99784655545890988}, 'M2': {'Pha': 2.729140847167737, 'Amp': 0.87131594055414263}, 'K1': {'Pha': -5.9289384852688727, 'Amp': 0.74675608275025374}}, 'West': {'N2': {'Pha': 1.8035783055008339, 'Amp': 0.96705193710790061}, 'Q1': {'Pha': 14.139475946283159, 'Amp': 0.96348802266580769}, 'S2': {'Pha': 4.0093996059906685, 'Amp': 1.0506161230881381}, 'O1': {'Pha': 15.072578656156807, 'Amp': 1.0190547114607584}, 'M2': {'Pha': -9.6711874443139667, 'Amp': 0.89769234884245885}, 'K1': {'Pha': -18.747764436328552, 'Amp': 1.0854844970422486}}}
TS5in = {'North': {'M2': {'Amp': 0.8503826575559933, 'Pha': 1.4765232701548285}, 'S2': {'Amp': 1.060093886807302, 'Pha': -6.946359019746533}, 'Q1': {'Amp': 1.5368297096448922, 'Pha': 60.42364948634719}, 'K1': {'Amp': 0.773677834111803, 'Pha': -108.3072633495973}, 'N2': {'Amp': 0.9871188616242617, 'Pha': -4.530096424751415}, 'O1': {'Amp': 0.923875247607606, 'Pha': 90.88987314530584}}, 'West': {'M2': {'Amp': 0.8765426451574038, 'Pha': -6.766842787292333}, 'S2': {'Amp': 1.0035869299692508, 'Pha': 8.728134209383496}, 'Q1': {'Amp': 0.9358987350001928, 'Pha': 28.204796180164475}, 'K1': {'Amp': 1.128562033874093, 'Pha': -27.67836501066415}, 'N2': {'Amp': 0.9293430555315706, 'Pha': 1.9060762160877864}, 'O1': {'Amp': 0.9736846815080314, 'Pha': 27.43518571910129}}}
TS4in = {'West': {'Q1': {'Amp': 0.95973008246671854, 'Pha': 11.726283958259742}, 'S2': {'Amp': 1.0560814538710048, 'Pha': 2.7883778835861137}, 'K1': {'Amp': 1.0836454717694404, 'Pha': -17.258576900678481}, 'M2': {'Amp': 0.91298101239070584, 'Pha': -12.883470958465448}, 'N2': {'Amp': 0.97616005994525723, 'Pha': 0.62431409913450864}, 'O1': {'Amp': 1.0224087908142427, 'Pha': 11.993685651677305}}, 'North': {'Q1': {'Amp': 1.2501178259629055, 'Pha': 22.116883975191229}, 'S2': {'Amp': 1.0453077941440578, 'Pha': -9.2572751948132552}, 'K1': {'Amp': 0.74541612168305771, 'Pha': -55.123000171765071}, 'M2': {'Amp': 0.93073892518672774, 'Pha': 5.8729325945818829}, 'N2': {'Amp': 0.99352352620481288, 'Pha': -5.3488189574785938}, 'O1': {'Amp': 0.93735590315618389, 'Pha': 33.986361779272698}}}
TS3in = {'West': {'Q1': {'Amp': 1.0210325925510757, 
                       'Pha': 19.713188044831874}, 
                'S2': {'Amp': 1.0619670281785616, 
                       'Pha': 1.6225000000000023}, 
                'K1': {'Amp': 1.0418394160583937, 
                       'Pha': -16.731369863013693}, 
                'M2': {'Amp': 0.89799999999999947, 
                       'Pha': -13.180000000000003}, 
                'N2': {'Amp': 0.98119624254615978, 
                       'Pha': -0.95666666666667055}, 
                'O1': {'Amp': 1.0285514282124055, 'Pha': 11.929584148727976}}, 'North': {'Q1': {'Amp': 1.6950033029840668, 'Pha': -17.727035647279536}, 'S2': {'Amp': 0.99589688506981933, 'Pha': -27.76166666666667}, 'K1': {'Amp': 0.76388461538461572, 'Pha': -40.112195121951224}, 'M2': {'Amp': 0.93099999999999972, 'Pha': 5.9250000000000007}, 'N2': {'Amp': 0.96926862611073172, 'Pha': -24.561666666666667}, 'O1': {'Amp': 1.2414115152944531, 'Pha': 35.273504645760752}}}
TS2in = {'West': {'M2': {'Amp': 0.898, 
                        'Pha': -13.18},
                  'K1': {'Amp': 1.076,
                        'Pha': -18.0},
                  'O1': {'Amp': 0.999,
                        'Pha': 13.6},
                  'S2': {'Amp': 1.037,
                        'Pha': 0.9},
                  'N2': {'Amp': 0.974,
                        'Pha': 0.53},
                  'Q1': {'Amp': 0.988,
                         'Pha': 12.9}
                  },
          'North' : {'M2': {'Amp': 0.931, 
                        'Pha': 6},
                  'K1': {'Amp': 0.769,
                        'Pha': -24.6},
                  'O1': {'Amp': 0.998,
                        'Pha': 53.},
                  'S2': {'Amp': 1.044,
                        'Pha': -9.5},
                  'N2': {'Amp': 0.993,
                        'Pha': -5.5},
                  'Q1': {'Amp': 1.344,
                         'Pha': 35.3}
                  }
        }
TS1in = {'West': {'M2': {'Amp': 0.909, 
                        'Pha': -13.47},
                  'K1': {'Amp': 1.016,
                        'Pha': -4.77},
                  'O1': {'Amp': 1.055,
                        'Pha': -1.88},
                  'S2': {'Amp': 1.075,
                        'Pha': -4.5},
                  'N2': {'Amp': 1.032,
                        'Pha': -0.27},
                  'Q1': {'Amp': 1.047,
                         'Pha': -3.28}
                  },
         'North': {'M2':  {'Amp': 0.953, 
                        'Pha': 5.7},
                  'K1': {'Amp': 0.764,
                        'Pha': 28.4},
                  'O1': {'Amp': 0.968,
                        'Pha': 0.4},
                  'S2': {'Amp': 1.020,
                        'Pha': -11.2},
                  'N2': {'Amp': 0.990,
                        'Pha': -5.3},
                  'Q1': {'Amp': 1.071,
                         'Pha': -0.6}
                  }
        }
def initialize_dict():
    TS = {'West': {'M2': {'Amp': 0, 
                        'Pha': 0},
                  'K1': {'Amp': 0,
                        'Pha': 0},
                  'O1': {'Amp': 0,
                        'Pha': 0},
                  'S2': {'Amp': 0,
                        'Pha': 0},
                  'N2': {'Amp': 0,
                        'Pha': 0},
                  'Q1': {'Amp': 0,
                         'Pha': 0}
                  },
         'North': {'M2': {'Amp': 0, 
                        'Pha': 0},
                  'K1': {'Amp': 0,
                        'Pha': 0},
                  'O1': {'Amp': 0,
                        'Pha': 0},
                  'S2': {'Amp': 0,
                        'Pha': 0},
                  'N2': {'Amp': 0,
                        'Pha': 0},
                  'Q1': {'Amp': 0,
                         'Pha': 0}
                  }
        }
    return TS
TSNin = initialize_dict()
TSN2in = initialize_dict()
for TS in (TS1in, TS2in, TS3in, TS4in, TS5in, TS6in, TS7in, TS8in, TS9in, TS10in, TS11in, TS12in, TS13in, 
           N36_Bin, N36_Cin):
    for const, symbol in zip(('M2', 'S2', 'N2'), ('o','s','^')):
        plt.plot(TS['West'][const]['Amp'], TS['West'][const]['Pha'],symbol)
for TS in (TS1in, TS2in, TS3in, TS4in, TS5in, TS6in, TS7in, TS8in, TS9in, TS10in, TS11in, TS12in, TS13in, 
           N36_Bin, N36_Cin):
    for const, symbol in zip(('K1', 'O1', 'Q1'), ('o','s','^')):
        plt.plot(TS['West'][const]['Amp'], TS['West'][const]['Pha'],symbol)
Ts1out = {'West': {'Q1': {'Amp': 1.0002572547617277, 'Pha': 3.0075447504032695}, 'S2': {'Amp': 0.95307125754457123, 'Pha': 5.7198115533444138}, 'K1': {'Amp': 1.0585313055637906, 'Pha': -13.200757777125908}, 'M2': {'Amp': 0.98799240608799199, 'Pha': 0.29234517194957516}, 'N2': {'Amp': 0.93318917930521317, 'Pha': 1.0654603431878371}, 'O1': {'Amp': 1.0029590524663352, 'Pha': 2.3038937822556562}}, 'North': {'Q1': {'Amp': 1.263438995383616, 'Pha': -17.096293558632283}, 'S2': {'Amp': 1.0004497332114852, 'Pha': 1.9782821187744162}, 'K1': {'Amp': 1.0063487360512036, 'Pha': -52.899421715538068}, 'M2': {'Amp': 0.97668547636460912, 'Pha': 0.30302472717710316}, 'N2': {'Amp': 0.97999881464282712, 'Pha': 0.082189463385645922}, 'O1': {'Amp': 1.0365442709803026, 'Pha': -0.42241125887312592}}}

Ts2out = {'West': {'Q1': {'Amp': 0.98356590441914449, 'Pha': -1.4334345475063373}, 'S2': {'Amp': 1.0216419632851881, 'Pha': 0.90779104737045202}, 'K1': {'Amp': 0.99266606835333504, 'Pha': 1.3508016934226554}, 'M2': {'Amp': 1.0015851836909175, 'Pha': -0.058748044962015362}, 'N2': {'Amp': 0.99537214954697717, 'Pha': 0.47459245342846879}, 'O1': {'Amp': 1.0336150491261633, 'Pha': -0.48588841857058185}}, 'North': {'Q1': {'Amp': 0.90960982150305669, 'Pha': -28.835321790582896}, 'S2': {'Amp': 1.0051059524147195, 'Pha': 0.76024295755041749}, 'K1': {'Amp': 1.2659586959029192, 'Pha': -11.966162418417269}, 'M2': {'Amp': 1.0001080402583795, 'Pha': -0.12727645118474129}, 'N2': {'Amp': 1.0024693099628155, 'Pha': 0.21684096723782886}, 'O1': {'Amp': 1.1317630850593585, 'Pha': -34.12635889300995}}}
#TS3o
Ts3out = {'West': {'Q1': {'Amp': 0.95110110499464851, 'Pha': -7.6426784791072464}, 'S2': {'Amp': 1.0202025932595069, 'Pha': 1.0144847613380019}, 'K1': {'Amp': 1.0272219086326759, 'Pha': 0.13292497155501992}, 'M2': {'Amp': 1.0008871425553614, 'Pha': -0.026401458001528565}, 'N2': {'Amp': 1.0045383235506544, 'Pha': 2.8578421947387653}, 'O1': {'Amp': 1.0284224577447008, 'Pha': 0.15177275062089279}}, 'North': {'Q1': {'Amp': 1.0491593153643064, 'Pha': 11.38432262097092}, 'S2': {'Amp': 1.0633942810638697, 'Pha': 22.092814038315055}, 'K1': {'Amp': 1.399915987512546, 'Pha': -14.492809784225329}, 'M2': {'Amp': 0.99934510071026761, 'Pha': -0.1857003075421062}, 'N2': {'Amp': 1.0354092178535133, 'Pha': 22.631314821886065}, 'O1': {'Amp': 1.0853916220804463, 'Pha': -25.230049427371426}}}
#TS3
TSRout = {'West': {'Q1': {'Amp': 0.9615240748671523, 'Pha': -8.0186552500333903}, 'S2': {'Amp': 1.0314281994044106, 'Pha': 1.5245866303987459}, 'K1': {'Amp': 1.0423440174621237, 'Pha': -0.42662190481817891}, 'M2': {'Amp': 1.0148414225529525, 'Pha': 0.30699215045163986}, 'N2': {'Amp': 1.0190109589854979, 'Pha': 3.1444151751516358}, 'O1': {'Amp': 1.0403371684399034, 'Pha': -0.3682571354704578}}, 'North': {'Q1': {'Amp': 1.0402483648893954, 'Pha': 9.9466892870592574}, 'S2': {'Amp': 1.0644803022440763, 'Pha': 23.072834208666109}, 'K1': {'Amp': 1.3417137185150854, 'Pha': -11.210779203809977}, 'M2': {'Amp': 0.97345565972896475, 'Pha': 1.1010105205821503}, 'N2': {'Amp': 1.0179979559630259, 'Pha': 24.008950313318181}, 'O1': {'Amp': 1.1091799512735716, 'Pha': -19.851697664023504}}}
#TS4
TS4out = {'West': {'Q1': {'Amp': 1.021710281717962, 'Pha': -1.2818051360898437}, 'S2': {'Amp': 1.0048287114712622, 'Pha': -0.77931142110978868}, 'K1': {'Amp': 1.0077723235798881, 'Pha': 0.050270335765687305}, 'M2': {'Amp': 1.0019637630738421, 'Pha': -0.084921979605779865}, 'N2': {'Amp': 0.99488881155208686, 'Pha': 0.31632214863880626}, 'O1': {'Amp': 1.0160040214143051, 'Pha': 0.28326329135653339}}, 'North': {'Q1': {'Amp': 1.1396837053873892, 'Pha': -22.343216315967823}, 'S2': {'Amp': 1.01031637074638, 'Pha': 0.61309589110754814}, 'K1': {'Amp': 1.4993965264182494, 'Pha': -19.036640927224198}, 'M2': {'Amp': 0.99847670218981277, 'Pha': -0.033309406172094214}, 'N2': {'Amp': 1.0048771725470016, 'Pha': 0.16683054836840938}, 'O1': {'Amp': 1.3692040838013475, 'Pha': -29.098224761850673}}}
#TS4 w Hollingsworth
TSHout = {'West': {'Q1': {'Amp': 1.0119383657601555, 'Pha': -1.9438847794043141}, 'S2': {'Amp': 0.99559468002265994, 'Pha': -1.4019991460643482}, 'K1': {'Amp': 0.98832300736547773, 'Pha': 0.28881171540387657}, 'M2': {'Amp': 0.98854451467568982, 'Pha': -0.5788869325603514}, 'N2': {'Amp': 0.98697982726560152, 'Pha': -0.052406117338830827}, 'O1': {'Amp': 0.99971651564967901, 'Pha': 0.2006417619422507}}, 'North': {'Q1': {'Amp': 1.1336904122250575, 'Pha': -22.262549937009737}, 'S2': {'Amp': 1.019390426248554, 'Pha': 1.0650283890524292}, 'K1': {'Amp': 1.4689939087715977, 'Pha': -19.71301519371076}, 'M2': {'Amp': 1.0095401002831588, 'Pha': 0.5060034580093884}, 'N2': {'Amp': 1.0141608691246866, 'Pha': 0.66414894517527046}, 'O1': {'Amp': 1.3401176934857579, 'Pha': -29.105986664905771}}}

TS4newBout = {'North': {'M2': {'Pha': -4.3964093244270543, 'Amp': 0.91366400882544685}, 'K1': {'Pha': -53.184263177832236, 'Amp': 1.0379140075008491}, 'O1': {'Pha': 3.7192481882009076, 'Amp': 1.0229871678905673}, 'Q1': {'Pha': -14.877497666676277, 'Amp': 1.2759573935003046}, 'S2': {'Pha': -2.0854931493603317, 'Amp': 0.92658797320536079}, 'N2': {'Pha': -3.5776867916998754, 'Amp': 0.90777415180494747}}, 'West': {'M2': {'Pha': 6.1166281711731152, 'Amp': 0.96008858153809173}, 'K1': {'Pha': -10.419788109985671, 'Amp': 1.041449499190275}, 'O1': {'Pha': 5.0217119574383133, 'Amp': 0.99181798223604978}, 'Q1': {'Pha': 6.0587241119190622, 'Amp': 1.0155889522120538}, 'S2': {'Pha': 12.056384496970498, 'Amp': 0.9123655647133796}, 'N2': {'Pha': 7.398390288126393, 'Amp': 0.91404237128654797}}}
TS5out = {'North': {'M2': {'Pha': 0.42758785421409584, 'Amp': 1.011625002682464}, 'K1': {'Pha': -29.472163528321573, 'Amp': 1.5805376110939042}, 'O1': {'Pha': -83.573669377494497, 'Amp': 1.9482260093882917}, 'Q1': {'Pha': -61.734484942181325, 'Amp': 1.0241774045384158}, 'S2': {'Pha': -1.4895386482369872, 'Amp': 0.99513722966584894}, 'N2': {'Pha': 0.10773931037238071, 'Amp': 1.0111376898211519}}, 'West': {'M2': {'Pha': -1.5309396078788888, 'Amp': 1.0378637494752101}, 'K1': {'Pha': 12.035886712521583, 'Amp': 0.94974179875911324}, 'O1': {'Pha': -3.7224212917422079, 'Amp': 1.0325092803506841}, 'Q1': {'Pha': -8.3677928244752877, 'Amp': 0.99273824278749245}, 'S2': {'Pha': -6.9463119651399552, 'Amp': 1.1154505816612328}, 'N2': {'Pha': -1.3598703918715493, 'Amp': 1.0890526878512701}}}
TS6out = {'West': {'O1': {'Amp': 0.99917259570573957, 'Pha': -0.26278166115388046}, 'N2': {'Amp': 1.0244990697827043, 'Pha': 1.224306456276878}, 'Q1': {'Amp': 1.0176497900134822, 'Pha': -1.4806862994981884}, 'S2': {'Amp': 1.0087992347785939, 'Pha': 0.1336154074221394}, 'M2': {'Amp': 1.009684365613287, 'Pha': 1.2434341458076474}, 'K1': {'Amp': 0.97410589754902577, 'Pha': 3.0078799229218589}}, 'North': {'O1': {'Amp': 1.1099589622402357, 'Pha': -27.838619895114306}, 'N2': {'Amp': 0.98180311923347008, 'Pha': -0.58195399212740995}, 'Q1': {'Amp': 0.91915208049571451, 'Pha': -25.717717368800777}, 'S2': {'Amp': 0.98467109778763395, 'Pha': -1.4704736261345488}, 'M2': {'Amp': 0.99011883203452811, 'Pha': -1.3444498805239675}, 'K1': {'Amp': 1.1904807255499437, 'Pha': -6.1957349307586469}}}
TS7out = {'North': {'Q1': {'Pha': -22.886425235514594, 'Amp': 0.93055076235820455}, 'M2': {'Pha': 1.8789511310803277, 'Amp': 1.0423735647108798}, 'K1': {'Pha': -7.0524623691283921, 'Amp': 1.1619354362342378}, 'N2': {'Pha': 2.2311317939641242, 'Amp': 1.0312508215460159}, 'O1': {'Pha': -25.60358248760835, 'Amp': 1.0881114343042568}, 'S2': {'Pha': 1.6180611113048258, 'Amp': 1.0326339034344933}}, 'West': {'Q1': {'Pha': -0.34469260821630598, 'Amp': 0.98149555239898412}, 'M2': {'Pha': 1.3234744539132743, 'Amp': 0.97796155111043792}, 'K1': {'Pha': 3.8762994934517199, 'Amp': 0.95946938123484593}, 'N2': {'Pha': 0.89717076965282549, 'Amp': 0.98678259304211158}, 'O1': {'Pha': 1.0664646301858483, 'Amp': 0.97995456282236715}, 'S2': {'Pha': -0.27450001446825567, 'Amp': 0.97941497283467949}}}

TS8out = {'West': {'K1': {'Amp': 0.97294394809883511, 'Pha': 2.7579367053216881}, 'Q1': {'Amp': 0.96966233066943985, 'Pha': 1.9150525736966344}, 'S2': {'Amp': 0.95472229971458944, 'Pha': 1.0372218360624021}, 'N2': {'Amp': 0.95752188775425451, 'Pha': 0.40262808850771226}, 'M2': {'Amp': 0.95858932366390581, 'Pha': 1.1601428772132749}, 'O1': {'Amp': 0.97183294662054664, 'Pha': 2.007318956120443}}, 'North': {'K1': {'Amp': 1.1547120834449451, 'Pha': -7.6129201656615066}, 'Q1': {'Amp': 0.96681474235607734, 'Pha': -15.124112334094548}, 'S2': {'Amp': 1.0513147965750143, 'Pha': 0.20788982904463182}, 'N2': {'Amp': 1.0526603636580936, 'Pha': 1.0521057205134241}, 'M2': {'Amp': 1.0521929700885222, 'Pha': 1.1130570825965833}, 'O1': {'Amp': 1.0868904745440655, 'Pha': -19.161141807354142}}}
TS9out = {'North': {'K1': {'Amp': 1.141806975674275, 'Pha': -6.8066122155455275}, 'O1': {'Amp': 1.0790183141135039, 'Pha': -12.693489398286005}, 'N2': {'Amp': 1.0276135396079655, 'Pha': 0.69195097514989357}, 'S2': {'Amp': 1.0267195882687952, 'Pha': -0.21023995360576464}, 'M2': {'Amp': 1.0273131680911955, 'Pha': 0.6410257630467413}, 'Q1': {'Amp': 0.99349042997534653, 'Pha': -11.450128659908728}}, 'West': {'K1': {'Amp': 1.0005922446358808, 'Pha': 0.30581150821401393}, 'O1': {'Amp': 0.99691301051231362, 'Pha': -0.27067321788786103}, 'N2': {'Amp': 0.97009487763399349, 'Pha': 0.079806302494018655}, 'S2': {'Amp': 0.97355520330980305, 'Pha': 0.52786277421644989}, 'M2': {'Amp': 0.97177309878878693, 'Pha': 0.65317168768398026}, 'Q1': {'Amp': 1.005747559953059, 'Pha': -0.38741079347094853}}}
TS10out = {'West': {'Q1': {'Amp': 0.98050924008569673, 'Pha': 2.1640812550494957}, 'N2': {'Amp': 0.98497707891758624, 'Pha': 0.73188917599328818}, 'S2': {'Amp': 0.98386804368385228, 'Pha': 0.49094103412041257}, 'M2': {'Amp': 0.9835814140583149, 'Pha': 0.33283810199147285}, 'K1': {'Amp': 0.98125945152519567, 'Pha': 2.0121855104044792}, 'O1': {'Amp': 0.98879469627003824, 'Pha': 2.423226052588376}}, 'North': {'Q1': {'Amp': 1.0262218515128376, 'Pha': -11.636416402243867}, 'N2': {'Amp': 1.0121869970770876, 'Pha': 0.25638965602854569}, 'S2': {'Amp': 1.0127597355406559, 'Pha': 0.59505848045751009}, 'M2': {'Amp': 1.0133909064729139, 'Pha': 0.33157708793285678}, 'K1': {'Amp': 1.1311741337398815, 'Pha': -6.2684264923129263}, 'O1': {'Amp': 1.0807892207906737, 'Pha': -15.033773286125751}}}

TS11out = {'West': {'N2': {'Amp': 0.9861002244759608, 'Pha': -0.10566829682310153}, 'K1': {'Amp': 0.99899667510872814, 'Pha': -0.036503272822104603}, 'M2': {'Amp': 0.98567279493454218, 'Pha': 0.3057391725200202}, 'Q1': {'Amp': 1.0010194819454052, 'Pha': 0.047263663169253789}, 'S2': {'Amp': 0.98418635692484369, 'Pha': 0.34645353156939507}, 'O1': {'Amp': 1.0045736271018535, 'Pha': -0.035061767485288442}}, 'North': {'N2': {'Amp': 1.0118494949360155, 'Pha': 0.37538197471974399}, 'K1': {'Amp': 1.0011334075203402, 'Pha': -4.4039853987503932}, 'M2': {'Amp': 1.0117183935668721, 'Pha': 0.33110599860091838}, 'Q1': {'Amp': 0.95470825319238906, 'Pha': -7.1123004897670796}, 'S2': {'Amp': 1.0103376571119917, 'Pha': 0.31215195736308488}, 'O1': {'Amp': 0.98265530252292388, 'Pha': -7.7938163393311299}}}
TS12out = {'North': {'Q1': {'Pha': -2.8028207797105438, 'Amp': 1.0067196858504108}, 'O1': {'Pha': -3.4538665865347014, 'Amp': 1.0238409720567998}, 'N2': {'Pha': 0.33510031771822923, 'Amp': 1.0091900611944493}, 'M2': {'Pha': 0.31120580423186084, 'Amp': 1.0100886881011024}, 'K1': {'Pha': -4.3189261967383743, 'Amp': 1.0276037991916289}, 'S2': {'Pha': 0.20258067707970895, 'Amp': 1.010827726447741}}, 'West': {'Q1': {'Pha': 0.23364280047611174, 'Amp': 1.0034113035505845}, 'O1': {'Pha': 0.16957879223932082, 'Amp': 1.0042583168341883}, 'N2': {'Pha': 0.17550044986570212, 'Amp': 0.98473045540527915}, 'M2': {'Pha': 0.28090946947771794, 'Amp': 0.98647781863541684}, 'K1': {'Pha': 0.0016394684952055845, 'Amp': 0.99968355103521234}, 'S2': {'Pha': 0.32145241386463219, 'Amp': 0.98671884010077271}}}
TS13out = {'West': {'O1': {'Pha': 0.04680136479113628, 'Amp': 1.0028414117632114}, 'N2': {'Pha': 0.28407505636140273, 'Amp': 0.98666343884396468}, 'S2': {'Pha': 0.30991534737121995, 'Amp': 0.98748279768091618}, 'M2': {'Pha': 0.2517691311556558, 'Amp': 0.9878931090830384}, 'K1': {'Pha': 0.014731604514469591, 'Amp': 0.99954343378996247}, 'Q1': {'Pha': 0.0071499783811859174, 'Amp': 1.0018607902885381}}, 'North': {'O1': {'Pha': -3.4702531096732798, 'Amp': 1.0239069789801176}, 'N2': {'Pha': 0.35918217891162385, 'Amp': 1.0087207644351472}, 'S2': {'Pha': 0.27295659468495614, 'Amp': 1.0097792960221685}, 'M2': {'Pha': 0.29874565143435916, 'Amp': 1.0083006574774827}, 'K1': {'Pha': -4.0578237330762477, 'Amp': 1.0270972397817333}, 'Q1': {'Pha': -4.235818999980836, 'Amp': 0.99737542293651305}}}
N36_Aout = {'West': {'S2': {'Pha': 0.024968663334318464, 'Amp': 0.99337155681265432}, 'Q1': {'Pha': 3.3569984413439684, 'Amp': 0.95663330904750743}, 'K1': {'Pha': 10.525916755897864, 'Amp': 0.95627620722297868}, 'O1': {'Pha': -0.019006280510751594, 'Amp': 1.0095477235303318}, 'N2': {'Pha': -0.0012874180538793301, 'Amp': 0.99344078977697381}, 'M2': {'Pha': 0.20672969828430446, 'Amp': 0.99007316601581041}}, 'North': {'S2': {'Pha': 0.11378081255770667, 'Amp': 1.0070620543538167}, 'Q1': {'Pha': 0.88814591096328854, 'Amp': 0.95394468894565598}, 'K1': {'Pha': 10.085614670042702, 'Amp': 0.99230295956348635}, 'O1': {'Pha': -2.8850242464157532, 'Amp': 1.022596420254793}, 'N2': {'Pha': 0.42669693943682319, 'Amp': 1.007929667620058}, 'M2': {'Pha': 0.27507562700012045, 'Amp': 1.0073131602562162}}}
N36_Bout = {'North': {'N2': {'Pha': 0.228619922684004, 'Amp': 1.0044197820734821}, 'O1': {'Pha': 8.4089357005164231, 'Amp': 0.98525392629581676}, 'S2': {'Pha': -0.46028630594918241, 'Amp': 1.0108745392383118}, 'Q1': {'Pha': 9.0291992812070987, 'Amp': 0.97501550156148509}, 'K1': {'Pha': 7.8443759889432698, 'Amp': 0.95588820757114035}, 'M2': {'Pha': 0.19904203096535866, 'Amp': 1.0024480929027397}}, 'West': {'N2': {'Pha': 1.0231581697589434, 'Amp': 0.99485890137137734}, 'O1': {'Pha': 0.51036973879503478, 'Amp': 1.0090380271121973}, 'S2': {'Pha': 0.19181980227444306, 'Amp': 0.98490801519221349}, 'Q1': {'Pha': 3.5029764974067277, 'Amp': 0.99309398972124918}, 'K1': {'Pha': 0.45180641855848502, 'Amp': 0.98606684406471978}, 'M2': {'Pha': 0.14578991784822209, 'Amp': 0.99131929120194784}}}
N36_Cout = {'North': {'O1': {'Pha': 7.3854138207617837, 'Amp': 0.94085326688379123}, 'Q1': {'Pha': 6.4006241776399975, 'Amp': 0.95897973076356524}, 'K1': {'Pha': 7.1413981914269868, 'Amp': 0.91658971870546968}, 'S2': {'Pha': -0.3595232949933802, 'Amp': 1.0060087070702608}, 'M2': {'Pha': -0.07795186160888079, 'Amp': 0.99633800734625722}, 'N2': {'Pha': -0.063366454852484821, 'Amp': 0.99810122970525916}}, 'West': {'O1': {'Pha': -0.79300780292307138, 'Amp': 0.98074493235008808}, 'Q1': {'Pha': -0.6739014812033588, 'Amp': 0.98943179187765928}, 'K1': {'Pha': -0.72383160181509798, 'Amp': 0.98614869389993487}, 'S2': {'Pha': 0.069163430058537756, 'Amp': 0.99327610629011942}, 'M2': {'Pha': -0.038238175514344983, 'Amp': 0.99773471593815255}, 'N2': {'Pha': -0.01545786753853351, 'Amp': 1.0017159403672811}}}
diurnals = ('K1', 'O1', 'Q1')
semis = ('M2', 'S2', 'N2')
for TS in (TS4newBout, TS5out, TS6out, TS7out, TS8out, TS9out, TS10out, TS11out, TS12out, TS13out, 
           N36_Aout, N36_Bout, N36_Cout):
    for side in ('West', 'North'):
        phaerror = 0
        amperror = 0
        for const in diurnals:
            phaerror += TS[side][const]['Pha']**2
            amperror += (TS[side][const]['Amp'] - 1)**2
        if side=='West':
            print (side, np.sqrt(phaerror/3.), np.sqrt(amperror/3.) )
correction = {'S2': {'Pha' : ('M2', False, True),
                    'Amp': ('M2', True, False)},
              'N2': {'Pha' : ('M2', False, True),
                    'Amp': ('M2', True, False)},
             'O1': {'Pha' : ('K1', False, True),
                   'Amp': ('K1', True, False)},
             'Q1': {'Pha' : ('K1', False, True),
                   'Amp': ('K1', True, False)},}

def correctionf(TS):
    TSc = initialize_dict()
    for side in ('West', 'North'):
        for const in ('M2', 'K1'):
            for pa in ('Pha', 'Amp'):
                TSc[side][const][pa] = TS[side][const][pa]
        for const in ('O1', 'Q1', 'S2', 'N2'):
            TSc[side][const]['Pha'] = (TS[side][const]['Pha'] - 
                                       TS[side][correction[const]['Pha'][0]]['Pha'])
            TSc[side][const]['Amp'] = (TS[side][const]['Amp'] / 
                                       TS[side][correction[const]['Amp'][0]]['Amp'])  
    return TSc
TS3corr = correctionf(Ts3out)
TS3Rcorr = correctionf(TSRout)
numruns = 7; x = np.zeros(numruns); y = np.zeros_like(x)

def make_comparison(freq, side):
    fig, ax = plt.subplots(1,2,figsize=(15,10))
    for ipa, pa in enumerate(('Amp', 'Pha')):
        for const in freq:
            for irun, (Tin, Tout) in enumerate(zip( (TS10in, 
                                                     TS11in, TS12in, TS13in, TS13in, N36_Bin, N36_Cin), 
                                                   (TS10out, TS11out, TS12out, TS13out, N36_Aout,
                                                   N36_Bout, N36_Cout))):                
                x[irun] = Tin[side][const][pa]
                y[irun] = Tout[side][const][pa]
     #           print const, x[irun]
                if const in ('O1', 'Q1', 'S2', 'N2'):
                    divisor = (correction[const][pa][1] * Tout[side][correction[const][pa][0]][pa] +
                    (1-correction[const][pa][1]))
                    y[irun] = (Tout[side][const][pa] / divisor
                                       - correction[const][pa][2] * 
                                                       Tout[side][correction[const][pa][0]][pa])
                    print (side, const, pa, y[irun])
                    
            
            ax[ipa].plot(x[:-3],y[:-3],'o', label=const)
            ax[ipa].plot(x[-3], y[-3], '<', label=const)
            ax[ipa].plot(x[-2], y[-2], '>', label=const)
            ax[ipa].plot(x[-1],y[-1],'^', label=const)   

            m, b = np.polyfit(x, y, 1)
            
            if pa == 'Pha':
                TSNin[side][const]['Pha'] = -b/m
                ax[ipa].plot(TSNin[side][const]['Pha'], 0., '*')
            else:
                TSNin[side][const]['Amp'] = (1-b)/m
                ax[ipa].plot(TSNin[side][const]['Amp'], 1., '*')
            
            
            if pa == 'Amp':
                if side == 'North' and const in diurnals:
                    exes = np.arange(0.7, 1.8, 0.1)
                else:
                    exes = np.arange(0.88,1.1,0.05)
            elif side == 'West':
                if const in diurnals:
                    exes = np.arange(-20, 21, 1)
                else:
                    exes = np.arange(-15,5,1)
            else:
                if const in diurnals:
                    exes = np.arange(-60, 60, 2)
                else:
                    exes = np.arange(-30, 10, 1)
            ax[ipa].plot(exes, m*exes+b)

        ax[ipa].set_xlabel('Forcing')
        ax[ipa].set_ylabel('Suggested Correction')
        ax[ipa].grid()
        ax[ipa].legend()
        if side == 'North' and pa == 'Amp' and const in diurnals:
            ax[ipa].set_ylim(0.5,2)
            ax[ipa].set_xlim(0.7, 1.2)
        elif side == 'North' and pa == 'Pha' and const in diurnals:
            ax[ipa].set_xlim(-30,10)
            ax[ipa].set_ylim(-14,11)
        elif side == 'West' and pa == 'Pha' and const in semis:
            ax[ipa].set_xlim(0,5)
            ax[ipa].set_ylim(-2.5,2.5)
        elif side== 'North' and pa == 'Pha' and const in semis:
            ax[ipa].set_xlim(-12,7)
            ax[ipa].set_ylim(-8,5)

    print (side, freq)
make_comparison(semis,'West')
side = 'West'; const = 'N2'; pa = 'Pha'
print (side, const, pa)
print (TS13in[side][const][pa], N36_Bin[side][const][pa], N36_Cin[side][const][pa], TSNin[side][const][pa])
#print (N36_Aout[side][const][pa], N36_Bout[side][const][pa], N36_Cout[side][const][pa])
make_comparison(diurnals, 'West')
side = 'West'; const = 'Q1'; pa = 'Pha'
print (side, const, pa)
print (TS13in[side][const][pa], N36_Bin[side][const][pa], N36_Cin[side][const][pa], TSNin[side][const][pa])
#print (N36_Aout[side][const][pa], N36_Bout[side][const][pa], N36_Cout[side][const][pa])

make_comparison(semis,'North')
side = 'North'; const = 'N2'; pa = 'Pha'
print (side, const, pa)
print (TS13in[side][const][pa], N36_Bin[side][const][pa], N36_Cin[side][const][pa], TSNin[side][const][pa])
#print (N36_Aout[side][const][pa], N36_Bout[side][const][pa], N36_Cout[side][const][pa])
make_comparison(diurnals,'North')
side = 'North'; const = 'Q1'; pa = 'Pha'
print (side, const, pa)
print (TS13in[side][const][pa], N36_Bin[side][const][pa], N36_Cin[side][const][pa], TSNin[side][const][pa])
#print (N36_Aout[side][const][pa], N36_Bout[side][const][pa], N36_Cout[side][const][pa])
TSNin['West']['S2']['Amp'] = 1.041
TSNin['West']['N2']['Amp'] = 0.981

TSNin['West']['S2']['Pha'] = 1.7

TSNin['West']['K1']['Amp'] = 0.98
TSNin['West']['O1']['Amp'] = 1.08
TSNin['West']['Q1']['Amp'] = 0.997

TSNin['West']['K1']['Pha'] = -3.5
TSNin['West']['O1']['Pha'] = 1.95
TSNin['West']['Q1']['Pha'] = 3.05

TSNin['North']['S2']['Amp'] = 1.039

TSNin['North']['S2']['Pha'] = -9.25

TSNin['North']['K1']['Pha'] = 8
TSNin['North']['O1']['Pha'] = -2
TSNin['North']['Q1']['Pha'] = -5.4


print (TSNin)
#for side in ('West', 'North'):          # don't correct North because we are missing River and Kelsey Bay
TSN2in['North'] = TSNin['North']
side = 'West'
print side
for const in semis + diurnals:
        print const, TSNin[side][const]
        print TS3Rcorr[side][const], 'River'
        print TS3corr[side][const], 'No River'
        differ = {key: TS3Rcorr[side][const][key] - TS3corr[side][const][key] for key in ('Pha','Amp')}
        print differ, 'Difference'
        TSN2in[side][const] = {key: TSNin[side][const][key] + differ[key] for key in ('Pha', 'Amp')}
        print TSN2in[side][const], 'Proposal'
print TSN2in
for side in ('West', 'North'):
    for const in semis + diurnals:
        print (side, const)
        print (TS4newBout[side][const]['Pha'] + TS4in[side][const]['Pha'], TS4in[side][const]['Pha'])
correction = {'S2': {'Pha' : ('M2', False, True),
                    'Amp': ('M2', True, False)},
              'N2': {'Pha' : ('M2', False, True),
                    'Amp': ('M2', True, False)},
             'O1': {'Pha' : ('K1', False, True),
                   'Amp': ('K1', True, False)},
             'Q1': {'Pha' : ('K1', False, True),
                   'Amp': ('K1', True, False)},}

def correction2(TSprevin, TSnewout):
    TSc = initialize_dict()
    for side in ('West', 'North'):
        for const in ('M2', 'K1'):
            TSc[side][const]['Pha'] = TSprevin[side][const]['Pha'] + TSnewout[side][const]['Pha']
            TSc[side][const]['Amp'] = TSprevin[side][const]['Amp'] * TSnewout[side][const]['Amp']
        for const in ('O1', 'Q1', 'S2', 'N2'):
            TSc[side][const]['Pha'] = (TSprevin[side][const]['Pha'] -
                                       TSnewout[side][correction[const]['Pha'][0]]['Pha'] +
                                      TSnewout[side][const]['Pha'])
            TSc[side][const]['Amp'] = (TSprevin[side][const]['Amp'] / 
                                       TSnewout[side][correction[const]['Amp'][0]]['Amp'] *
                                      TSnewout[side][const]['Amp'])  
    return TSc

TS5in = correction2(TS4in, TS4newBout)
print (TS5in)
print (TS4in)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup