-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_figures_v2.py
1573 lines (1489 loc) · 83.1 KB
/
plot_figures_v2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import json
import Constants as CON
import h5py
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.ioff()
import dedalus
import dedalus.public as de
import scipy.signal as sc
import seawater as sw
from matplotlib import colors
from matplotlib.gridspec import GridSpec
import matplotlib.patches as patches
import math
from uncertainties import ufloat
from scipy.ndimage.filters import gaussian_filter
matplotlib.rcParams['mathtext.fontset'] = 'stix'
matplotlib.rcParams['font.family'] = 'STIXGeneral'
def keel(a):
h = a*(H-z0)
sigma = 3.9*h
return -h*sigma**2/(sigma**2+4*(np.linspace(0, L, Nx)-l)**2)
d = 300
Nx = CON.Nx
Nz = CON.Nz
H = CON.H
L = CON.L
l = CON.l
h = CON.h
z0 = CON.z0
h_z = CON.H-z0
mu = CON.mu
sigma = CON.sigma
DB = 9.8*(sw.dens0(30,-2)-sw.dens0(28,-2))/sw.dens0(28,-2)
E_0 = (9.8*(sw.dens0(30,-2)-sw.dens0(28,-2))*(H-z0)**2)
phi_0 = sw.dens0(28,-2)*np.sqrt(DB*(H-z0)**(7))
epsilon_0 = np.sqrt(DB**3*(H-z0))
t_0 = np.sqrt((H-z0)/DB)
#xbasis = de.Chebyshev('x', 1280, interval=(0, L))
#zbasis = de.Chebyshev('z', 640, interval=(0, H))
#domain = de.Domain([xbasis, zbasis], grid_dtype=np.float64)
def average_data(d, c=0):
return np.mean(d[22:])
def stdev_data(d, c):
return np.std(d[22:])
def stdev_log_data(d, c):
return np.std(np.log10(d[22:]))
def generate_modes(L_1, L_2, H_1, H_2):
Nf_x = math.ceil(Nx/L*L_2)
Ni_x = math.floor(Nx/L*L_1)
Ni_z = math.ceil((1-H_2/H)*Nz)
Nf_z = math.floor((1-H_1/H)*Nz)
return Nf_x, Ni_x, Nf_z, Ni_z
def sort_rho_z(h5_file, Ni_x, Nf_x, Ni_z, Nf_z):
with h5py.File(h5_file, mode='r') as f:
rho = f['tasks']['rho'][0][Ni_x: Nf_x, Ni_z: Nf_z]
rho_sort = np.reshape(-np.sort(-rho.flatten()), (Nf_x-Ni_x, Nf_z-Ni_z), order='F')
return rho_sort
plt.rcParams.update({'font.size':16})
#x, z = domain.grids()
#a = ['a005', 'a009', 'a102', 'a200'] #heights
#c = ['c005', 'c100', 'c105', 'c200'] #speeds
sp = [[220, 260, 450, 450], [220, 260, 450, 450], [220, 260, 450, 450], [220, 260, 450, 450]]
a = ['a005', 'a095', 'a102', 'a200']
c = ['c005', 'c100', 'c105', 'c200']
labels_height = ['$\\eta=0.5$', '$\\eta=0.95$', '$\\eta=1.2$', '$\\eta=2.0$']
labels_height_Fr = ['$Fr=0.5$', '$Fr=1.0$', '$Fr=1.5$', '$Fr=2.0$']
labels_regime_up = ['Unstable Supercritical', 'Stable Subcritical', 'Unstable Subcritical'] #Old: ['Supercritical', 'Rarefaction', 'Solitary Waves', 'Blocking']
labels_regime_down = ['Vortex Shedding','Fast-Laminar', 'Lee Waves'] #Old: ['Vortex Shedding', 'Stirred', 'Laminar Jump', 'Blocked', 'Lee Waves']
markers_labels_up = ['P', 'D', 'o']
markers_labels_down = ['*', '^', 's']
markers1 = [['D', 'D', 'o', 'P'], ['D', 'o', 'o', 'P'], ['D', 'o', 'o', 'P'], ['D', 'o', 'o', 'P']] #vortex shedding = star, bore & MSD = circle, blocking = square, bore & TD = triangle, MSD=diamond, lee = plus
markers2 = [['s', '^', '^', '*'], ['s', '^', '*', '*'], ['s', '^', '*', '*'], ['p', 'p', '*', '*']] #vortex shedding = star, bore & MSD = circle, blocking = square, bore & TD = triangle, MSD=diamond, lee = plus
titles = ["a) Vortex Shedding", "b) Solitary waves & Turbulent Downstream", "c) Solitary waves & Minimum Stirring Downstream", "d) Minimum Stirring Downstream", "e) Blocking", "f) Lee waves"]
data = [[], [], [], []] #Height[Speeds]
salt_data_up = [[], [], [], []] #Height[Speeds]
salt_data_down = [[], [], [], []] #Height[Speeds]
avgs = [{}, {}, {}, {}] #a=0.5,0.9,1.2,2 Heights{MLD: [speeds], KED: [speeds], ...}
MLD_std = [[], [], [], []]
for i in range(len(a)):
for j in range(len(c)):
f = open('potentialdata_{0}_{1}-{2}.txt'.format(a[i]+c[j], "70", sp[i][j]), 'r')
temp = f.readline()
MLD_std[i].append(float(temp[:temp.find('\\')]))
f.close()
data[i].append(np.loadtxt('potentialdata_{0}_{1}-{2}.txt'.format(a[i]+c[j], "70", sp[i][j]), unpack=True, skiprows=2))
K_import_up = json.load(open('K_values_{0}-{1}.txt'.format(160, l)))
K_import_down = json.load(open('K_values_{0}-{1}.txt'.format(l, 920)))
z_mix_import_up = json.load(open('z_mix_values_{0}-{1}.txt'.format(160, l)))
z_mix_import_down = json.load(open('z_mix_values_{0}-{1}.txt'.format(l, 920)))
phid_import_up = json.load(open('phi_d_values_{0}-{1}.txt'.format(160, l)))
phid_import_down = json.load(open('phi_d_values_{0}-{1}.txt'.format(l, 920)))
conv_id = {'a005': 'H05', 'a095': 'H09', 'a102': 'H12', 'a200': 'H20', 'c005': 'F05', 'c100': 'F10', 'c105': 'F15', 'c200': 'F20'}
for i in range(len(a)):
avgs[i]['time'] = []
avgs[i]['MLD'] = []
avgs[i]['MLD_stdev'] = []
avgs[i]['KED_D'] = []
avgs[i]['KED_D_stdev'] = []
avgs[i]['Phi_d_D'] = []
avgs[i]['Phi_d_D_stdev'] = []
avgs[i]['KED_U'] = []
avgs[i]['KED_U_stdev'] = []
avgs[i]['Phi_d_U'] = []
avgs[i]['Phi_d_U_stdev'] = []
avgs[i]['K_p_U'] = []
avgs[i]['K_p_D'] = []
avgs[i]['K_p_D_series'] = []
avgs[i]['K_p_U_series'] = []
avgs[i]['Phi_d_D_series'] = []
avgs[i]['Phi_d_U_series'] = []
avgs[i]['z_mix_U'] = []
avgs[i]['z_mix_D'] = []
for j in range(len(c)):
avgs[i]['MLD'].append(average_data(data[i][j][7], c[j]))
avgs[i]['MLD_stdev'].append(MLD_std[i][j])
avgs[i]['KED_D'].append(average_data(data[i][j][15], c[j]))
avgs[i]['KED_D_stdev'].append(stdev_data(data[i][j][15], c[j]))
avgs[i]['Phi_d_D'].append(average_data(phid_import_down[conv_id[c[j]]+conv_id[a[i]]][0], c[j][0]))
avgs[i]['Phi_d_D_stdev'].append(stdev_data(phid_import_down[conv_id[c[j]]+conv_id[a[i]]][0], c[j][0]))
avgs[i]['KED_U'].append(average_data(data[i][j][22], c[j]))
avgs[i]['KED_U_stdev'].append(stdev_data(data[i][j][22], c[j]))
avgs[i]['Phi_d_U'].append(average_data(phid_import_up[conv_id[c[j]]+conv_id[a[i]]][0], c[j]))
avgs[i]['Phi_d_D_series'].append(phid_import_down[conv_id[c[j]]+conv_id[a[i]]])
avgs[i]['Phi_d_U_series'].append(phid_import_up[conv_id[c[j]]+conv_id[a[i]]])
avgs[i]['Phi_d_U_stdev'].append(stdev_data(phid_import_up[conv_id[c[j]]+conv_id[a[i]]][0], c[j]))
avgs[i]['time'].append(data[i][j][0])
avgs[i]['K_p_U_series'].append(K_import_up[conv_id[c[j]]+conv_id[a[i]]])
avgs[i]['K_p_D_series'].append(K_import_down[conv_id[c[j]]+conv_id[a[i]]])
# Import diffusivities
avgs[i]['K_p_U'].append(average_data(K_import_up[conv_id[c[j]]+conv_id[a[i]]][0]))
avgs[i]['K_p_D'].append(average_data(K_import_down[conv_id[c[j]]+conv_id[a[i]]][0]))
avgs[i]['z_mix_U'].append(average_data(z_mix_import_up[conv_id[c[j]]+conv_id[a[i]]][0]))
avgs[i]['z_mix_D'].append(average_data(z_mix_import_down[conv_id[c[j]]+conv_id[a[i]]][0]))
print('Label', 'K_U', 'Phi_U', 'z_mix_U', 'K_D', 'Phi_D', 'z_mix_D')
print(avgs[0]['Phi_d_U'][0], np.mean(json.load(open('phi_d_values_{0}-{1}.txt'.format(160, l)))['F05H05'][0][22:]))
for j in range(len(c)):
for i in range(len(a)):
print('{0}{1} & {2} & {3} & {4} & {5} & {6} & {7}\\\\'.format(a[i], c[j], round(avgs[i]['K_p_U'][j], 3), round(avgs[i]['Phi_d_U'][j]/avgs[0]['Phi_d_U'][0], 3), round(avgs[i]['z_mix_U'][j]/8, 3), round(avgs[i]['K_p_D'][j], 3), round(avgs[i]['Phi_d_D'][j]/avgs[0]['Phi_d_U'][0], 3), round(avgs[i]['z_mix_D'][j]/8, 3)))
c_axis = [0.5, 1.0, 1.5, 2]
colors1 = ['#99c0ff', '#3385ff', '#0047b3', '#000a1a']
def MLD_downstream():
#MLD Downstream
plt.plot(c_axis, np.ones(len(c_axis)), linestyle='dashed', color='black')
for i in range(len(a)):
for j in range(len(c)):
plt.errorbar(c_axis[j], -avgs[i]['MLD'][j]/(H-z0), yerr=avgs[i]['MLD_stdev'][j]/(H-z0), capsize=5, marker=markers2[i][j], linestyle='None', color=colors1[i], label=labels_height[i])
if j == len(c)-1:
plt.plot([], [], marker='o', linestyle='None', color=colors1[i], label=labels_height[i])
plt.xlabel('$U/\\sqrt{{z_0 \\Delta B}}$')
plt.ylabel('(Average Mixed Layer Depth)$/z_0$')
plt.xticks([0.5, 0.75, 1, 1.25, 1.5, 1.75, 2])
plt.ylim(plt.ylim()[::-1])
plt.grid()
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::-1], handles[::-1]))
plt.legend(by_label.values(), by_label.keys())
plt.savefig('MLD_figure.png', dpi=d, bbox_inches='tight')
plt.clf()
def KED_downstream():
#KED Downstream
color_lines = []
marker_lines = []
for i in range(len(a)):
for j in range(len(c)):
plt.plot(c_axis[j], avgs[i]['KED_D'][j]/epsilon_0, marker=markers2[i][j], linestyle='None', color=colors1[i], label=labels_height[i])
#if j == len(c)-1:
# plt.plot([], [], marker='o', linestyle='None', color=colors1[i], label=labels[i])
for i in range(len(a)):
color_lines.append(plt.plot([], [], marker='X', linestyle='None', color=colors1[i], label=labels_height[i]))
plt.plot([], [], marker='o', label=' ', color='white')
for i in range(5):
marker_lines.append(plt.plot([], [], marker=markers_labels_down[i], linestyle='None', color='black', label=labels_regime_down[i]))
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::1], handles[::1]))
plt.legend(by_label.values(), by_label.keys(), fancybox=True, shadow=True, prop={'size': 10}, loc='upper left', ncol=2, handleheight=0.5)
plt.xlabel('Froude Number $Fr$')
plt.ylabel(r'Downstream Dissipation Rate $\langle\overline{{\varepsilon_k}}\rangle_D/\xi$')
plt.ylim(0, plt.ylim()[1])
plt.xticks([0.5, 0.75, 1, 1.25, 1.5, 1.75, 2])
plt.grid()
plt.savefig('KED_Downstream_figure.png', dpi=d, bbox_inches='tight')
plt.clf()
def KED_upstream():
#KED Upstream
color_lines = []
marker_lines = []
for i in range(len(a)):
for j in range(len(c)):
plt.plot(c_axis[j], avgs[i]['KED_U'][j]/epsilon_0, marker=markers1[i][j], linestyle='None', color=colors1[i], label=labels_height[i])
plt.xlabel('Froude Number $Fr$')
plt.ylabel(r'Upstream Dissipation Rate $\langle\overline{{\varepsilon_k}}\rangle_U/\xi$')
plt.xticks([0, 0.5, 1.0, 1.5])
plt.grid()
plt.ylim(0, plt.ylim()[1])
for i in range(len(a)):
color_lines.append(plt.plot([], [], marker='X', linestyle='None', color=colors1[i], label=labels_height[i]))
for i in range(4):
marker_lines.append(plt.plot([], [], marker=markers_labels_up[i], linestyle='None', color='black', label=labels_regime_up[i]))
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::1], handles[::1]))
plt.legend(by_label.values(), by_label.keys(), fancybox=True, shadow=True, prop={'size': 10}, loc='upper left', ncol=2, handleheight=0.5)
plt.savefig('KED_Upstream_figure.png', dpi=d, bbox_inches='tight')
plt.clf()
def phi_d_subplots():
#phi_d Upstream
plt.rcParams.update({'font.size':18})
fig = plt.figure(figsize=(13,5))
a_axis = [0.5, 0.95, 1.2, 2.0] #eta
block_width, block_depth = 0.1, 0.1
phi_0_up = 9e-7
ax = fig.add_subplot(1, 2, 1, projection='3d')
ax.view_init(elev=30, azim=225)
for i in range(len(a)):
for j in range(len(c)):
print(i, j, avgs[i]['Phi_d_U'][j]/avgs[0]['Phi_d_U'][0])
ax.bar3d(x=c_axis[j]-block_width, y=a_axis[i]-block_width, z=block_depth, dx=block_width, dy=block_depth, dz=avgs[i]['Phi_d_U'][j]/avgs[0]['Phi_d_U'][0], color=colors2[markers1[i][j]], edgecolor='k', shade=True)
ax.plot([], [], marker='s', linestyle='None', color=colors2['D'], mec='k', label='Stable Subcritical', ms=11)
ax.plot([], [], marker='s', linestyle='None', color=colors2['o'], mec='k', label='Unstable Subcritical', ms=11)
ax.plot([], [], marker='s', linestyle='None', color=colors2['P'], mec='k', label='Unstable Supercritical', ms=11)
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::-1], handles[::-1]))
ax.legend(by_label.values(), by_label.keys(), loc='upper right', bbox_to_anchor=(1.26,1), prop={'size': 15}, fancybox=True, shadow=True)
ax.xaxis.set_rotate_label(False)
ax.set_xlabel('\n$Fr$', linespacing=3.2)
ax.set_xticks([0.5, 1, 1.5, 2])
ax.yaxis.set_rotate_label(False)
ax.set_ylabel('\n$\\eta$', linespacing=3.2)
ax.set_yticks([0.5, 1, 1.5, 2])
ax.zaxis.set_rotate_label(False)
ax.set_zlim(0, 3)
#ax.set_zticks([0, 0.5, 1.0, 1.5])
#ax.set_zticklabels(['$10^{{{0}}}$'.format(ii) for ii in [0, 0.5, 1.0, 1.5]])
ax.set_zlabel(r'$\dfrac{\overline{\Phi}_U}{\overline{\Phi}_0}$ ')
ax.set_title('(a)', loc='left')
ax = fig.add_subplot(1, 2, 2, projection='3d')
ax.view_init(elev=30, azim=225)
for i in range(len(a)):
for j in range(len(c)):
print('k', avgs[i]['Phi_d_D'][j]/avgs[0]['Phi_d_U'][0])
ax.bar3d(c_axis[j]-block_width, a_axis[i]-block_width, block_depth, block_width, block_depth, avgs[i]['Phi_d_D'][j]/avgs[0]['Phi_d_U'][0], color=colors2[markers2[i][j]], edgecolor='k', shade=True)
ax.plot([], [], marker='s', linestyle='None', color=colors2['p'], mec='k', label='Diffusive BL', ms=11)
ax.plot([], [], marker='s', linestyle='None', color=colors2['s'], mec='k', label='Lee Waves', ms=11)
ax.plot([], [], marker='s', linestyle='None', color=colors2['^'], mec='k', label='Fast-laminar', ms=11)
ax.plot([], [], marker='s', linestyle='None', color=colors2['*'], mec='k', label='Vortex Shedding', ms=11)
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::-1], handles[::-1]))
ax.legend(by_label.values(), by_label.keys(), loc='upper right', bbox_to_anchor=(1.295,1.01), prop={'size': 15}, fancybox=True, shadow=True)
ax.xaxis.set_rotate_label(False)
ax.set_xlabel('\n$Fr$', linespacing=3.2)
ax.set_xticks([0.5, 1, 1.5, 2])
ax.yaxis.set_rotate_label(False)
ax.set_ylabel('\n$\\eta$', linespacing=3.2)
ax.set_yticks([0.5, 1, 1.5, 2])
ax.zaxis.set_rotate_label(False)
ax.set_zlim(0,3)
#ax.set_zticks([0, 0.5, 1.0, 1.5])
#ax.set_zticklabels(['$10^{{{0}}}$'.format(ii) for ii in [0, 0.5, 1.0, 1.5]])
ax.set_zlabel(r'$\dfrac{\overline{\Phi}_D}{\overline{\Phi}_0}$ ')
ax.set_title('(b)', loc='left')
plt.tight_layout()
fig.savefig('phid_subplots_var4.pdf', format='pdf')
plt.clf()
plt.rcParams.update({'font.size':16})
def phi_d_downstream():
#phi_d Downstream
for i in range(len(a)):
for j in range(len(c)):
plt.errorbar(c_axis[j], avgs[i]['Phi_d_D'][j], yerr=avgs[i]['Phi_d_D_stdev'][j]/epsilon_0, capsize=5, linestyle='None', marker=markers2[i][j], color=colors1[i], label=labels_height[i])
if j == len(c)-1:
plt.plot([], [], marker='o', linestyle='None', color=colors1[i], label=labels_height[i])
plt.xlabel('$U/\\sqrt{{z_0 \\Delta B}}$')
plt.ylabel('$\\Phi_d/(\\sqrt{{\\Delta B^3 z_0}})$')
plt.xticks([0.5, 0.75, 1, 1.25, 1.5, 1.75, 2])
plt.grid()
plt.ylim(0, plt.ylim()[1])
plt.title('Downstream')
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::-1], handles[::-1]))
plt.legend(by_label.values(), by_label.keys())
plt.savefig('phid_Downstream_figure.png', dpi=d, bbox_inches='tight')
plt.clf()
def K_p_upstream():
#K_p Upstream
color_lines = []
marker_lines = []
for i in range(len(a)):
for j in range(len(c)):
plt.plot(c_axis[j], avgs[i]['K_p_U'][j]/mu, marker=markers1[i][j], linestyle='None', color=colors1[i], label=labels_height[i], ms=12)
plt.xlabel('Froude Number $Fr$')
plt.ylabel(r'Upstream Diapycnal Diffusivity $K_{{\rho}}^U/\mu$')
plt.xticks([0.5, 0.75, 1, 1.25, 1.5, 1.75, 2])
plt.grid()
plt.yscale('log', nonposy='clip')
plt.ylim(plt.ylim()[0], 1e5)
for i in range(len(a)):
color_lines.append(plt.plot([], [], marker='X', linestyle='None', color=colors1[i], label=labels_height[i]))
for i in range(4):
marker_lines.append(plt.plot([], [], marker=markers_labels_up[i], linestyle='None', color='black', label=labels_regime_up[i]))
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::1], handles[::1]))
plt.legend(by_label.values(), by_label.keys(), fancybox=True, shadow=True, prop={'size': 10}, loc='upper left', ncol=2, handleheight=0.5)
plt.title('(a) Upstream')
plt.gcf().set_size_inches(8,6, forward=True)
plt.savefig('Kp_Upstream_figure.pdf', format='pdf', dpi=d, bbox_inches='tight')
plt.clf()
def K_p_downstream():
color_lines = []
marker_lines = []
#K_p Downstream
for i in range(len(a)):
for j in range(len(c)):
plt.plot(c_axis[j], avgs[i]['K_p_D'][j]/mu, linestyle='None', marker=markers2[i][j], color=colors1[i], label=labels_height[i], ms=12)
plt.xlabel('Froude number $Fr$')
plt.ylabel(r'Downstream Diapycnal Diffusivity $K_{{\rho}}^D/\mu$')
plt.xticks([0.5, 0.75, 1, 1.25, 1.5, 1.75, 2])
plt.grid()
plt.yscale('log')
plt.ylim(plt.ylim()[0], 1e5)
for i in range(len(a)):
color_lines.append(plt.plot([], [], marker='X', linestyle='None', color=colors1[i], label=labels_height[i]))
plt.plot([], [], marker='o', label=' ', color='white')
for i in range(5):
marker_lines.append(plt.plot([], [], marker=markers_labels_down[i], linestyle='None', color='black', label=labels_regime_down[i]))
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::1], handles[::1]))
plt.legend(by_label.values(), by_label.keys(), fancybox=True, shadow=True, prop={'size': 10}, loc='upper left', ncol=2, handleheight=0.5)
plt.title('(b) Downstream')
plt.gcf().set_size_inches(8,6, forward=True)
plt.savefig('Kp_Downstream_figure.pdf', format='pdf', dpi=d, bbox_inches='tight')
plt.clf()
def K_p_upstream_var1():
#K_p Upstream var1: (Fr, eta) space with colormap
a_axis = [0.5, 0.95, 1.2, 2.0]
color_lines = []
marker_lines = []
for i in range(len(a)):
for j in range(len(c)):
plt.scatter(c_axis[j], a_axis[i], c=np.log10(avgs[i]['K_p_D'][j]/mu), s=70, vmin=0, vmax=4, cmap='plasma', marker=markers1[i][j], label=labels_height[i], zorder=10)
plt.xlabel('Froude Number $Fr$')
plt.ylabel('Dimensionless Keel Draught $\\eta$')
plt.xticks([0.5, 0.75, 1, 1.25, 1.5, 1.75, 2])
plt.grid()
for i in range(len(a)):
color_lines.append(plt.plot([], [], marker='X', linestyle='None', color=colors1[i], label=labels_height[i]))
for i in range(4):
marker_lines.append(plt.plot([], [], marker=markers_labels_up[i], linestyle='None', color='black', label=labels_regime_up[i]))
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::1], handles[::1]))
plt.legend(by_label.values(), by_label.keys(), fancybox=True, shadow=True, prop={'size': 10}, loc='upper left', ncol=2, handleheight=0.5)
plt.title('(a) Upstream')
plt.colorbar()
plt.gcf().set_size_inches(8,6, forward=True)
plt.savefig('Kp_Upstream_figure_var1.pdf', format='pdf', dpi=d, bbox_inches='tight')
plt.clf()
def K_p_downstream_var1():
#K_p downstream var1: (Fr, eta) space with colormap
a_axis = [0.5, 0.95, 1.2, 2.0]
color_lines = []
marker_lines = []
for i in range(len(a)):
for j in range(len(c)):
plt.scatter(c_axis[j], a_axis[i], c=np.log10(avgs[i]['K_p_D'][j]/mu), s=70, vmin=0, vmax=4, cmap='plasma', marker=markers2[i][j], label=labels_height[i], zorder=10)
plt.xlabel('Froude Number $Fr$')
plt.ylabel('Dimensionless Keel Draught $\\eta$')
plt.xticks([0.5, 0.75, 1, 1.25, 1.5, 1.75, 2])
plt.grid()
for i in range(len(a)):
color_lines.append(plt.plot([], [], marker='X', linestyle='None', color=colors1[i], label=labels_height[i]))
for i in range(4):
marker_lines.append(plt.plot([], [], marker=markers_labels_up[i], linestyle='None', color='black', label=labels_regime_down[i]))
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::1], handles[::1]))
plt.legend(by_label.values(), by_label.keys(), fancybox=True, shadow=True, prop={'size': 10}, loc='upper left', ncol=2, handleheight=0.5)
plt.title('(a) Downstream')
plt.colorbar()
plt.gcf().set_size_inches(8,6, forward=True)
plt.savefig('Kp_Downstream_figure_var1.pdf', format='pdf', dpi=d, bbox_inches='tight')
plt.clf()
colors2 = {'D': 'darkgreen', '^': '#663300', 's': 'red', 'o': '#ff3399', 'P': 'darkviolet', '*': '#fcb900', 'p': '#0066ff'}
# P: #fcb900
def K_p_upstream_var2():
#K_p Upstream var2: (Fr, eta) space with marker sizes
a_axis = [0.5, 0.95, 1.2, 2.0]
color_lines = []
marker_lines = []
max_up = np.log10(avgs[-1]['K_p_U'][-1]/mu)
for i in range(len(a)):
for j in range(len(c)):
marker_size = np.exp(2.0*np.log10(avgs[i]['K_p_U'][j]/mu)/max_up) * 55
plt.scatter(c_axis[j], a_axis[i], c=np.log10(avgs[i]['K_p_D'][j]/mu), s=marker_size, vmin=0, vmax=4, cmap='plasma', marker=markers1[i][j], label=labels_height[i], zorder=10)
plt.xlabel('Froude Number $Fr$')
plt.ylabel('Dimensionless Keel Draught $\\eta$')
plt.xticks([0.5, 0.75, 1, 1.25, 1.5, 1.75, 2])
plt.grid()
for i in range(len(a)):
color_lines.append(plt.plot([], [], marker='X', linestyle='None', color=colors1[i], label=labels_height[i]))
for i in range(4):
marker_lines.append(plt.plot([], [], marker=markers_labels_up[i], linestyle='None', color='black', label=labels_regime_up[i]))
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::1], handles[::1]))
plt.legend(by_label.values(), by_label.keys(), fancybox=True, shadow=True, prop={'size': 10}, loc='upper left', ncol=2, handleheight=0.5)
plt.title('(a) Upstream')
plt.gcf().set_size_inches(8,6, forward=True)
plt.savefig('Kp_Upstream_figure_var2.pdf', format='pdf', dpi=d, bbox_inches='tight')
plt.clf()
def K_p_downstream_var2():
#K_p downstream var1: (Fr, eta) space with marker sizes
a_axis = [0.5, 0.95, 1.2, 2.0]
color_lines = []
marker_lines = []
max_down = np.log10(avgs[-1]['K_p_D'][-1]/mu)
for i in range(len(a)):
for j in range(len(c)):
marker_size = np.exp(2.0*np.log10(avgs[i]['K_p_U'][j]/mu)/max_down) * 55
plt.scatter(c_axis[j], a_axis[i], c=np.log10(avgs[i]['K_p_D'][j]/mu), s=marker_size, vmin=0, vmax=4, cmap='plasma', marker=markers2[i][j], label=labels_height[i], zorder=10)
plt.xlabel('Froude Number $Fr$')
plt.ylabel('Dimensionless Keel Draught $\\eta$')
plt.xticks([0.5, 0.75, 1, 1.25, 1.5, 1.75, 2])
plt.grid()
for i in range(len(a)):
color_lines.append(plt.plot([], [], marker='X', linestyle='None', color=colors1[i], label=labels_height[i]))
for i in range(4):
marker_lines.append(plt.plot([], [], marker=markers_labels_up[i], linestyle='None', color='black', label=labels_regime_down[i]))
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::1], handles[::1]))
plt.legend(by_label.values(), by_label.keys(), fancybox=True, shadow=True, prop={'size': 10}, loc='upper left', ncol=2, handleheight=0.5)
plt.title('(a) Downstream')
plt.colorbar()
plt.gcf().set_size_inches(8,6, forward=True)
plt.savefig('Kp_Downstream_figure_var2.pdf', format='pdf', dpi=d, bbox_inches='tight')
plt.clf()
def K_p_upstream_var3():
#K_p Upstream var3: Horizontal axis is eta and coloring is Fr
a_axis = [0.5, 0.95, 1.2, 2.0]
color_lines = []
marker_lines = []
for i in range(len(a)):
for j in range(len(c)):
plt.plot(a_axis[i], avgs[i]['K_p_U'][j]/mu, marker=markers1[i][j], linestyle='None', color=colors1[j], label=labels_height_Fr[j], ms=12)
plt.xlabel('Dimensionless Keel Draught $\\eta$')
plt.ylabel(r'Upstream Diapycnal Diffusivity $K_{{\rho}}^U/\mu$')
plt.xticks([0.5, 0.75, 1, 1.25, 1.5, 1.75, 2])
plt.grid()
plt.yscale('log', nonposy='clip')
plt.ylim(plt.ylim()[0], 1e5)
for i in range(len(a)):
color_lines.append(plt.plot([], [], marker='X', linestyle='None', color=colors1[i], label=labels_height_Fr[i]))
for i in range(4):
marker_lines.append(plt.plot([], [], marker=markers_labels_up[i], linestyle='None', color='black', label=labels_regime_up[i]))
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::1], handles[::1]))
plt.legend(by_label.values(), by_label.keys(), fancybox=True, shadow=True, prop={'size': 10}, loc='upper left', ncol=2, handleheight=0.5)
plt.title('(a) Upstream')
plt.gcf().set_size_inches(8,6, forward=True)
plt.savefig('Kp_Upstream_figure_var3.pdf', format='pdf', dpi=d, bbox_inches='tight')
plt.clf()
def K_p_downstream_var3():
#K_p Upstream var3: Horizontal axis is eta and coloring is Fr
a_axis = [0.5, 0.95, 1.2, 2.0]
color_lines = []
marker_lines = []
for i in range(len(a)):
for j in range(len(c)):
plt.plot(a_axis[i], avgs[i]['K_p_D'][j]/mu, marker=markers2[i][j], linestyle='None', color=colors1[j], label=labels_height_Fr[j], ms=12)
plt.xlabel('Dimensionless Keel Draught $\\eta$')
plt.ylabel(r'Upstream Diapycnal Diffusivity $K_{{\rho}}^U/\mu$')
plt.xticks([0.5, 0.75, 1, 1.25, 1.5, 1.75, 2])
plt.grid()
plt.yscale('log', nonposy='clip')
plt.ylim(plt.ylim()[0], 1e5)
for i in range(len(a)):
color_lines.append(plt.plot([], [], marker='X', linestyle='None', color=colors1[i], label=labels_height_Fr[i]))
for i in range(4):
marker_lines.append(plt.plot([], [], marker=markers_labels_down[i], linestyle='None', color='black', label=labels_regime_down[i]))
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::1], handles[::1]))
plt.legend(by_label.values(), by_label.keys(), fancybox=True, shadow=True, prop={'size': 10}, loc='upper left', ncol=2, handleheight=0.5)
plt.title('(a) Downstream')
plt.gcf().set_size_inches(8,6, forward=True)
plt.savefig('Kp_Downstream_figure_var3.pdf', format='pdf', dpi=d, bbox_inches='tight')
plt.clf()
def K_p_upstream_var4():
#K_p upstream var4: (Fr, eta) space with height
fig = plt.figure(figsize=(7, 6))
ax = fig.gca(projection='3d')
ax.view_init(elev=30, azim=225)
a_axis = [0.5, 0.95, 1.2, 2.0] #eta
block_width = 0.1
block_depth = 0.1
for i in range(len(a)):
for j in range(len(c)):
ax.bar3d(c_axis[j]-block_width, a_axis[i]-block_width, 0, block_width, block_depth, np.log10(avgs[i]['K_p_U'][j]/mu), color=colors2[markers1[i][j]], edgecolor='k', shade=True)
plt.plot([], [], marker='s', linestyle='None', color=colors2['D'], mec='k', label='Stable Subcritical')
plt.plot([], [], marker='s', linestyle='None', color=colors2['o'], mec='k', label='Unstable Subcritical')
plt.plot([], [], marker='s', linestyle='None', color=colors2['P'], mec='k', label='Supercritical')
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::-1], handles[::-1]))
plt.legend(by_label.values(), by_label.keys(), loc='upper right', prop={'size': 14}, fancybox=True, shadow=True)
ax.xaxis.set_rotate_label(False)
ax.set_xlabel(' $Fr$')
ax.yaxis.set_rotate_label(False)
ax.set_ylabel('$\\eta$ ')
ax.zaxis.set_rotate_label(False)
ax.set_zlim(0, 5)
ax.set_zticks(range(5))
ax.set_zticklabels([r'$10^{0}$'.format(ii) for ii in range(5)])
ax.set_zlabel(r'$\overline{K}_U$')
fig.savefig('Kp_Upstream_figure_var4.pdf', format='pdf')
plt.clf()
def K_p_downstream_var4():
#K_p downstream var4: (Fr, eta) space with height
fig = plt.figure(figsize=(7, 6))
ax = fig.gca(projection='3d')
ax.view_init(elev=30, azim=225)
a_axis = [0.5, 0.95, 1.2, 2.0] #eta
block_width = 0.1
block_depth = 0.1
for i in range(len(a)):
for j in range(len(c)):
ax.bar3d(c_axis[j]-block_width, a_axis[i]-block_width, 0, block_width, block_depth, np.log10(avgs[i]['K_p_D'][j]/mu), color=colors2[markers2[i][j]], edgecolor='k', shade=True)
plt.plot([], [], marker='s', linestyle='None', color=colors2['s'], mec='k', label='Lee Waves')
plt.plot([], [], marker='s', linestyle='None', color=colors2['^'], mec='k', label='Fast-laminar')
plt.plot([], [], marker='s', linestyle='None', color=colors2['*'], mec='k', label='Vortex Shedding')
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::-1], handles[::-1]))
plt.legend(by_label.values(), by_label.keys(), loc='upper right', prop={'size': 14}, fancybox=True, shadow=True)
ax.xaxis.set_rotate_label(False)
ax.set_xlabel('$ Fr$')
ax.yaxis.set_rotate_label(False)
ax.set_ylabel('$\\eta$ ')
ax.zaxis.set_rotate_label(False)
#ax.set_zlabel(r'$\log (\overline{K}_D / \mu)$ ')
ax.set_zlim(0, 5)
ax.set_zticks(range(5))
ax.set_zticklabels([r'$10^{0}$'.format(ii) for ii in range(5)])
ax.set_zlabel(r'$\overline{K}_D$')
fig.savefig('Kp_Downstream_figure_var4.pdf', format='pdf', bbox_inches='tight')
plt.clf()
def K_p_subplots_4():
#var4, both up and downstream
fig = plt.figure(figsize=(6.5,9.75))
a_axis = [0.5, 0.95, 1.2, 2.0] #eta
block_width, block_depth = 0.1, 0.1
ax = fig.add_subplot(2, 1, 1, projection='3d')
ax.view_init(elev=30, azim=225)
for i in range(len(a)):
for j in range(len(c)):
print(c_axis[j]-block_width, a_axis[i]-block_width, avgs[i]['K_p_U'][j])
ax.bar3d(c_axis[j]-block_width, a_axis[i]-block_width, block_depth, block_width, block_depth, avgs[i]['K_p_U'][j], color=colors2[markers1[i][j]], edgecolor='k', shade=True)
ax.plot([], [], marker='s', linestyle='None', color=colors2['D'], mec='k', label='Stable Subcritical', ms=11)
ax.plot([], [], marker='s', linestyle='None', color=colors2['o'], mec='k', label='Unstable Subcritical', ms=11)
ax.plot([], [], marker='s', linestyle='None', color=colors2['P'], mec='k', label='Unstable Supercritical', ms=11)
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::-1], handles[::-1]))
ax.legend(by_label.values(), by_label.keys(), loc='upper right', bbox_to_anchor=(1.4,1), prop={'size': 15}, fancybox=True, shadow=True)
ax.xaxis.set_rotate_label(False)
ax.set_xlabel('\n$Fr$', linespacing=3.2)
ax.set_xticks([0.5, 1, 1.5, 2])
ax.yaxis.set_rotate_label(False)
ax.set_ylabel('\n$\\eta$', linespacing=3.2)
ax.set_yticks([0.5, 1, 1.5, 2])
ax.zaxis.set_rotate_label(False)
ax.set_zlim(0, 3)
#ax.set_zticks([0, 2.5, 5, 7.5, 10])
#ax.set_zticklabels(['$10^{{{0}}}$'.format(ii) for ii in [0, 2.5, 5, 7.5, 10]])
ax.set_zlabel(r'$\overline{K}_U$ ')
ax.set_title('(a)', loc='left')
ax = fig.add_subplot(2, 1, 2, projection='3d')
ax.view_init(elev=30, azim=225)
for i in range(len(a)):
for j in range(len(c)):
ax.bar3d(c_axis[j]-block_width, a_axis[i]-block_width, block_depth, block_width, block_depth, avgs[i]['K_p_D'][j], color=colors2[markers2[i][j]], edgecolor='k', shade=True)
ax.plot([], [], marker='s', linestyle='None', color=colors2['s'], mec='k', label='Lee Waves', ms=11)
ax.plot([], [], marker='s', linestyle='None', color=colors2['^'], mec='k', label='Fast-laminar', ms=11)
ax.plot([], [], marker='s', linestyle='None', color=colors2['*'], mec='k', label='Vortex Shedding', ms=11)
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::-1], handles[::-1]))
ax.legend(by_label.values(), by_label.keys(), loc='upper right', bbox_to_anchor=(1.22,1), prop={'size': 14}, fancybox=True, shadow=True)
ax.xaxis.set_rotate_label(False)
ax.set_xlabel('\n$Fr$', linespacing=3.2)
ax.set_xticks([0.5, 1, 1.5, 2])
ax.yaxis.set_rotate_label(False)
ax.set_ylabel('\n$\\eta$', linespacing=3.2)
ax.set_yticks([0.5, 1, 1.5, 2])
ax.zaxis.set_rotate_label(False)
ax.set_zlim(0, 3)
#ax.set_zticks([0, 2.5, 5, 7.5, 10])
#ax.set_zticklabels(['$10^{{{0}}}$'.format(ii) for ii in [0, 2.5, 5, 7.5, 10]])
ax.set_zlabel(r'$\overline{K}_D$ ')
ax.set_title('(b)', loc='left')
plt.tight_layout()
fig.savefig('Kp_subplots_var4.pdf', format='pdf', bbox_inches='tight', pad_inches=0.8)
plt.clf()
def K_p_upstream_var5():
#K_p upstream var5: (Fr, eta) space with height and marker for regime
fig = plt.figure(figsize=(7, 6))
ax = fig.gca(projection='3d')
ax.view_init(elev=30, azim=225)
a_axis = [0.5, 0.95, 1.2, 2.0] #eta
for i in range(len(a)):
for j in range(len(c)):
line_y = np.linspace(a_axis[i], 2.25, 50)
line_x = np.full(shape=line_y.shape, fill_value=c_axis[j])
line_z = np.full(shape=line_y.shape, fill_value=np.log10(avgs[i]['K_p_U'][j]/mu))
plt.plot(line_x, line_y, line_z, color='gray', ls='dotted')
markerline, stemlines, baseline = ax.stem([c_axis[j]], [a_axis[i]], [np.log10(avgs[i]['K_p_U'][j]/mu)], linefmt=colors2[markers1[i][j]], markerfmt=markers1[i][j])
markerline.set_markeredgecolor(colors2[markers1[i][j]])
markerline.set_markerfacecolor(colors2[markers1[i][j]])
markerline.set_markersize(10)
plt.plot([], [], marker='D', linestyle='None', color=colors2['D'], label='LBR')
plt.plot([], [], marker='o', linestyle='None', color=colors2['o'], label='Solitary Waves')
plt.plot([], [], marker='P', linestyle='None', color=colors2['P'], label='Supercritical')
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::-1], handles[::-1]))
plt.legend(by_label.values(), by_label.keys(), loc='upper right', prop={'size': 11}, fancybox=True, shadow=True)
ax.set_xlabel('Fr')
ax.set_xlim(0.4, 2.1)
ax.yaxis.set_rotate_label(False)
ax.set_ylabel('$\\eta$')
ax.set_ylim(0.4, 2.1)
ax.zaxis.set_rotate_label(False)
ax.set_zlabel(r'$\log (\overline{K}_U / \mu)$ ')
ax.set_zlim(0, 4.5)
fig.savefig('Kp_Upstream_figure_var5.pdf', format='pdf')
plt.clf()
def K_p_downstream_var5():
#K_p downstream var5: (Fr, eta) space with height and marker for regime
fig = plt.figure(figsize=(7, 6))
ax = fig.gca(projection='3d')
ax.view_init(elev=30, azim=225)
a_axis = [0.5, 0.95, 1.2, 2.0] #eta
for i in range(len(a)):
for j in range(len(c)):
line_y = np.linspace(a_axis[i], 2.25, 50)
line_x = np.full(shape=line_y.shape, fill_value=c_axis[j])
line_z = np.full(shape=line_y.shape, fill_value=np.log10(avgs[i]['K_p_D'][j]/mu))
plt.plot(line_x, line_y, line_z, color='gray', ls='dotted')
markerline, stemlines, baseline = ax.stem([c_axis[j]], [a_axis[i]], [np.log10(avgs[i]['K_p_D'][j]/mu)], linefmt=colors2[markers2[i][j]], markerfmt=markers2[i][j])
markerline.set_markeredgecolor(colors2[markers2[i][j]])
markerline.set_markerfacecolor(colors2[markers2[i][j]])
markerline.set_markersize(10)
plt.plot([], [], marker='s', linestyle='None', color=colors2['s'], label='Lee Waves')
plt.plot([], [], marker='^', linestyle='None', color=colors2['^'], label='Quasi-laminar')
plt.plot([], [], marker='*', linestyle='None', color=colors2['*'], label='Vortex Shedding')
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::-1], handles[::-1]))
plt.legend(by_label.values(), by_label.keys(), loc='upper right', prop={'size': 11}, fancybox=True, shadow=True)
ax.set_xlabel('Fr')
ax.yaxis.set_rotate_label(False)
ax.set_ylabel('$\\eta$')
ax.zaxis.set_rotate_label(False)
ax.set_zlabel(r'$\log (\overline{K}_D / \mu)$ ')
ax.set_zlim(0, 4.5)
fig.savefig('Kp_Downstream_figure_var5.pdf', format='pdf')
plt.clf()
"""
def regime_upstream():
#vortex shedding = star, bore & MSD = circle, blocking = square, bore & TD = triangle, MSD=diamond, lee = plus
#Regime layout upstream
for i in range(len(a)):
for j in range(len(c)):
plt.errorbar(c_axis[j], [0.5, 0.95, 1.2, 2][i], capsize=5, linestyle='None', marker=markers1[i][j], color=colors2[markers1[i][j]])
plt.plot([], [], marker='s', linestyle='None', color=colors2['s'], label='Blocked')
plt.plot([], [], marker='o', linestyle='None', color=colors2['o'], label='Solitary waves')
plt.plot([], [], marker='D', linestyle='None', color=colors2['D'], label='Rarefaction')
plt.plot([], [], marker='d', linestyle='None', color=colors2['d'], label='Supercritical')
plt.xlabel('Froude Number $Fr$')
plt.ylabel('Dimensionless Keel Depth $\\eta$')
plt.xticks([0.5, 1, 1.5, 2])
plt.yticks([0.5, 0.75, 1, 1.25, 1.5, 1.75, 2])
plt.grid()
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::-1], handles[::-1]))
plt.legend(by_label.values(), by_label.keys(), loc='center right', bbox_to_anchor=(0.944, 0.73), prop={'size': 11}, fancybox=True, shadow=True)
plt.savefig('regime_figure_upstream.png', dpi=d, bbox_inches='tight')
plt.clf()
def regime_downstream():
#Regime layout Downstream
for i in range(len(a)):
for j in range(len(c)):
plt.errorbar(c_axis[j], [0.5, 0.95, 1.2, 2][i], capsize=5, linestyle='None', marker=markers2[i][j], color=colors2[markers2[i][j]])
plt.plot([], [], marker='P', linestyle='None', color=colors2['P'], label='Lee waves')
plt.plot([], [], marker='s', linestyle='None', color=colors2['s'], label='Blocking')
plt.plot([], [], marker='p', linestyle='None', color=colors2['p'], label='Stirred')
plt.plot([], [], marker='^', linestyle='None', color=colors2['^'], label='Laminar jump')
plt.plot([], [], marker='*', linestyle='None', color=colors2['*'], label='Vortex shedding')
plt.xlabel('Froude Number $Fr$')
plt.ylabel('Dimensionless Keel Depth $\\eta$')
plt.xticks([0.5, 1, 1.5, 2])
plt.yticks([0.5, 0.75, 1, 1.25, 1.5, 1.75, 2])
plt.grid()
handles, labels_temp = plt.gca().get_legend_handles_labels()
by_label = dict(zip(labels_temp[::-1], handles[::-1]))
plt.legend(by_label.values(), by_label.keys(), loc='center right', bbox_to_anchor=(0.944, 0.73), prop={'size': 11}, fancybox=True, shadow=True)
plt.savefig('regime_figure_downstream.png', dpi=d, bbox_inches='tight')
plt.clf()
"""
def joint_regime():
#Joint regime layout
shift = 0.032
ms = {'o': 17.5, 'D': 15, 'P': 18, 's': 17, '^': 18, '*': 20.5, 'p': 19.5}
plt.figure(figsize=(6,5))
for i in range(len(a)):
for j in range(len(c)):
plt.plot(c_axis[j]-shift, [0.5, 0.95, 1.2, 2][i], markeredgecolor='k', linestyle='None', marker=markers1[i][j], color=colors2[markers1[i][j]], ms=ms[markers1[i][j]], zorder=10)
# line4, = plt.plot([], [], marker='D', linestyle='None', color=colors2['D'], label='LBR', ms=11)
line3, = plt.plot([], [], marker='D', markeredgecolor='k', linestyle='None', color=colors2['D'], label='Stable Subcritical', ms=ms['D'] * 0.75)
line2, = plt.plot([], [], marker='o', markeredgecolor='k', linestyle='None', color=colors2['o'], label='Unstable Subcritical', ms=ms['o'] * 0.75)
line1, = plt.plot([], [], marker='P', markeredgecolor='k', linestyle='None', color=colors2['P'], label='Unstable Supercritical', ms=ms['P'] * 0.75)
for i in range(len(a)):
for j in range(len(c)):
plt.plot(c_axis[j]+shift, [0.5, 0.95, 1.2, 2][i], markeredgecolor='k', linestyle='None', marker=markers2[i][j], color=colors2[markers2[i][j]], ms=ms[markers2[i][j]], zorder=10)
line9, = plt.plot([], [], marker='s', markeredgecolor='k', linestyle='None', color=colors2['s'], label='Lee Waves', ms=ms['s'] * 0.75)
# line8, = plt.plot([], [], marker='s', linestyle='None', color=colors2['s'], label='Blocked', ms=11)
line7, = plt.plot([], [], marker='^', markeredgecolor='k', linestyle='None', color=colors2['^'], label='Fast-Laminar', ms=ms['^'] * 0.75)
# line6, = plt.plot([], [], marker='p', linestyle='None', color=colors2['p'], label='Stirred', ms=11)
line5, = plt.plot([], [], marker='p', markeredgecolor='k', linestyle='None', color=colors2['p'], label='Diffusive BL', ms=ms['p'] * 0.75)
line6, = plt.plot([], [], marker='*', markeredgecolor='k', linestyle='None', color=colors2['*'], label='Vortex Shedding', ms=ms['*'] * 0.75)
first_legend = plt.legend(handles=[line1, line2, line3], loc='lower center', bbox_to_anchor=(0.27, -0.451), prop={'size': 13}, fancybox=True, shadow=True)
plt.gca().add_artist(first_legend)
plt.legend(handles=[line6, line7, line9, line5], loc='lower center', bbox_to_anchor=(0.76, -0.52), prop={'size': 13}, fancybox=True, shadow=True)
plt.xlabel('$Fr$')
plt.ylabel('$\\eta$ ', rotation=False)
plt.xlim(0.3, 2.2)
plt.yticks([0.5, 1.0, 1.5, 2.0])
plt.ylim(0.3, 2.2)
plt.text(0.83, -0.04, 'Upstream', ha='center', va='center')
plt.text(1.75, -0.05, 'Downstream', ha='center', va='center')
plt.grid()
# plt.gcf().set_size_inches(10,6, forward=True)
# plt.gca().set_aspect(1.3)
plt.savefig('regime_layout.pdf', format='pdf', bbox_inches='tight')
plt.clf()
def joint_regime_ms():
#Joint regime layout with ms
shift = 0.032
ms = {'o': 17.5, 'D': 15, 'P': 18, 's': 17, '^': 18, '*': 20.5}
plt.figure(figsize=(6,5))
max_up = np.log10(avgs[-1]['K_p_U'][-1]/mu)
max_down = np.log10(avgs[-1]['K_p_D'][-1]/mu)
for i in range(len(a)):
for j in range(len(c)):
marker_size = np.exp(2.2*np.log10(avgs[i]['K_p_U'][j]/mu)/max_up) * 2
shift = (ms[markers1[i][j]]-13+12*marker_size)/6500
plt.plot(c_axis[j]-shift, [0.5, 0.95, 1.2, 2][i], markeredgecolor='k', linestyle='None', marker=markers1[i][j], color=colors2[markers1[i][j]], ms=ms[markers1[i][j]]-13+marker_size, zorder=10)
# line4, = plt.plot([], [], marker='D', linestyle='None', color=colors2['D'], label='LBR', ms=11)
line3, = plt.plot([], [], marker='D', markeredgecolor='k', linestyle='None', color=colors2['D'], label='Stable Subcritical', ms=ms['D'] * 0.75)
line2, = plt.plot([], [], marker='o', markeredgecolor='k', linestyle='None', color=colors2['o'], label='Unstable Subcritical', ms=ms['o'] * 0.75)
line1, = plt.plot([], [], marker='P', markeredgecolor='k', linestyle='None', color=colors2['P'], label='Unstable Supercritical', ms=ms['P'] * 0.75)
for i in range(len(a)):
for j in range(len(c)):
marker_size = np.exp(2.7*np.log10(avgs[i]['K_p_D'][j]/mu)/max_down) * 1.5
shift = (ms[markers1[i][j]]-13+12*marker_size)/6500
plt.plot(c_axis[j]+shift, [0.5, 0.95, 1.2, 2][i], markeredgecolor='k', linestyle='None', marker=markers2[i][j], color=colors2[markers2[i][j]], ms=ms[markers2[i][j]]-13+marker_size, zorder=10)
line9, = plt.plot([], [], marker='s', markeredgecolor='k', linestyle='None', color=colors2['s'], label='Lee Waves', ms=ms['s'] * 0.75)
# line8, = plt.plot([], [], marker='s', linestyle='None', color=colors2['s'], label='Blocked', ms=11)
line7, = plt.plot([], [], marker='^', markeredgecolor='k', linestyle='None', color=colors2['^'], label='Fast-Laminar', ms=ms['^'] * 0.75)
# line6, = plt.plot([], [], marker='p', linestyle='None', color=colors2['p'], label='Stirred', ms=11)
line5, = plt.plot([], [], marker='*', markeredgecolor='k', linestyle='None', color=colors2['*'], label='Vortex Shedding', ms=ms['*'] * 0.75)
first_legend = plt.legend(handles=[line1, line2, line3], loc='lower center', bbox_to_anchor=(0.21, -0.5), prop={'size': 13}, fancybox=True, shadow=True)
plt.gca().add_artist(first_legend)
plt.legend(handles=[line5, line7, line9], loc='lower center', bbox_to_anchor=(0.7, -0.5), prop={'size': 13}, fancybox=True, shadow=True)
plt.xlabel('Froude Number $Fr$')
plt.ylabel('Dimensionless Keel Draft $\\eta$')
plt.yticks([0.5, 1.0, 1.5, 2.0])
plt.xlim(0.3,2.2)
plt.ylim(0.3,2.2)
plt.text(0.73, -0.13, 'Upstream', ha='center', va='center')
plt.text(1.635, -0.13, 'Downstream', ha='center', va='center')
plt.grid()
plt.savefig('regime_layout_ms.pdf', dpi=d, bbox_inches='tight')
plt.clf()
def Fr(z0, Si, Sf, U):
dB = 9.8*(sw.dens0(Sf, -2) - sw.dens0(Si, -2))/sw.dens0(Si, -2)
return U/np.sqrt(z0*dB)
def eta(z0, h):
return h/z0
def sigma_rho(S, S_sigma): # Error in EOS (found the exact equation for EOS and derived error formula for leading order terms, needs to be checked)
return S_sigma*np.sqrt((0.8)**2+9/4*(0.005)**2*S+4*(0.0004)**2*S**2)
def sigma_Fr(z0, Si, Sf, z0_sigma, Si_sigma, Sf_sigma, U):
rhoi_sigma = sigma_rho(Si, Si_sigma)
rhof_sigma = sigma_rho(Sf, Sf_sigma)
rhoi = ufloat(sw.dens0(Si, -2), rhoi_sigma)
rhof = ufloat(sw.dens0(Sf, -2), rhof_sigma)
z0u = ufloat(z0, z0_sigma)
dB = 9.8*(rhof-rhoi)/rhoi
Fr = U/(z0u*dB)**0.5
return Fr.std_dev
def arctic_plot(h, color1, color2):
# Set salinity and ML depth base values (with uncertainty)
# We organize the data into two categories: summer (denoted with i) and winter (f), each with uncertainties (u)
# Summer corresponds to the July value for the particular region and April for winter
# Salinity values taken from Figure 8 in PFW (visually estimated, somewhat subjective)
S_values = {'Chukchi Sea': {'Si': 29.1, 'Si_u': 1.00, 'Sf': 30.1, 'Sf_u': 0.1},
'Southern Beaufort Sea': {'Si': 28.0, 'Si_u': 3.8, 'Sf': 30.5, 'Sf_u': 2.5},
'Canada Basin': {'Si': 27.2, 'Si_u': 1.8, 'Sf': 30.1, 'Sf_u': 0.1},
'Eurasian Basin': {'Si': 33.4, 'Si_u': 0.8, 'Sf': 33.8, 'Sf_u': 0.7},
'Barents Sea': {'Si': 33.1, 'Si_u': 0.3, 'Sf': 34.5, 'Sf_u': 0.03}}
# MLD values taken from Figure 6 in PFW
# We only consider summer values (since our initial layer in our simulation is the "summer ML")
z0_values = {'Chukchi Sea': {'z0': 12.3, 'z0_u': 4},
'Southern Beaufort Sea': {'z0': 8.5, 'z0_u': 4.5},
'Canada Basin': {'z0': 8.9, 'z0_u': 3.9},
'Eurasian Basin': {'z0': 22.3, 'z0_u': 11.3},
'Barents Sea': {'z0': 17.7, 'z0_u': 12.2}}
# Trends of salinity and MLD in units of [value] per year
# Taken from Figure 14 in PFW
# Salinity trends are taken from the ice-covered (ic) column
S_trends = {'Chukchi Sea': {'Si_t': 0.02, 'Sf_t': -0.07},
'Southern Beaufort Sea': {'Si_t': 0.29, 'Sf_t': -0.04},
'Canada Basin': {'Si_t': -0.11, 'Sf_t': -0.19},
'Eurasian Basin': {'Si_t': -0.05, 'Sf_t': -0.07},
'Barents Sea': {'Si_t': 0.02, 'Sf_t': 0.02,}} # Using summer trend for winter (due to missing trend in PFW)
# MLD trends are taken from the ice-covered (ic) summer column
z0_trends = {'Chukchi Sea': {'z0_t': -0.43}, # Using Winter ic trend (due to missing trend in PFW)
'Southern Beaufort Sea': {'z0_t': 0.33},
'Canada Basin': {'z0_t': -0.33},
'Eurasian Basin': {'z0_t': -0.19},
'Barents Sea': {'z0_t': 0.51}} # Using Summer ice-free trend (due to missing trend in PFW)
# All regions that have a trend not from ice-covered summer are marked with a (*)
labels_region = {'Chukchi Sea': '*1', 'Southern Beaufort Sea': '2', 'Canada Basin': '3', 'Eurasian Basin': '4', 'Barents Sea': '*5'}
regions = S_values.keys()
U = 0.2 # Ice speed (fixed for every region right now)
# Compute (Fr, eta) values for each region
Fr_values = {}
eta_values = {}
for region in regions:
# Compute Fr
Fr_val = Fr(z0_values[region]['z0'], S_values[region]['Si'], S_values[region]['Sf'], U)
Fr_er = sigma_Fr(z0_values[region]['z0'], S_values[region]['Si'], S_values[region]['Sf'], z0_values[region]['z0_u'], S_values[region]['Si_u'], S_values[region]['Sf_u'], U)
Fr_values[region] = (Fr_val, Fr_er) # (Fr, Fr_error)
# Compute eta
eta_val = eta(z0_values[region]['z0'], h=h)
eta_er = eta(z0_values[region]['z0'], h=h)/z0_values[region]['z0']*z0_values[region]['z0_u']
eta_values[region] = (eta_val, eta_er) # (eta, eta_error)
# Compute predicted (Fr, eta) values for each region. Note that the prediction is linear (only a rough first derivative is used)
years = 5 # How many years into the future we predict
U_rate = 1.009 # Ice speed trend (increase of 0.9% per year from Rampal I think?)
Fr_pred_values = {}
eta_pred_values = {}
for region in regions:
# Compute new predicted values with trends
z0_new = z0_values[region]['z0']+years*z0_trends[region]['z0_t']
S_i_new = S_values[region]['Si']+years*S_trends[region]['Si_t']
S_f_new = S_values[region]['Sf']+years*S_trends[region]['Sf_t']
U_new = U*U_rate**years
# Store data
Fr_pred = Fr(z0_new, S_i_new, S_f_new, U_new)
eta_pred = eta(z0_new, h=h)
Fr_pred_values[region] = Fr_pred
eta_pred_values[region] = eta_pred
# Plot the regional markers
k = 0 # Counter for zordering
for region in regions:
# Import values
Fr_value = Fr_values[region][0]
Fr_er = Fr_values[region][1]
eta_value = eta_values[region][0]
eta_er = eta_values[region][1]
Fr_pred_value = Fr_pred_values[region]
eta_pred_value = eta_pred_values[region]
# Plot error boxes
plt.gca().add_patch(patches.FancyBboxPatch(xy=(Fr_value-Fr_er, eta_value-eta_er), width=2*Fr_er, height=2*eta_er, linewidth=1, color=color2, fill='false', mutation_scale=0.05, alpha=0.10))
# Plot predictive arrows
plt.arrow(x=Fr_value, y=eta_value, dx=Fr_pred_value-Fr_value, dy=eta_pred_value-eta_value, linestyle='-', linewidth=2.8, length_includes_head=True, zorder=98+k, head_width=0.03)
# Plot marker boxes
plt.plot(Fr_value, eta_value, marker='s', color=color1, ms=18, zorder=101+k, markeredgecolor='k')
# Plot text in marker boxes
plt.text(Fr_value, eta_value-0.012, labels_region[region], fontsize=15, weight='bold', ha='center', va='center', zorder=101+k)
k += 1
def joint_regime_arctic():
#Joint regime Arctic layout
shift = 0 # offset the marker for each point
max_up = np.log10(avgs[-1]['K_p_U'][-1]/mu) # Scaling for marker size
max_down = np.log10(avgs[-1]['K_p_D'][-1]/mu) # Scaling for marker size
ms = {'o': 17.5, 'D': 15, 'P': 18, 's': 17, '^': 18, '*': 20.5, 'p':17}
# Plot upstream markers
for i in range(len(a)):
for j in range(len(c)):
marker_size = np.exp(1.9*np.log10(avgs[i]['K_p_U'][j]/mu)/max_up) * 4.0 # Chosen through trial and error (feel free to change)
shift = (ms[markers1[i][j]]-13+12*marker_size)/6500
plt.plot(c_axis[j]-shift, [0.5, 0.95, 1.2, 2][i], markeredgecolor='k', linestyle='None', marker=markers1[i][j], color=colors2[markers1[i][j]], ms=ms[markers1[i][j]]-13+marker_size, zorder=10)
line2, = plt.plot([], [], marker='o', markeredgecolor='k', linestyle='None', color=colors2['o'], label='Unstable Subcritical', ms=ms['o'] * 0.75)
line3, = plt.plot([], [], marker='D', markeredgecolor='k', linestyle='None', color=colors2['D'], label='Stable Subcritical', ms=ms['D'] * 0.75)
line1, = plt.plot([], [], marker='P', markeredgecolor='k', linestyle='None', color=colors2['P'], label='Unstable Supercritical', ms=ms['P'] * 0.75)
# Plot downstream markers
for i in range(len(a)):
for j in range(len(c)):
marker_size = np.exp(1.9*np.log10(avgs[i]['K_p_D'][j]/mu)/max_down) * 4.0 # Chosen through trial and error (feel free to change)
shift = (ms[markers1[i][j]]-13+12*marker_size)/6500
plt.plot(c_axis[j]+shift, [0.5, 0.95, 1.2, 2][i], markeredgecolor='k', linestyle='None', marker=markers2[i][j], color=colors2[markers2[i][j]], ms=ms[markers2[i][j]]-13+marker_size, zorder=10)
line9, = plt.plot([], [], marker='s', markeredgecolor='k', linestyle='None', color=colors2['s'], label='Lee Waves', ms=ms['s'] * 0.75)
line7, = plt.plot([], [], marker='^', markeredgecolor='k', linestyle='None', color=colors2['^'], label='Fast-Laminar', ms=ms['^'] * 0.75)
line5, = plt.plot([], [], marker='*', markeredgecolor='k', linestyle='None', color=colors2['*'], label='Vortex Shedding', ms=ms['*'] * 0.75)
# Plot legends
first_legend = plt.legend(handles=[line1, line2, line3], loc='lower center', bbox_to_anchor=(0.26, -0.37), prop={'size': 13}, fancybox=True, shadow=True)
plt.gca().add_artist(first_legend)
plt.legend(handles=[line5, line7, line9], loc='lower center', bbox_to_anchor=(0.75, -0.37), prop={'size': 13}, fancybox=True, shadow=True)
# Other plot details
plt.xlim(0,2.2)
plt.ylim(0,2.7)
plt.xlabel('Froude Number $Fr$')
plt.ylabel('Dimensionless Keel Draft $\\eta$ ')
plt.xticks([0.5, 1, 1.5, 2])
plt.yticks([0.5, 1, 1.5, 2, 2.5])
plt.text(0.58, -0.39, 'Upstream', ha='center', va='center')
plt.text(1.66, -0.39, 'Downstream', ha='center', va='center')
plt.grid(zorder=0)
# Add Arctic region markers (the most importnat part)
arctic_plot(h=7.45, color1='#b30000', color2='#b30000')
arctic_plot(h=7.45*2.5, color1='blue', color2='blue')
#Arctic stuff
# Winter data is March data, likewise summer is July. All std and averages are taken from these two months
# ML depth is ice covered July data
# Winter ML salinity is April ice covered data
# Summer ML salinity is July ice covered data
# We reject Makaraov data as PFW did
plt.gcf().set_size_inches(8,6, forward=True)
plt.savefig('regime_layout_regional.pdf', format='pdf', bbox_inches='tight')
plt.clf()
#Heat maps
xbasis = de.Fourier('x', 1280, interval=(0, 640))
zbasis = de.Fourier('z', 640, interval=(0, 80))
domain = de.Domain([xbasis, zbasis], grid_dtype=np.float64)
class CyclicNormalize(colors.Normalize):
def __init__(self, cmin=0, cmax=1, vmin=0, vmax=1, clip=False):
self.cmin = cmin
self.cmax = cmax
colors.Normalize.__init__(self, vmin, vmax, clip=clip)
def __call__(self, value, clip=False):
x, y = [self.cmin, self.cmax], [0, 1]
return np.ma.masked_array(np.interp(value, x, y, period=self.cmax - self.cmin))
def methods():
with h5py.File('regime_files/data-mixingsim-Test-00_s1.h5', mode='r') as f:
rho = f['tasks']['rho'][0]
fig_j, ax_j = plt.subplots(figsize=(12,12))